MockMVC and Mockito returns Status expected <200> but was <415>

Also you might add accept

 mockMvc.perform(post("/api/sender/sms/")
            .accept(MediaType.APPLICATION_JSON_UTF8)
            .contentType(MediaType.APPLICATION_JSON_UTF8)
            .content("{ \"serviceName\":\"serviceName\",  \"apiId\":\"apiId\",  \"to\":\"to\",  \"msg\":\"msg\" }")
    )
        .andExpect(MockMvcResultMatchers.status().isOk())
        .andReturn();

You might also be missing some annotations on your controller class. Make sure you use @EnableWebMvc and @Controller

Check out this answer for details


HTTP Error 415 Unsupported media type - means that you send the data which is not supported by the service. In this case it means that you don't set the Content-Type header and actual content in the request. I suppose the JSON is expected content, so your call should look like this:

this.mockMvc.perform(post("/payment").contentType(MediaType.APPLICATION_JSON)
    .content("{\"json\":\"request to be send\"}"))
    .andExpect(status().isOk())
    .and_the_rest_of_validation_part