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
9e6ce320
authored
Dec 17, 2020
by
Antonio Rueda
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Renombrado de clase de test
parent
53517a44
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
0 additions
and
164 deletions
src/test/java/es/ujaen/dae/ujacoin/controladoresREST/ControladorClientesTest.java
src/test/java/es/ujaen/dae/ujacoin/controladoresREST/ControladorClientesTest.java
deleted
100644 → 0
View file @
53517a44
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package
es
.
ujaen
.
dae
.
ujacoin
.
controladoresREST
;
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.entidades.Cliente
;
import
es.ujaen.dae.ujacoin.entidades.movimientos.Ingreso
;
import
es.ujaen.dae.ujacoin.entidades.movimientos.Movimiento
;
import
es.ujaen.dae.ujacoin.servicios.ServicioLimpiadoBaseDatos
;
import
java.time.LocalDate
;
import
java.time.LocalDateTime
;
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
;
import
org.springframework.boot.test.web.client.TestRestTemplate
;
import
org.springframework.boot.web.client.RestTemplateBuilder
;
import
org.springframework.boot.web.server.LocalServerPort
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.http.converter.json.MappingJackson2HttpMessageConverter
;
/**
* Test para controlador REST de clientes
* @author ajrueda
*/
@SpringBootTest
(
classes
=
es
.
ujaen
.
dae
.
ujacoin
.
app
.
UjaCoinApp
.
class
,
webEnvironment
=
SpringBootTest
.
WebEnvironment
.
RANDOM_PORT
)
public
class
ControladorClientesTest
{
@Autowired
ServicioLimpiadoBaseDatos
limpiadorBaseDatos
;
@LocalServerPort
int
localPort
;
@Autowired
MappingJackson2HttpMessageConverter
springBootJacksonConverter
;
TestRestTemplate
restTemplate
;
/** Crear un TestRestTemplate para las pruebas */
@PostConstruct
void
crearRestTemplate
()
{
RestTemplateBuilder
restTemplateBuilder
=
new
RestTemplateBuilder
()
.
rootUri
(
"http://localhost:"
+
localPort
+
"/ujacoin"
)
.
additionalMessageConverters
(
List
.
of
(
springBootJacksonConverter
));
restTemplate
=
new
TestRestTemplate
(
restTemplateBuilder
);
}
@Test
public
void
testAltaClienteInvalido
()
{
// Cliente con e-mail incorrecto!!!
DTOCliente
cliente
=
new
DTOCliente
(
"11995667D"
,
"Juan España España"
,
LocalDate
.
of
(
1990
,
11
,
1
),
"Cl La Luz, 13 - Jaén"
,
"988674533"
,
"jeegmail.com"
,
"clave"
);
ResponseEntity
<
DTOCuenta
>
respuesta
=
restTemplate
.
postForEntity
(
"/clientes"
,
cliente
,
DTOCuenta
.
class
);
Assertions
.
assertThat
(
respuesta
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
BAD_REQUEST
);
}
@Test
public
void
testAltaYLoginClienteCuenta
()
{
DTOCliente
cliente
=
new
DTOCliente
(
"11995667D"
,
"Juan España España"
,
LocalDate
.
of
(
1990
,
11
,
1
),
"Cl La Luz, 13 - Jaén"
,
"988674533"
,
"jee@gmail.com"
,
"clave"
);
ResponseEntity
<
DTOCuenta
>
respuestaAlta
=
restTemplate
.
postForEntity
(
"/clientes"
,
cliente
,
DTOCuenta
.
class
);
Assertions
.
assertThat
(
respuestaAlta
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
CREATED
);
ResponseEntity
<
DTOCliente
>
respuestaLogin
=
restTemplate
.
getForEntity
(
"/clientes/{dni}?clave={clave}"
,
DTOCliente
.
class
,
cliente
.
getDni
(),
cliente
.
getClave
());
Assertions
.
assertThat
(
respuestaLogin
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
DTOCliente
clienteLogin
=
respuestaLogin
.
getBody
();
Assertions
.
assertThat
(
clienteLogin
.
getDni
()).
isEqualTo
(
cliente
.
getDni
());
}
@Test
public
void
testAnadirTarjetaACliente
()
{
// Registrar cliente y realizar login
DTOCliente
cliente
=
new
DTOCliente
(
"11995667D"
,
"Juan España España"
,
LocalDate
.
of
(
1990
,
11
,
1
),
"Cl La Luz, 13 - Jaén"
,
"988674533"
,
"jee@gmail.com"
,
"clave"
);
restTemplate
.
postForEntity
(
"/clientes"
,
cliente
,
DTOCuenta
.
class
);
DTOTarjeta
tarjeta
=
new
DTOTarjeta
(
"4111111111111111"
,
cliente
.
getNombre
(),
LocalDate
.
of
(
2022
,
12
,
1
),
"365"
);
ResponseEntity
<
DTOTarjeta
>
respuesta
=
restTemplate
.
postForEntity
(
"/clientes/{dni}/tarjetas"
,
tarjeta
,
DTOTarjeta
.
class
,
cliente
.
getDni
());
Assertions
.
assertThat
(
respuesta
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
CREATED
);
respuesta
=
restTemplate
.
getForEntity
(
"/clientes/{dni}/tarjetas/{num}"
,
DTOTarjeta
.
class
,
cliente
.
getDni
(),
tarjeta
.
getNum
());
Assertions
.
assertThat
(
respuesta
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
DTOTarjeta
tarjetaRecibida
=
respuesta
.
getBody
();
Assertions
.
assertThat
(
tarjetaRecibida
.
getNum
()).
isEqualTo
(
tarjeta
.
getNum
());
Assertions
.
assertThat
(
tarjetaRecibida
.
getTitular
()).
isEqualTo
(
tarjeta
.
getTitular
());
Assertions
.
assertThat
(
tarjetaRecibida
.
getFechaCaducidad
()).
isEqualTo
(
tarjeta
.
getFechaCaducidad
());
Assertions
.
assertThat
(
tarjetaRecibida
.
getCvc
()).
isEqualTo
(
tarjeta
.
getCvc
());
}
@Test
public
void
testIngreso
()
{
// Registrar cliente y realizar login
DTOCliente
cliente
=
new
DTOCliente
(
"11995667D"
,
"Juan España España"
,
LocalDate
.
of
(
1990
,
11
,
1
),
"Cl La Luz, 13 - Jaén"
,
"988674533"
,
"jee@gmail.com"
,
"clave"
);
DTOCuenta
cuenta
=
restTemplate
.
postForEntity
(
"/clientes"
,
cliente
,
DTOCuenta
.
class
).
getBody
();
DTOTarjeta
tarjeta
=
new
DTOTarjeta
(
"4111111111111111"
,
cliente
.
getNombre
(),
LocalDate
.
of
(
2022
,
12
,
1
),
"365"
);
restTemplate
.
postForEntity
(
"/clientes/{dni}/tarjetas"
,
tarjeta
,
DTOTarjeta
.
class
,
cliente
.
getDni
());
// Realizar ingreso y comprobar estado de la cuenta
DTOMovimiento
ingreso
=
DTOMovimiento
.
ingreso
(
tarjeta
.
getNum
(),
1000
);
ResponseEntity
<
Void
>
respuestaRegistroMovimiento
=
restTemplate
.
postForEntity
(
"/clientes/{dni}/cuentas/{num}/movimientos"
,
ingreso
,
Void
.
class
,
cliente
.
getDni
(),
cuenta
.
getNum
());
Assertions
.
assertThat
(
respuestaRegistroMovimiento
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
CREATED
);
// TODO: Comprobar saldo de la cuenta
ResponseEntity
<
DTOMovimiento
[]>
respuestaListadoMovimientos
=
restTemplate
.
getForEntity
(
"/clientes/{dni}/cuentas/{num}/movimientos"
,
DTOMovimiento
[].
class
,
cliente
.
getDni
(),
cuenta
.
getNum
());
DTOMovimiento
[]
movimientos
=
respuestaListadoMovimientos
.
getBody
();
Assertions
.
assertThat
(
movimientos
).
hasSize
(
1
);
Assertions
.
assertThat
(
movimientos
[
0
].
getTipo
()).
isEqualTo
(
DTOMovimiento
.
INGRESO
);
Assertions
.
assertThat
(
movimientos
[
0
].
getImporte
()).
isEqualTo
(
ingreso
.
getImporte
());
}
@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