dimanche 1 janvier 2017

Spring Boot Test: Test Response throws "Could not find acceptable representation" , App works correctly

I am using Spring Boot to create an app. When I run my application, and test the service, I get this which is correct.

Picture of service running

However, when I run my test which looks like this:

public class CatalogControllerTet {
    private MockMvc mvc;
    @Autowired
    private WebApplicationContext context;
    @Autowired
    private CatalogRepository catalogRepository;

    @Before
    public void setUp() throws Exception {
        this.mvc = MockMvcBuilders.webAppContextSetup(this.context).build();
    }

    @Test
    public void getHello() throws Exception {

        MvcResult r = mvc.perform(MockMvcRequestBuilders
                .get("/catalogs")
                .accept(MediaType.APPLICATION_JSON)).andReturn();
        String content = r.getResponse().getContentAsString();
        int i = 100;
    }
}

When I put a breakpoint in my test, I see this. One thing I noticed is that I don't see anything in the "supportedMediaTypes" list mentioning JSON.

I've seen some other similar questions as mine, but they were traced back to the response object not having any getters/setters or something having to do with Jackson libraries. The fact that the service starts up and runs correctly means that it isn't those issues.

enter image description here

Any help on this is greatly appreciated.

Aucun commentaire:

Enregistrer un commentaire