Search in sources :

Example 11 with EqualToJsonPattern

use of com.github.tomakehurst.wiremock.matching.EqualToJsonPattern in project wiremock by wiremock.

the class RequestBodyPatternFactoryJsonDeserializerTest method correctlyDeserializesWithEqualToJsonMatcher.

@Test
public void correctlyDeserializesWithEqualToJsonMatcher() {
    RequestBodyPatternFactory bodyPatternFactory = deserializeJson("{                                    \n" + "    \"matcher\": \"equalToJson\",    \n" + "    \"ignoreArrayOrder\": false,     \n" + "    \"ignoreExtraElements\": true    \n" + "}                                      ");
    EqualToJsonPattern bodyPattern = (EqualToJsonPattern) bodyPatternFactory.forRequest(mockRequest().body("1"));
    assertThat(bodyPattern.isIgnoreArrayOrder(), is(false));
    assertThat(bodyPattern.isIgnoreExtraElements(), is(true));
}
Also used : EqualToJsonPattern(com.github.tomakehurst.wiremock.matching.EqualToJsonPattern) Test(org.junit.jupiter.api.Test)

Example 12 with EqualToJsonPattern

use of com.github.tomakehurst.wiremock.matching.EqualToJsonPattern in project wiremock by wiremock.

the class RequestBodyEqualToJsonPatternFactoryTest method withIgnoreArrayOrder.

@Test
public void withIgnoreArrayOrder() {
    RequestBodyEqualToJsonPatternFactory patternFactory = new RequestBodyEqualToJsonPatternFactory(true, false);
    EqualToJsonPattern pattern = patternFactory.forRequest(mockRequest().body("{}"));
    assertThat(pattern.getEqualToJson(), is("{}"));
    assertThat(pattern.isIgnoreExtraElements(), is(false));
    assertThat(pattern.isIgnoreArrayOrder(), is(true));
}
Also used : EqualToJsonPattern(com.github.tomakehurst.wiremock.matching.EqualToJsonPattern) Test(org.junit.jupiter.api.Test)

Example 13 with EqualToJsonPattern

use of com.github.tomakehurst.wiremock.matching.EqualToJsonPattern in project wiremock by wiremock.

the class RequestBodyEqualToJsonPatternFactoryTest method withIgnoreExtraElements.

@Test
public void withIgnoreExtraElements() {
    RequestBodyEqualToJsonPatternFactory patternFactory = new RequestBodyEqualToJsonPatternFactory(false, true);
    EqualToJsonPattern pattern = patternFactory.forRequest(mockRequest().body("{}"));
    assertThat(pattern.getEqualToJson(), is("{}"));
    assertThat(pattern.isIgnoreExtraElements(), is(true));
    assertThat(pattern.isIgnoreArrayOrder(), is(false));
}
Also used : EqualToJsonPattern(com.github.tomakehurst.wiremock.matching.EqualToJsonPattern) Test(org.junit.jupiter.api.Test)

Example 14 with EqualToJsonPattern

use of com.github.tomakehurst.wiremock.matching.EqualToJsonPattern in project wiremock by wiremock.

the class RecordingDslAcceptanceTest method supportsInstanceClientWithSpec.

@Test
public void supportsInstanceClientWithSpec() {
    targetService.stubFor(post("/record-this-with-body").willReturn(ok()));
    adminClient.startStubRecording(recordSpec().forTarget(targetBaseUrl).matchRequestBodyWithEqualToJson(true, true));
    client.postJson("/record-this-with-body", "{}");
    List<StubMapping> returnedMappings = adminClient.stopStubRecording().getStubMappings();
    EqualToJsonPattern bodyPattern = (EqualToJsonPattern) returnedMappings.get(0).getRequest().getBodyPatterns().get(0);
    assertThat(bodyPattern.isIgnoreArrayOrder(), is(true));
    assertThat(bodyPattern.isIgnoreExtraElements(), is(true));
}
Also used : EqualToJsonPattern(com.github.tomakehurst.wiremock.matching.EqualToJsonPattern) StubMapping(com.github.tomakehurst.wiremock.stubbing.StubMapping) Test(org.junit.jupiter.api.Test)

Example 15 with EqualToJsonPattern

use of com.github.tomakehurst.wiremock.matching.EqualToJsonPattern in project wiremock by wiremock.

the class RecordingDslAcceptanceTest method supportsDirectDslCallsWithSpec.

@Test
public void supportsDirectDslCallsWithSpec() {
    targetService.stubFor(post("/record-this-with-body").willReturn(ok()));
    proxyingService.startRecording(recordSpec().forTarget(targetBaseUrl).matchRequestBodyWithEqualToJson(true, true));
    client.postJson("/record-this-with-body", "{}");
    List<StubMapping> returnedMappings = proxyingService.stopRecording().getStubMappings();
    EqualToJsonPattern bodyPattern = (EqualToJsonPattern) returnedMappings.get(0).getRequest().getBodyPatterns().get(0);
    assertThat(bodyPattern.isIgnoreArrayOrder(), is(true));
    assertThat(bodyPattern.isIgnoreExtraElements(), is(true));
}
Also used : EqualToJsonPattern(com.github.tomakehurst.wiremock.matching.EqualToJsonPattern) StubMapping(com.github.tomakehurst.wiremock.stubbing.StubMapping) Test(org.junit.jupiter.api.Test)

Aggregations

EqualToJsonPattern (com.github.tomakehurst.wiremock.matching.EqualToJsonPattern)29 Test (org.junit.Test)22 Matchers.containsString (org.hamcrest.Matchers.containsString)18 EqualToPattern (com.github.tomakehurst.wiremock.matching.EqualToPattern)11 DbPackage (org.folio.repository.packages.DbPackage)9 Package (org.folio.rest.jaxrs.model.Package)9 PackagesTestUtil.buildDbPackage (org.folio.util.PackagesTestUtil.buildDbPackage)9 PackagesTestUtil.savePackage (org.folio.util.PackagesTestUtil.savePackage)9 PackageByIdData (org.folio.holdingsiq.model.PackageByIdData)8 UrlPathPattern (com.github.tomakehurst.wiremock.matching.UrlPathPattern)7 AccessTypeMapping (org.folio.repository.accesstypes.AccessTypeMapping)7 AccessTypesTestUtil.insertAccessTypeMapping (org.folio.util.AccessTypesTestUtil.insertAccessTypeMapping)7 Test (org.junit.jupiter.api.Test)5 RegexPattern (com.github.tomakehurst.wiremock.matching.RegexPattern)4 AccessType (org.folio.rest.jaxrs.model.AccessType)4 AccessTypesTestUtil.insertAccessType (org.folio.util.AccessTypesTestUtil.insertAccessType)4 ResponseDefinitionBuilder (com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder)2 StubMapping (com.github.tomakehurst.wiremock.stubbing.StubMapping)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 TestEnvironments (fi.otavanopisto.muikku.TestEnvironments)1