2

Combining server testing MockMvc, and client testing @RestClientTest. Is this possible or will they always clash with each other?

@AutoConfigureMockMvc
@RestClientTest(BackendApiClient.class)
public class ApiGatewayControllerTest extends ApiTest {

    @Autowired
    private MockMvc mockMvc;

    @Autowired
    private MockRestServiceServer mockServer;

    @Test
    public void get_backend_defs_should_return_200() throws Exception {
        mockServer.expect(ExpectedCount.once(), requestTo("/apirepo"))
                .andExpect(method(HttpMethod.GET))
                .andRespond(withStatus(HttpStatus.OK)
                .contentType(MediaType.APPLICATION_JSON)
                .body(loadFileAsString("json/client/get_all.json")));


        getJson("/get/backend").andExpect(isOk()).andExpect(
                MockMvcResultMatchers.content().json(loadFileAsString("json/controller/get_all.json")));
        mockServer.verify();
    }

    private ResultActions getJson(String path) throws Exception {
        return mockMvc.perform(
            MockMvcRequestBuilders.get(path).accept(MediaType.APPLICATION_JSON));
    }

}

Thank you

Karakaz
  • 33
  • 4

0 Answers0