Search in sources :

Example 1 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 2 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 3 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 4 with RequestPatternBuilder

use of com.github.tomakehurst.wiremock.matching.RequestPatternBuilder in project sda-dropwizard-commons by SDA-SE.

the class OpaRule method verify.

@Override
void verify(int count, StubBuilder builder) {
    RequestPatternBuilder requestPattern = buildRequestPattern(builder);
    wireMockClassRule.verify(count, requestPattern);
}
Also used : RequestPatternBuilder(com.github.tomakehurst.wiremock.matching.RequestPatternBuilder)

Example 5 with RequestPatternBuilder

use of com.github.tomakehurst.wiremock.matching.RequestPatternBuilder in project junit-servers by mjeanroy.

the class WireMockTestUtils method assertRequestWithHeader.

/**
 * Verify that a given request has been triggered.
 *
 * @param endpoint Request endpoint.
 * @param method Request method.
 * @param headerName Header name.
 * @param headerValue Header value.
 */
static void assertRequestWithHeader(String endpoint, HttpMethod method, String headerName, String headerValue) {
    UrlPattern urlPattern = urlEqualTo(endpoint);
    RequestMethod rqMethod = new RequestMethod(method.name());
    RequestPatternBuilder rq = new RequestPatternBuilder(rqMethod, urlPattern);
    rq.withHeader(headerName, equalTo(headerValue));
    WireMock.verify(1, rq);
}
Also used : RequestMethod(com.github.tomakehurst.wiremock.http.RequestMethod) RequestPatternBuilder(com.github.tomakehurst.wiremock.matching.RequestPatternBuilder) UrlPattern(com.github.tomakehurst.wiremock.matching.UrlPattern)

Aggregations

RequestPatternBuilder (com.github.tomakehurst.wiremock.matching.RequestPatternBuilder)32 UrlPattern (com.github.tomakehurst.wiremock.matching.UrlPattern)11 Test (org.junit.jupiter.api.Test)10 RequestMethod (com.github.tomakehurst.wiremock.http.RequestMethod)9 RequestPattern (com.github.tomakehurst.wiremock.matching.RequestPattern)6 StubMapping (com.github.tomakehurst.wiremock.stubbing.StubMapping)5 EqualToPattern (com.github.tomakehurst.wiremock.matching.EqualToPattern)4 VerificationResult (com.github.tomakehurst.wiremock.verification.VerificationResult)4 Test (org.junit.Test)4 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)4 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 MockRequest.mockRequest (com.github.tomakehurst.wiremock.matching.MockRequest.mockRequest)2 StringValuePattern (com.github.tomakehurst.wiremock.matching.StringValuePattern)2 GString (groovy.lang.GString)2 Arrays (java.util.Arrays)2