Testowanie @Request Springa za pomocą Spring MockMVC

Próbuję przetestować metodę, która wysyła obiekt do bazy danych za pomocą frameworka MockMVC firmy Spring. Skonstruowałem test w następujący sposób:

@Test
public void testInsertObject() throws Exception { 

    String url = BASE_URL + "/object";

    ObjectBean anObject = new ObjectBean();
    anObject.setObjectId("33");
    anObject.setUserId("4268321");
    //... more

    Gson gson = new Gson();
    String json = gson.toJson(anObject);

    MvcResult result = this.mockMvc.perform(
            post(url)
            .contentType(MediaType.APPLICATION_JSON)
            .content(json))
            .andExpect(status().isOk())
            .andReturn();
}

Metoda, którą testuję, używa @RequestBody Springa do otrzymania ObjectBean, ale test zawsze zwraca błąd 400.

@ResponseBody
@RequestMapping(    consumes="application/json",
                    produces="application/json",
                    method=RequestMethod.POST,
                    value="/object")
public ObjectResponse insertObject(@RequestBody ObjectBean bean){

    this.photonetService.insertObject(bean);

    ObjectResponse response = new ObjectResponse();
    response.setObject(bean);

    return response;
}

Json stworzony przez Gsona w teście:

{
   "objectId":"33",
   "userId":"4268321",
   //... many more
}

Klasa ObjectBean

public class ObjectBean {

private String objectId;
private String userId;
//... many more

public String getObjectId() {
    return objectId;
}

public void setObjectId(String objectId) {
    this.objectId = objectId;
}

public String getUserId() {
    return userId;
}

public void setUserId(String userId) {
    this.userId = userId;
}
//... many more
}

Moje pytanie brzmi: jak przetestować tę metodę za pomocą Spring MockMVC?

questionAnswers(3)

yourAnswerToTheQuestion