Search in sources :

Example 1 with HttpException

use of org.folio.gobi.exceptions.HttpException in project mod-gobi by folio-org.

the class PostGobiOrdersHelperTest method testHandleErrorHttpClientInternalServerError.

@Test
public void testHandleErrorHttpClientInternalServerError(TestContext context) {
    logger.info("Begin: Testing handleError on HttpException 500");
    Async async = context.async();
    String msg = "you zigged when you should have zagged";
    Handler<AsyncResult<javax.ws.rs.core.Response>> asyncResultHandler = response -> {
        context.assertEquals(500, response.result().getStatus());
        context.assertEquals(msg, response.result().getEntity());
        async.complete();
    };
    PostGobiOrdersHelper helper = new PostGobiOrdersHelper(null, asyncResultHandler, null, null);
    helper.handleError(new CompletionException(new HttpException(500, 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) Async(io.vertx.ext.unit.Async) CompletionException(java.util.concurrent.CompletionException) HttpException(org.folio.gobi.exceptions.HttpException) AsyncResult(io.vertx.core.AsyncResult) Test(org.junit.Test)

Example 2 with HttpException

use of org.folio.gobi.exceptions.HttpException 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 3 with HttpException

use of org.folio.gobi.exceptions.HttpException 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)

Example 4 with HttpException

use of org.folio.gobi.exceptions.HttpException in project mod-gobi by folio-org.

the class PostGobiOrdersHelperTest method testHandleErrorHttpClientUnauthorized.

@Test
public void testHandleErrorHttpClientUnauthorized(TestContext context) {
    logger.info("Begin: Testing handleError on HttpException 401");
    Async async = context.async();
    String msg = "requires permission foo.bar.get";
    Handler<AsyncResult<javax.ws.rs.core.Response>> asyncResultHandler = response -> {
        context.assertEquals(401, response.result().getStatus());
        context.assertEquals(msg, response.result().getEntity());
        async.complete();
    };
    PostGobiOrdersHelper helper = new PostGobiOrdersHelper(null, asyncResultHandler, null, null);
    helper.handleError(new CompletionException(new HttpException(401, 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) Async(io.vertx.ext.unit.Async) CompletionException(java.util.concurrent.CompletionException) HttpException(org.folio.gobi.exceptions.HttpException) AsyncResult(io.vertx.core.AsyncResult) Test(org.junit.Test)

Example 5 with HttpException

use of org.folio.gobi.exceptions.HttpException in project mod-gobi by folio-org.

the class PostGobiOrdersHelperTest method testHandleErrorHttpClientNotImplemented.

@Test
public void testHandleErrorHttpClientNotImplemented(TestContext context) {
    logger.info("Begin: Testing handleError on HttpException 501");
    Async async = context.async();
    String msg = "not implemented";
    Handler<AsyncResult<javax.ws.rs.core.Response>> asyncResultHandler = response -> {
        context.assertEquals(500, response.result().getStatus());
        context.assertEquals(msg, response.result().getEntity());
        async.complete();
    };
    PostGobiOrdersHelper helper = new PostGobiOrdersHelper(null, asyncResultHandler, null, null);
    helper.handleError(new CompletionException(new HttpException(501, 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) Async(io.vertx.ext.unit.Async) CompletionException(java.util.concurrent.CompletionException) HttpException(org.folio.gobi.exceptions.HttpException) AsyncResult(io.vertx.core.AsyncResult) Test(org.junit.Test)

Aggregations

GobiPurchaseOrderParserException (org.folio.gobi.exceptions.GobiPurchaseOrderParserException)6 HttpException (org.folio.gobi.exceptions.HttpException)6 GobiResponse (org.folio.rest.gobi.model.GobiResponse)6 AsyncResult (io.vertx.core.AsyncResult)5 Handler (io.vertx.core.Handler)5 Vertx (io.vertx.core.Vertx)5 HttpServer (io.vertx.core.http.HttpServer)5 Async (io.vertx.ext.unit.Async)5 TestContext (io.vertx.ext.unit.TestContext)5 VertxUnitRunner (io.vertx.ext.unit.junit.VertxUnitRunner)5 InputStream (java.io.InputStream)5 StringReader (java.io.StringReader)5 HashMap (java.util.HashMap)5 Map (java.util.Map)5 CompletionException (java.util.concurrent.CompletionException)5 JAXBContext (javax.xml.bind.JAXBContext)5 JAXBException (javax.xml.bind.JAXBException)5 Unmarshaller (javax.xml.bind.Unmarshaller)5 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)5 LogManager (org.apache.logging.log4j.LogManager)5