Search in sources :

Example 26 with EqualToJsonPattern

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

the class EholdingsPackagesTest method shouldUpdateAllAttributesInSelectedPackage.

@Test
public void shouldUpdateAllAttributesInSelectedPackage() throws URISyntaxException, IOException {
    boolean updatedSelected = true;
    boolean updatedAllowEbscoToAddTitles = true;
    boolean updatedHidden = true;
    String updatedBeginCoverage = "2003-01-01";
    String updatedEndCoverage = "2004-01-01";
    EqualToJsonPattern putBodyPattern = new EqualToJsonPattern(readFile("requests/rmapi/packages/put-package-is-selected.json"), true, true);
    PackageByIdData packageData = mapper.readValue(getFile(PACKAGE_STUB_FILE), PackageByIdData.class);
    packageData = packageData.toByIdBuilder().isSelected(updatedSelected).customCoverage(CoverageDates.builder().beginCoverage(updatedBeginCoverage).endCoverage(updatedEndCoverage).build()).allowEbscoToAddTitles(updatedAllowEbscoToAddTitles).visibilityData(packageData.getVisibilityData().toBuilder().isHidden(updatedHidden).build()).build();
    String updatedPackageValue = mapper.writeValueAsString(packageData);
    mockUpdateScenario(readFile(PACKAGE_STUB_FILE), updatedPackageValue);
    Package aPackage = putWithOk(PACKAGES_PATH, readFile("requests/kb-ebsco/package/put-package-selected.json"), STUB_TOKEN_HEADER).as(Package.class);
    verify(putRequestedFor(PACKAGE_URL_PATTERN).withRequestBody(putBodyPattern));
    assertEquals(updatedSelected, aPackage.getData().getAttributes().getIsSelected());
    assertEquals(updatedAllowEbscoToAddTitles, aPackage.getData().getAttributes().getAllowKbToAddTitles());
    assertEquals(updatedHidden, aPackage.getData().getAttributes().getVisibilityData().getIsHidden());
    assertEquals(updatedBeginCoverage, aPackage.getData().getAttributes().getCustomCoverage().getBeginCoverage());
    assertEquals(updatedEndCoverage, aPackage.getData().getAttributes().getCustomCoverage().getEndCoverage());
}
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)

Example 27 with EqualToJsonPattern

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

the class EholdingsPackagesTest method shouldUpdateAllAttributesInSelectedPackageAndCreateNewAccessTypeMapping.

@Test
public void shouldUpdateAllAttributesInSelectedPackageAndCreateNewAccessTypeMapping() throws URISyntaxException, IOException {
    List<AccessType> accessTypes = insertAccessTypes(testData(configuration.getId()), vertx);
    String accessTypeId = accessTypes.get(0).getId();
    boolean updatedSelected = true;
    boolean updatedAllowEbscoToAddTitles = true;
    boolean updatedHidden = true;
    String updatedBeginCoverage = "2003-01-01";
    String updatedEndCoverage = "2004-01-01";
    EqualToJsonPattern putBodyPattern = new EqualToJsonPattern(readFile("requests/rmapi/packages/put-package-is-selected.json"), true, true);
    PackageByIdData packageData = mapper.readValue(getFile(PACKAGE_STUB_FILE), PackageByIdData.class);
    packageData = packageData.toByIdBuilder().isSelected(updatedSelected).customCoverage(CoverageDates.builder().beginCoverage(updatedBeginCoverage).endCoverage(updatedEndCoverage).build()).allowEbscoToAddTitles(updatedAllowEbscoToAddTitles).visibilityData(packageData.getVisibilityData().toBuilder().isHidden(updatedHidden).build()).build();
    String updatedPackageValue = mapper.writeValueAsString(packageData);
    mockUpdateScenario(readFile(PACKAGE_STUB_FILE), updatedPackageValue);
    String putBody = String.format(readFile("requests/kb-ebsco/package/put-package-selected-with-access-type.json"), accessTypeId);
    Package aPackage = putWithOk(PACKAGES_PATH, putBody, STUB_TOKEN_HEADER).as(Package.class);
    verify(putRequestedFor(PACKAGE_URL_PATTERN).withRequestBody(putBodyPattern));
    assertEquals(updatedSelected, aPackage.getData().getAttributes().getIsSelected());
    assertEquals(updatedAllowEbscoToAddTitles, aPackage.getData().getAttributes().getAllowKbToAddTitles());
    assertEquals(updatedHidden, aPackage.getData().getAttributes().getVisibilityData().getIsHidden());
    assertEquals(updatedBeginCoverage, aPackage.getData().getAttributes().getCustomCoverage().getBeginCoverage());
    assertEquals(updatedEndCoverage, aPackage.getData().getAttributes().getCustomCoverage().getEndCoverage());
    List<AccessTypeMapping> accessTypeMappingsInDB = getAccessTypeMappings(vertx);
    assertEquals(1, accessTypeMappingsInDB.size());
    assertEquals(aPackage.getData().getId(), accessTypeMappingsInDB.get(0).getRecordId());
    assertEqualsUUID(accessTypeId, accessTypeMappingsInDB.get(0).getAccessTypeId());
    assertEquals(PACKAGE, accessTypeMappingsInDB.get(0).getRecordType());
    assertNotNull(aPackage.getIncluded());
    assertEquals(accessTypeId, aPackage.getData().getRelationships().getAccessType().getData().getId());
    assertEquals(accessTypeId, ((LinkedHashMap<?, ?>) aPackage.getIncluded().get(0)).get("id"));
}
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) AccessTypesTestUtil.insertAccessTypeMapping(org.folio.util.AccessTypesTestUtil.insertAccessTypeMapping) AccessTypeMapping(org.folio.repository.accesstypes.AccessTypeMapping) AccessType(org.folio.rest.jaxrs.model.AccessType) AccessTypesTestUtil.insertAccessType(org.folio.util.AccessTypesTestUtil.insertAccessType) PackageByIdData(org.folio.holdingsiq.model.PackageByIdData) Test(org.junit.Test)

