The import org.springframework.test.web.servlet cannot be resolved

I am currently working on an integration test to validate the functionality of my REST endpoint for installing web apps. The unit tests I have written shows that the module works as expected when passed the right arguments but it misses out the request mapping, hence I have not been able to test that the route works when hit.

I aim to do a test that imitates:

     mockMvc.perform(post("/rest/owa/installapp")
           .contentType(MediaType.APPLICATION_JSON)
           .content("{ \"urlValue\": \"https://www.installapp...\" }")      
           .accept(MediaType.APPLICATION_JSON))
           .andExpect(jsonPath("$.urlValue").value("https://www.installapp..."))      

I need to import new packages to make this possible such as:

     import org.springframework.test.web.servlet.MockMvc;
     import org.springframework.test.web.servlet

But they keep throwing up the warning sign that import cannot be resolved. I guess I am missing it in my dependencies but I have not been able to figure how to resolve this issue.

Please how do I go about getting this to work ?

Thanks.

cc @dkayiwa @suthagar23

Can you please send us the commit, then we can check with whole code part.

This is a link to the PR: https://github.com/openmrs/openmrs-module-owa/pull/54/files

The immediate change I am adding to suppport the integration tests can be found here:

openmrs-module-owa/omod/src/test/java/org/openmrs/module/owa/web/routes/OwaRestRoutesTest.java

cc @suthagar23

Here, Why are you using a new MockMvc library?

I think you can achieve this test using existing HttpServletRequest and HttpServletRespones? Did you try that way?

So I wasn’t aware that the HttpServletRequest and HttpServletRespones could get this done until about an hour ago. Trying to test that out but if you do have pointers to resources that can aid me. Please send them along.

Thanks

@afrocode how did this go?

@dkayiwa From my research and the documentation, I couldn’t get a means of making a mock request via the endpoint and getting the actual response back except I try to import the mockMVC I planned to do initially. Why I opted to write the client and test the endpoint via it.