Search in sources :

Example 1 with AccessType

use of org.folio.rest.jaxrs.model.AccessType 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 AccessType

use of org.folio.rest.jaxrs.model.AccessType in project mod-kb-ebsco-java by folio-org.

the class EholdingsPackagesTest method shouldReturnPackageWithAccessTypeOnGetById.

@Test
public void shouldReturnPackageWithAccessTypeOnGetById() throws IOException, URISyntaxException {
    List<AccessType> accessTypes = insertAccessTypes(testData(configuration.getId()), vertx);
    String expectedAccessTypeId = accessTypes.get(0).getId();
    insertAccessTypeMapping(FULL_PACKAGE_ID, PACKAGE, expectedAccessTypeId, vertx);
    mockGet(new RegexPattern(PACKAGE_BY_ID_URL), CUSTOM_PACKAGE_STUB_FILE);
    Package packageData = getWithOk(PACKAGES_ENDPOINT + "/" + FULL_PACKAGE_ID, STUB_TOKEN_HEADER).as(Package.class);
    assertNotNull(packageData.getIncluded());
    assertEquals(expectedAccessTypeId, packageData.getData().getRelationships().getAccessType().getData().getId());
    assertEquals(expectedAccessTypeId, ((LinkedHashMap<?, ?>) packageData.getIncluded().get(0)).get("id"));
}
Also used : RegexPattern(com.github.tomakehurst.wiremock.matching.RegexPattern) 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) AccessType(org.folio.rest.jaxrs.model.AccessType) AccessTypesTestUtil.insertAccessType(org.folio.util.AccessTypesTestUtil.insertAccessType) Test(org.junit.Test)

Example 3 with AccessType

use of org.folio.rest.jaxrs.model.AccessType in project mod-kb-ebsco-java by folio-org.

the class EholdingsTitlesTest method shouldReturnEmptyTitlesOnSearchByAccessTypesThatIsNotExist.

@Test
public void shouldReturnEmptyTitlesOnSearchByAccessTypesThatIsNotExist() throws IOException, URISyntaxException {
    List<AccessType> accessTypes = insertAccessTypes(testData(configuration.getId()), vertx);
    insertAccessTypeMapping(STUB_MANAGED_RESOURCE_ID, RESOURCE, accessTypes.get(0).getId(), vertx);
    insertAccessTypeMapping(STUB_MANAGED_RESOURCE_ID_2, RESOURCE, accessTypes.get(1).getId(), vertx);
    mockGetTitles();
    String resourcePath = EHOLDINGS_TITLES_PATH + "?filter[access-type]=Not Exist";
    TitleCollection titleCollection = getWithOk(resourcePath, STUB_TOKEN_HEADER).as(TitleCollection.class);
    List<TitleCollectionItem> titles = titleCollection.getData();
    assertThat(titles, hasSize(0));
    assertEquals(0, (int) titleCollection.getMeta().getTotalResults());
}
Also used : TitleCollectionItem(org.folio.rest.jaxrs.model.TitleCollectionItem) Matchers.containsString(org.hamcrest.Matchers.containsString) AccessType(org.folio.rest.jaxrs.model.AccessType) TitleCollection(org.folio.rest.jaxrs.model.TitleCollection) Test(org.junit.Test)

Example 4 with AccessType

use of org.folio.rest.jaxrs.model.AccessType in project mod-kb-ebsco-java by folio-org.

the class EholdingsProvidersImplTest method shouldReturnEmptyResponseWhenPackagesReturnedWithErrorOnSearchByAccessType.

@Test
public void shouldReturnEmptyResponseWhenPackagesReturnedWithErrorOnSearchByAccessType() {
    List<AccessType> accessTypes = insertAccessTypes(testData(configuration.getId()), vertx);
    insertAccessTypeMapping(FULL_PACKAGE_ID, PACKAGE, accessTypes.get(0).getId(), vertx);
    insertAccessTypeMapping(FULL_PACKAGE_ID_4, PACKAGE, accessTypes.get(0).getId(), vertx);
    mockGet(new RegexPattern(".*vendors/.*/packages/.*"), SC_INTERNAL_SERVER_ERROR);
    String resourcePath = PROVIDER_PACKAGES + "?filter[access-type]=" + STUB_ACCESS_TYPE_NAME;
    PackageCollection packageCollection = getWithOk(resourcePath, STUB_TOKEN_HEADER).as(PackageCollection.class);
    List<PackageCollectionItem> packages = packageCollection.getData();
    assertEquals(2, (int) packageCollection.getMeta().getTotalResults());
    assertEquals(0, packages.size());
}
Also used : PackageCollectionItem(org.folio.rest.jaxrs.model.PackageCollectionItem) RegexPattern(com.github.tomakehurst.wiremock.matching.RegexPattern) Matchers.containsString(org.hamcrest.Matchers.containsString) PackageCollection(org.folio.rest.jaxrs.model.PackageCollection) AccessType(org.folio.rest.jaxrs.model.AccessType) Test(org.junit.Test)

