Search in sources :

Example 1 with CompositePurchaseOrder

use of org.folio.rest.acq.model.CompositePurchaseOrder in project mod-gobi by folio-org.

the class GOBIIntegrationServiceResourceImplTest method testPostGobiOrdersNoProductIdTypes.

@Test
public final void testPostGobiOrdersNoProductIdTypes() throws Exception {
    logger.info("Begin: Testing for checking if productId is set if there are no productIdTypes in the environment");
    final String body = getMockData(PO_LISTED_ELECTRONIC_MONOGRAPH_PATH);
    final GobiResponse order = postOrderSuccess(body, new Header(MOCK_OKAPI_GET_IDENTIFIER_HEADER, MOCK_INSTRUCTION_NO_PRODUCTYPE));
    assertNotNull(order.getPoLineNumber());
    List<JsonObject> identifierTypes = MockServer.serverRqRs.get(IDENTIFIER_TYPES, HttpMethod.GET);
    // 2 calls must be made to identifiers endpoint
    assertEquals(2, identifierTypes.size());
    List<JsonObject> postedOrder = MockServer.serverRqRs.get(PURCHASE_ORDER, HttpMethod.POST);
    CompositePurchaseOrder compPO = postedOrder.get(0).mapTo(CompositePurchaseOrder.class);
    // assert that the productId is mapped, so that if the order is created in Pending state even though
    // there is no ProductIdType
    assertNull(compPO.getCompositePoLines().get(0).getDetails().getProductIds().get(0).getProductIdType());
    assertNotNull(compPO.getCompositePoLines().get(0).getDetails().getProductIds().get(0).getProductId());
    verifyRequiredFieldsAreMapped(compPO);
    assertNotNull(compPO.getCompositePoLines().get(0).getFundDistribution().get(0).getFundId());
    logger.info("End: Testing for checking if productId is set if there are no productIdTypes in the environment");
}
Also used : Header(io.restassured.http.Header) JsonObject(io.vertx.core.json.JsonObject) CompositePurchaseOrder(org.folio.rest.acq.model.CompositePurchaseOrder) GobiResponse(org.folio.rest.gobi.model.GobiResponse) Test(org.junit.Test)

Example 2 with CompositePurchaseOrder

use of org.folio.rest.acq.model.CompositePurchaseOrder in project mod-gobi by folio-org.

the class GOBIIntegrationServiceResourceImplTest method testPostGobiOrdersFallBackContributorTypeName.

@Test
public final void testPostGobiOrdersFallBackContributorTypeName() throws Exception {
    logger.info("Begin: Testing for falling back to the first random contributor name type, if a non existent code is sent");
    final String body = getMockData(PO_LISTED_ELECTRONIC_MONOGRAPH_PATH);
    GobiResponse order = postOrderSuccess(body, new Header(MOCK_OKAPI_GET_CONTRIBUTOR_NAME_HEADER, MOCK_INSTRUCTION_USE_DEFAULT));
    assertNotNull(order.getPoLineNumber());
    List<JsonObject> types = MockServer.serverRqRs.get(CONTRIBUTOR_NAME_TYPES, HttpMethod.GET);
    // 2 calls must be made
    assertEquals(2, types.size());
    List<JsonObject> postedOrder = MockServer.serverRqRs.get(PURCHASE_ORDER, HttpMethod.POST);
    assertEquals(1, postedOrder.size());
    CompositePurchaseOrder compPO = postedOrder.get(0).mapTo(CompositePurchaseOrder.class);
    verifyRequiredFieldsAreMapped(compPO);
    assertNotNull(compPO.getCompositePoLines().get(0).getContributors().get(0).getContributorNameTypeId());
    assertNotNull(compPO.getCompositePoLines().get(0).getContributors().get(0).getContributor());
    logger.info("End: Testing for falling back to the first random contributor name type, if a non existent code is sent");
}
Also used : Header(io.restassured.http.Header) JsonObject(io.vertx.core.json.JsonObject) CompositePurchaseOrder(org.folio.rest.acq.model.CompositePurchaseOrder) GobiResponse(org.folio.rest.gobi.model.GobiResponse) Test(org.junit.Test)

Example 3 with CompositePurchaseOrder

use of org.folio.rest.acq.model.CompositePurchaseOrder in project mod-gobi by folio-org.

the class GOBIIntegrationServiceResourceImplTest method testPostGobiOrdersPOListedPrintSerial.

@Test
public final void testPostGobiOrdersPOListedPrintSerial(TestContext context) throws Exception {
    logger.info("Begin: Testing for 201 - posted order listed print serial");
    final Async asyncLocal = context.async();
    final String body = getMockData(PO_LISTED_PRINT_SERIAL_PATH);
    final GobiResponse order = postOrderSuccess(body);
    context.assertNotNull(order.getPoLineNumber());
    Map<String, List<JsonObject>> column = MockServer.serverRqRs.column(HttpMethod.GET);
    assertThat(column.keySet(), containsInAnyOrder(CONFIGURATION, FUNDS, LOCATION, MATERIAL_TYPES, PURCHASE_ORDER, VENDOR, EXPENSE_CLASS, ACQUISITION_METHOD, MATERIAL_SUPPLIER));
    List<JsonObject> postedOrder = MockServer.serverRqRs.get(PURCHASE_ORDER, HttpMethod.POST);
    CompositePurchaseOrder compPO = postedOrder.get(0).mapTo(CompositePurchaseOrder.class);
    // verify if default currency is used
    assertEquals("USD", compPO.getCompositePoLines().get(0).getCost().getCurrency());
    verifyRequiredFieldsAreMapped(compPO);
    assertNotNull(compPO.getCompositePoLines().get(0).getFundDistribution().get(0).getFundId());
    assertTrue(compPO.getCompositePoLines().get(0).getTags().getTagList().isEmpty());
    asyncLocal.complete();
    logger.info("End: Testing for 201 - posted order listed print serial");
}
Also used : Async(io.vertx.ext.unit.Async) JsonObject(io.vertx.core.json.JsonObject) List(java.util.List) ArrayList(java.util.ArrayList) CompositePurchaseOrder(org.folio.rest.acq.model.CompositePurchaseOrder) GobiResponse(org.folio.rest.gobi.model.GobiResponse) Test(org.junit.Test)

