Skip to content

Commit b8dc957

Browse files
committed
refactor the integration tests to return the expect the new message when some entity not found
1 parent ff733a8 commit b8dc957

File tree

5 files changed

+32
-18
lines changed

5 files changed

+32
-18
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<groupId>com.wora</groupId>
1212
<artifactId>state-of-dev</artifactId>
1313
<version>0.0.1-SNAPSHOT</version>
14-
<name>state-of-dev</name>
14+
<name>IT Survey</name>
1515
<description>State of dev like</description>
1616
<url/>
1717
<licenses>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.wora.state_of_dev;
2+
3+
import org.junit.jupiter.api.DisplayName;
4+
import org.junit.jupiter.api.Test;
5+
6+
public class ModularityTests {
7+
// ApplicationModules modules = ApplicationModules.of(Application.class);
8+
//
9+
// @Test
10+
// @DisplayName("test the application modularity")
11+
// void modulesShouldBeDefined() {
12+
// modules.verify();
13+
// }
14+
}

src/test/java/com/wora/state_of_dev/survey/infrastructure/web/ChapterControllerIntegrationTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,9 @@ void givenCorrectRequestAndInvalidSurveyEditionId_whenCreate_shouldReturnNotFoun
8484
mockMvc.perform(post("/api/v1/chapters" )
8585
.contentType(MediaType.APPLICATION_JSON_VALUE)
8686
.content(objectMapper.writeValueAsString(request)))
87-
.andExpect(status().isNotFound())
88-
.andExpect(jsonPath("$.code").value(404))
89-
.andExpect(jsonPath("$.message").value(ENTITY_NOT_FOUND_MESSAGE))
87+
.andExpect(status().isBadRequest())
88+
.andExpect(jsonPath("$.code").value(400))
89+
.andExpect(jsonPath("$.message").value(VALIDATION_FAILED_MESSAGE))
9090
.andDo(print());
9191
}
9292

src/test/java/com/wora/state_of_dev/survey/infrastructure/web/QuestionControllerIntegrationTest.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -111,15 +111,15 @@ void givenExistentQuestionId_whenFindById_shouldReturnFoundQuestion() throws Exc
111111
class CreateTests {
112112
@Test
113113
@Rollback
114-
void givenChapterIdDoesNotExists_whenCreate_shouldReturnNotFound() throws Exception {
114+
void givenChapterIdDoesNotExists_whenCreate_shouldReturnBadRequest() throws Exception {
115115
QuestionRequestDto invalidRequest = new QuestionRequestDto("your stack", 3939L, AnswerType.SINGLE_CHOICE, answerRequestDtos);
116116

117117
mockMvc.perform(post("/api/v1/questions")
118118
.contentType(MediaType.APPLICATION_JSON_VALUE)
119119
.content(objectMapper.writeValueAsString(invalidRequest)))
120-
.andExpect(status().isNotFound())
121-
.andExpect(jsonPath("$.message").value(ENTITY_NOT_FOUND_MESSAGE))
122-
.andExpect(jsonPath("$.code").value(404));
120+
.andExpect(status().isBadRequest())
121+
.andExpect(jsonPath("$.message").value(VALIDATION_FAILED_MESSAGE))
122+
.andExpect(jsonPath("$.code").value(400));
123123
}
124124

125125
@Test
@@ -186,9 +186,9 @@ void givenChapterIdDoesNotExists_whenUpdate_shouldReturnNotFound() throws Except
186186
mockMvc.perform(put("/api/v1/questions/{id}", question.id())
187187
.contentType(MediaType.APPLICATION_JSON_VALUE)
188188
.content(objectMapper.writeValueAsString(invalidRequest)))
189-
.andExpect(status().isNotFound())
190-
.andExpect(jsonPath("$.message").value(ENTITY_NOT_FOUND_MESSAGE))
191-
.andExpect(jsonPath("$.code").value(404));
189+
.andExpect(status().isBadRequest())
190+
.andExpect(jsonPath("$.message").value(VALIDATION_FAILED_MESSAGE))
191+
.andExpect(jsonPath("$.code").value(400));
192192
}
193193

194194
@Test

src/test/java/com/wora/state_of_dev/survey/infrastructure/web/SurveyEditionControllerIntegrationTest.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -104,15 +104,15 @@ void givenInvalidRequest_whenCreate_shouldReturnBadRequest() throws Exception {
104104

105105
@Test
106106
@Rollback
107-
void givenNotExistentSurveyId_whenCreate_shouldReturnNotFound() throws Exception {
107+
void givenNotExistentSurveyId_whenCreate_shouldReturnBadRequest() throws Exception {
108108
SurveyEditionRequestDto invalidRequest = new SurveyEditionRequestDto(LocalDateTime.now().plusDays(1), LocalDateTime.now().plusDays(39), Year.now(), 9393L);
109109

110110
mockMvc.perform(post("/api/v1/survey-editions")
111111
.contentType(MediaType.APPLICATION_JSON_VALUE)
112112
.content(objectMapper.writeValueAsString(invalidRequest)))
113-
.andExpect(status().isNotFound())
114-
.andExpect(jsonPath("$.code").value(404))
115-
.andExpect(jsonPath("$.message").value(ENTITY_NOT_FOUND_MESSAGE));
113+
.andExpect(status().isBadRequest())
114+
.andExpect(jsonPath("$.code").value(400))
115+
.andExpect(jsonPath("$.message").value(VALIDATION_FAILED_MESSAGE));
116116
}
117117

118118
@Test
@@ -151,9 +151,9 @@ void givenNotExistentSurveyId_whenUpdate_shouldReturnNotFound() throws Exception
151151
mockMvc.perform(put("/api/v1/survey-editions/{id}", 9999L)
152152
.contentType(MediaType.APPLICATION_JSON_VALUE)
153153
.content(objectMapper.writeValueAsString(validRequest)))
154-
.andExpect(status().isNotFound())
155-
.andExpect(jsonPath("$.code").value(404))
156-
.andExpect(jsonPath("$.message").value(ENTITY_NOT_FOUND_MESSAGE));
154+
.andExpect(status().isBadRequest())
155+
.andExpect(jsonPath("$.code").value(400))
156+
.andExpect(jsonPath("$.message").value(VALIDATION_FAILED_MESSAGE));
157157
}
158158

159159
@Test

0 commit comments

Comments
 (0)