Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Rubén Ramírez
/
MangAffinity
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
52982c49
authored
Feb 23, 2025
by
Rubén Ramírez
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
fix: [TestUsuariosController]: Corregidos test del controlador recurso
parent
39f49635
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
20 additions
and
7 deletions
src/main/java/com/ujaen/tfg/mangaffinity/rest/DTO/DTOUsuario.java
src/main/java/com/ujaen/tfg/mangaffinity/rest/UsuariosController.java
src/test/java/com/ujaen/tfg/mangaffinity/rest/TestUsuariosController.java
src/test/java/com/ujaen/tfg/mangaffinity/servicios/TestServicioUsuarios.java
src/main/java/com/ujaen/tfg/mangaffinity/rest/DTO/DTOUsuario.java
View file @
52982c49
...
...
@@ -13,7 +13,7 @@ import lombok.Setter;
@NoArgsConstructor
@AllArgsConstructor
public
class
DTOUsuario
{
private
Long
id
=
null
;
// Permito que sea nulo al crear
private
Long
id
;
@Email
private
String
email
;
...
...
@@ -24,4 +24,11 @@ public class DTOUsuario {
@NotBlank
private
String
contrasenia
;
public
DTOUsuario
(
String
email
,
String
nombreUsuario
,
String
contrasenia
)
{
id
=
null
;
this
.
email
=
email
;
this
.
nombreUsuario
=
nombreUsuario
;
this
.
contrasenia
=
contrasenia
;
}
}
\ No newline at end of file
src/main/java/com/ujaen/tfg/mangaffinity/rest/UsuariosController.java
View file @
52982c49
...
...
@@ -35,7 +35,9 @@ public class UsuariosController {
try
{
Usuario
usuario
=
mapper
.
entity
(
dtoUsuario
);
servicioUsuarios
.
crearUsuario
(
usuario
);
return
ResponseEntity
.
status
(
HttpStatus
.
CREATED
).
body
(
mapper
.
dto
(
usuario
));
Usuario
usuarioGuardado
=
servicioUsuarios
.
buscaUsuario
(
usuario
.
getEmail
());
//Obtiene un id
return
ResponseEntity
.
status
(
HttpStatus
.
CREATED
).
body
(
mapper
.
dto
(
usuarioGuardado
));
}
catch
(
UsuarioYaRegistrado
e
)
{
return
ResponseEntity
.
status
(
HttpStatus
.
CONFLICT
).
build
();
}
...
...
src/test/java/com/ujaen/tfg/mangaffinity/rest/TestUsuariosController.java
View file @
52982c49
...
...
@@ -2,10 +2,13 @@ package com.ujaen.tfg.mangaffinity.rest;
import
com.ujaen.tfg.mangaffinity.MangAffinityApplication
;
import
com.ujaen.tfg.mangaffinity.config.JpaTestConfig
;
import
com.ujaen.tfg.mangaffinity.entidades.Usuario
;
import
com.ujaen.tfg.mangaffinity.rest.DTO.DTOLoginRespuesta
;
import
com.ujaen.tfg.mangaffinity.rest.DTO.DTOUsuario
;
import
com.ujaen.tfg.mangaffinity.rest.DTO.Mapper
;
import
org.assertj.core.api.Assertions
;
import
org.junit.jupiter.api.Test
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.context.SpringBootTest
;
...
...
@@ -31,7 +34,8 @@ public class TestUsuariosController {
int
localPort
;
TestRestTemplate
restTemplateUsuarios
;
@Autowired
private
Mapper
mapper
;
@PostConstruct
...
...
@@ -81,6 +85,9 @@ public class TestUsuariosController {
@Test
@DirtiesContext
void
testIniciarSesion
()
{
var
usuarioValido
=
new
DTOUsuario
(
"pedro@gmail.com"
,
"Pedro"
,
"pedrito"
);
restTemplateUsuarios
.
postForEntity
(
"/"
,
usuarioValido
,
DTOUsuario
.
class
);
// Registramos usuario
// Caso 1: Usuario no encontrado
var
emailInexistente
=
"noexiste@example.com"
;
var
cuerpoInexistente
=
Map
.
of
(
"clave"
,
"password123"
);
...
...
@@ -92,9 +99,6 @@ public class TestUsuariosController {
Assertions
.
assertThat
(
respuestaInexistente
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
UNAUTHORIZED
);
// Caso 2: Contraseña incorrecta
var
usuarioValido
=
new
DTOUsuario
(
null
,
"pedro@gmail.com"
,
"Pedro"
,
"pedrito"
);
restTemplateUsuarios
.
postForEntity
(
"/"
,
usuarioValido
,
DTOUsuario
.
class
);
// Registramos usuario
var
cuerpoIncorrecto
=
Map
.
of
(
"clave"
,
"incorrecta"
);
var
respuestaIncorrecta
=
restTemplateUsuarios
.
postForEntity
(
"/"
+
usuarioValido
.
getEmail
(),
...
...
src/test/java/com/ujaen/tfg/mangaffinity/servicios/TestServicioUsuarios.java
View file @
52982c49
...
...
@@ -28,7 +28,6 @@ public class TestServicioUsuarios {
@Autowired
JwtUtil
jwtUtil
;
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
TestServicioUsuarios
.
class
);
@Test
@DirtiesContext
...
...
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