Search in sources :

Example 6 with GobiResponse

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

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");
}
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 8 with GobiResponse

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");
}
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 9 with GobiResponse

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)));
}
Also used : DataSourceResolver(org.folio.gobi.DataSourceResolver) TestContext(io.vertx.ext.unit.TestContext) Async(io.vertx.ext.unit.Async) HttpServer(io.vertx.core.http.HttpServer) CODE_BAD_REQUEST(org.folio.rest.impl.PostGobiOrdersHelper.CODE_BAD_REQUEST) GobiPurchaseOrderParserException(org.folio.gobi.exceptions.GobiPurchaseOrderParserException) RunWith(org.junit.runner.RunWith) HashMap(java.util.HashMap) HttpException(org.folio.gobi.exceptions.HttpException) Document(org.w3c.dom.Document) Map(java.util.Map) After(org.junit.After) Assert.fail(org.junit.Assert.fail) AsyncResult(io.vertx.core.AsyncResult) JAXBContext(javax.xml.bind.JAXBContext) Before(org.junit.Before) CODE_INVALID_XML(org.folio.rest.impl.PostGobiOrdersHelper.CODE_INVALID_XML) Unmarshaller(javax.xml.bind.Unmarshaller) BinaryOutStream(org.folio.rest.tools.utils.BinaryOutStream) Vertx(io.vertx.core.Vertx) CompletionException(java.util.concurrent.CompletionException) Test(org.junit.Test) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) GobiResponse(org.folio.rest.gobi.model.GobiResponse) JAXBException(javax.xml.bind.JAXBException) NetworkUtils(org.folio.rest.tools.utils.NetworkUtils) Logger(org.apache.logging.log4j.Logger) StringReader(java.io.StringReader) Mapping(org.folio.rest.mappings.model.Mapping) OrderMappings(org.folio.rest.mappings.model.OrderMappings) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) Handler(io.vertx.core.Handler) LogManager(org.apache.logging.log4j.LogManager) Assert.assertEquals(org.junit.Assert.assertEquals) InputStream(java.io.InputStream) GobiPurchaseOrderParserException(org.folio.gobi.exceptions.GobiPurchaseOrderParserException) BinaryOutStream(org.folio.rest.tools.utils.BinaryOutStream) JAXBException(javax.xml.bind.JAXBException) Async(io.vertx.ext.unit.Async) CompletionException(java.util.concurrent.CompletionException) StringReader(java.io.StringReader) AsyncResult(io.vertx.core.AsyncResult) GobiResponse(org.folio.rest.gobi.model.GobiResponse)

Example 10 with GobiResponse

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)));
}
Also used : DataSourceResolver(org.folio.gobi.DataSourceResolver) TestContext(io.vertx.ext.unit.TestContext) Async(io.vertx.ext.unit.Async) HttpServer(io.vertx.core.http.HttpServer) CODE_BAD_REQUEST(org.folio.rest.impl.PostGobiOrdersHelper.CODE_BAD_REQUEST) GobiPurchaseOrderParserException(org.folio.gobi.exceptions.GobiPurchaseOrderParserException) RunWith(org.junit.runner.RunWith) HashMap(java.util.HashMap) HttpException(org.folio.gobi.exceptions.HttpException) Document(org.w3c.dom.Document) Map(java.util.Map) After(org.junit.After) Assert.fail(org.junit.Assert.fail) AsyncResult(io.vertx.core.AsyncResult) JAXBContext(javax.xml.bind.JAXBContext) Before(org.junit.Before) CODE_INVALID_XML(org.folio.rest.impl.PostGobiOrdersHelper.CODE_INVALID_XML) Unmarshaller(javax.xml.bind.Unmarshaller) BinaryOutStream(org.folio.rest.tools.utils.BinaryOutStream) Vertx(io.vertx.core.Vertx) CompletionException(java.util.concurrent.CompletionException) Test(org.junit.Test) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) GobiResponse(org.folio.rest.gobi.model.GobiResponse) JAXBException(javax.xml.bind.JAXBException) NetworkUtils(org.folio.rest.tools.utils.NetworkUtils) Logger(org.apache.logging.log4j.Logger) StringReader(java.io.StringReader) Mapping(org.folio.rest.mappings.model.Mapping) OrderMappings(org.folio.rest.mappings.model.OrderMappings) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) Handler(io.vertx.core.Handler) LogManager(org.apache.logging.log4j.LogManager) Assert.assertEquals(org.junit.Assert.assertEquals) InputStream(java.io.InputStream) BinaryOutStream(org.folio.rest.tools.utils.BinaryOutStream) JAXBException(javax.xml.bind.JAXBException) Async(io.vertx.ext.unit.Async) CompletionException(java.util.concurrent.CompletionException) StringReader(java.io.StringReader) HttpException(org.folio.gobi.exceptions.HttpException) AsyncResult(io.vertx.core.AsyncResult) 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