Spring test expected 400 bat was 404 no found endpoint
I have the next controller: @Operation(summary = "Create a student meeting for agency ") @ApiResponses({ @ApiResponse(responseCode = "200", content = { @Content(schema = @Schema(implementation = MeetingResponse.class), mediaType = "application/json") }), @ApiResponse(responseCode = "400", content = { @Content(schema = @Schema(implementation = ErrorResponse.class), mediaType = "application/json") }), @ApiResponse(responseCode = "401", content = { @Content(schema = @Schema(implementation = ErrorResponse.class), mediaType = "application/json") }), }) @PostMapping(path = "/student/meeting") public MeetingJoinToken setupMeeting(@RequestBody StudentMeetingRequest studentMeetingRequest){ SetupMeetingRequest setupMeetingRequest = validateAndCreateSetupMeetingRequest(studentMeetingRequest, ParticipantRole.ATTENDEE); return studentService.setupMeeting(setupMeetingRequest); } And also I have the next test: @RunWith(SpringRunner.class) @SpringBootTest(classes = ThApplication.class) @ComponentScan(basePackages = "com.agency") @AutoConfigureMockMvc public class ControllerIntTest { private final String patientMeeting ="/student/meeting"; @Autowired private MockMvc mockMvc; @MockBean IamTokenManagerRepository iamTokenManagerRepository; @MockBean ConfigmapFilesDownloader configmapFilesDownloader; @BeforeClass public static void setupClass() { AthenaLogInitializer.getInstance().initialize(); } @Test public void th_joinSession_BadRequest() throws Exception { mockMvc.perform(MockMvcRequestBuilders.post("/student/meeting")) .andExpect(MockMvcResultMatchers.status().isBadRequest()); } } After running the test I got Expected :400 Actual :404 I guess I am missing something in the configuration of the test, any ideas? These are my dependencies: testImplementation 'org.mockito:mockito-inline' testImplementation 'org.mockito:mockito-core' testImplementation 'org.junit.jupiter:junit-jupiter-engine' testImplementation 'org.mockito:mockito-junit-jupiter' testImplementation 'org.springframework.boot:spring-boot-starter-test' testImplementation 'org.springframework.boot:spring-boot-test-autoconfigure' testImplementation 'junit:junit' testImplementation 'org.springframework:spring-test' sourceSets { integrationTest { java { compileClasspath += main.output + test.output runtimeClasspath += main.output + test.output } } } configurations { integrationTestImplementation.extendsFrom(testImplementation) integrationTestRuntimeOnly.extendsFrom(testRuntimeOnly) } Thanks!
I have the next controller:
@Operation(summary = "Create a student meeting for agency ")
@ApiResponses({
@ApiResponse(responseCode = "200", content = {
@Content(schema = @Schema(implementation = MeetingResponse.class), mediaType = "application/json")
}),
@ApiResponse(responseCode = "400", content = {
@Content(schema = @Schema(implementation = ErrorResponse.class), mediaType = "application/json")
}),
@ApiResponse(responseCode = "401", content = {
@Content(schema = @Schema(implementation = ErrorResponse.class), mediaType = "application/json")
}),
})
@PostMapping(path = "/student/meeting")
public MeetingJoinToken setupMeeting(@RequestBody StudentMeetingRequest studentMeetingRequest){
SetupMeetingRequest setupMeetingRequest = validateAndCreateSetupMeetingRequest(studentMeetingRequest, ParticipantRole.ATTENDEE);
return studentService.setupMeeting(setupMeetingRequest);
}
And also I have the next test:
@RunWith(SpringRunner.class)
@SpringBootTest(classes = ThApplication.class)
@ComponentScan(basePackages = "com.agency")
@AutoConfigureMockMvc
public class ControllerIntTest {
private final String patientMeeting ="/student/meeting";
@Autowired
private MockMvc mockMvc;
@MockBean
IamTokenManagerRepository iamTokenManagerRepository;
@MockBean
ConfigmapFilesDownloader configmapFilesDownloader;
@BeforeClass
public static void setupClass() {
AthenaLogInitializer.getInstance().initialize();
}
@Test
public void th_joinSession_BadRequest() throws Exception {
mockMvc.perform(MockMvcRequestBuilders.post("/student/meeting"))
.andExpect(MockMvcResultMatchers.status().isBadRequest());
}
}
After running the test I got
Expected :400
Actual :404
I guess I am missing something in the configuration of the test, any ideas?
These are my dependencies:
testImplementation 'org.mockito:mockito-inline'
testImplementation 'org.mockito:mockito-core'
testImplementation 'org.junit.jupiter:junit-jupiter-engine'
testImplementation 'org.mockito:mockito-junit-jupiter'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.boot:spring-boot-test-autoconfigure'
testImplementation 'junit:junit'
testImplementation 'org.springframework:spring-test'
sourceSets {
integrationTest {
java {
compileClasspath += main.output + test.output
runtimeClasspath += main.output + test.output
}
}
}
configurations {
integrationTestImplementation.extendsFrom(testImplementation)
integrationTestRuntimeOnly.extendsFrom(testRuntimeOnly)
}
Thanks!