Search in sources :

Example 1 with PackageByIdData

use of org.folio.holdingsiq.model.PackageByIdData in project mod-kb-ebsco-java by folio-org.

the class EholdingsPackagesTest method shouldUpdateAllAttributesInCustomPackageAndCreateNewAccessTypeMapping.

@Test
public void shouldUpdateAllAttributesInCustomPackageAndCreateNewAccessTypeMapping() throws URISyntaxException, IOException {
    List<AccessType> accessTypes = insertAccessTypes(testData(configuration.getId()), vertx);
    String accessTypeId = accessTypes.get(0).getId();
    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);
    String putBody = String.format(readFile("requests/kb-ebsco/package/put-package-custom-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(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());
    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 2 with PackageByIdData

use of org.folio.holdingsiq.model.PackageByIdData in project mod-kb-ebsco-java by folio-org.

the class EholdingsPackagesTest method shouldReturn200WhenSelectingPackage.

@Test
public void shouldReturn200WhenSelectingPackage() throws URISyntaxException, IOException {
    boolean updatedIsSelected = true;
    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(updatedIsSelected).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);
    assertEquals(updatedIsSelected, aPackage.getData().getAttributes().getIsSelected());
    verify(putRequestedFor(PACKAGE_URL_PATTERN).withRequestBody(putBodyPattern));
}
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 3 with PackageByIdData

use of org.folio.holdingsiq.model.PackageByIdData in project mod-kb-ebsco-java by folio-org.

the class EholdingsPackagesTest method shouldPassIsFullPackageAttributeToRMAPI.

@Test
public void shouldPassIsFullPackageAttributeToRMAPI() throws URISyntaxException, IOException {
    PackageByIdData updatedPackage = mapper.readValue(getFile(PACKAGE_STUB_FILE), PackageByIdData.class).toByIdBuilder().isSelected(true).build();
    mockUpdateScenario(readFile(PACKAGE_STUB_FILE), mapper.writeValueAsString(updatedPackage));
    PackagePutRequest request = mapper.readValue(readFile("requests/kb-ebsco/package/put-package-selected.json"), PackagePutRequest.class);
    request.getData().getAttributes().setIsFullPackage(false);
    putWithOk(PACKAGES_PATH, mapper.writeValueAsString(request), STUB_TOKEN_HEADER).as(Package.class);
    PackagePut rmApiPutRequest = mapper.readValue(readFile("requests/rmapi/packages/put-package-is-selected.json"), PackagePut.class).toBuilder().isFullPackage(false).build();
    verify(putRequestedFor(PACKAGE_URL_PATTERN).withRequestBody(new EqualToJsonPattern(mapper.writeValueAsString(rmApiPutRequest), true, true)));
}
Also used : EqualToJsonPattern(com.github.tomakehurst.wiremock.matching.EqualToJsonPattern) PackagePut(org.folio.holdingsiq.model.PackagePut) PackagePutRequest(org.folio.rest.jaxrs.model.PackagePutRequest) PackageByIdData(org.folio.holdingsiq.model.PackageByIdData) Test(org.junit.Test)

Example 4 with PackageByIdData

use of org.folio.holdingsiq.model.PackageByIdData 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)

Example 5 with PackageByIdData

use of org.folio.holdingsiq.model.PackageByIdData in project mod-kb-ebsco-java by folio-org.

the class PackageConverter method convert.

@Override
public Package convert(@NonNull PackageResult result) {
    PackageByIdData packageByIdData = result.getPackageData();
    Titles titles = result.getTitles();
    VendorById vendor = result.getVendor();
    AccessType accessType = result.getAccessType();
    Package packageData = new Package().withData(packageCollectionItemConverter.convert(packageByIdData)).withJsonapi(RestConstants.JSONAPI);
    packageData.getData().withRelationships(createEmptyPackageRelationship()).withType(PACKAGES_TYPE).getAttributes().withProxy(convertToProxy(packageByIdData.getProxy())).withPackageToken(tokenInfoConverter.convert(packageByIdData.getPackageToken())).withTags(result.getTags());
    if (titles != null) {
        packageData.getData().withRelationships(new PackageRelationship().withResources(new HasManyRelationship().withMeta(new MetaDataIncluded().withIncluded(true)).withData(convertResourcesRelationship(packageByIdData, titles))));
        packageData.getIncluded().addAll(resourcesConverter.convert(titles).getData());
    }
    if (vendor != null) {
        packageData.getIncluded().add(vendorConverter.convert(vendor).getData());
        packageData.getData().getRelationships().withProvider(new HasOneRelationship().withData(new RelationshipData().withId(String.valueOf(vendor.getVendorId())).withType(PROVIDERS_TYPE)));
    }
    if (accessType != null) {
        packageData.getIncluded().add(accessType);
        packageData.getData().getRelationships().withAccessType(new HasOneRelationship().withData(new RelationshipData().withId(accessType.getId()).withType(AccessType.Type.ACCESS_TYPES.value())).withMeta(new MetaDataIncluded().withIncluded(true)));
    }
    return packageData;
}
Also used : PackageRelationship(org.folio.rest.jaxrs.model.PackageRelationship) PackageConverterUtils.createEmptyPackageRelationship(org.folio.rest.converter.packages.PackageConverterUtils.createEmptyPackageRelationship) RelationshipData(org.folio.rest.jaxrs.model.RelationshipData) MetaDataIncluded(org.folio.rest.jaxrs.model.MetaDataIncluded) VendorById(org.folio.holdingsiq.model.VendorById) Package(org.folio.rest.jaxrs.model.Package) HasOneRelationship(org.folio.rest.jaxrs.model.HasOneRelationship) Titles(org.folio.holdingsiq.model.Titles) AccessType(org.folio.rest.jaxrs.model.AccessType) PackageByIdData(org.folio.holdingsiq.model.PackageByIdData) HasManyRelationship(org.folio.rest.jaxrs.model.HasManyRelationship)

Aggregations

PackageByIdData (org.folio.holdingsiq.model.PackageByIdData)15 Test (org.junit.Test)11 Package (org.folio.rest.jaxrs.model.Package)9 EqualToJsonPattern (com.github.tomakehurst.wiremock.matching.EqualToJsonPattern)8 DbPackage (org.folio.repository.packages.DbPackage)8 AccessType (org.folio.rest.jaxrs.model.AccessType)8 Matchers.containsString (org.hamcrest.Matchers.containsString)8 PackagesTestUtil.buildDbPackage (org.folio.util.PackagesTestUtil.buildDbPackage)7 PackagesTestUtil.savePackage (org.folio.util.PackagesTestUtil.savePackage)7 AccessTypeMapping (org.folio.repository.accesstypes.AccessTypeMapping)5 AccessTypesTestUtil.insertAccessType (org.folio.util.AccessTypesTestUtil.insertAccessType)5 AccessTypesTestUtil.insertAccessTypeMapping (org.folio.util.AccessTypesTestUtil.insertAccessTypeMapping)5 CustomerResources (org.folio.holdingsiq.model.CustomerResources)2 PackageId (org.folio.holdingsiq.model.PackageId)2 PackagePut (org.folio.holdingsiq.model.PackagePut)2 Title (org.folio.holdingsiq.model.Title)2 Titles (org.folio.holdingsiq.model.Titles)2 VendorById (org.folio.holdingsiq.model.VendorById)2 ResponseDefinitionBuilder (com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder)1 AsyncResult (io.vertx.core.AsyncResult)1