Search in sources :

Example 11 with RequestPatternBuilder

use of com.github.tomakehurst.wiremock.matching.RequestPatternBuilder in project dsbulk by datastax.

the class PrometheusManagerTest method should_push_metrics_to_gateway.

@ParameterizedTest
@MethodSource
@ExtendWith(WiremockResolver.class)
void should_push_metrics_to_gateway(boolean success, boolean groupByInstance, boolean groupByOperationId, ImmutableMap<String, String> groupingKeys, String pathRegex, @Wiremock WireMockServer server) throws MalformedURLException {
    // given
    PushConfig pushConfig = new PushConfig(new URL(server.baseUrl()), "user1", "password1", groupByInstance, groupByOperationId, groupingKeys);
    PrometheusManager manager = new PrometheusManager(registry, "execution1", "job1", ImmutableMap.of("name1", "value1"), null, pushConfig);
    server.givenThat(post(urlPathEqualTo(pathRegex)).willReturn(aResponse().withStatus(201)));
    // when
    manager.init();
    registry.counter("records/total").inc(123456);
    manager.pushMetrics(Duration.ofSeconds(123), success);
    // then
    String version = WorkflowUtils.getBulkLoaderVersion();
    String driverVersion = Session.OSS_DRIVER_COORDINATES.getVersion().toString();
    String expectedLabelsAsString = "{name1=\"value1\",application_version=\"" + version + "\",application_name=\"DataStax Bulk Loader execution1\",client_id=\"de13b396-eb09-31d1-9876-cba56b790be0\",driver_version=\"" + driverVersion + "\",operation_id=\"execution1\",job=\"job1\",}";
    RequestPatternBuilder builder = postRequestedFor(urlPathMatching(pathRegex)).withHeader("Content-Type", containing("text/plain")).withHeader("Authorization", equalTo("Basic dXNlcjE6cGFzc3dvcmQx")).withRequestBody(containing("dsbulk_elapsed_time_seconds" + expectedLabelsAsString + " 123.0")).withRequestBody(containing("dsbulk_records_total" + expectedLabelsAsString + " 123456.0"));
    if (success) {
        builder = builder.withRequestBody(containing("dsbulk_success" + expectedLabelsAsString + " 1.0")).withRequestBody(containing("dsbulk_last_success" + expectedLabelsAsString));
    } else {
        builder = builder.withRequestBody(containing("dsbulk_success" + expectedLabelsAsString + " 0.0")).withRequestBody(notMatching(".*dsbulk_last_success.*"));
    }
    server.verify(builder);
}
Also used : PushConfig(com.datastax.oss.dsbulk.workflow.commons.metrics.prometheus.PrometheusManager.PushConfig) RequestPatternBuilder(com.github.tomakehurst.wiremock.matching.RequestPatternBuilder) URL(java.net.URL) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource) ExtendWith(org.junit.jupiter.api.extension.ExtendWith)

Example 12 with RequestPatternBuilder

use of com.github.tomakehurst.wiremock.matching.RequestPatternBuilder in project spring-boot-admin by codecentric.

the class AbstractClientApplicationTest method test_context.

@Test
public void test_context() throws InterruptedException, UnknownHostException {
    cdl.await();
    Thread.sleep(2500);
    String hostName = InetAddress.getLocalHost().getCanonicalHostName();
    String serviceHost = "http://" + hostName + ":" + getServerPort();
    String managementHost = "http://" + hostName + ":" + getManagementPort();
    RequestPatternBuilder request = postRequestedFor(urlEqualTo("/instances"));
    request.withHeader("Content-Type", equalTo("application/json")).withRequestBody(matchingJsonPath("$.name", equalTo("Test-Client"))).withRequestBody(matchingJsonPath("$.healthUrl", equalTo(managementHost + "/mgmt/health"))).withRequestBody(matchingJsonPath("$.managementUrl", equalTo(managementHost + "/mgmt"))).withRequestBody(matchingJsonPath("$.serviceUrl", equalTo(serviceHost + "/"))).withRequestBody(matchingJsonPath("$.metadata.startup", matching(".+")));
    wireMock.verify(request);
}
Also used : RequestPatternBuilder(com.github.tomakehurst.wiremock.matching.RequestPatternBuilder) Test(org.junit.jupiter.api.Test)

Example 13 with RequestPatternBuilder

use of com.github.tomakehurst.wiremock.matching.RequestPatternBuilder in project spring-boot-admin by codecentric.

