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");
}
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");
}
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)");
}
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");
}
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");
}
Aggregations