У меня java .lang.AssertionError: ожидается: <201>, но было: <400>
mockHttpServletResponse.getStatus() = 400
вместо 201
201 правильный ответ:
"строка"
Это мой контроллер. java
@ApiOperation(value = "description")
@ResponseStatus(code = HttpStatus.CREATED)
@RequestMapping (value= {"/{country}/uois/getUserForOrganization"}, method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<String> getUserForOrganization (
@RequestBody UserForOrganization getUserForOrganizationType,
@ApiParam(required=true, value="Country Code (example: DE)")
@PathVariable String country,
) throws Exception {
return service.getUserForOrganization(getUserForOrganizationType, country);ponse;
}
Это мой ControllerTest. java
String countryString = "DE";
@MockBean
RestTemplate restTemplate;
@SuppressWarnings("unchecked")
@Test
public void testControllerGetUserForOrganization() throws Exception {
when(restTemplate.exchange(Mockito.contains("localhost:8080/" + countryString + "/uois/getUserForOrganization"),
Mockito.any(), Mockito.any(), ArgumentMatchers.any(Class.class))).thenReturn(
new ResponseEntity<String>("\"string\"",
HttpStatus.CREATED));
String body = "\"string\"";
URI uri = new URI("/" + countryString + "/uois/getUserForOrganization");
MvcResult mvcResult = mvc
.perform(MockMvcRequestBuilders.post(uri).contentType(MediaType.APPLICATION_JSON_VALUE).content(body))
.andReturn();
MockHttpServletResponse mockHttpServletResponse = mvcResult.getResponse();
assertEquals(201, mockHttpServletResponse.getStatus());
}