@@ -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
0 commit comments