Example 5 with AccessType

use of org.folio.rest.jaxrs.model.AccessType in project mod-kb-ebsco-java by folio-org.

the class EholdingsProvidersImplTest method shouldReturnPackagesOnSearchByProviderIdAndAccessTypeWithPagination.

@Test
public void shouldReturnPackagesOnSearchByProviderIdAndAccessTypeWithPagination() throws IOException, URISyntaxException {
    List<AccessType> accessTypes = insertAccessTypes(testData(configuration.getId()), vertx);
    insertAccessTypeMapping(FULL_PACKAGE_ID, PACKAGE, accessTypes.get(0).getId(), vertx);
    insertAccessTypeMapping(FULL_PACKAGE_ID_4, PACKAGE, accessTypes.get(1).getId(), vertx);
    String credentialsId = configuration.getId();
    setUpPackage(vertx, credentialsId, STUB_PACKAGE_ID, STUB_VENDOR_ID, STUB_PACKAGE_NAME);
    setUpPackage(vertx, credentialsId, STUB_PACKAGE_ID_2, STUB_VENDOR_ID, STUB_PACKAGE_NAME_2);
    setUpPackage(vertx, credentialsId, STUB_PACKAGE_ID_3, STUB_VENDOR_ID, STUB_PACKAGE_NAME_3);
    String resourcePath = PROVIDER_PACKAGES + "?page=2&count=1&filter[access-type]=" + STUB_ACCESS_TYPE_NAME + "&filter[access-type]=" + STUB_ACCESS_TYPE_NAME_2;
    PackageCollection packageCollection = getWithOk(resourcePath, STUB_TOKEN_HEADER).as(PackageCollection.class);
    List<PackageCollectionItem> packages = packageCollection.getData();
    assertEquals(2, (int) packageCollection.getMeta().getTotalResults());
    assertEquals(1, packages.size());
    assertEquals(STUB_PACKAGE_NAME, packages.get(0).getAttributes().getName());
}
Also used : PackageCollectionItem(org.folio.rest.jaxrs.model.PackageCollectionItem) Matchers.containsString(org.hamcrest.Matchers.containsString) PackageCollection(org.folio.rest.jaxrs.model.PackageCollection) AccessType(org.folio.rest.jaxrs.model.AccessType) Test(org.junit.Test)

Aggregations

AccessType (org.folio.rest.jaxrs.model.AccessType)50 Test (org.junit.Test)41 Matchers.containsString (org.hamcrest.Matchers.containsString)34 AccessTypesTestUtil.insertAccessType (org.folio.util.AccessTypesTestUtil.insertAccessType)26 PackageByIdData (org.folio.holdingsiq.model.PackageByIdData)10 Package (org.folio.rest.jaxrs.model.Package)8 AccessTypeMapping (org.folio.repository.accesstypes.AccessTypeMapping)7 DbPackage (org.folio.repository.packages.DbPackage)7 AccessTypePostRequest (org.folio.rest.jaxrs.model.AccessTypePostRequest)7 AccessTypesTestUtil.insertAccessTypeMapping (org.folio.util.AccessTypesTestUtil.insertAccessTypeMapping)7 PackageCollection (org.folio.rest.jaxrs.model.PackageCollection)6 List (java.util.List)5 Map (java.util.Map)5 CompletableFuture (java.util.concurrent.CompletableFuture)5 Function (java.util.function.Function)5 NotFoundException (javax.ws.rs.NotFoundException)5 EqualToJsonPattern (com.github.tomakehurst.wiremock.matching.EqualToJsonPattern)4 RowSetUtils.toUUID (org.folio.db.RowSetUtils.toUUID)4 CustomerResources (org.folio.holdingsiq.model.CustomerResources)4 RecordKey (org.folio.repository.RecordKey)4