use of org.folio.rest.jaxrs.model.ResourceCollection in project mod-kb-ebsco-java by folio-org.
the class EholdingsPackagesTest method shouldReturnEmptyListWhenResourcesAreNotFound.
@Test
public void shouldReturnEmptyListWhenResourcesAreNotFound() throws IOException, URISyntaxException {
mockResourceById(RESOURCES_BY_PACKAGE_ID_EMPTY_STUB_FILE);
ResourceCollection actual = getWithOk(PACKAGE_RESOURCES_PATH, STUB_TOKEN_HEADER).as(ResourceCollection.class);
assertThat(actual.getData(), empty());
assertEquals(0, (int) actual.getMeta().getTotalResults());
}
use of org.folio.rest.jaxrs.model.ResourceCollection in project mod-kb-ebsco-java by folio-org.
the class ResourceCollectionResultConverter method convert.
@Override
public ResourceCollection convert(@NonNull ResourceCollectionResult resourceCollectionResult) {
final Titles titles = resourceCollectionResult.getTitles();
final List<DbResource> resources = resourceCollectionResult.getTitlesList();
final List<DbHoldingInfo> holdings = resourceCollectionResult.getHoldings();
final List<ResourceCollectionItem> resourceCollectionItems = mapItems(titles.getTitleList(), title -> mapResourceCollectionItem(resources, resourceCollectionItemConverter.convert(title), createResourceId(title)));
final List<ResourceCollectionItem> holdingCollectionItems = mapItems(holdings, dbHolding -> mapResourceCollectionItem(resources, holdingCollectionItemConverter.convert(dbHolding), createResourceId(dbHolding)));
resourceCollectionItems.addAll(holdingCollectionItems);
resourceCollectionItems.sort(Comparator.comparing(o -> o.getAttributes().getName()));
return new ResourceCollection().withJsonapi(RestConstants.JSONAPI).withMeta(new MetaTotalResults().withTotalResults(titles.getTotalResults())).withData(resourceCollectionItems);
}
use of org.folio.rest.jaxrs.model.ResourceCollection in project mod-kb-ebsco-java by folio-org.
the class EholdingsPackagesTest method shouldReturnResourcesWithAccessTypesOnGetWithResourcesWithPagination.
@Test
public void shouldReturnResourcesWithAccessTypesOnGetWithResourcesWithPagination() 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);
mockResourceById("responses/rmapi/titles/get-title-by-id-response.json");
String resourcePath = PACKAGES_ENDPOINT + "/" + FULL_PACKAGE_ID + "/resources?page=2&count=1&" + "filter[access-type]=" + STUB_ACCESS_TYPE_NAME + "&filter[access-type]=" + STUB_ACCESS_TYPE_NAME_2;
ResourceCollection resourceCollection = getWithOk(resourcePath, STUB_TOKEN_HEADER).as(ResourceCollection.class);
List<ResourceCollectionItem> resources = resourceCollection.getData();
assertEquals(2, (int) resourceCollection.getMeta().getTotalResults());
assertEquals(1, resources.size());
assertThat(resources, everyItem(hasProperty("id", equalTo(STUB_MANAGED_RESOURCE_ID))));
}
use of org.folio.rest.jaxrs.model.ResourceCollection in project mod-kb-ebsco-java by folio-org.
the class EholdingsPackagesTest method shouldReturnResourcesWhenIncludedFlagIsSetToResources.
@Test
public void shouldReturnResourcesWhenIncludedFlagIsSetToResources() throws IOException, URISyntaxException, JSONException {
mockGet(new RegexPattern(PACKAGE_BY_ID_URL), CUSTOM_PACKAGE_STUB_FILE);
mockResourceById(RESOURCES_BY_PACKAGE_ID_STUB_FILE);
Package packageData = getWithOk(PACKAGES_PATH + "?include=resources", STUB_TOKEN_HEADER).as(Package.class);
Package expectedPackage = mapper.readValue(readFile(EXPECTED_PACKAGE_BY_ID_STUB_FILE), Package.class);
ResourceCollection expectedResources = mapper.readValue(readFile(EXPECTED_RESOURCES_STUB_FILE), ResourceCollection.class);
expectedPackage.getIncluded().addAll(expectedResources.getData());
JSONAssert.assertEquals(mapper.writeValueAsString(expectedPackage), mapper.writeValueAsString(packageData), false);
}
use of org.folio.rest.jaxrs.model.ResourceCollection in project mod-kb-ebsco-java by folio-org.
the class EholdingsPackagesTest method shouldReturnFilteredResourcesWithNonEmptyCustomerResourceList.
@Test
public void shouldReturnFilteredResourcesWithNonEmptyCustomerResourceList() throws IOException, URISyntaxException {
mockResourceById(RESOURCES_BY_PACKAGE_ID_EMPTY_CUSTOMER_RESOURCE_LIST_STUB_FILE);
final ResourceCollection resourceCollection = getWithOk(PACKAGE_RESOURCES_PATH, STUB_TOKEN_HEADER).as(ResourceCollection.class);
final MetaTotalResults metaTotalResults = resourceCollection.getMeta();
assertThat(metaTotalResults.getTotalResults(), equalTo(3));
}
Aggregations