Search in sources :

Example 1 with GobiResponse

use of org.folio.rest.gobi.model.GobiResponse 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 GobiResponse

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

the class GOBIIntegrationServiceResourceImplTest method testPostGobiOrdersFailedToRetrieveExistingOrder.

@Test
public final void testPostGobiOrdersFailedToRetrieveExistingOrder() throws Exception {
    logger.info("Begin: Testing for 201 - Create new Order if retrieving existing Order fails");
    final String body = getMockData(PO_LISTED_ELECTRONIC_SERIAL_PATH);
    final GobiResponse order = postOrderSuccess(body, new Header(MOCK_OKAPI_GET_ORDER_HEADER, MOCK_INSTRUCTION_FAIL_ORDER));
    // should try to fetch the order, and gets 500
    List<JsonObject> getOrder = MockServer.serverRqRs.get(PURCHASE_ORDER, HttpMethod.GET);
    assertNull(getOrder);
    // should create an order if the call to fetch existing order fails
    List<JsonObject> postedOrder = MockServer.serverRqRs.get(PURCHASE_ORDER, HttpMethod.POST);
    assertEquals(1, postedOrder.size());
    // should not call PUT to open order
    List<JsonObject> putOrder = MockServer.serverRqRs.get(COMPOSITE_PURCHASE_ORDER, HttpMethod.PUT);
    assertNull(putOrder);
    // return the created PO Line Number
    assertNotNull(order.getPoLineNumber());
    logger.info("End: Testing for 201 - Create new Order if retrieving existing Order fails");
}
Also used : Header(io.restassured.http.Header) JsonObject(io.vertx.core.json.JsonObject) GobiResponse(org.folio.rest.gobi.model.GobiResponse) Test(org.junit.Test)

Example 3 with GobiResponse

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

the class GOBIIntegrationServiceResourceImplTest method testPostGobiOrdersPOListedElectronicMonographBadData.

@Test
public final void testPostGobiOrdersPOListedElectronicMonographBadData(TestContext context) throws Exception {
    logger.info("Begin: Testing for 400 - posted order listed electronic monograph bad data (missing tag)");
    final Async asyncLocal = context.async();
    final String body = getMockData(PO_LISTED_ELECTRONIC_MONOGRAPH_BAD_DATA_PATH);
    final GobiResponse error = buildRequest(body).when().post(ORDERS_PATH).then().statusCode(400).contentType(ContentType.XML).extract().body().as(GobiResponse.class, ObjectMapperType.JAXB);
    context.assertNotNull(error);
    context.assertNotNull(error.getError());
    context.assertEquals(CODE_INVALID_XML, error.getError().getCode());
    context.assertNotNull(error.getError().getMessage());
    assertTrue(MockServer.serverRqRs.isEmpty());
    asyncLocal.complete();
    logger.info("End: Testing for 400 - posted order listed electronic monograph bad data (missing tag)");
}
Also used : Async(io.vertx.ext.unit.Async) GobiResponse(org.folio.rest.gobi.model.GobiResponse) Test(org.junit.Test)

Example 4 with GobiResponse

use of org.folio.rest.gobi.model.GobiResponse 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 5 with GobiResponse

use of org.folio.rest.gobi.model.GobiResponse 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)

Aggregations

GobiResponse (org.folio.rest.gobi.model.GobiResponse)25 Test (org.junit.Test)23 JsonObject (io.vertx.core.json.JsonObject)20 CompositePurchaseOrder (org.folio.rest.acq.model.CompositePurchaseOrder)15 Async (io.vertx.ext.unit.Async)14 Header (io.restassured.http.Header)10 ArrayList (java.util.ArrayList)7 List (java.util.List)7 AsyncResult (io.vertx.core.AsyncResult)3 Handler (io.vertx.core.Handler)3 Map (java.util.Map)3 LogManager (org.apache.logging.log4j.LogManager)3 Logger (org.apache.logging.log4j.Logger)3 GobiPurchaseOrderParserException (org.folio.gobi.exceptions.GobiPurchaseOrderParserException)3 HttpException (org.folio.gobi.exceptions.HttpException)3 BinaryOutStream (org.folio.rest.tools.utils.BinaryOutStream)3 Vertx (io.vertx.core.Vertx)2 HttpServer (io.vertx.core.http.HttpServer)2 TestContext (io.vertx.ext.unit.TestContext)2 VertxUnitRunner (io.vertx.ext.unit.junit.VertxUnitRunner)2