Skip to content

Commit 4b06cbd

Browse files
committed
Integration test: buscaPorEmail, with page parameters.
Searches for an e-mail address and returns a page with the client from that e-mail.
1 parent b116da8 commit 4b06cbd

File tree

2 files changed

+37
-3
lines changed

2 files changed

+37
-3
lines changed

src/test/java/com/sistemaclliente/ClienteControllerIntegrationTest.java

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,40 @@ public void atualizarParcial_invalidEmailAdress_returns400(String email) throws
567567
.andExpect(content().string(containsString("inválido")));
568568
}
569569

570-
570+
@Test @Transactional() @DisplayName("Searches for an e-mail address and returns a page with the"
571+
+ "client from that e-mail.")
572+
public void buscaPorEmail_successPage_withPageParameters_return200() throws Exception{
573+
/*This is only a test to make sure that the correct content is returned. The e-mail address is
574+
*unique and we can't have two clients with the same e-mail. For that reason the real Page only
575+
*return one client.*/
576+
Cliente cliente1 = new Cliente();
577+
cliente1.setNome("Marcus");
578+
cliente1.setCpf("23501206586");
579+
cliente1.setEmail("marcus@gmail.com");
580+
581+
Cliente cliente2 = new Cliente();
582+
cliente2.setNome("Antonio");
583+
cliente2.setCpf("20219064674");
584+
cliente2.setEmail("antonio@gmail.com");
585+
586+
Cliente cliente3 = new Cliente();
587+
cliente3.setNome("Marcelo");
588+
cliente3.setCpf("47852136582");
589+
cliente3.setEmail("marcus@gmail.com");
590+
591+
repository.saveAndFlush(cliente1);
592+
repository.saveAndFlush(cliente2);
593+
repository.saveAndFlush(cliente3);
594+
595+
mvc.perform(get("/buscaemail?email=marcus@gmail.com&pagina=0&itens=3")).andExpect(status().isOk())
596+
.andExpect(jsonPath("$.content[0].nome").value("Marcus"))
597+
.andExpect(jsonPath("$.content[0].email").value("marcus@gmail.com"))
598+
.andExpect(jsonPath("$.content[0].cpf").value("23501206586"))
599+
.andExpect(jsonPath("$.content[1].nome").value("Marcelo"))
600+
.andExpect(jsonPath("$.content[1].email").value("marcus@gmail.com"))
601+
.andExpect(jsonPath("$.content[1].cpf").value("47852136582"))
602+
.andExpect(jsonPath("$.content.length()").value(2));
603+
}
571604

572605
}
573606

src/test/java/com/sistemaclliente/ClienteControllerTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ public void listarClientes_listaVazia_retorno200() throws Exception {
125125
}
126126

127127
@Test
128-
public void listarClientes_retornao500() throws Exception {
128+
public void listarClientes_retorna500() throws Exception {
129129
when(service.listagemCliente()).thenThrow(new RuntimeException());
130130

131131
mvc.perform(get("/listarclientes")).andExpect(status().isInternalServerError())
@@ -798,7 +798,8 @@ public void atualizarParcial_verboIncorreto_retorno405() throws Exception{
798798
verifyNoMoreInteractions(service);
799799
}
800800

801-
@Test
801+
@Test @DisplayName("Searches for an e-mail address and returns a page with the"
802+
+ "client from that e-mail.")
802803
public void buscaPorEmail_sucessoPaginaCheia_comParametros_retorno200() throws Exception{
803804
List<ClienteResponseDTO> lista = List.of(cliente1);
804805
Page<ClienteResponseDTO> page = new PageImpl<>(lista);

0 commit comments

Comments
 (0)