Search in sources :

Example 6 with EqualToJsonPattern

use of com.github.tomakehurst.wiremock.matching.EqualToJsonPattern in project mod-kb-ebsco-java by folio-org.

the class EholdingsTitlesTest method shouldReturn400WhenInvalidPostRequest.

@Test
public void shouldReturn400WhenInvalidPostRequest() throws URISyntaxException, IOException {
    String errorResponse = "responses/rmapi/packages/post-package-400-error-response.json";
    String titlePostStubRequestFile = "requests/kb-ebsco/title/post-title-request.json";
    EqualToJsonPattern postBodyPattern = new EqualToJsonPattern("{\n  \"titleName\" : \"Test Title\",\n  \"edition\" : \"Test edition\",\n  \"publisherName\" : \"Test publisher\",\n  \"pubType\" : \"thesisdissertation\",\n  \"description\" : \"Lorem ipsum dolor sit amet, consectetuer adipiscing elit.\",\n  \"isPeerReviewed\" : true,\n  \"identifiersList\" : [ {\n    \"id\" : \"1111-2222-3333\",\n    \"subtype\" : 2,\n    \"type\" : 0\n  } ],\n  \"contributorsList\" : [ {\n    \"type\" : \"author\",\n    \"contributor\" : \"smith, john\"\n  }, {\n    \"type\" : \"illustrator\",\n    \"contributor\" : \"smith, ralph\"\n  } ],\n  \"peerReviewed\" : true\n}", true, true);
    stubFor(post(new UrlPathPattern(new EqualToPattern("/rm/rmaccounts/" + STUB_CUSTOMER_ID + "/vendors/" + STUB_VENDOR_ID + "/packages/" + STUB_PACKAGE_ID + "/titles"), false)).withRequestBody(postBodyPattern).willReturn(new ResponseDefinitionBuilder().withBody(readFile(errorResponse)).withStatus(SC_BAD_REQUEST)));
    JsonapiError error = postWithStatus(EHOLDINGS_TITLES_PATH, readFile(titlePostStubRequestFile), SC_BAD_REQUEST, STUB_TOKEN_HEADER).as(JsonapiError.class);
    assertErrorContainsTitle(error, "Package with the provided name already exists");
}
Also used : ResponseDefinitionBuilder(com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder) EqualToJsonPattern(com.github.tomakehurst.wiremock.matching.EqualToJsonPattern) UrlPathPattern(com.github.tomakehurst.wiremock.matching.UrlPathPattern) JsonapiError(org.folio.rest.jaxrs.model.JsonapiError) EqualToPattern(com.github.tomakehurst.wiremock.matching.EqualToPattern) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 7 with EqualToJsonPattern

use of com.github.tomakehurst.wiremock.matching.EqualToJsonPattern in project mod-kb-ebsco-java by folio-org.

the class EholdingsResourcesImplTest method shouldDeleteTagsOnDeleteRequest.

@Test
public void shouldDeleteTagsOnDeleteRequest() throws IOException, URISyntaxException {
    saveTag(vertx, STUB_CUSTOM_RESOURCE_ID, RecordType.RESOURCE, STUB_TAG_VALUE);
    EqualToJsonPattern putBodyPattern = new EqualToJsonPattern("{\"isSelected\":false}", true, true);
    deleteResource(putBodyPattern);
    List<String> actualTags = TagsTestUtil.getTags(vertx);
    assertThat(actualTags, empty());
}
Also used : EqualToJsonPattern(com.github.tomakehurst.wiremock.matching.EqualToJsonPattern) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 8 with EqualToJsonPattern

use of com.github.tomakehurst.wiremock.matching.EqualToJsonPattern in project mod-kb-ebsco-java by folio-org.

the class EholdingsResourcesImplTest method shouldSendDeleteRequestForResourceAssociatedWithCustomPackage.

@Test
public void shouldSendDeleteRequestForResourceAssociatedWithCustomPackage() throws IOException, URISyntaxException {
    EqualToJsonPattern putBodyPattern = new EqualToJsonPattern("{\"isSelected\":false}", true, true);
    deleteResource(putBodyPattern);
    verify(1, putRequestedFor(new UrlPathPattern(new EqualToPattern(CUSTOM_RESOURCE_ENDPOINT), false)).withRequestBody(putBodyPattern));
}
Also used : EqualToJsonPattern(com.github.tomakehurst.wiremock.matching.EqualToJsonPattern) UrlPathPattern(com.github.tomakehurst.wiremock.matching.UrlPathPattern) EqualToPattern(com.github.tomakehurst.wiremock.matching.EqualToPattern) Test(org.junit.Test)

Example 9 with EqualToJsonPattern

use of com.github.tomakehurst.wiremock.matching.EqualToJsonPattern in project mod-kb-ebsco-java by folio-org.

the class EholdingsResourcesImplTest method shouldDeselectManagedResourceOnPutWithSelectedFalse.

