Search in sources :

Example 1 with DbHoldingInfo

use of org.folio.repository.holdings.DbHoldingInfo in project mod-kb-ebsco-java by folio-org.

the class EholdingsCostperuseImplTest method shouldReturnPackageCostPerUseWhenPackageCostIsEmpty.

@Test
public void shouldReturnPackageCostPerUseWhenPackageCostIsEmpty() {
    int packageId = 222222;
    String year = "2019";
    String platform = "all";
    var holding1 = new DbHoldingInfo(1, packageId, 1, "Ionicis tormentos accelerare!", "Sunt hydraes", "Book");
    var holding2 = new DbHoldingInfo(2, packageId, 1, "Vortex, plasmator, et lixa.", "Est germanus byssus", "Book");
    saveHolding(credentialsId, holding1, OffsetDateTime.now(), vertx);
    saveHolding(credentialsId, holding2, OffsetDateTime.now(), vertx);
    String stubApigeeGetPackageResponseFile = "responses/uc/packages/get-package-cost-per-use-with-empty-cost-response.json";
    mockSuccessfulPackageCostPerUse(packageId, stubApigeeGetPackageResponseFile);
    String stubApigeeGetTitlePackageResponseFile = "responses/uc/title-packages/get-title-packages-cost-per-use-for-package-response.json";
    mockSuccessfulTitlePackageCostPerUse(stubApigeeGetTitlePackageResponseFile);
    String kbEbscoResponseFile = "responses/kb-ebsco/costperuse/packages/expected-package-cost-per-use-when-cost-is-empty.json";
    PackageCostPerUse expected = Json.decodeValue(readFile(kbEbscoResponseFile), PackageCostPerUse.class);
    PackageCostPerUse actual = getWithOk(packageEndpoint(packageId, year, platform), JOHN_TOKEN_HEADER).as(PackageCostPerUse.class);
    assertEquals(expected, actual);
}
Also used : PackageCostPerUse(org.folio.rest.jaxrs.model.PackageCostPerUse) DbHoldingInfo(org.folio.repository.holdings.DbHoldingInfo) Test(org.junit.Test)

Example 2 with DbHoldingInfo

use of org.folio.repository.holdings.DbHoldingInfo in project mod-kb-ebsco-java by folio-org.

the class DefaultLoadHoldingsImplTest method shouldStartLoadingWhenStatusInProgressAndStartedMoreThen5DaysBefore.

@Test
public void shouldStartLoadingWhenStatusInProgressAndStartedMoreThen5DaysBefore(TestContext context) throws IOException, URISyntaxException {
    saveKbCredentials(STUB_CREDENTIALS_ID, getWiremockUrl(), STUB_CREDENTIALS_NAME, STUB_API_KEY, STUB_CUSTOMER_ID, vertx);
    OffsetDateTime dateTime = OffsetDateTime.now().minus(6, ChronoUnit.DAYS);
    HoldingsLoadingStatus statusLoadingHoldings = getStatusLoadingHoldings(1000, 500, 10, 5);
    statusLoadingHoldings.getData().getAttributes().setUpdated(dateTime.format(DateTimeFormatter.ISO_OFFSET_DATE_TIME));
    saveStatus(STUB_CREDENTIALS_ID, statusLoadingHoldings, PROCESS_ID, dateTime, vertx);
    insertRetryStatus(STUB_CREDENTIALS_ID, vertx);
    runPostHoldingsWithMocks(context);
    final List<DbHoldingInfo> holdingsList = HoldingsTestUtil.getHoldings(vertx);
    assertThat(holdingsList.size(), Matchers.notNullValue());
}
Also used : HoldingsLoadingStatus(org.folio.rest.jaxrs.model.HoldingsLoadingStatus) OffsetDateTime(java.time.OffsetDateTime) DbHoldingInfo(org.folio.repository.holdings.DbHoldingInfo) Test(org.junit.Test)

Example 3 with DbHoldingInfo

use of org.folio.repository.holdings.DbHoldingInfo 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 4 with DbHoldingInfo

use of org.folio.repository.holdings.DbHoldingInfo in project mod-kb-ebsco-java by folio-org.

the class TransactionLoadHoldingsImplTest method shouldUpdateHoldingsWithDeltas.

