use of org.folio.rest.jaxrs.model.PackageCostPerUse 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.rest.jaxrs.model.PackageCostPerUse in project mod-kb-ebsco-java by folio-org.
the class PackageCostPerUseConverter method convert.
@Override
public PackageCostPerUse convert(@NotNull PackageCostPerUseResult source) {
var ucPackageCostPerUse = source.getUcPackageCostPerUse();
var titlePackageCost = source.getTitlePackageCostMap();
Double cost;
if (titlePackageCost != null) {
cost = getPackageTitlesTotalCost(titlePackageCost);
} else {
cost = ucPackageCostPerUse.getAnalysis().getCurrent().getCost();
}
var costAnalysis = new CostAnalysis();
var allPlatformUsages = getAllPlatformUsages(ucPackageCostPerUse.getUsage());
switch(source.getPlatformType()) {
case PUBLISHER:
costAnalysis.setPublisherPlatforms(getCostAnalysisAttributes(getPublisherUsages(allPlatformUsages), cost));
break;
case NON_PUBLISHER:
costAnalysis.setNonPublisherPlatforms(getCostAnalysisAttributes(getNonPublisherUsages(allPlatformUsages), cost));
break;
default:
costAnalysis.setPublisherPlatforms(getCostAnalysisAttributes(getPublisherUsages(allPlatformUsages), cost));
costAnalysis.setNonPublisherPlatforms(getCostAnalysisAttributes(getNonPublisherUsages(allPlatformUsages), cost));
costAnalysis.setAllPlatforms(getCostAnalysisAttributes(allPlatformUsages, cost));
}
return new PackageCostPerUse().withPackageId(source.getPackageId()).withType(PackageCostPerUse.Type.PACKAGE_COST_PER_USE).withAttributes(new PackageCostPerUseDataAttributes().withAnalysis(costAnalysis).withParameters(convertParameters(source.getConfiguration())));
}
use of org.folio.rest.jaxrs.model.PackageCostPerUse in project mod-kb-ebsco-java by folio-org.
the class EholdingsCostperuseImplTest method shouldReturnPackageCostPerUse.
@Test
public void shouldReturnPackageCostPerUse() {
int packageId = 222222;
String year = "2019";
String platform = "all";
String stubApigeeGetPackageResponseFile = "responses/uc/packages/get-package-cost-per-use-response.json";
mockSuccessfulPackageCostPerUse(packageId, stubApigeeGetPackageResponseFile);
String kbEbscoResponseFile = "responses/kb-ebsco/costperuse/packages/expected-package-cost-per-use.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);
}
Aggregations