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);
}
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());
}
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);
}
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());
}
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());
}
Aggregations