@Test
public void shouldDeselectManagedResourceOnPutWithSelectedFalse() throws IOException, URISyntaxException, JSONException {
    String stubResponseFile = "responses/rmapi/resources/get-managed-resource-updated-response-is-selected-false.json";
    String expectedResourceFile = "responses/kb-ebsco/resources/expected-managed-resource.json";
    ResourcePutRequest request = readJsonFile("requests/kb-ebsco/resource/put-managed-resource-is-not-selected.json", ResourcePutRequest.class);
    request.getData().getAttributes().setIsSelected(false);
    String actualResponse = mockUpdateResourceScenario(stubResponseFile, MANAGED_RESOURCE_ENDPOINT, STUB_MANAGED_RESOURCE_ID, Json.encode(request));
    Resource expectedResource = readJsonFile(expectedResourceFile, Resource.class);
    expectedResource.getData().getAttributes().setIsSelected(false);
    JSONAssert.assertEquals(Json.encode(expectedResource), actualResponse, false);
    verify(1, putRequestedFor(new UrlPathPattern(new RegexPattern(MANAGED_RESOURCE_ENDPOINT), true)).withRequestBody(new EqualToJsonPattern(readFile("requests/rmapi/resources/put-managed-resource-is-not-selected.json"), true, true)));
}
Also used : EqualToJsonPattern(com.github.tomakehurst.wiremock.matching.EqualToJsonPattern) UrlPathPattern(com.github.tomakehurst.wiremock.matching.UrlPathPattern) RegexPattern(com.github.tomakehurst.wiremock.matching.RegexPattern) ResourcePutRequest(org.folio.rest.jaxrs.model.ResourcePutRequest) DbResource(org.folio.repository.resources.DbResource) Resource(org.folio.rest.jaxrs.model.Resource) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 10 with EqualToJsonPattern

use of com.github.tomakehurst.wiremock.matching.EqualToJsonPattern in project mod-kb-ebsco-java by folio-org.

the class EholdingsPackagesTest method shouldUpdateAllAttributesInCustomPackage.

@Test
public void shouldUpdateAllAttributesInCustomPackage() throws URISyntaxException, IOException {
    boolean updatedSelected = true;
    boolean updatedHidden = true;
    String updatedBeginCoverage = "2003-01-01";
    String updatedEndCoverage = "2004-01-01";
    String updatedPackageName = "name of the ages forever and ever";
    EqualToJsonPattern putBodyPattern = new EqualToJsonPattern(readFile("requests/rmapi/packages/put-package-custom.json"), true, true);
    PackageByIdData packageData = mapper.readValue(getFile(CUSTOM_PACKAGE_STUB_FILE), PackageByIdData.class);
    packageData = packageData.toByIdBuilder().isSelected(updatedSelected).visibilityData(packageData.getVisibilityData().toBuilder().isHidden(updatedHidden).build()).customCoverage(CoverageDates.builder().beginCoverage(updatedBeginCoverage).endCoverage(updatedEndCoverage).build()).packageName(updatedPackageName).contentType("streamingmedia").build();
    String updatedPackageValue = mapper.writeValueAsString(packageData);
    mockUpdateScenario(readFile(CUSTOM_PACKAGE_STUB_FILE), updatedPackageValue);
    Package aPackage = putWithOk(PACKAGES_PATH, readFile("requests/kb-ebsco/package/put-package-custom-multiple-attributes.json"), STUB_TOKEN_HEADER).as(Package.class);
    verify(putRequestedFor(PACKAGE_URL_PATTERN).withRequestBody(putBodyPattern));
    assertEquals(updatedSelected, aPackage.getData().getAttributes().getIsSelected());
    assertEquals(updatedHidden, aPackage.getData().getAttributes().getVisibilityData().getIsHidden());
    assertEquals(updatedBeginCoverage, aPackage.getData().getAttributes().getCustomCoverage().getBeginCoverage());
    assertEquals(updatedEndCoverage, aPackage.getData().getAttributes().getCustomCoverage().getEndCoverage());
    assertEquals(updatedPackageName, aPackage.getData().getAttributes().getName());
    assertEquals(ContentType.STREAMING_MEDIA, aPackage.getData().getAttributes().getContentType());
}
Also used : EqualToJsonPattern(com.github.tomakehurst.wiremock.matching.EqualToJsonPattern) Matchers.containsString(org.hamcrest.Matchers.containsString) Package(org.folio.rest.jaxrs.model.Package) PackagesTestUtil.buildDbPackage(org.folio.util.PackagesTestUtil.buildDbPackage) DbPackage(org.folio.repository.packages.DbPackage) PackagesTestUtil.savePackage(org.folio.util.PackagesTestUtil.savePackage) PackageByIdData(org.folio.holdingsiq.model.PackageByIdData) Test(org.junit.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