Skip to content

Commit 68249cb

Browse files
committed
Integration test: buscaPorEmail, no page paremeters.
Searches for an e-mail address and returns a page with the client from that email. Page parameters are NOT provided.
1 parent 48a30e1 commit 68249cb

File tree

2 files changed

+41
-5
lines changed

2 files changed

+41
-5
lines changed

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

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ public void atualizarParcial_invalidName_returns400(String nome) throws Exceptio
550550

551551
@ParameterizedTest @NullAndEmptySource @Transactional
552552
@ValueSource(strings = {" ", "marcus@marcus@marcus", "marcus.com", "@marcus.com", "marcus@"})
553-
@DisplayName("It tries to update partial information of the client with an invalid e-mail address and"
553+
@DisplayName("It tries to update partial information of the client with an invalid email address and"
554554
+ "returns 400.")
555555
public void atualizarParcial_invalidEmailAdress_returns400(String email) throws Exception{
556556
Cliente cliente1 = new Cliente();
@@ -567,9 +567,9 @@ public void atualizarParcial_invalidEmailAdress_returns400(String email) throws
567567
.andExpect(content().string(containsString("inválido")));
568568
}
569569

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{
570+
@Test @Transactional() @DisplayName("Searches for an email address and returns a page with the"
571+
+ "client from that email. Page parameters are provided.")
572+
public void buscaPorEmail_successFullPage_withPageParameters_returns200() throws Exception{
573573
/*This is only a test to make sure that the correct content is returned. The e-mail address is
574574
*unique and we can't have two clients with the same e-mail. For that reason the real Page only
575575
*return one client.*/
@@ -601,6 +601,41 @@ public void buscaPorEmail_successPage_withPageParameters_return200() throws Exce
601601
.andExpect(jsonPath("$.content[1].cpf").value("47852136582"))
602602
.andExpect(jsonPath("$.content.length()").value(2));
603603
}
604+
605+
@Test @Transactional @DisplayName("Searches for an e-mail address and returns a page with the"
606+
+ "client from that email. Page parameters are NOT provided.")
607+
public void buscaPorEmail_successFullPage_noParameters_returns200() throws Exception{
608+
/*This is only a test to make sure that the correct content is returned. The email address is
609+
*unique and we can't have two clients with the same e-mail. For that reason the real Page only
610+
*return one client.*/
611+
Cliente cliente1 = new Cliente();
612+
cliente1.setNome("Marcus");
613+
cliente1.setCpf("23501206586");
614+
cliente1.setEmail("marcus@gmail.com");
615+
616+
Cliente cliente2 = new Cliente();
617+
cliente2.setNome("Antonio");
618+
cliente2.setCpf("20219064674");
619+
cliente2.setEmail("antonio@gmail.com");
620+
621+
Cliente cliente3 = new Cliente();
622+
cliente3.setNome("Marcelo");
623+
cliente3.setCpf("47852136582");
624+
cliente3.setEmail("marcus@gmail.com");
625+
626+
repository.saveAndFlush(cliente1);
627+
repository.saveAndFlush(cliente2);
628+
repository.saveAndFlush(cliente3);
629+
630+
mvc.perform(get("/buscaemail?email=marcus@gmail.com")).andExpect(status().isOk())
631+
.andExpect(jsonPath("$.content[0].nome").value("Marcus"))
632+
.andExpect(jsonPath("$.content[0].email").value("marcus@gmail.com"))
633+
.andExpect(jsonPath("$.content[0].cpf").value("23501206586"))
634+
.andExpect(jsonPath("$.content[1].nome").value("Marcelo"))
635+
.andExpect(jsonPath("$.content[1].email").value("marcus@gmail.com"))
636+
.andExpect(jsonPath("$.content[1].cpf").value("47852136582"))
637+
.andExpect(jsonPath("$.content.length()").value(2));
638+
}
604639

605640
}
606641

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -836,7 +836,8 @@ public void buscaPorEmail_sucessoPaginaCheia_comParametros_retorno200() throws E
836836
verifyNoMoreInteractions(service);
837837
}
838838

839-
@Test
839+
@Test @DisplayName("Searches for an e-mail address and returns a page with the client from that"
840+
+ " email. Page parameters are NOT provided.")
840841
public void buscaPorEmail_sucessoPaginaCheia_semParametros_retorno200() throws Exception{
841842
List<ClienteResponseDTO> lista = List.of(cliente1);
842843
Page<ClienteResponseDTO> page = new PageImpl<>(lista);

0 commit comments

Comments
 (0)