Giriş
Açıklaması şöyle
ÖrnekThis will set up a mock server before each test and tear it down after each test.
Şöyle yaparız
@RunWith(WireMockRunner.class)public class MockServerTest {@Testpublic void testMockServer() throws Exception {stubFor(get(urlEqualTo("/api/endpoint")).willReturn(aResponse().withStatus(200).withHeader("Content-Type", "application/json").withBody("{\"message\": \"Hello, World!\"}")));URL url = new URL("http://localhost:8080/api/endpoint");HttpURLConnection connection = (HttpURLConnection) url.openConnection();connection.setRequestMethod("GET");connection.connect();assertThat(connection.getResponseCode(), is(200));assertThat(connection.getHeaderField("Content-Type"), is("application/json"));assertThat(new BufferedReader(new InputStreamReader(connection.getInputStream())).lines().collect(Collectors.joining()), is("{\"message\": \"Hello, World!\"}"));}}
Hiç yorum yok:
Yorum Gönder