Skip to content

Commit 3b667c9

Browse files
committed
Integration test: AtualizarCliente, returns 200.
Updates client according to the DTO object, returns 200.
1 parent ee2cc9a commit 3b667c9

File tree

3 files changed

+35
-3
lines changed

3 files changed

+35
-3
lines changed

pom.xml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<groupId>org.springframework.boot</groupId>
88
<artifactId>spring-boot-starter-parent</artifactId>
99
<version>3.5.3</version>
10-
<relativePath /> <!-- lookup parent from repository -->
10+
<relativePath />
1111
</parent>
1212
<groupId>com.sistemacliente</groupId>
1313
<artifactId>sistema-clientes-java</artifactId>
@@ -81,6 +81,14 @@
8181

8282
<build>
8383
<plugins>
84+
85+
<!--corrige o parent-->
86+
<plugin>
87+
<groupId>org.apache.maven.plugins</groupId>
88+
<artifactId>maven-resources-plugin</artifactId>
89+
<version>3.1.0</version>
90+
</plugin>
91+
8492
<plugin>
8593
<groupId>org.apache.maven.plugins</groupId>
8694
<artifactId>maven-compiler-plugin</artifactId>
@@ -129,7 +137,7 @@
129137
</execution>
130138
</executions>
131139
</plugin>
132-
140+
133141
<!--Sufire para o JaCoCo-->
134142
<plugin>
135143
<groupId>org.apache.maven.plugins</groupId>

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

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete;
66
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
77
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
8+
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put;
89
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
910
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
1011
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
@@ -198,12 +199,34 @@ public void deletarClientePorId_success_returns204() throws Exception {
198199
}
199200

200201
@Test @Transactional
201-
@DisplayName("Deletes a client by a non-existing ID and returns 404")
202+
@DisplayName("Deletes a client by a non-existing ID and returns 404.")
202203
public void deletarClientePorId_clientNotFound_returns404() throws Exception{
203204
mvc.perform(delete("/deletarporid/999")).andExpect(status().isNotFound());
204205

205206
assertThat(repository.findById(999L)).isNotPresent();
206207
}
208+
209+
@Test @Transactional
210+
@DisplayName("Updates client according to the DTO object, returns 200.")
211+
public void atualizarCliente_success_returns200() throws Exception{
212+
Cliente cliente1 = new Cliente();
213+
cliente1.setNome("Marcus");
214+
cliente1.setCpf("23501206586");
215+
cliente1.setEmail("marcus@gmail.com");
216+
repository.saveAndFlush(cliente1);
217+
218+
ClienteRequestDTO dto = new ClienteRequestDTO();
219+
dto.setNome("Marcus");
220+
dto.setCpf("23501206586");
221+
dto.setEmail("carlos@gmail.com");
222+
223+
mvc.perform(put("/clientes/"+cliente1.getId()).contentType(MediaType.APPLICATION_JSON)
224+
.content(mapper.writeValueAsString(dto))).andExpect(status().isOk());
225+
226+
Cliente encontrado = repository.findById(cliente1.getId()).get();
227+
228+
assertThat(encontrado.getEmail()).isEqualTo("carlos@gmail.com");
229+
}
207230
}
208231

209232

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,7 @@ public void deletarClientePorId_erroServidor_retorno500() throws Exception{
325325
}
326326

327327
@Test
328+
@DisplayName("Updates client according to the DTO object, returns 200.")
328329
public void atualizarCliente_sucesso_retorno200() throws Exception{
329330
when(service.atualizarCliente(anyLong(), any(ClienteRequestDTO.class))).thenReturn(cliente1);
330331

0 commit comments

Comments
 (0)