Java Code Examples for com.github.tomakehurst.wiremock.WireMockServer#stop()

The following examples show how to use com.github.tomakehurst.wiremock.WireMockServer#stop() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NettyNioAsyncHttpClientWireMockTest.java    From aws-sdk-java-v2 with Apache License 2.0 6 votes vote down vote up
@Test
public void builderUsesProvidedTrustManagersProvider() throws Exception {
    WireMockServer selfSignedServer = HttpTestUtils.createSelfSignedServer();

    TrustManagerFactory managerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
    managerFactory.init(HttpTestUtils.getSelfSignedKeyStore());

    try (SdkAsyncHttpClient netty = NettyNioAsyncHttpClient.builder()
                                                           .tlsTrustManagersProvider(managerFactory::getTrustManagers)
                                                           .build()) {
        selfSignedServer.start();
        URI uri = URI.create("https://localhost:" + selfSignedServer.httpsPort());

        SdkHttpRequest request = createRequest(uri);
        RecordingResponseHandler recorder = new RecordingResponseHandler();
        client.execute(AsyncExecuteRequest.builder().request(request).requestContentPublisher(createProvider("")).responseHandler(recorder).build());

        recorder.completeFuture.get(5, TimeUnit.SECONDS);
    } finally {
        selfSignedServer.stop();
    }
}
 
Example 2
Source File: SdkHttpClientTestSuite.java    From aws-sdk-java-v2 with Apache License 2.0 6 votes vote down vote up
@Test
public void testCustomTlsTrustManager() throws Exception {
    WireMockServer selfSignedServer = HttpTestUtils.createSelfSignedServer();

    TrustManagerFactory managerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
    managerFactory.init(HttpTestUtils.getSelfSignedKeyStore());

    SdkHttpClientOptions httpClientOptions = new SdkHttpClientOptions();
    httpClientOptions.tlsTrustManagersProvider(managerFactory::getTrustManagers);

    selfSignedServer.start();

    try {
        SdkHttpClient client = createSdkHttpClient(httpClientOptions);
        SdkHttpFullRequest request = mockSdkRequest("https://localhost:" + selfSignedServer.httpsPort(), SdkHttpMethod.POST);

        client.prepareRequest(HttpExecuteRequest.builder().request(request).build()).call();
    } finally {
        selfSignedServer.stop();
    }
}
 
Example 3
Source File: JSONTest.java    From validatar with Apache License 2.0 6 votes vote down vote up
@Test
public void testGet() throws Exception {
    WireMockServer server = startWireMockServer(WIRE_MOCK_PORT);

    String maxJSON = "\"14\"";
    stubFor(get(urlEqualTo("/api/visits/max")).willReturn(aResponse().withBody(maxJSON)));

    Query query = getQueryFrom("rest-tests/sample.yaml", "Query2");
    json.execute(query);

    Assert.assertFalse(query.failed());
    Assert.assertEquals(query.getResult().getColumns().size(), 1);
    List<TypedObject> max = query.getResult().getColumn("max").getValues();
    Assert.assertEquals(max.size(), 1);
    Assert.assertEquals(max.get(0).data, 14L);
    Assert.assertEquals(max.get(0).type, TypeSystem.Type.LONG);

    server.stop();
}
 
Example 4
Source File: OkHttpMetricsEventListenerTest.java    From micrometer with Apache License 2.0 5 votes vote down vote up
@Test
void timeFailureDueToTimeout(@WiremockResolver.Wiremock WireMockServer server) {
    Request request = new Request.Builder()
            .url(server.baseUrl())
            .build();

    server.stop();

    OkHttpClient client = new OkHttpClient.Builder()
            .connectTimeout(1, TimeUnit.MILLISECONDS)
            .eventListener(OkHttpMetricsEventListener.builder(registry, "okhttp.requests")
                    .tags(Tags.of("foo", "bar"))
                    .uriMapper(URI_MAPPER)
                    .build())
            .build();

    try {
        client.newCall(request).execute().close();
        fail("Expected IOException.");
    } catch (IOException ignored) {
        // expected
    }

    assertThat(registry.get("okhttp.requests")
            .tags("foo", "bar", "uri", URI_EXAMPLE_VALUE, "status", "IO_ERROR", "target.host", "localhost")
            .timer().count()).isEqualTo(1L);
}
 
Example 5
Source File: JSONTest.java    From validatar with Apache License 2.0 5 votes vote down vote up
@Test
public void testPost() throws Exception {
    WireMockServer server = startWireMockServer(WIRE_MOCK_PORT);

    String userJSON = "[{\"name\": \"foo\", \"count\": 4},{\"name\": \"bar\", \"count\": 1}]";
    stubFor(post(urlEqualTo("/api/users")).willReturn(aResponse().withBody(userJSON)));

    Query query = getQueryFrom("rest-tests/sample.yaml", "Query1");
    json.execute(query);

    Assert.assertFalse(query.failed());
    Assert.assertEquals(query.getResult().getColumns().size(), 2);

    List<TypedObject> users = query.getResult().getColumn("users").getValues();
    Assert.assertEquals(users.size(), 2);
    Assert.assertEquals(users.get(0).data, "foo");
    Assert.assertEquals(users.get(0).type, TypeSystem.Type.STRING);
    Assert.assertEquals(users.get(1).data, "bar");
    Assert.assertEquals(users.get(1).type, TypeSystem.Type.STRING);

    List<TypedObject> counts = query.getResult().getColumn("counts").getValues();
    Assert.assertEquals(counts.size(), 2);
    Assert.assertEquals(counts.get(0).data, 4L);
    Assert.assertEquals(counts.get(0).type, TypeSystem.Type.LONG);
    Assert.assertEquals(counts.get(1).data, 1L);
    Assert.assertEquals(counts.get(1).type, TypeSystem.Type.LONG);

    server.stop();
}
 
Example 6
Source File: VersionUtilTest.java    From otroslogviewer with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetCurrentVersion() throws Exception {
  //given
  final WireMockServer wireMockServer = new WireMockServer();
  wireMockServer
    .stubFor(
      get(urlMatching("/currentVersion.*"))
      .willReturn(aResponse()
      .withStatus(200)
      .withBody("currentVersion=1.2.3\n".getBytes()))
    );
  wireMockServer.start();

  final int port = wireMockServer.port();
  final VersionUtil versionUtil = new VersionUtil("http://localhost:" + port+"/currentVersion");
  final OtrosApplication otrosApplication = new OtrosApplication();
  otrosApplication.setConfiguration(new DataConfiguration(new BaseConfiguration()));
  otrosApplication.getConfiguration().setProperty(ConfKeys.UUID,"C9457787-AF59-4B9F-B4E8-FB75334EBEF8");

  //when
  final Optional<String> currentVersion = versionUtil.getCurrentVersion("1.2.3", Proxy.NO_PROXY, otrosApplication);
  wireMockServer.stop();

  //then
  assertEquals(currentVersion,Optional.of("1.2.3"));

}
 
Example 7
Source File: WireMockExtension.java    From junit-servers with MIT License 5 votes vote down vote up
@Override
public void afterEach(ExtensionContext context) {
	Store store = getStore(context);
	WireMockServer wireMockServer = store.get(STORE_KEY, WireMockServer.class);

	try {
		wireMockServer.stop();
	}
	finally {
		store.remove(STORE_KEY);
	}
}
 
Example 8
Source File: WireMockExtension.java    From wiremock-extension with MIT License 4 votes vote down vote up
private static void stopServer(final WireMockServer server) {
	server.stop();
}