Контроллер
@PostMapping(value = "/agents/log/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public ResponseEntity<CallbackResponse> agentsLogFileUpload(@RequestParam("eventId") String id,
@RequestPart("file") MultipartFile file) throws ResourceNotFoundException, IOException {
agentLogService.saveLogFile(file, file.getName(), id);
eventService.updateEvent(id, new ExecutionSummary(Status.SUCCEEDED),
serviceAuthClient.getDefaultJwtTokenObserver().getJwtAccessToken());
return new ResponseEntity<>(new CallbackResponse(true), HttpStatus.OK);
}
Я написал следующий метод теста
@Test
public void testAgentsLogFileUpload() throws Exception {
MockMultipartFile file = new MockMultipartFile("file", "test.txt", "multipart/form-data", "Test".getBytes());
AgentLog agentLog = new AgentLog();
Mono<Event> event = Mono.just(new Event());
Mockito.when(agentLogService.saveLogFile(Mockito.any(), Mockito.anyString(), Mockito.anyString()))
.thenReturn(agentLog);
Mockito.when(eventService.updateEvent(Mockito.anyString(), Mockito.any(), Mockito.anyString()))
.thenReturn(event);
RequestBuilder requestBuilder = MockMvcRequestBuilders.multipart("/agents/log/upload").file(file)
.contentType(MediaType.MULTIPART_FORM_DATA_VALUE).param("eventId", "123");
MvcResult result = mvc.perform(requestBuilder).andDo(MockMvcResultHandlers.print()).andReturn();
assertEquals(HttpStatus.OK.value(), result.getResponse().getStatus());
}
Я добавил стековую запись моего метода тестирования ниже.
org.opentest4j.AssertionFailedError: expected: <200> but was: <500>
at org.junit.jupiter.api.AssertionUtils.fail(AssertionUtils.java:55)
at org.junit.jupiter.api.AssertionUtils.failNotEqual(AssertionUtils.java:62)
at org.junit.jupiter.api.AssertEquals.assertEquals(AssertEquals.java:150)
at org.junit.jupiter.api.AssertEquals.assertEquals(AssertEquals.java:145)
at org.junit.jupiter.api.Assertions.assertEquals(Assertions.java:510)
at com.cygilant.endpoint.security.cloud.rest.controller.ExecutionControllerTest.testAgentsLogFileUpload(ExecutionControllerTest.java:204)
Когда я запускаю этот тест, я получаю HTTP Error 500 и NullPointerException. Может кто-нибудь сказать мне, где я делаю неправильно?