Search in sources :

Example 1 with OrderType

use of org.folio.rest.mappings.model.OrderMappings.OrderType in project mod-gobi by folio-org.

the class MappingHelperTest method setUp.

@Before
public void setUp() {
    logger.info("Begin: SetUp by initializing a default mapping");
    JsonObject expectedListedPrintMonographJsonObj = new JsonObject();
    expectedListedPrintMonographJsonObj.put("orderType", "ListedPrintMonograph");
    JsonObject accessProvider = new JsonObject().put("field", ACCESS_PROVIDER.value()).put("dataSource", new JsonObject().put("from", "//PurchaseOption/VendorPOCode").put("translation", "lookupOrganization"));
    JsonObject expenseClass = new JsonObject().put("field", EXPENSE_CLASS.value()).put("dataSource", new JsonObject().put("from", "//LocalData[Description='LocalData5']/Value").put("translation", "lookupExpenseClassId"));
    ;
    expectedListedPrintMonographJsonObj.put("mappings", new JsonArray().add(accessProvider).add(expenseClass));
    JsonObject combinatorTitle = new JsonObject().put("field", TITLE.value()).put("dataSource", new JsonObject().put("from", "//datafield[@tag='245']/*").put("combinator", "concat"));
    ;
    expectedListedPrintMonographJsonObj.put("mappings", new JsonArray().add(accessProvider).add(expenseClass).add(combinatorTitle));
    String expectedListedPrintMonographJson = expectedListedPrintMonographJsonObj.toString();
    JsonObject expectedUnListedPrintMonographJsonObj = new JsonObject();
    expectedUnListedPrintMonographJsonObj.put("orderType", "UnlistedPrintMonograph");
    expectedUnListedPrintMonographJsonObj.put("mappings", new JsonArray().add(new JsonObject().put("field", "PRODUCT_ID").put("dataSource", new JsonObject().put("from", "//datafield[@tag='020']/subfield[@code='a']"))).add(new JsonObject().put("field", "CONTRIBUTOR").put("dataSource", new JsonObject().put("from", "//datafield[@tag='100']/*").put("combinator", "concat"))));
    String expectedUnListedPrintMonographJson = expectedUnListedPrintMonographJsonObj.toString();
    actualListedPrintJson = MappingHelper.readMappingsFile(LISTED_PRINT_PATH);
    assertEquals(expectedListedPrintMonographJson, actualListedPrintJson.replaceAll("\\s", ""));
    actuallistedPrintMappings = Json.decodeValue(actualListedPrintJson, OrderMappings.class);
    actualUnlistedPrintJson = MappingHelper.readMappingsFile(UNLISTED_PRINT_PATH);
    assertEquals(expectedUnListedPrintMonographJson, actualUnlistedPrintJson.replaceAll("\\s", ""));
    actualUnlistedPrintMappings = Json.decodeValue(actualUnlistedPrintJson, OrderMappings.class);
    OrderType orderType1 = actuallistedPrintMappings.getOrderType();
    OrderType orderType2 = actualUnlistedPrintMappings.getOrderType();
    assertEquals(EXPECTEDORDERTYPE1, orderType1.toString());
    assertEquals(EXPECTEDORDERTYPE2, orderType2.toString());
    List<Mapping> mappingsList1 = actuallistedPrintMappings.getMappings();
    List<Mapping> mappingsList2 = actualUnlistedPrintMappings.getMappings();
    mappingAccessProvider = mappingsList1.get(0);
    mappingExpenseClass = mappingsList1.get(1);
    mappingCombinatorNotExist = mappingsList1.get(2);
    mappingCombinatorNotExist.getDataSource().setCombinator(null);
    mapping2 = mappingsList2.get(0);
    assertEquals(3, mappingsList1.size());
    assertEquals(2, mappingsList2.size());
    assertEquals(Mapping.Field.ACCESS_PROVIDER.value(), mappingAccessProvider.getField().toString());
    assertEquals(EXPENSE_CLASS.value(), mappingExpenseClass.getField().toString());
    assertEquals("PRODUCT_ID", mapping2.getField().toString());
}
Also used : JsonArray(io.vertx.core.json.JsonArray) OrderType(org.folio.rest.mappings.model.OrderMappings.OrderType) OrderMappings(org.folio.rest.mappings.model.OrderMappings) JsonObject(io.vertx.core.json.JsonObject) Mapping(org.folio.rest.mappings.model.Mapping) Before(org.junit.Before)

Aggregations

JsonArray (io.vertx.core.json.JsonArray)1 JsonObject (io.vertx.core.json.JsonObject)1 Mapping (org.folio.rest.mappings.model.Mapping)1 OrderMappings (org.folio.rest.mappings.model.OrderMappings)1 OrderType (org.folio.rest.mappings.model.OrderMappings.OrderType)1 Before (org.junit.Before)1