Skip to content

Commit ed3894b

Browse files
committed
Integration test: buscarPorEmailOrdenada, Return 200.
1 parent 322e7a1 commit ed3894b

File tree

3 files changed

+35
-6
lines changed

3 files changed

+35
-6
lines changed

src/main/java/com/sistemacliente/controller/ClienteController.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,17 +98,16 @@ public ResponseEntity<ClienteResponseDTO> atualizarParcial(@PathVariable Long id
9898
return ResponseEntity.ok(response);
9999
}
100100

101-
@GetMapping(value = "/buscaemail")
102-
public ResponseEntity<Page<ClienteResponseDTO>> buscaPorEmail
101+
@GetMapping(value = "/buscaemail") public ResponseEntity<Page<ClienteResponseDTO>> buscaPorEmail
103102
(@RequestParam(required = false) String email, @RequestParam(defaultValue = "0") int pagina,
104103
@RequestParam(defaultValue = "3") int itens){
105104
Page<ClienteResponseDTO> page = service.buscarPorEmail(email, pagina, itens);
106105
return ResponseEntity.ok(page);
107106
}
108107

109108
@PatchMapping(value = "/atualizaremail/{id}")
110-
public ResponseEntity<ClienteResponseDTO>
111-
atualizarEmail(@PathVariable Long id, @RequestParam(required = false) String email){
109+
public ResponseEntity<ClienteResponseDTO> atualizarEmail(@PathVariable Long id,
110+
@RequestParam(required = false) String email){
112111
ClienteResponseDTO response= service.atualizarEmail(id, email);
113112
return ResponseEntity.ok(response);
114113
}

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

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,7 @@ public void buscaPorEmail_successFullPage_withPageParameters_returns200() throws
605605
@Test @Transactional @DisplayName("Searches for an e-mail address and returns a page with the"
606606
+ "client from that email. Page parameters are NOT provided.")
607607
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
608+
/*This is only a test to ensure that the correct content is returned. The email address is
609609
*unique and we can't have two clients with the same e-mail. For that reason the real Page only
610610
*return one client.*/
611611
Cliente cliente1 = new Cliente();
@@ -712,7 +712,36 @@ public void atualizarEmail_existingEmail_returns409() throws Exception{
712712

713713
mvc.perform(patch("/atualizaremail/"+cliente1.getId()).param("email", "antonio@gmail.com"))
714714
.andExpect(status().isConflict()).andExpect(content().string(containsString("indisponível")));
715+
}
716+
717+
@Test @Transactional @DisplayName("Searches for the client by email and returns a Page with that "
718+
+ "client. Returns 200.")
719+
public void buscarPorEmailOrdenada_successFullPage_returns200() throws Exception {
720+
/*This is only a test to ensure that the correct content is returned. The email address is
721+
*unique and we cannot have two clients with the same e-mail. For that reason the real Page only
722+
*return one client.*/
723+
Cliente cliente1 = new Cliente();
724+
cliente1.setNome("Marcus");
725+
cliente1.setCpf("23501206586");
726+
cliente1.setEmail("marcus@gmail.com");
727+
728+
Cliente cliente2 = new Cliente();
729+
cliente2.setNome("Antonio");
730+
cliente2.setCpf("20219064674");
731+
cliente2.setEmail("antonio@gmail.com");
732+
733+
Cliente cliente3 = new Cliente();
734+
cliente3.setNome("Marcelo");
735+
cliente3.setCpf("47852136582");
736+
cliente3.setEmail("marcus@gmail.com");
737+
738+
repository.saveAndFlush(cliente1);
739+
repository.saveAndFlush(cliente2);
740+
repository.saveAndFlush(cliente3);
715741

742+
mvc.perform(get("/buscarporemail").param("email", "marcus@gmail.com")
743+
.param("pagina", "0").param("itens", "2").param("ordenadoPor", "id"))
744+
.andExpect(status().isOk()).andExpect(jsonPath("$.content[0].nome").value("Marcus"));
716745
}
717746

718747
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -987,7 +987,8 @@ public void atualizarEmail_erroDeServidor_retorno500() throws Exception{
987987
verifyNoMoreInteractions(service);
988988
}
989989

990-
@Test
990+
@Test @DisplayName("Searches for the client by email and returns a Page with that client. "
991+
+ "Returns 200.")
991992
public void buscarPorEmailOrdenada_sucessoPageCheia_retorno200() throws Exception {
992993
List<ClienteResponseDTO> lista = List.of(cliente1, cliente2);
993994
Page<ClienteResponseDTO> page = new PageImpl<>(lista);

0 commit comments

Comments
 (0)