Search in sources :

Example 6 with RequestPatternBuilder

use of com.github.tomakehurst.wiremock.matching.RequestPatternBuilder in project furms by unity-idm.

the class UnityClientTest method shouldSend_DELETE_toUnityServer.

@Test
void shouldSend_DELETE_toUnityServer() {
    // given
    RequestPattern request = new RequestPatternBuilder(DELETE, new UrlPattern(new EqualToPattern("/path/to/unity/test?recursive=true"), false)).build();
    server.addStubMapping(new StubMapping(request, ResponseDefinitionBuilder.responseDefinition().withHeader(CONTENT_TYPE, APPLICATION_JSON_VALUE).withStatus(SC_OK).build()));
    // when
    unityClient.delete("/path/to/unity/test", Map.of("recursive", TRUE.toString()));
    // then
    VerificationResult verificationResult = server.countRequestsMatching(request);
    assertThat(verificationResult.getCount()).isEqualTo(1);
}
Also used : VerificationResult(com.github.tomakehurst.wiremock.verification.VerificationResult) EqualToPattern(com.github.tomakehurst.wiremock.matching.EqualToPattern) StubMapping(com.github.tomakehurst.wiremock.stubbing.StubMapping) RequestPattern(com.github.tomakehurst.wiremock.matching.RequestPattern) RequestPatternBuilder(com.github.tomakehurst.wiremock.matching.RequestPatternBuilder) UrlPattern(com.github.tomakehurst.wiremock.matching.UrlPattern) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 7 with RequestPatternBuilder

use of com.github.tomakehurst.wiremock.matching.RequestPatternBuilder in project furms by unity-idm.

the class UnityClientTest method shouldSend_GET_toUnityServer.

@Test
void shouldSend_GET_toUnityServer() {
    // given
    RequestPattern request = new RequestPatternBuilder(GET, new UrlPattern(new EqualToPattern("/path/to/unity/test?param1=stringValue&param2=1"), false)).build();
    server.addStubMapping(new StubMapping(request, ResponseDefinitionBuilder.responseDefinition().withBody("{\"field\": \"string_value\"}").withHeader(CONTENT_TYPE, APPLICATION_JSON_VALUE).withStatus(SC_OK).build()));
    // when
    SampleDto response = unityClient.get("/path/to/unity/test", SampleDto.class, Map.of("param1", "stringValue", "param2", "1"));
    // then
    VerificationResult verificationResult = server.countRequestsMatching(request);
    assertThat(verificationResult.getCount()).isEqualTo(1);
    assertThat(response.getField()).isEqualTo("string_value");
}
Also used : VerificationResult(com.github.tomakehurst.wiremock.verification.VerificationResult) EqualToPattern(com.github.tomakehurst.wiremock.matching.EqualToPattern) StubMapping(com.github.tomakehurst.wiremock.stubbing.StubMapping) RequestPattern(com.github.tomakehurst.wiremock.matching.RequestPattern) RequestPatternBuilder(com.github.tomakehurst.wiremock.matching.RequestPatternBuilder) UrlPattern(com.github.tomakehurst.wiremock.matching.UrlPattern) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 8 with RequestPatternBuilder

use of com.github.tomakehurst.wiremock.matching.RequestPatternBuilder in project testnorge by navikt.

the class JsonWiremockHelper method verifyGet.

public void verifyGet() {
    RequestPatternBuilder requestPatternBuilder = getRequestedFor(urlPathPattern);
    verify(requestPatternBuilder);
}
Also used : RequestPatternBuilder(com.github.tomakehurst.wiremock.matching.RequestPatternBuilder)

Example 9 with RequestPatternBuilder

use of com.github.tomakehurst.wiremock.matching.RequestPatternBuilder in project testnorge by navikt.

the class JsonWiremockHelper method verifyPost.

public void verifyPost() {
    RequestPatternBuilder requestPatternBuilder = postRequestedFor(urlPathPattern);
    if (requestBody != null) {
        if (requestFieldsToIgnore.isEmpty()) {
            requestPatternBuilder.withRequestBody(equalToJson(requestBody));
        } else {
            requestPatternBuilder.withRequestBody(matching(convertToRegexString(requestBody, requestFieldsToIgnore.toArray(String[]::new))));
        }
    }
    verify(requestPatternBuilder);
}
Also used : RequestPatternBuilder(com.github.tomakehurst.wiremock.matching.RequestPatternBuilder)

Example 10 with RequestPatternBuilder

use of com.github.tomakehurst.wiremock.matching.RequestPatternBuilder in project testnorge by navikt.

the class JsonWiremockHelper method verifyDelete.

public void verifyDelete() {
    RequestPatternBuilder requestPatternBuilder = deleteRequestedFor(urlPathPattern);
    if (requestBody != null) {
        if (requestFieldsToIgnore.isEmpty()) {
            requestPatternBuilder.withRequestBody(equalToJson(requestBody));
        } else {
            requestPatternBuilder.withRequestBody(matching(convertToRegexString(requestBody, requestFieldsToIgnore.toArray(String[]::new))));
        }
    }
    verify(requestPatternBuilder);
}
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