I'm trying to make a mockMvc call run together with wiremock. But the mockMvc call below in the code keeps throwing 404 instead of the expected 200 HTTP status code.
I know that wiremock is running .. I can do http://localhost:8070/lala through browser when wiremock is running.
Can someone please advise ?
@RunWith(SpringRunner.class)
@SpringBootTest(classes = TestApp.class)
@AutoConfigureMockMvc
public class MyControllerTest {
@Inject
public MockMvc mockMvc;
@ClassRule
public static final WireMockClassRule wireMockRule = new WireMockClassRule(8070);
@Rule
public WireMockClassRule instanceRule = wireMockRule;
public ResponseDefinitionBuilder responseBuilder(HttpStatus httpStatus) {
return aResponse()
.withStatus(httpStatus.value());
}
@Test
public void testOne() throws Exception {
stubFor(WireMock
.request(HttpMethod.GET.name(), urlPathMatching("/lala"))
.willReturn(responseBuilder(HttpStatus.OK)));
Thread.sleep(1000000);
mockMvc.perform(MockMvcRequestBuilders.request(HttpMethod.GET, "/lala")) .andExpect(status().isOk());
}
}