Commit 08da552f by Antonio Rueda

Actualizado testing mediante base de datos para testing.

parents bea00abe 9ef7b48f
......@@ -16,10 +16,17 @@ Después arranca el contenedor, define _secret_ como clave de root y
asocia MySQL al puerto de la máquina anfitrión 33060.
```
docker exec mysql-db mysql -psecret -e create database ujacoin; use ujacoin; create user 'ujacoin' identified by 'secret'; grant all privileges on ujacoin.* to 'ujacoin'@'%'"
docker exec mysql-db mysql -psecret -e "create database ujacoin; use ujacoin; create user 'ujacoin' identified by 'secret'; grant all privileges on ujacoin.* to 'ujacoin'@'%'"
```
Este comando ejecuta la utilidad de administración `mysql` dentro del contenedor,
crea la base de datos *ujacoin*, un usuario con el mismo nombre y clave _secret_
y finalmente le otorga los permisos necesarios para trabajar con la base
de datos.
Para el testing, crear una nueva base de datos ujacoin_test y dar permisos al usuario creado anteriormente.
```
docker exec mysql-db mysql -psecret -e "create database ujacoin_test; use ujacon_test; grant all privileges on ujacoin_test.* to 'ujacoin'@'%'"
```
......@@ -45,6 +45,12 @@
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
......
## Fichero de configuración para UjaCoin durante testing
# spring.datasource.url: jdbc:mysql://localhost:33060/ujacoin_test
spring.datasource.url: jdbc:h2:mem:ujacoin_test;MODE=MYSQL;DATABASE_TO_LOWER=TRUE;DB_CLOSE_DELAY=-1
spring.jpa.properties.javax.persistence.schema-generation.database.action: drop-and-create
## YAML Template.
## Fichero de configuración para UjaCoin
spring.datasource.url: jdbc:mysql://localhost:33060/ujacoin
spring.datasource.username: ujacoin
......
......@@ -9,12 +9,10 @@ import es.ujaen.dae.ujacoin.controladoresREST.DTO.DTOCliente;
import es.ujaen.dae.ujacoin.controladoresREST.DTO.DTOCuenta;
import es.ujaen.dae.ujacoin.controladoresREST.DTO.DTOMovimiento;
import es.ujaen.dae.ujacoin.controladoresREST.DTO.DTOTarjeta;
import es.ujaen.dae.ujacoin.servicios.ServicioLimpiadoBaseDatos;
import java.time.LocalDate;
import java.util.List;
import javax.annotation.PostConstruct;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
......@@ -24,6 +22,8 @@ import org.springframework.boot.web.server.LocalServerPort;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ActiveProfiles;
/**
* Test para controlador REST de clientes
......@@ -31,27 +31,27 @@ import org.springframework.http.converter.json.MappingJackson2HttpMessageConvert
* @author ajrueda
*/
@SpringBootTest(classes = es.ujaen.dae.ujacoin.app.UjaCoinApp.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@ActiveProfiles(profiles = {"test"})
public class ControladorRESTTest {
@Autowired
ServicioLimpiadoBaseDatos limpiadorBaseDatos;
@LocalServerPort
int localPort;
@Autowired
MappingJackson2HttpMessageConverter springBootJacksonConverter;
RestTemplateBuilder restTemplateBuilder;
TestRestTemplate restTemplate;
/**
* Crear un TestRestTemplate para las pruebas
*/
@PostConstruct
void crearRestTemplateBuilder() {
restTemplateBuilder = new RestTemplateBuilder()
RestTemplateBuilder restTemplateBuilder = new RestTemplateBuilder()
.rootUri("http://localhost:" + localPort + "/ujacoin")
.additionalMessageConverters(List.of(springBootJacksonConverter));
restTemplate = new TestRestTemplate(restTemplateBuilder);
}
/**
......@@ -69,7 +69,6 @@ public class ControladorRESTTest {
"jeegmail.com",
"clave");
TestRestTemplate restTemplate = new TestRestTemplate(restTemplateBuilder);
ResponseEntity<DTOCuenta> respuesta = restTemplate.postForEntity(
"/clientes",
cliente,
......@@ -83,6 +82,7 @@ public class ControladorRESTTest {
* test de alta y login de cliente
*/
@Test
@DirtiesContext(methodMode = DirtiesContext.MethodMode.AFTER_METHOD)
public void testAltaYAccesoDatosCliente() {
DTOCliente cliente = new DTOCliente(
"11995667D",
......@@ -93,7 +93,6 @@ public class ControladorRESTTest {
"jee@gmail.com",
"clave");
TestRestTemplate restTemplate = new TestRestTemplate(restTemplateBuilder);
ResponseEntity<DTOCuenta> respuestaAlta = restTemplate.postForEntity(
"/clientes",
cliente,
......@@ -102,9 +101,8 @@ public class ControladorRESTTest {
Assertions.assertThat(respuestaAlta.getStatusCode()).isEqualTo(HttpStatus.CREATED);
TestRestTemplate restTemplateAutenticado = new TestRestTemplate(restTemplateBuilder.basicAuthentication(cliente.getDni(), cliente.getClave()));
ResponseEntity<DTOCliente> respuestaLogin = restTemplateAutenticado
ResponseEntity<DTOCliente> respuestaLogin = restTemplate
.withBasicAuth(cliente.getDni(), cliente.getClave())
.getForEntity(
"/clientes/{dni}",
DTOCliente.class,
......@@ -121,6 +119,7 @@ public class ControladorRESTTest {
* test de alta e intento de acceso a datos de otro cliente
*/
@Test
@DirtiesContext(methodMode = DirtiesContext.MethodMode.AFTER_METHOD)
public void testAltaYAccesoDatosClienteDiferente() {
DTOCliente cliente = new DTOCliente(
"11995667D",
......@@ -131,7 +130,6 @@ public class ControladorRESTTest {
"jee@gmail.com",
"clave");
TestRestTemplate restTemplate = new TestRestTemplate(restTemplateBuilder);
restTemplate.postForEntity(
"/clientes",
cliente,
......@@ -155,10 +153,9 @@ public class ControladorRESTTest {
DTOCuenta.class
).getBody();
TestRestTemplate restTemplateAutenticado = new TestRestTemplate(restTemplateBuilder.basicAuthentication(cliente.getDni(), cliente.getClave()));
// Acceso con credenciales del primer cliente a la información del segundo
ResponseEntity<DTOCliente> respuestaLogin = restTemplateAutenticado
ResponseEntity<DTOCliente> respuestaLogin = restTemplate
.withBasicAuth(cliente.getDni(), cliente.getClave())
.getForEntity(
"/clientes/{dni}",
DTOCliente.class,
......@@ -172,6 +169,7 @@ public class ControladorRESTTest {
* Creación de cuenta adicional
*/
@Test
@DirtiesContext(methodMode = DirtiesContext.MethodMode.AFTER_METHOD)
public void testCuentaAdicional() {
DTOCliente cliente = new DTOCliente(
"11995667D",
......@@ -182,15 +180,14 @@ public class ControladorRESTTest {
"jee@gmail.com",
"clave");
TestRestTemplate restTemplate = new TestRestTemplate(restTemplateBuilder);
restTemplate.postForEntity(
"/clientes",
cliente,
DTOCuenta.class
);
TestRestTemplate restTemplateAutenticado = new TestRestTemplate(restTemplateBuilder.basicAuthentication(cliente.getDni(), cliente.getClave()));
ResponseEntity<DTOCuenta> respuesta = restTemplateAutenticado
ResponseEntity<DTOCuenta> respuesta = restTemplate
.withBasicAuth(cliente.getDni(), cliente.getClave())
.postForEntity(
"/clientes/{dni}/cuentas",
null,
......@@ -200,7 +197,8 @@ public class ControladorRESTTest {
Assertions.assertThat(respuesta.getStatusCode()).isEqualTo(HttpStatus.CREATED);
DTOCuenta[] cuentas = restTemplateAutenticado
DTOCuenta[] cuentas = restTemplate
.withBasicAuth(cliente.getDni(), cliente.getClave())
.getForEntity(
"/clientes/{dni}/cuentas",
DTOCuenta[].class,
......@@ -215,6 +213,7 @@ public class ControladorRESTTest {
* Test de creación de tarjeta
*/
@Test
@DirtiesContext(methodMode = DirtiesContext.MethodMode.AFTER_METHOD)
public void testAnadirTarjetaACliente() {
// Registrar cliente
DTOCliente cliente = new DTOCliente(
......@@ -226,13 +225,12 @@ public class ControladorRESTTest {
"jee@gmail.com",
"clave");
TestRestTemplate restTemplate = new TestRestTemplate(restTemplateBuilder);
restTemplate.postForEntity("/clientes", cliente, DTOCuenta.class);
DTOTarjeta tarjeta = new DTOTarjeta("4111111111111111", cliente.getNombre(), LocalDate.of(2022, 12, 1), "365");
TestRestTemplate restTemplateAutenticado = new TestRestTemplate(restTemplateBuilder.basicAuthentication(cliente.getDni(), cliente.getClave()));
ResponseEntity<DTOTarjeta> respuesta = restTemplateAutenticado
ResponseEntity<DTOTarjeta> respuesta = restTemplate
.withBasicAuth(cliente.getDni(), cliente.getClave())
.postForEntity(
"/clientes/{dni}/tarjetas",
tarjeta,
......@@ -242,7 +240,8 @@ public class ControladorRESTTest {
Assertions.assertThat(respuesta.getStatusCode()).isEqualTo(HttpStatus.CREATED);
respuesta = restTemplateAutenticado
respuesta = restTemplate
.withBasicAuth(cliente.getDni(), cliente.getClave())
.getForEntity(
"/clientes/{dni}/tarjetas/{num}",
DTOTarjeta.class,
......@@ -263,6 +262,7 @@ public class ControladorRESTTest {
* Test de ingreso en cuenta
*/
@Test
@DirtiesContext(methodMode = DirtiesContext.MethodMode.AFTER_METHOD)
public void testIngreso() {
// Registrar cliente
DTOCliente cliente = new DTOCliente(
......@@ -275,7 +275,6 @@ public class ControladorRESTTest {
"clave"
);
TestRestTemplate restTemplate = new TestRestTemplate(restTemplateBuilder);
DTOCuenta cuenta = restTemplate.postForEntity(
"/clientes",
cliente,
......@@ -289,8 +288,8 @@ public class ControladorRESTTest {
"365"
);
TestRestTemplate restTemplateAutenticado = new TestRestTemplate(restTemplateBuilder.basicAuthentication(cliente.getDni(), cliente.getClave()));
restTemplateAutenticado
restTemplate
.withBasicAuth(cliente.getDni(), cliente.getClave())
.postForEntity(
"/clientes/{dni}/tarjetas",
tarjeta,
......@@ -300,7 +299,8 @@ public class ControladorRESTTest {
// Realizar ingreso y comprobar estado de la cuenta
DTOMovimiento ingreso = DTOMovimiento.ingreso(tarjeta.getNum(), 1000);
ResponseEntity<Void> respuestaRegistroMovimiento = restTemplateAutenticado
ResponseEntity<Void> respuestaRegistroMovimiento = restTemplate
.withBasicAuth(cliente.getDni(), cliente.getClave())
.postForEntity(
"/clientes/{dni}/cuentas/{num}/movimientos",
ingreso,
......@@ -311,14 +311,16 @@ public class ControladorRESTTest {
Assertions.assertThat(respuestaRegistroMovimiento.getStatusCode()).isEqualTo(HttpStatus.CREATED);
// Refrescar estado de la cuenta y comprobar saldo
cuenta = restTemplateAutenticado
cuenta = restTemplate
.withBasicAuth(cliente.getDni(), cliente.getClave())
.getForObject("/clientes/{dni}/cuentas/{num}",
DTOCuenta.class,
cliente.getDni(), cuenta.getNum());
Assertions.assertThat(cuenta.getSaldo()).isEqualTo(1000);
ResponseEntity<DTOMovimiento[]> respuestaListadoMovimientos = restTemplateAutenticado
ResponseEntity<DTOMovimiento[]> respuestaListadoMovimientos = restTemplate
.withBasicAuth(cliente.getDni(), cliente.getClave())
.getForEntity(
"/clientes/{dni}/cuentas/{num}/movimientos",
DTOMovimiento[].class,
......@@ -336,6 +338,7 @@ public class ControladorRESTTest {
* Test de transferencia entre cuentas
*/
@Test
@DirtiesContext(methodMode = DirtiesContext.MethodMode.AFTER_METHOD)
public void testTransferencia() {
// Registrar cliente
DTOCliente cliente = new DTOCliente(
......@@ -348,7 +351,6 @@ public class ControladorRESTTest {
"clave"
);
TestRestTemplate restTemplate = new TestRestTemplate(restTemplateBuilder);
DTOCuenta cuentaOrigen = restTemplate.postForEntity(
"/clientes",
cliente,
......@@ -362,8 +364,9 @@ public class ControladorRESTTest {
"365"
);
TestRestTemplate restTemplateAutenticado1 = new TestRestTemplate(restTemplateBuilder.basicAuthentication(cliente.getDni(), cliente.getClave()));
restTemplateAutenticado1.postForEntity(
restTemplate
.withBasicAuth(cliente.getDni(), cliente.getClave())
.postForEntity(
"/clientes/{dni}/tarjetas",
tarjeta,
DTOTarjeta.class,
......@@ -372,7 +375,9 @@ public class ControladorRESTTest {
// Realizar ingreso y comprobar estado de la cuenta
DTOMovimiento ingreso = DTOMovimiento.ingreso(tarjeta.getNum(), 1000);
restTemplateAutenticado1.postForEntity(
restTemplate
.withBasicAuth(cliente.getDni(), cliente.getClave())
.postForEntity(
"/clientes/{dni}/cuentas/{num}/movimientos",
ingreso,
Void.class,
......@@ -398,7 +403,9 @@ public class ControladorRESTTest {
// Realizar transferencia
DTOMovimiento transferencia = DTOMovimiento.transferencia(cuentaDestino.getNum(), 500);
restTemplateAutenticado1.postForEntity(
restTemplate
.withBasicAuth(cliente.getDni(), cliente.getClave())
.postForEntity(
"/clientes/{dni}/cuentas/{num}/movimientos",
transferencia,
Void.class,
......@@ -407,19 +414,24 @@ public class ControladorRESTTest {
// Refrescar cuenta origen y destino
// Refrescar estados de la cuentas y comprobar saldos
cuentaOrigen = restTemplateAutenticado1.getForObject("/clientes/{dni}/cuentas/{num}",
cuentaOrigen = restTemplate
.withBasicAuth(cliente.getDni(), cliente.getClave())
.getForObject("/clientes/{dni}/cuentas/{num}",
DTOCuenta.class,
cliente.getDni(), cuentaOrigen.getNum());
Assertions.assertThat(cuentaOrigen.getSaldo()).isEqualTo(500);
TestRestTemplate restTemplateAutenticado2 = new TestRestTemplate(restTemplateBuilder.basicAuthentication(cliente2.getDni(), cliente2.getClave()));
cuentaDestino = restTemplateAutenticado2.getForObject("/clientes/{dni}/cuentas/{num}",
cuentaDestino = restTemplate
.withBasicAuth(cliente2.getDni(), cliente2.getClave())
.getForObject("/clientes/{dni}/cuentas/{num}",
DTOCuenta.class,
cliente2.getDni(), cuentaDestino.getNum());
Assertions.assertThat(cuentaDestino.getSaldo()).isEqualTo(500);
// Listar movimientos de la cuenta origen
DTOMovimiento[] movimientos = restTemplateAutenticado1.getForEntity(
DTOMovimiento[] movimientos = restTemplate
.withBasicAuth(cliente.getDni(), cliente.getClave())
.getForEntity(
"/clientes/{dni}/cuentas/{num}/movimientos",
DTOMovimiento[].class,
cliente.getDni(), cuentaOrigen.getNum()
......@@ -429,7 +441,9 @@ public class ControladorRESTTest {
Assertions.assertThat(movimientos[1].getTipo()).isEqualTo(DTOMovimiento.TRANSFERENCIA_EMITIDA);
// Listar movimientos de la cuenta destino
movimientos = restTemplateAutenticado2.getForEntity(
movimientos = restTemplate
.withBasicAuth(cliente2.getDni(), cliente2.getClave())
.getForEntity(
"/clientes/{dni}/cuentas/{num}/movimientos",
DTOMovimiento[].class,
cliente2.getDni(), cuentaDestino.getNum()
......@@ -443,6 +457,7 @@ public class ControladorRESTTest {
* Reintegro sin saldo suficiente
*/
@Test
@DirtiesContext(methodMode = DirtiesContext.MethodMode.AFTER_METHOD)
public void testReintegroSinSaldo() {
// Registrar cliente
DTOCliente cliente = new DTOCliente(
......@@ -455,7 +470,6 @@ public class ControladorRESTTest {
"clave"
);
TestRestTemplate restTemplate = new TestRestTemplate(restTemplateBuilder);
DTOCuenta cuenta = restTemplate.postForEntity(
"/clientes",
cliente,
......@@ -469,8 +483,9 @@ public class ControladorRESTTest {
"365"
);
TestRestTemplate restTemplateAutenticado = new TestRestTemplate(restTemplateBuilder.basicAuthentication(cliente.getDni(), cliente.getClave()));
restTemplateAutenticado.postForEntity(
restTemplate
.withBasicAuth(cliente.getDni(), cliente.getClave())
.postForEntity(
"/clientes/{dni}/tarjetas",
tarjeta,
DTOTarjeta.class,
......@@ -479,7 +494,9 @@ public class ControladorRESTTest {
// Realizar ingreso en cuenta
DTOMovimiento ingreso = DTOMovimiento.ingreso(tarjeta.getNum(), 1000);
restTemplateAutenticado.postForEntity(
restTemplate
.withBasicAuth(cliente.getDni(), cliente.getClave())
.postForEntity(
"/clientes/{dni}/cuentas/{num}/movimientos",
ingreso,
Void.class,
......@@ -488,7 +505,9 @@ public class ControladorRESTTest {
// Primer reintegro correcto
DTOMovimiento reintegro = DTOMovimiento.reintegro(tarjeta.getNum(), 1000);
ResponseEntity<Void> respuesta = restTemplateAutenticado.postForEntity(
ResponseEntity<Void> respuesta = restTemplate
.withBasicAuth(cliente.getDni(), cliente.getClave())
.postForEntity(
"/clientes/{dni}/cuentas/{num}/movimientos",
reintegro,
Void.class,
......@@ -498,7 +517,9 @@ public class ControladorRESTTest {
Assertions.assertThat(respuesta.getStatusCode()).isEqualTo(HttpStatus.CREATED);
// No hay saldo suficiente para el segundo reintegro
respuesta = restTemplateAutenticado.postForEntity(
respuesta = restTemplate
.withBasicAuth(cliente.getDni(), cliente.getClave())
.postForEntity(
"/clientes/{dni}/cuentas/{num}/movimientos",
reintegro,
Void.class,
......@@ -512,6 +533,7 @@ public class ControladorRESTTest {
* Test de listado de movimientos con paginación
*/
@Test
@DirtiesContext(methodMode = DirtiesContext.MethodMode.AFTER_METHOD)
public void testListadoMovimientosPaginado() {
// Registrar cliente
DTOCliente cliente = new DTOCliente(
......@@ -524,7 +546,6 @@ public class ControladorRESTTest {
"clave"
);
TestRestTemplate restTemplate = new TestRestTemplate(restTemplateBuilder);
DTOCuenta cuenta = restTemplate.postForEntity(
"/clientes",
cliente,
......@@ -538,8 +559,9 @@ public class ControladorRESTTest {
"365"
);
TestRestTemplate restTemplateAutenticado = new TestRestTemplate(restTemplateBuilder.basicAuthentication(cliente.getDni(), cliente.getClave()));
restTemplateAutenticado.postForEntity(
restTemplate
.withBasicAuth(cliente.getDni(), cliente.getClave())
.postForEntity(
"/clientes/{dni}/tarjetas",
tarjeta,
DTOTarjeta.class,
......@@ -552,7 +574,9 @@ public class ControladorRESTTest {
float[] importeIngresos = {10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120};
for (float importe : importeIngresos) {
restTemplateAutenticado.postForEntity(
restTemplate
.withBasicAuth(cliente.getDni(), cliente.getClave())
.postForEntity(
"/clientes/{dni}/cuentas/{num}/movimientos",
DTOMovimiento.ingreso(tarjeta.getNum(), importe),
Void.class,
......@@ -561,7 +585,9 @@ public class ControladorRESTTest {
}
// Obtener primera página (10 elementos)
ResponseEntity<DTOMovimiento[]> respuesta1 = restTemplateAutenticado.getForEntity(
ResponseEntity<DTOMovimiento[]> respuesta1 = restTemplate
.withBasicAuth(cliente.getDni(), cliente.getClave())
.getForEntity(
"/clientes/{dni}/cuentas/{num}/movimientos",
DTOMovimiento[].class,
cliente.getDni(), cuenta.getNum()
......@@ -573,7 +599,9 @@ public class ControladorRESTTest {
Assertions.assertThat(movimientos[0].getImporte()).isEqualTo(10);
// Obtener segunda página (2 selementos)
ResponseEntity<DTOMovimiento[]> respuesta2 = restTemplateAutenticado.getForEntity(
ResponseEntity<DTOMovimiento[]> respuesta2 = restTemplate
.withBasicAuth(cliente.getDni(), cliente.getClave())
.getForEntity(
"/clientes/{dni}/cuentas/{num}/movimientos?pag=2",
DTOMovimiento[].class,
cliente.getDni(), cuenta.getNum()
......@@ -585,7 +613,9 @@ public class ControladorRESTTest {
Assertions.assertThat(movimientos[0].getImporte()).isEqualTo(110);
// Obtener primera página con 5 elementos solo
ResponseEntity<DTOMovimiento[]> respuesta3 = restTemplateAutenticado.getForEntity(
ResponseEntity<DTOMovimiento[]> respuesta3 = restTemplate
.withBasicAuth(cliente.getDni(), cliente.getClave())
.getForEntity(
"/clientes/{dni}/cuentas/{num}/movimientos?pag=1&num=5",
DTOMovimiento[].class,
cliente.getDni(), cuenta.getNum()
......@@ -596,9 +626,4 @@ public class ControladorRESTTest {
Assertions.assertThat(movimientos).hasSize(5);
Assertions.assertThat(movimientos[0].getImporte()).isEqualTo(10);
}
@BeforeEach
void limpiarBaseDatos() {
limpiadorBaseDatos.limpiar();
}
}
package es.ujaen.dae.ujacoin.servicios;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.support.TransactionTemplate;
/**
* Servicio auxiliar de borrado de los datos en la base de datos (sólo para testing)
* @author ajrueda
*/
@Service
public class ServicioLimpiadoBaseDatos {
@PersistenceContext
EntityManager em;
@Autowired
TransactionTemplate transactionTemplate;
/**
* Lista de entidades a borrar. Ojo: el orden es muy importante
* para evitar errores de violación de integridad
*/
final String[] entidades = {
"Movimiento",
"Cuenta",
"Tarjeta",
"Cliente"
};
final String deleteFrom = "delete from ";
/** Realizar borrado */
public void limpiar() {
transactionTemplate.executeWithoutResult(transactionStatus -> {
for (String tabla : entidades) {
em.createQuery(deleteFrom + tabla).executeUpdate();
}
});
}
}
......@@ -18,10 +18,12 @@ import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import javax.validation.ConstraintViolationException;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.annotation.DirtiesContext.MethodMode;
import org.springframework.test.context.ActiveProfiles;
/**
* Test de integración de la aplicación
......@@ -29,14 +31,12 @@ import org.springframework.boot.test.context.SpringBootTest;
*/
// @Disabled
@SpringBootTest(classes = es.ujaen.dae.ujacoin.app.UjaCoinApp.class)
@ActiveProfiles(profiles = {"test"})
public class ServicioUjaCoinTest {
@Autowired
ServicioUjaCoin servicioUjaCoin;
@Autowired
ServicioLimpiadoBaseDatos limpiadorBaseDatos;
@Test
public void testAccesoServicioUjaCoin() {
Assertions.assertThat(servicioUjaCoin).isNotNull();
......@@ -60,6 +60,7 @@ public class ServicioUjaCoinTest {
}
@Test
@DirtiesContext(methodMode = MethodMode.AFTER_METHOD)
public void testAltaYLoginClienteCuenta() {
Cliente cliente = new Cliente(
"11995667D",
......@@ -79,6 +80,7 @@ public class ServicioUjaCoinTest {
}
@Test
@DirtiesContext(methodMode = MethodMode.AFTER_METHOD)
public void testCreacionCuentaAdicional() {
Cliente cliente = new Cliente(
"11995667D",
......@@ -101,6 +103,7 @@ public class ServicioUjaCoinTest {
}
@Test
@DirtiesContext(methodMode = MethodMode.AFTER_METHOD)
public void testAnadirTarjetaACliente() {
// Registrar cliente y realizar login
Cliente cliente = new Cliente(
......@@ -124,6 +127,7 @@ public class ServicioUjaCoinTest {
}
@Test
@DirtiesContext(methodMode = MethodMode.AFTER_METHOD)
public void testIngreso() {
// Registrar cliente y realizar login
Cliente cliente = new Cliente(
......@@ -157,6 +161,7 @@ public class ServicioUjaCoinTest {
}
@Test
@DirtiesContext(methodMode = MethodMode.AFTER_METHOD)
public void testTransferencia() {
// Registrar cliente
Cliente cliente = new Cliente(
......@@ -212,6 +217,7 @@ public class ServicioUjaCoinTest {
}
@Test
@DirtiesContext(methodMode = MethodMode.AFTER_METHOD)
public void testReintegroDoble() {
// Registrar cliente
Cliente cliente = new Cliente(
......@@ -240,6 +246,7 @@ public class ServicioUjaCoinTest {
}
@Test
@DirtiesContext(methodMode = MethodMode.AFTER_METHOD)
public void testReintegroDobleParalelo() {
// Registrar cliente
Cliente cliente = new Cliente(
......@@ -287,9 +294,4 @@ public class ServicioUjaCoinTest {
}
}).isInstanceOfAny(SaldoInsuficienteParaOperacion.class);
}
@BeforeEach
void limpiarBaseDatos() {
limpiadorBaseDatos.limpiar();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment