I am using mockmvc for my rest services integration test. I have a post rest service, called it from postman and getted 200 but when i call it with mockmvc porform method returned 415 unsupported media type exception.
Rest method
@RequestMapping(value = "/users/test/{groupId}",
method = RequestMethod.POST,
produces=MediaType.APPLICATION_JSON_VALUE,
consumes=MediaType.APPLICATION_JSON_VALUE)
private GenericResponse postTest(@PathVariable("groupId")String groupId,@RequestBody List<Contact> test, @RequestHeader("Authorization")String authorization) {
return new GenericResponse();
}
Test Method
@Test
public void testPost() throws Exception {
Contact contact = new Contact();
contact.setName("contact1");
contact.setMsisdn("901234567890");
Contact contact2 = new Contact();
contact2.setName("contact2");
contact2.setMsisdn("901234567890");
List<Contact> contactList = new ArrayList<>();
contactList.add(contact);
contactList.add(contact2);
Gson gson = new Gson();
String request = gson.toJson(contactList);
MvcResult result = mvc.perform(
post("/users/test/{groupId}","123")
.with(httpBasic(username,password))
.contentType(MediaType.APPLICATION_JSON_VALUE)
.accept(MediaType.APPLICATION_JSON_VALUE)
.content(request)
)
.andDo(print())
.andExpect(status().isOk())
.andReturn();
}
When use String instead of List in RequestBody 200 success returned. What is my mistake about collection in requestbody how can i fix it?