use of org.folio.rest.gobi.model.GobiResponse 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");
}
use of org.folio.rest.gobi.model.GobiResponse in project mod-gobi by folio-org.
the class GOBIIntegrationServiceResourceImplTest method testPostGobiOrdersRetryToOpenOrderSuccess.
@Test
public final void testPostGobiOrdersRetryToOpenOrderSuccess() throws Exception {
logger.info("Begin: Testing for 201 - Return existing Order even if it is pending, and retry to Open succeeds");
final String body = getMockData(PO_LISTED_ELECTRONIC_SERIAL_PATH);
final GobiResponse order = postOrderSuccess(body, new Header(MOCK_OKAPI_GET_ORDER_HEADER, MOCK_INSTRUCTION_GET_PENDING_ORDER));
// should fetch existing order which is in Pending state
List<JsonObject> getOrder = MockServer.serverRqRs.get(PURCHASE_ORDER, HttpMethod.GET);
assertEquals(1, getOrder.size());
// should try to Open, the existing Pending Order, which succeds
List<JsonObject> putOrder = MockServer.serverRqRs.get(COMPOSITE_PURCHASE_ORDER, HttpMethod.PUT);
assertEquals(1, putOrder.size());
// should not try to create a new Order
List<JsonObject> postedOrder = MockServer.serverRqRs.get(PURCHASE_ORDER, HttpMethod.POST);
assertNull(postedOrder);
// return the existing PO Line Number
assertNotNull(order.getPoLineNumber());
logger.info("End: Testing for 201 - Return existing Order even if it is pending, and retry to Open succeeds");
}
use of org.folio.rest.gobi.model.GobiResponse in project mod-gobi by folio-org.
the class GOBIIntegrationServiceResourceImplTest method testPostGobiOrdersExistingOrder.
@Test
public final void testPostGobiOrdersExistingOrder() throws Exception {
logger.info("Begin: Testing for 201 - posted order returns existing Order if present");
final String body = getMockData(PO_LISTED_ELECTRONIC_SERIAL_PATH);
final GobiResponse order = postOrderSuccess(body, new Header(MOCK_OKAPI_GET_ORDER_HEADER, MOCK_INSTRUCTION_GET_OPEN_ORDER));
// should try to fetch the order in Open status
List<JsonObject> getOrder = MockServer.serverRqRs.get(PURCHASE_ORDER, HttpMethod.GET);
assertEquals(1, getOrder.size());
// Should not try to create an order if present
List<JsonObject> postedOrder = MockServer.serverRqRs.get(PURCHASE_ORDER, HttpMethod.POST);
assertNull(postedOrder);
// Returned order is Open, should not retry to Open
List<JsonObject> putOrder = MockServer.serverRqRs.get(COMPOSITE_PURCHASE_ORDER, HttpMethod.PUT);
assertNull(putOrder);
// return the existing PO Line Number
assertNotNull(order.getPoLineNumber());
logger.info("End: Testing for 201 - posted order returns existing Order if present");
}
use of org.folio.rest.gobi.model.GobiResponse in project mod-gobi by folio-org.
the class PostGobiOrdersHelperTest method testHandleErrorGobiPurchaseOrderParserException.
public void testHandleErrorGobiPurchaseOrderParserException(TestContext context) {
logger.info("Begin: Testing handleError on HttpException bad request");
Async async = context.async();
String msg = "invalid gobi request xml";
Handler<AsyncResult<javax.ws.rs.core.Response>> asyncResultHandler = response -> {
context.assertEquals(400, response.result().getStatus());
try {
String body = new String(((BinaryOutStream) response.result().getEntity()).getData());
GobiResponse gobiResp = (GobiResponse) jaxbUnmarshaller.unmarshal(new StringReader(body));
context.assertEquals(CODE_INVALID_XML, gobiResp.getError().getCode());
context.assertEquals(msg, gobiResp.getError().getMessage());
} catch (JAXBException e) {
context.fail(e.getMessage());
}
async.complete();
};
PostGobiOrdersHelper helper = new PostGobiOrdersHelper(null, asyncResultHandler, null, null);
helper.handleError(new CompletionException(new GobiPurchaseOrderParserException(msg)));
}
use of org.folio.rest.gobi.model.GobiResponse in project mod-gobi by folio-org.
the class PostGobiOrdersHelperTest method testHandleErrorHttpClientBadRequest.
@Test
public void testHandleErrorHttpClientBadRequest(TestContext context) {
logger.info("Begin: Testing handleError on HttpException bad request");
Async async = context.async();
Throwable t = new Throwable("invalid foo");
Handler<AsyncResult<javax.ws.rs.core.Response>> asyncResultHandler = response -> {
context.assertEquals(400, response.result().getStatus());
try {
String body = new String(((BinaryOutStream) response.result().getEntity()).getData());
GobiResponse gobiResp = (GobiResponse) jaxbUnmarshaller.unmarshal(new StringReader(body));
context.assertEquals(CODE_BAD_REQUEST, gobiResp.getError().getCode());
context.assertEquals(t.toString(), gobiResp.getError().getMessage());
} catch (JAXBException e) {
context.fail(e.getMessage());
}
async.complete();
};
PostGobiOrdersHelper helper = new PostGobiOrdersHelper(null, asyncResultHandler, null, null);
helper.handleError(new CompletionException(new HttpException(400, t)));
}
Aggregations