Search in sources :

Example 1 with ResourceCollection

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());
}
Also used : ResourceCollection(org.folio.rest.jaxrs.model.ResourceCollection) Test(org.junit.Test)

Example 2 with ResourceCollection

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);
}
Also used : Converter(org.springframework.core.convert.converter.Converter) RestConstants(org.folio.rest.util.RestConstants) MetaTotalResults(org.folio.rest.jaxrs.model.MetaTotalResults) ResourceCollectionResult(org.folio.rmapi.result.ResourceCollectionResult) DbResource(org.folio.repository.resources.DbResource) Tags(org.folio.rest.jaxrs.model.Tags) Autowired(org.springframework.beans.factory.annotation.Autowired) Titles(org.folio.holdingsiq.model.Titles) DbHoldingInfo(org.folio.repository.holdings.DbHoldingInfo) List(java.util.List) Component(org.springframework.stereotype.Component) ListUtils.mapItems(org.folio.common.ListUtils.mapItems) ResourceCollection(org.folio.rest.jaxrs.model.ResourceCollection) NonNull(org.springframework.lang.NonNull) Comparator(java.util.Comparator) ResourceId(org.folio.holdingsiq.model.ResourceId) Title(org.folio.holdingsiq.model.Title) Collections(java.util.Collections) ResourceCollectionItem(org.folio.rest.jaxrs.model.ResourceCollectionItem) DbResource(org.folio.repository.resources.DbResource) MetaTotalResults(org.folio.rest.jaxrs.model.MetaTotalResults) ResourceCollectionItem(org.folio.rest.jaxrs.model.ResourceCollectionItem) DbHoldingInfo(org.folio.repository.holdings.DbHoldingInfo) Titles(org.folio.holdingsiq.model.Titles) ResourceCollection(org.folio.rest.jaxrs.model.ResourceCollection)

Example 3 with ResourceCollection

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))));
}
Also used : ResourceCollectionItem(org.folio.rest.jaxrs.model.ResourceCollectionItem) Matchers.containsString(org.hamcrest.Matchers.containsString) AccessType(org.folio.rest.jaxrs.model.AccessType) AccessTypesTestUtil.insertAccessType(org.folio.util.AccessTypesTestUtil.insertAccessType) ResourceCollection(org.folio.rest.jaxrs.model.ResourceCollection) Test(org.junit.Test)

Example 4 with ResourceCollection

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);
}
Also used : RegexPattern(com.github.tomakehurst.wiremock.matching.RegexPattern) 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) ResourceCollection(org.folio.rest.jaxrs.model.ResourceCollection) Test(org.junit.Test)

Example 5 with ResourceCollection

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));
}
Also used : MetaTotalResults(org.folio.rest.jaxrs.model.MetaTotalResults) ResourceCollection(org.folio.rest.jaxrs.model.ResourceCollection) Test(org.junit.Test)

Aggregations

ResourceCollection (org.folio.rest.jaxrs.model.ResourceCollection)6 Test (org.junit.Test)5 ResourceCollectionItem (org.folio.rest.jaxrs.model.ResourceCollectionItem)3 AccessType (org.folio.rest.jaxrs.model.AccessType)2 MetaTotalResults (org.folio.rest.jaxrs.model.MetaTotalResults)2 AccessTypesTestUtil.insertAccessType (org.folio.util.AccessTypesTestUtil.insertAccessType)2 Matchers.containsString (org.hamcrest.Matchers.containsString)2 RegexPattern (com.github.tomakehurst.wiremock.matching.RegexPattern)1 Collections (java.util.Collections)1 Comparator (java.util.Comparator)1 List (java.util.List)1 ListUtils.mapItems (org.folio.common.ListUtils.mapItems)1 ResourceId (org.folio.holdingsiq.model.ResourceId)1 Title (org.folio.holdingsiq.model.Title)1 Titles (org.folio.holdingsiq.model.Titles)1 DbHoldingInfo (org.folio.repository.holdings.DbHoldingInfo)1 DbPackage (org.folio.repository.packages.DbPackage)1 DbResource (org.folio.repository.resources.DbResource)1 Package (org.folio.rest.jaxrs.model.Package)1 Tags (org.folio.rest.jaxrs.model.Tags)1