use of org.folio.gobi.DataSourceResolver in project mod-gobi by folio-org.
the class PostGobiOrdersHelperTest method testLookupDefaultOrderMappings.
@Test
public final void testLookupDefaultOrderMappings(TestContext context) {
logger.info("Begin: Testing for Order Mappings to fetch default mappings if configuration Call fails");
final Async async = context.async();
final Vertx vertx = Vertx.vertx();
final HttpServer server = vertx.createHttpServer();
server.requestHandler(req -> {
if (req.path().equals(PostGobiOrdersHelper.CONFIGURATION_ENDPOINT)) {
req.response().setStatusCode(500).end("Unrecheable End point: " + req.path());
}
});
int port = NetworkUtils.nextFreePort();
server.listen(port, "localhost", ar -> {
context.assertTrue(ar.succeeded());
Map<String, String> okapiHeaders = new HashMap<>();
okapiHeaders.put("X-Okapi-Url", "http://localhost:" + port);
okapiHeaders.put("x-okapi-tenant", "testLookupOrderMappings");
PostGobiOrdersHelper pgoh = new PostGobiOrdersHelper(GOBIIntegrationServiceResourceImpl.getHttpClient(okapiHeaders), null, okapiHeaders, vertx.getOrCreateContext());
pgoh.lookupOrderMappings(OrderMappings.OrderType.fromValue("ListedElectronicMonograph")).thenAccept(map -> {
context.assertNotNull(map);
context.assertNotNull(map.get(Mapping.Field.CURRENCY));
DataSourceResolver ds = map.get(Mapping.Field.CURRENCY);
context.assertEquals("//ListPrice/Currency", ds.from);
context.assertEquals("USD", ds.defValue);
context.assertNotNull(map.get(Mapping.Field.LIST_UNIT_PRICE_ELECTRONIC));
ds = map.get(Mapping.Field.LIST_UNIT_PRICE_ELECTRONIC);
context.assertEquals("//ListPrice/Amount", ds.from);
context.assertEquals("0", ds.defValue);
try {
Double result = (Double) ds.translation.apply(ds.defValue.toString()).get();
context.assertEquals(0.0, result);
} catch (Exception e) {
logger.error("Failed to execute translation LIST_PRICE", e);
}
vertx.close(context.asyncAssertSuccess());
async.complete();
});
});
}
use of org.folio.gobi.DataSourceResolver in project mod-gobi by folio-org.
the class PostGobiOrdersHelperTest method testLookupOrderMappings.
@Test
public final void testLookupOrderMappings(TestContext context) {
final Async async = context.async();
final Vertx vertx = Vertx.vertx();
final HttpServer server = vertx.createHttpServer();
server.requestHandler(req -> {
if (req.path().equals(PostGobiOrdersHelper.CONFIGURATION_ENDPOINT)) {
req.response().setStatusCode(200).putHeader("content-type", "application/json").sendFile("ConfigData/success.json");
} else {
req.response().setStatusCode(500).end("Unexpected call: " + req.path());
}
});
int port = NetworkUtils.nextFreePort();
server.listen(port, "localhost", ar -> {
context.assertTrue(ar.succeeded());
Map<String, String> okapiHeaders = new HashMap<>();
okapiHeaders.put("X-Okapi-Url", "http://localhost:" + port);
okapiHeaders.put("x-okapi-tenant", "testLookupOrderMappings");
PostGobiOrdersHelper pgoh = new PostGobiOrdersHelper(GOBIIntegrationServiceResourceImpl.getHttpClient(okapiHeaders), null, okapiHeaders, vertx.getOrCreateContext());
pgoh.lookupOrderMappings(OrderMappings.OrderType.fromValue("ListedElectronicMonograph")).thenAccept(map -> {
context.assertNotNull(map);
context.assertNotNull(map.get(Mapping.Field.CURRENCY));
DataSourceResolver ds = map.get(Mapping.Field.CURRENCY);
context.assertEquals("//ListPrice/Currency", ds.from);
context.assertEquals("USD", ds.defValue);
context.assertNotNull(map.get(Mapping.Field.LIST_UNIT_PRICE_ELECTRONIC));
ds = map.get(Mapping.Field.LIST_UNIT_PRICE_ELECTRONIC);
context.assertEquals("//ListPrice/Amount", ds.from);
context.assertEquals("0", ds.defValue);
try {
Double result = (Double) ds.translation.apply(ds.defValue.toString()).get();
context.assertEquals(0.0, result);
} catch (Exception e) {
logger.error("Failed to execute translation LIST_PRICE", e);
}
context.assertNotNull((map.get(Mapping.Field.PO_LINE_ESTIMATED_PRICE)));
ds = map.get(Mapping.Field.PO_LINE_ESTIMATED_PRICE);
context.assertEquals("//NetPrice/Amount", ds.from);
context.assertNotNull(ds.defValue);
DataSourceResolver defVal = (DataSourceResolver) ds.defValue;
context.assertEquals("//ListPrice/Amount//EstPrice", defVal.from);
context.assertEquals("15.0", defVal.defValue);
try {
Double result = (Double) defVal.translation.apply(defVal.defValue.toString()).get();
context.assertEquals(15.0, result);
} catch (Exception e) {
logger.error("Failed to execute translation for ESTIMATED_ PRICE with recursive default mapping", e);
}
vertx.close(context.asyncAssertSuccess());
async.complete();
});
});
}
Aggregations