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