Search in sources :

Example 16 with CompositePurchaseOrder

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

the class GOBIIntegrationServiceResourceImplTest method testPostGobiOrdersContributorNameTypeNotAvailable.

@Test
public final void testPostGobiOrdersContributorNameTypeNotAvailable() throws Exception {
    logger.info("Begin: Testing contributor is ignored if contributor name type cannot be resolved");
    final String body = getMockData(PO_LISTED_ELECTRONIC_MONOGRAPH_PATH);
    GobiResponse order = postOrderSuccess(body, new Header(MOCK_OKAPI_GET_CONTRIBUTOR_NAME_HEADER, MOCK_INSTRUCTION_NOT_EXIST));
    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);
    assertTrue(compPO.getCompositePoLines().get(0).getContributors().isEmpty());
    logger.info("End: Testing contributor is ignored if contributor name type cannot be resolved");
}
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 17 with CompositePurchaseOrder

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

the class GOBIIntegrationServiceResourceImplTest method testPostGobiOrdersFallBackMaterialTypes.

@Test
public final void testPostGobiOrdersFallBackMaterialTypes(TestContext context) throws Exception {
    logger.info("Begin: Testing for falling back to the unspecified material 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(MATERIAL_TYPES, HttpMethod.GET);
    // 2 calls must be made to material types end point, once for non existent and other for unspecified
    assertEquals(2, configEntries.size());
    List<JsonObject> postedOrder = MockServer.serverRqRs.get(PURCHASE_ORDER, HttpMethod.POST);
    CompositePurchaseOrder compPO = postedOrder.get(0).mapTo(CompositePurchaseOrder.class);
    assertEquals(UNSPECIFIED_MATERIAL_TYPE_ID, compPO.getCompositePoLines().get(0).getEresource().getMaterialType());
    verifyRequiredFieldsAreMapped(compPO);
    assertNotNull(compPO.getCompositePoLines().get(0).getFundDistribution().get(0).getFundId());
    asyncLocal.complete();
    logger.info("End: Testing for falling back to the unspecified material 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 18 with CompositePurchaseOrder

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

the class GOBIIntegrationServiceResourceImplTest method testPostGobiOrdersPOListedPrintMonograph.

@Test
public final void testPostGobiOrdersPOListedPrintMonograph(TestContext context) throws Exception {
    logger.info("Begin: Testing for 201 - posted order listed print monograph");
    final Async asyncLocal = context.async();
    final String body = getMockData(PO_LISTED_PRINT_MONOGRAPH_PATH);
    final GobiResponse order = postOrderSuccess(body);
    context.assertNotNull(order.getPoLineNumber());
    Map<String, List<JsonObject>> column = MockServer.serverRqRs.column(HttpMethod.GET);
    // Listed Print 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, EXPENSE_CLASS, ACQUISITION_METHOD, MATERIAL_SUPPLIER));
    List<JsonObject> postedOrder = MockServer.serverRqRs.get(PURCHASE_ORDER, HttpMethod.POST);
    CompositePurchaseOrder compPO = postedOrder.get(0).mapTo(CompositePurchaseOrder.class);
    assertThat(compPO.getCompositePoLines().get(0).getCost().getListUnitPriceElectronic(), nullValue());
    assertThat(compPO.getCompositePoLines().get(0).getCost().getListUnitPrice(), equalTo(14.95));
    assertNotNull(compPO.getCompositePoLines().get(0).getFundDistribution().get(0).getFundId());
    assertNotNull(compPO.getCompositePoLines().get(0).getFundDistribution().get(0).getExpenseClassId());
    assertNotNull(compPO.getCompositePoLines().get(0).getAcquisitionMethod());
    verifyRequiredFieldsAreMapped(compPO);
    assertNotNull(compPO.getCompositePoLines().get(0).getFundDistribution().get(0).getFundId());
    assertFalse(compPO.getCompositePoLines().get(0).getTags().getTagList().isEmpty());
    asyncLocal.complete();
    logger.info("End: Testing for 201 - posted order listed print 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)

Example 19 with CompositePurchaseOrder

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

the class GOBIIntegrationServiceResourceImplTest method testPostGobiOrdersNoFundsExist.

@Test
public final void testPostGobiOrdersNoFundsExist() throws Exception {
    logger.info("Begin: Testing for checking if FundId is not set if there are no Funds in the environment");
    final String body = getMockData(PO_LISTED_ELECTRONIC_MONOGRAPH_PATH);
    final GobiResponse order = postOrderSuccess(body, new Header(MOCK_OKAPI_GET_FUND_HEADER, MOCK_INSTRUCTION_NOT_EXIST));
    assertNotNull(order.getPoLineNumber());
    List<JsonObject> fundsRequests = MockServer.serverRqRs.get(FUNDS, HttpMethod.GET);
    // 1 call must be made to Funds endpoint, as there is no default mapping
    assertEquals(1, fundsRequests.size());
    List<JsonObject> postedOrder = MockServer.serverRqRs.get(PURCHASE_ORDER, HttpMethod.POST);
    CompositePurchaseOrder compPO = postedOrder.get(0).mapTo(CompositePurchaseOrder.class);
    verifyRequiredFieldsAreMapped(compPO);
    // Fund Distribution List must be empty, with no proper FundId
    assertEquals(Collections.emptyList(), compPO.getCompositePoLines().get(0).getFundDistribution());
    logger.info("End: Testing for checking if FundId is not set if there are no Funds 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 20 with CompositePurchaseOrder

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

the class GOBIIntegrationServiceResourceImplTest method testPostGobiOrdersPOUnlistedPrintMonograph.

@Test
public final void testPostGobiOrdersPOUnlistedPrintMonograph(TestContext context) throws Exception {
    logger.info("Begin: Testing for 201 - posted order unlisted print monograph");
    final Async asyncLocal = context.async();
    final String body = getMockData(PO_UNLISTED_PRINT_MONOGRAPHPATH);
    final GobiResponse order = postOrderSuccess(body);
    context.assertNotNull(order.getPoLineNumber());
    Map<String, List<JsonObject>> column = MockServer.serverRqRs.column(HttpMethod.GET);
    assertThat(column.keySet(), containsInAnyOrder(CONFIGURATION, CONTRIBUTOR_NAME_TYPES, FUNDS, LOCATION, MATERIAL_TYPES, PURCHASE_ORDER, VENDOR, ACQUISITION_METHOD, MATERIAL_SUPPLIER));
    verifyResourceCreateInventoryNotMapped();
    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());
    assertFalse(compPO.getCompositePoLines().get(0).getTags().getTagList().isEmpty());
    asyncLocal.complete();
    logger.info("End: Testing for 201 - posted order unlisted print 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