Example 4 with CompositePurchaseOrder

use of org.folio.rest.acq.model.CompositePurchaseOrder in project mod-gobi by folio-org.

the class GOBIIntegrationServiceResourceImplTest method testPostGobiOrdersFallBackLocation.

@Test
public final void testPostGobiOrdersFallBackLocation(TestContext context) throws Exception {
    logger.info("Begin: Testing for falling back to the first location id, if a non existent code is sent");
    final Async asyncLocal = context.async();
    final String body = getMockData(PO_LISTED_ELECTRONIC_SERIAL_PATH);
    final GobiResponse order = postOrderSuccess(body);
    context.assertNotNull(order.getPoLineNumber());
    List<JsonObject> configEntries = MockServer.serverRqRs.get(LOCATION, HttpMethod.GET);
    // 2 calls must be made to location end point
    assertEquals(2, configEntries.size());
    List<JsonObject> postedOrder = MockServer.serverRqRs.get(PURCHASE_ORDER, HttpMethod.POST);
    CompositePurchaseOrder compPO = postedOrder.get(0).mapTo(CompositePurchaseOrder.class);
    verifyRequiredFieldsAreMapped(compPO);
    asyncLocal.complete();
    logger.info("End: Testing for falling back to tthe first location id, if a non existent code is sent");
}
Also used : Async(io.vertx.ext.unit.Async) JsonObject(io.vertx.core.json.JsonObject) CompositePurchaseOrder(org.folio.rest.acq.model.CompositePurchaseOrder) GobiResponse(org.folio.rest.gobi.model.GobiResponse) Test(org.junit.Test)

Example 5 with CompositePurchaseOrder

use of org.folio.rest.acq.model.CompositePurchaseOrder in project mod-gobi by folio-org.

the class GOBIIntegrationServiceResourceImplTest method testPostGobiOrdersPOListedElectronicMonograph.

@Test
public final void testPostGobiOrdersPOListedElectronicMonograph(TestContext context) throws Exception {
    logger.info("Begin: Testing for 201 - posted order listed electronic monograph");
    final Async asyncLocal = context.async();
    final String body = getMockData(PO_LISTED_ELECTRONIC_MONOGRAPH_PATH);
    final GobiResponse order = postOrderSuccess(body);
    context.assertNotNull(order.getPoLineNumber());
    Map<String, List<JsonObject>> column = MockServer.serverRqRs.column(HttpMethod.GET);
    // Listed Electronic Monograph has to get the Product type ID so there will be an additional call made
    assertThat(column.keySet(), containsInAnyOrder(CONFIGURATION, CONTRIBUTOR_NAME_TYPES, FUNDS, IDENTIFIER_TYPES, LOCATION, MATERIAL_TYPES, PURCHASE_ORDER, VENDOR, ACQUISITION_METHOD, MATERIAL_SUPPLIER));
    List<JsonObject> postedOrder = MockServer.serverRqRs.get(PURCHASE_ORDER, HttpMethod.POST);
    CompositePurchaseOrder compPO = postedOrder.get(0).mapTo(CompositePurchaseOrder.class);
    verifyRequiredFieldsAreMapped(compPO);
    assertNotNull(compPO.getCompositePoLines().get(0).getFundDistribution().get(0).getFundId());
    // make sure that the qualifier field is empty
    assertNull(compPO.getCompositePoLines().get(0).getDetails().getProductIds().get(0).getQualifier());
    assertEquals("9781410352224", compPO.getCompositePoLines().get(0).getDetails().getProductIds().get(0).getProductId());
    assertFalse(compPO.getCompositePoLines().get(0).getTags().getTagList().isEmpty());
    asyncLocal.complete();
    logger.info("End: Testing for 201 - posted order listed electronic monograph");
}
Also used : Async(io.vertx.ext.unit.Async) JsonObject(io.vertx.core.json.JsonObject) List(java.util.List) ArrayList(java.util.ArrayList) CompositePurchaseOrder(org.folio.rest.acq.model.CompositePurchaseOrder) GobiResponse(org.folio.rest.gobi.model.GobiResponse) Test(org.junit.Test)

Aggregations

CompositePurchaseOrder (org.folio.rest.acq.model.CompositePurchaseOrder)21 JsonObject (io.vertx.core.json.JsonObject)20 GobiResponse (org.folio.rest.gobi.model.GobiResponse)17 Test (org.junit.Test)16 Async (io.vertx.ext.unit.Async)12 ArrayList (java.util.ArrayList)12 List (java.util.List)12 Header (io.restassured.http.Header)6 Map (java.util.Map)5 StringUtils (org.apache.commons.lang3.StringUtils)5 LogManager (org.apache.logging.log4j.LogManager)5 Logger (org.apache.logging.log4j.Logger)5 Collections (java.util.Collections)4 Optional (java.util.Optional)4 CompletableFuture (java.util.concurrent.CompletableFuture)4 CompletableFuture.completedFuture (java.util.concurrent.CompletableFuture.completedFuture)4 Collectors (java.util.stream.Collectors)4 Stream (java.util.stream.Stream)4 HelperUtils.extractFundCode (org.folio.gobi.HelperUtils.extractFundCode)4 AcquisitionMethod (org.folio.rest.acq.model.AcquisitionMethod)4