Example 28 with EqualToJsonPattern

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

the class EholdingsPackagesTest method shouldReturn200OnPostPackageWithExistedAccessType.

@Test
public void shouldReturn200OnPostPackageWithExistedAccessType() throws URISyntaxException, IOException {
    String accessTypeId = insertAccessType(testData(configuration.getId()).get(0), vertx);
    String packagePostRMAPIRequestFile = "requests/rmapi/packages/post-package.json";
    String requestBody = String.format(readFile("requests/kb-ebsco/package/post-package-with-access-type-request.json"), accessTypeId);
    Package createdPackage = sendPost(requestBody).as(Package.class);
    assertTrue(Objects.isNull(createdPackage.getData().getAttributes().getTags()));
    EqualToJsonPattern postBodyPattern = new EqualToJsonPattern(readFile(packagePostRMAPIRequestFile), false, true);
    verify(1, postRequestedFor(new UrlPathPattern(new EqualToPattern(PACKAGES_STUB_URL), false)).withRequestBody(postBodyPattern));
    List<AccessTypeMapping> accessTypeMappingsInDB = getAccessTypeMappings(vertx);
    assertEquals(1, accessTypeMappingsInDB.size());
    assertEqualsUUID(accessTypeId, accessTypeMappingsInDB.get(0).getAccessTypeId());
    assertEquals(PACKAGE, accessTypeMappingsInDB.get(0).getRecordType());
    assertNotNull(createdPackage.getIncluded());
    assertEquals(accessTypeId, createdPackage.getData().getRelationships().getAccessType().getData().getId());
    assertEquals(accessTypeId, ((LinkedHashMap<?, ?>) createdPackage.getIncluded().get(0)).get("id"));
}
Also used : EqualToJsonPattern(com.github.tomakehurst.wiremock.matching.EqualToJsonPattern) UrlPathPattern(com.github.tomakehurst.wiremock.matching.UrlPathPattern) EqualToPattern(com.github.tomakehurst.wiremock.matching.EqualToPattern) 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) AccessTypesTestUtil.insertAccessTypeMapping(org.folio.util.AccessTypesTestUtil.insertAccessTypeMapping) AccessTypeMapping(org.folio.repository.accesstypes.AccessTypeMapping) Test(org.junit.Test)

Example 29 with EqualToJsonPattern

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

the class EholdingsPackagesTest method shouldDeletePackageAccessTypeMappingOnDelete.

@Test
public void shouldDeletePackageAccessTypeMappingOnDelete() throws IOException, URISyntaxException {
    String accessTypeId = insertAccessTypes(testData(configuration.getId()), vertx).get(0).getId();
    insertAccessTypeMapping(FULL_PACKAGE_ID, PACKAGE, accessTypeId, vertx);
    mockGet(new EqualToPattern(PACKAGE_BY_ID_URL), CUSTOM_PACKAGE_STUB_FILE);
    EqualToJsonPattern putBodyPattern = new EqualToJsonPattern("{\"isSelected\":false}", true, true);
    mockPut(new EqualToPattern(PACKAGE_BY_ID_URL), putBodyPattern, SC_NO_CONTENT);
    deleteWithNoContent(PACKAGES_PATH, STUB_TOKEN_HEADER);
    List<AccessTypeMapping> mappingsAfterRequest = AccessTypesTestUtil.getAccessTypeMappings(vertx);
    assertThat(mappingsAfterRequest, empty());
}
Also used : EqualToJsonPattern(com.github.tomakehurst.wiremock.matching.EqualToJsonPattern) EqualToPattern(com.github.tomakehurst.wiremock.matching.EqualToPattern) Matchers.containsString(org.hamcrest.Matchers.containsString) AccessTypesTestUtil.insertAccessTypeMapping(org.folio.util.AccessTypesTestUtil.insertAccessTypeMapping) AccessTypeMapping(org.folio.repository.accesstypes.AccessTypeMapping) 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