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
3c4635e0
authored
Feb 21, 2025
by
Rubén Ramírez
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
feat: [TestUsuariosController]: Implementada el test de inicio de sesión en el controlador
parent
bd99341a
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
44 additions
and
0 deletions
src/test/java/com/ujaen/tfg/mangaffinity/rest/TestUsuariosController.java
src/test/java/com/ujaen/tfg/mangaffinity/rest/TestUsuariosController.java
View file @
3c4635e0
...
...
@@ -2,6 +2,7 @@ package com.ujaen.tfg.mangaffinity.rest;
import
com.ujaen.tfg.mangaffinity.MangAffinityApplication
;
import
com.ujaen.tfg.mangaffinity.config.JpaTestConfig
;
import
com.ujaen.tfg.mangaffinity.rest.DTO.DTOLoginRespuesta
;
import
com.ujaen.tfg.mangaffinity.rest.DTO.DTOUsuario
;
import
org.assertj.core.api.Assertions
;
import
org.junit.jupiter.api.Test
;
...
...
@@ -18,6 +19,8 @@ import org.springframework.test.annotation.DirtiesContext;
import
org.springframework.test.context.ActiveProfiles
;
import
jakarta.annotation.PostConstruct
;
import
java.util.Map
;
@SpringBootTest
(
classes
=
{
MangAffinityApplication
.
class
,
JpaTestConfig
.
class
},
webEnvironment
=
SpringBootTest
.
WebEnvironment
.
RANDOM_PORT
)
@ActiveProfiles
(
"test"
)
public
class
TestUsuariosController
{
...
...
@@ -74,4 +77,45 @@ public class TestUsuariosController {
);
Assertions
.
assertThat
(
respuestaDuplicado
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
CONFLICT
);
}
@Test
@DirtiesContext
void
testIniciarSesion
()
{
// Caso 1: Usuario no encontrado
var
emailInexistente
=
"noexiste@example.com"
;
var
cuerpoInexistente
=
Map
.
of
(
"clave"
,
"password123"
);
var
respuestaInexistente
=
restTemplateUsuarios
.
postForEntity
(
"/"
+
emailInexistente
,
cuerpoInexistente
,
Void
.
class
);
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
(),
cuerpoIncorrecto
,
Void
.
class
);
Assertions
.
assertThat
(
respuestaIncorrecta
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
UNAUTHORIZED
);
// Caso 3: Inicio de sesión exitoso
var
cuerpoValido
=
Map
.
of
(
"clave"
,
"pedrito"
);
var
respuestaValida
=
restTemplateUsuarios
.
postForEntity
(
"/"
+
usuarioValido
.
getEmail
(),
cuerpoValido
,
DTOLoginRespuesta
.
class
);
Assertions
.
assertThat
(
respuestaValida
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
Assertions
.
assertThat
(
respuestaValida
.
getBody
()).
isNotNull
();
Assertions
.
assertThat
(
respuestaValida
.
getBody
().
getToken
()).
isNotEmpty
();
}
}
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