11package com .sistemaclliente ;
22
33import static org .springframework .test .web .servlet .request .MockMvcRequestBuilders .get ;
4+ import static org .springframework .test .web .servlet .request .MockMvcRequestBuilders .post ;
45import static org .springframework .test .web .servlet .result .MockMvcResultMatchers .jsonPath ;
56import static org .springframework .test .web .servlet .result .MockMvcResultMatchers .status ;
67
910import org .springframework .beans .factory .annotation .Autowired ;
1011import org .springframework .boot .test .autoconfigure .web .servlet .AutoConfigureMockMvc ;
1112import org .springframework .boot .test .context .SpringBootTest ;
13+ import org .springframework .http .MediaType ;
1214import org .springframework .test .context .ActiveProfiles ;
1315import org .springframework .test .web .servlet .MockMvc ;
1416
1517import com .fasterxml .jackson .databind .ObjectMapper ;
1618import com .sistemacliente .SistemaClientesJavaApplication ;
1719import com .sistemacliente .model .Cliente ;
20+ import com .sistemacliente .model .dto .ClienteRequestDTO ;
1821import com .sistemacliente .model .dto .ClienteResponseDTO ;
1922import com .sistemacliente .repository .ClienteRepository ;
2023
@@ -39,8 +42,8 @@ public void contextLoads(){}
3942
4043 @ Test
4144 @ Transactional
42- @ DisplayName ("Retorna 200 e lista de todos os clientes do banco de dados ." )
43- public void listarClientes_listaCheia_retornar200 () throws Exception {
45+ @ DisplayName ("Returns 200 and a list of the clients from the database ." )
46+ public void listarClientes_fullList_return200 () throws Exception {
4447 repository .deleteAll ();
4548
4649 Cliente cliente1 = new Cliente ();
@@ -63,13 +66,28 @@ public void listarClientes_listaCheia_retornar200() throws Exception {
6366
6467 @ Test
6568 @ Transactional
66- @ DisplayName ("Retorna 200 e lista vazia, pois o banco foi limpo ." )
67- public void listarClientes_listaVazia_retorno200 () throws Exception {
69+ @ DisplayName ("Returns 200 and an empty list because we clened the database ." )
70+ public void listarClientes_emptyList_return200 () throws Exception {
6871 repository .deleteAll ();
6972 mvc .perform (get ("/listarclientes" )).andExpect (status ().isOk ())
7073 .andExpect (jsonPath ("$.length()" ).value (0 ));
7174 }
7275
76+ @ Test
77+ @ Transactional
78+ @ DisplayName ("Returns 200 when saving DTO client." )
79+ public void salvarCliente_success_return201 () throws Exception {
80+ ClienteRequestDTO dto = new ClienteRequestDTO ();
81+ dto .setNome ("Marcus" );
82+ dto .setCpf ("23501206586" );
83+ dto .setEmail ("marcus@gmail.com" );
84+
85+ mvc .perform (post ("/salvarcliente" ).content (mapper .writeValueAsString (dto ))
86+ .contentType (MediaType .APPLICATION_JSON )).andExpect (status ().isCreated ())
87+ .andExpect (jsonPath ("$.nome" ).value ("Marcus" )).andExpect (jsonPath ("$.cpf" ).value ("23501206586" ))
88+ .andExpect (jsonPath ("$.email" ).value ("marcus@gmail.com" ));
89+ }
90+
7391}
7492
7593
@@ -90,6 +108,5 @@ public void listarClientes_listaVazia_retorno200() throws Exception {
90108
91109
92110
93-
94111
95112
0 commit comments