Search in sources :

Example 1 with PackageCollectionItem

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

the class EholdingsPackagesTest method shouldReturnEmptyResponseWhenPackagesReturnedWithErrorOnSearchByTags.

@Test
public void shouldReturnEmptyResponseWhenPackagesReturnedWithErrorOnSearchByTags() {
    savePackage(buildDbPackage(FULL_PACKAGE_ID, configuration.getId(), STUB_PACKAGE_NAME), vertx);
    savePackage(buildDbPackage(FULL_PACKAGE_ID_2, configuration.getId(), STUB_PACKAGE_NAME_2), vertx);
    saveTag(vertx, FULL_PACKAGE_ID, PACKAGE, STUB_TAG_VALUE);
    saveTag(vertx, FULL_PACKAGE_ID_2, PACKAGE, STUB_TAG_VALUE);
    mockGet(new RegexPattern(".*vendors/.*/packages/.*"), HttpStatus.SC_INTERNAL_SERVER_ERROR);
    PackageCollection packageCollection = getWithOk(PACKAGES_ENDPOINT + "?filter[tags]=" + STUB_TAG_VALUE, 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) PackageCollection(org.folio.rest.jaxrs.model.PackageCollection) Test(org.junit.Test)

Example 2 with PackageCollectionItem

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

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

Example 4 with PackageCollectionItem

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

the class EholdingsPackagesTest method shouldReturnPackagesOnSearchWithPagination.

@Test
public void shouldReturnPackagesOnSearchWithPagination() throws IOException, URISyntaxException {
    saveTag(vertx, FULL_PACKAGE_ID, PACKAGE, STUB_TAG_VALUE);
    saveTag(vertx, FULL_PACKAGE_ID_2, PACKAGE, STUB_TAG_VALUE);
    saveTag(vertx, FULL_PACKAGE_ID_3, PACKAGE, STUB_TAG_VALUE);
    setUpPackages(vertx, configuration.getId());
    PackageCollection packageCollection = getWithOk(PACKAGES_ENDPOINT + "?page=2&count=1&filter[tags]=" + STUB_TAG_VALUE, STUB_TOKEN_HEADER).as(PackageCollection.class);
    List<PackageCollectionItem> packages = packageCollection.getData();
    assertEquals(3, (int) packageCollection.getMeta().getTotalResults());
    assertEquals(1, packages.size());
    assertEquals(STUB_PACKAGE_NAME_2, packages.get(0).getAttributes().getName());
}
Also used : PackageCollectionItem(org.folio.rest.jaxrs.model.PackageCollectionItem) PackageCollection(org.folio.rest.jaxrs.model.PackageCollection) Test(org.junit.Test)

Example 5 with PackageCollectionItem

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

the class PackageCollectionResultConverter method convert.

@Override
public PackageCollection convert(@NonNull PackageCollectionResult packagesResult) {
    Packages packages = packagesResult.getPackages();
    List<DbPackage> dbPackages = packagesResult.getDbPackages();
    List<PackageCollectionItem> packageList = mapItems(packages.getPackagesList(), packageData -> {
        PackageCollectionItem item = packageCollectionItemConverter.convert(packageData);
        item.getAttributes().withTags(new Tags().withTagList(getTagsById(dbPackages, createPackageId(packageData))));
        return item;
    });
    return new PackageCollection().withJsonapi(RestConstants.JSONAPI).withMeta(new MetaTotalResults().withTotalResults(packages.getTotalResults())).withData(packageList);
}
Also used : PackageCollectionItem(org.folio.rest.jaxrs.model.PackageCollectionItem) Packages(org.folio.holdingsiq.model.Packages) DbPackage(org.folio.repository.packages.DbPackage) MetaTotalResults(org.folio.rest.jaxrs.model.MetaTotalResults) PackageCollection(org.folio.rest.jaxrs.model.PackageCollection) Tags(org.folio.rest.jaxrs.model.Tags)

Aggregations

PackageCollectionItem (org.folio.rest.jaxrs.model.PackageCollectionItem)11 PackageCollection (org.folio.rest.jaxrs.model.PackageCollection)10 Test (org.junit.Test)9 Matchers.containsString (org.hamcrest.Matchers.containsString)6 AccessType (org.folio.rest.jaxrs.model.AccessType)4 RegexPattern (com.github.tomakehurst.wiremock.matching.RegexPattern)3 AccessTypesTestUtil.insertAccessType (org.folio.util.AccessTypesTestUtil.insertAccessType)2 Packages (org.folio.holdingsiq.model.Packages)1 DbPackage (org.folio.repository.packages.DbPackage)1 Coverage (org.folio.rest.jaxrs.model.Coverage)1 MetaTotalResults (org.folio.rest.jaxrs.model.MetaTotalResults)1 PackageDataAttributes (org.folio.rest.jaxrs.model.PackageDataAttributes)1 Tags (org.folio.rest.jaxrs.model.Tags)1 VisibilityData (org.folio.rest.jaxrs.model.VisibilityData)1