I wrote a JUnit test that runs successfully in Intellij and is passed. But if I run mvn clean test, that particular test fails. To be more specific, the challenge is to check whether the request has been sent or not. Therefore, when I run the test in IntelliJ, the test passes with status code 201 (successful). But when I run mvn clean install, it shows it as status code 400 (Bad request).
I searched the Internet about this, but could not find a solution. Please help me.
Below is the code. It does not work on the first statement assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());::
@Test
public void testUpdateMultiValueAttributes() throws URISyntaxException {
String createPayload =
"{\n" +
" \"id\": 9,\n" +
" \"email\": \"" + "ismith@zzz.com" + "\",\n" +
" \"profile\": {\"userAttrs\":[" +
" {\"CUST_ATTR_MULTI_VALUE\": \"CUST_ATTR_MULTI_VALUE_3\"}" +
" ]}" +
"}";
MockHttpRequest request = MockHttpRequest.put("/subscribers/9");
request.contentType(MediaType.APPLICATION_JSON);
request.content(createPayload.getBytes());
MockHttpResponse response = new MockHttpResponse();
dispatcher.invoke(request, response);
LOG.error(response.getContentAsString());
response.toString();
assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());
SubscriberDto subscriber = null ;
try {
subscriber = MarshallingUtils.unmarshallJSON(new TypeReference<SubscriberDto>() {
}, response.getContentAsString());
} catch (Exception e) {
fail(e.getMessage());
}
Collection<SubscriberAttributeDto> customAttributes = subscriber.getProfile().getUserAttrs();
if (customAttributes!=null)
assertTrue(customAttributes.contains(new SubscriberAttributeDto("CUST_ATTR_MULTI_VALUE", "CUST_ATTR_MULTI_VALUE_3")));
source
share