@Test
public void shouldUpdateHoldingsWithDeltas(TestContext context) throws IOException, URISyntaxException {
    HoldingsTestUtil.saveHolding(STUB_CREDENTIALS_ID, Json.decodeValue(readFile("responses/kb-ebsco/holdings/custom-holding.json"), DbHoldingInfo.class), OffsetDateTime.now(), vertx);
    HoldingsTestUtil.saveHolding(STUB_CREDENTIALS_ID, Json.decodeValue(readFile("responses/kb-ebsco/holdings/custom-holding2.json"), DbHoldingInfo.class), OffsetDateTime.now(), vertx);
    TransactionIdTestUtil.addTransactionId(STUB_CREDENTIALS_ID, PREVIOUS_TRANSACTION_ID, vertx);
    HoldingsDownloadTransaction previousTransaction = HoldingsDownloadTransaction.builder().creationDate(OffsetDateTime.now().minus(500, ChronoUnit.HOURS).toString()).transactionId(PREVIOUS_TRANSACTION_ID).build();
    mockTransactionList(Collections.singletonList(previousTransaction));
    mockPostHoldings();
    mockGet(new EqualToPattern(getStatusEndpoint(PREVIOUS_TRANSACTION_ID)), RMAPI_RESPONSE_TRANSACTION_STATUS_COMPLETED);
    mockGet(new EqualToPattern(getStatusEndpoint(TRANSACTION_ID)), RMAPI_RESPONSE_TRANSACTION_STATUS_COMPLETED);
    mockPostDeltaReport();
    mockGet(new EqualToPattern(getDeltaReportStatusEndpoint()), "responses/rmapi/holdings/status/get-delta-report-status-completed.json");
    mockGet(new EqualToPattern(getDeltaEndpoint()), "responses/rmapi/holdings/delta/get-delta.json");
    Async async = context.async();
    handleStatusChange(COMPLETED, holdingsStatusRepository, o -> async.complete());
    postWithStatus(HOLDINGS_LOAD_BY_ID_URL, "", SC_NO_CONTENT, STUB_TOKEN_HEADER);
    async.await(TIMEOUT);
    Map<String, DbHoldingInfo> holdings = HoldingsTestUtil.getHoldings(vertx).stream().collect(Collectors.toMap(this::getHoldingsId, Function.identity()));
    assertFalse(holdings.containsKey(DELETED_HOLDING_ID));
    DbHoldingInfo updatedHolding = holdings.get(UPDATED_HOLDING_ID);
    assertEquals("Test Title Updated", updatedHolding.getPublicationTitle());
    assertEquals("Test one Press Updated", updatedHolding.getPublisherName());
    assertEquals("Book", updatedHolding.getResourceType());
    DbHoldingInfo addedHolding = holdings.get(ADDED_HOLDING_ID);
    assertEquals("Added test title", addedHolding.getPublicationTitle());
    assertEquals("Added test publisher", addedHolding.getPublisherName());
    assertEquals("Book", addedHolding.getResourceType());
}
Also used : HoldingsDownloadTransaction(org.folio.holdingsiq.model.HoldingsDownloadTransaction) Async(io.vertx.ext.unit.Async) EqualToPattern(com.github.tomakehurst.wiremock.matching.EqualToPattern) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) DbHoldingInfo(org.folio.repository.holdings.DbHoldingInfo) Test(org.junit.Test)

Example 5 with DbHoldingInfo

use of org.folio.repository.holdings.DbHoldingInfo in project mod-kb-ebsco-java by folio-org.

the class DefaultLoadHoldingsImplTest method shouldSaveMultiHoldings.

@Test
public void shouldSaveMultiHoldings(TestContext context) throws IOException, URISyntaxException {
    setupDefaultLoadKBConfiguration();
    Async async = context.async();
    handleStatusChange(COMPLETED, holdingsStatusRepository, o -> async.complete());
    mockGet(new EqualToPattern(RMAPI_HOLDINGS_STATUS_URL), RMAPI_RESPONSE_HOLDINGS_STATUS_COMPLETED);
    mockPostHoldings();
    mockGet(new RegexPattern(RMAPI_POST_HOLDINGS_URL), RMAPI_RESPONSE_HOLDINGS);
    postWithStatus(HOLDINGS_LOAD_URL, "", SC_NO_CONTENT, STUB_TOKEN_HEADER);
    async.await(TIMEOUT);
    final List<DbHoldingInfo> holdingsList = HoldingsTestUtil.getHoldings(vertx);
    assertThat(holdingsList.size(), Matchers.notNullValue());
}
Also used : RegexPattern(com.github.tomakehurst.wiremock.matching.RegexPattern) Async(io.vertx.ext.unit.Async) EqualToPattern(com.github.tomakehurst.wiremock.matching.EqualToPattern) DbHoldingInfo(org.folio.repository.holdings.DbHoldingInfo) Test(org.junit.Test)

Aggregations

DbHoldingInfo (org.folio.repository.holdings.DbHoldingInfo)6 Test (org.junit.Test)5 EqualToPattern (com.github.tomakehurst.wiremock.matching.EqualToPattern)2 Async (io.vertx.ext.unit.Async)2 ResourceCollectionItem (org.folio.rest.jaxrs.model.ResourceCollectionItem)2 RegexPattern (com.github.tomakehurst.wiremock.matching.RegexPattern)1 OffsetDateTime (java.time.OffsetDateTime)1 Collections (java.util.Collections)1 Comparator (java.util.Comparator)1 List (java.util.List)1 ListUtils.mapItems (org.folio.common.ListUtils.mapItems)1 HoldingsDownloadTransaction (org.folio.holdingsiq.model.HoldingsDownloadTransaction)1 ResourceId (org.folio.holdingsiq.model.ResourceId)1 Title (org.folio.holdingsiq.model.Title)1 Titles (org.folio.holdingsiq.model.Titles)1 DbResource (org.folio.repository.resources.DbResource)1 HoldingsLoadingStatus (org.folio.rest.jaxrs.model.HoldingsLoadingStatus)1 MetaTotalResults (org.folio.rest.jaxrs.model.MetaTotalResults)1 PackageCostPerUse (org.folio.rest.jaxrs.model.PackageCostPerUse)1 ResourceCollection (org.folio.rest.jaxrs.model.ResourceCollection)1