the class AbstractRegistrationClientTest method register_should_return_id_when_successful.

@Test
public void register_should_return_id_when_successful() {
    ResponseDefinitionBuilder response = created().withHeader("Content-Type", "application/json").withHeader("Location", this.wireMock.url("/instances/abcdef")).withBody("{ \"id\" : \"-id-\" }");
    this.wireMock.stubFor(post(urlEqualTo("/instances")).willReturn(response));
    assertThat(this.registrationClient.register(this.wireMock.url("/instances"), this.application)).isEqualTo("-id-");
    RequestPatternBuilder expectedRequest = postRequestedFor(urlEqualTo("/instances")).withHeader("Accept", equalTo("application/json")).withHeader("Content-Type", equalTo("application/json"));
    this.wireMock.verify(expectedRequest);
}
Also used : ResponseDefinitionBuilder(com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder) RequestPatternBuilder(com.github.tomakehurst.wiremock.matching.RequestPatternBuilder) Test(org.junit.jupiter.api.Test)

Example 14 with RequestPatternBuilder

use of com.github.tomakehurst.wiremock.matching.RequestPatternBuilder in project sonar-java by SonarSource.

the class WireMockTest method verifyClient.

@Test
public void verifyClient() {
    // Compliant
    RequestPatternBuilder requestPatternBuilder = new RequestPatternBuilder().allRequests().withUrl("/hello/world/*");
    WireMock.verify(requestPatternBuilder);
}
Also used : RequestPatternBuilder(com.github.tomakehurst.wiremock.matching.RequestPatternBuilder) Test(org.junit.Test)

Example 15 with RequestPatternBuilder

use of com.github.tomakehurst.wiremock.matching.RequestPatternBuilder in project mule-oauth-module by mulesoft.

the class AbstractOAuthAuthorizationTestCase method verifyRequestDoneToTokenUrlForAuthorizationCode.

protected void verifyRequestDoneToTokenUrlForAuthorizationCode(boolean requestThroughProxy) throws UnsupportedEncodingException {
    final RequestPatternBuilder verification = postRequestedFor(urlEqualTo(TOKEN_PATH)).withRequestBody(containing(CLIENT_ID_PARAMETER + "=" + encode(clientId.getValue(), UTF_8.name()))).withRequestBody(containing(CODE_PARAMETER + "=" + encode(AUTHENTICATION_CODE, UTF_8.name()))).withRequestBody(containing(CLIENT_SECRET_PARAMETER + "=" + encode(clientSecret.getValue(), UTF_8.name()))).withRequestBody(containing(GRANT_TYPE_PARAMETER + "=" + encode(GRANT_TYPE_AUTHENTICATION_CODE, UTF_8.name()))).withRequestBody(containing(REDIRECT_URI_PARAMETER + "=" + encode(localCallbackUrl.getValue(), UTF_8.name())));
    if (requestThroughProxy) {
        verification.withHeader(PROXY_CONNECTION_HEADER, containing(KEEP_ALIVE));
        proxyWireMockRule.verify(postRequestedFor(urlEqualTo(TOKEN_PATH)));
    }
    wireMockRule.verify(verification);
}
Also used : RequestPatternBuilder(com.github.tomakehurst.wiremock.matching.RequestPatternBuilder)

Aggregations

RequestPatternBuilder (com.github.tomakehurst.wiremock.matching.RequestPatternBuilder)37 Test (org.junit.jupiter.api.Test)13 UrlPattern (com.github.tomakehurst.wiremock.matching.UrlPattern)11 RequestMethod (com.github.tomakehurst.wiremock.http.RequestMethod)9 RequestPattern (com.github.tomakehurst.wiremock.matching.RequestPattern)6 StubMapping (com.github.tomakehurst.wiremock.stubbing.StubMapping)5 Map (java.util.Map)5 Test (org.junit.Test)5 EqualToPattern (com.github.tomakehurst.wiremock.matching.EqualToPattern)4 VerificationResult (com.github.tomakehurst.wiremock.verification.VerificationResult)4 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)4 AbstractWireMockTest (com.redhat.service.smartevents.test.wiremock.AbstractWireMockTest)3 QuarkusTest (io.quarkus.test.junit.QuarkusTest)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 WireMock (com.github.tomakehurst.wiremock.client.WireMock)2 Parameters (com.github.tomakehurst.wiremock.extension.Parameters)2 Request (com.github.tomakehurst.wiremock.http.Request)2 ContentPattern (com.github.tomakehurst.wiremock.matching.ContentPattern)2