Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Antonio Rueda
/
UJACoin
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
2d303701
authored
Oct 23, 2021
by
Antonio Rueda
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Cambio testing JPA usando base de datos para testing con drop-and-create
parent
ea948d43
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
19 additions
and
54 deletions
src/main/resources/application-test.yml
src/main/resources/application.yml
src/test/java/es/ujaen/dae/ujacoin/servicios/ServicioLimpiadoBaseDatos.java
src/test/java/es/ujaen/dae/ujacoin/servicios/ServicioUjaCoinTest.java
src/main/resources/application-test.yml
0 → 100644
View file @
2d303701
## Fichero de configuración para UjaCoin durante testing
spring.datasource.url
:
jdbc:mysql://localhost:33060/ujacoin_test
spring.jpa.properties.javax.persistence.schema-generation.database.action
:
drop-and-create
src/main/resources/application.yml
View file @
2d303701
##
YAML Template.
##
Fichero de configuración para UjaCoin
spring.datasource.url
:
jdbc:mysql://localhost:33060/ujacoin
spring.datasource.username
:
ujacoin
...
...
src/test/java/es/ujaen/dae/ujacoin/servicios/ServicioLimpiadoBaseDatos.java
deleted
100644 → 0
View file @
ea948d43
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 */
void
limpiar
()
{
transactionTemplate
.
executeWithoutResult
(
transactionStatus
->
{
for
(
String
tabla
:
entidades
)
{
em
.
createQuery
(
deleteFrom
+
tabla
).
executeUpdate
();
}
});
}
}
src/test/java/es/ujaen/dae/ujacoin/servicios/ServicioUjaCoinTest.java
View file @
2d303701
...
...
@@ -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
();
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment