I try to integrate Unittests in my App and fail on testing an PUT(JSON) REST API.
Test Code:
@RunWith(SpringRunner.class)
@SpringBootTest
@AutoConfigureMockMvc
public class EventOrderRestTest {
@Autowired
private MockMvc mvc;
@Autowired
ObjectMapper objectMapper;
private Integer id;
@Test
public void a_saveNewEventOrder() throws Exception {
EventOrder o = new EventOrder();
o.setPlz(54321);
this.id = Integer.parseInt(
mvc.perform(put("/order")
.contentType(MediaType.APPLICATION_JSON)
.content(objectMapper.writeValueAsString(o))
.accept(MediaType.TEXT_PLAIN))
.andExpect(status().isOk())
.andReturn().getResponse().getContentAsString()
);
}
I have no other Test Configurations in my App.
So while running the API and calling it manually, it returns a code 200 and the new ObjectId.
While the test is running with same value in body it returns a code 406.
Whats wrong with it? What did I miss?