could you please help me.
I try to implement an JUnit-Test for a Restcontroller with parameter PersistentEntityResourceAssembler.
Here is my RestController:
It seems that you have missed something. I faced this error and fixed it, the problem was that I forgot to add an annotation @RequestBody to the parameter of the method. Next code works fine:
//interface:
@ResponseStatus(value = HttpStatus.ACCEPTED)
@RequestMapping(method = RequestMethod.POST, produces = { MediaType.APPLICATION_JSON_VALUE }, consumes = { MediaType.APPLICATION_JSON_VALUE })
public Message greeting(@RequestBody GreetingRequestMessage requestMessage);
//implementation:
public Message greeting(@RequestBody GreetingRequestMessage requestMessage) {
}
//setup @Before:
mvc = MockMvcBuilders.standaloneSetup(testObj).build();
GreetingRequestMessage requestMessage = new GreetingRequestMessage();
payloadString = mapper.writeValueAsString(requestMessage);
//test:
payloadString = mapper.writeValueAsString(request);
mvc.perform(
MockMvcRequestBuilders.post("/greeting")
.content(payloadString)
.contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON))
.andExpect(status().is(202));
From your controller method I don't see if you are using PersistentEntityResourceAssembler. Please check your use case. To fix this, in your controller, you can use @RepositoryRestController instead of @RestController. Please check http://docs.spring.io/spring-data/rest/docs/current/reference/html/#customizing-sdr.overriding-sdr-response-handlers. I found the similar issue has been reported for some different use case. This issue is still in open state. https://jira.spring.io/browse/DATAREST-657