use of org.folio.rest.impl.PoNumberApiTest.NONEXISTING_PO_NUMBER in project mod-orders by folio-org.
the class MockServer method handleGetPurchaseOrderByQuery.
private void handleGetPurchaseOrderByQuery(RoutingContext ctx, String orderType) {
String query = StringUtils.trimToEmpty(ctx.request().getParam("query"));
addServerRqQuery(orderType, query);
JsonObject po = new JsonObject();
PurchaseOrderCollection orderCollection = new PurchaseOrderCollection();
// Attempt to find POLine in mock server memory
List<JsonObject> postedOrders = serverRqRs.column(HttpMethod.SEARCH).get(orderType);
if (postedOrders != null) {
orderCollection.withPurchaseOrders(postedOrders.stream().peek(order -> order.remove(COMPOSITE_PO_LINES)).map(order -> order.mapTo(PurchaseOrder.class)).collect(Collectors.toList())).withTotalRecords(orderCollection.getPurchaseOrders().size());
po = JsonObject.mapFrom(orderCollection);
po.remove(COMPOSITE_PO_LINES);
po.remove("totalEstimatedPrice");
po.remove("totalItems");
addServerRqRsData(HttpMethod.GET, orderType, po);
} else {
if (query.contains(BAD_QUERY)) {
serverResponse(ctx, 400, APPLICATION_JSON, Response.Status.BAD_REQUEST.getReasonPhrase());
} else if (query.contains(ID_FOR_INTERNAL_SERVER_ERROR)) {
serverResponse(ctx, 500, APPLICATION_JSON, Response.Status.INTERNAL_SERVER_ERROR.getReasonPhrase());
} else {
addServerRqRsData(HttpMethod.GET, orderType, po);
Matcher matcher = Pattern.compile(".*poNumber==(\\S[^)]+).*").matcher(query);
final String poNumber = matcher.find() ? matcher.group(1) : EMPTY;
switch(poNumber) {
case EXISTING_PO_NUMBER:
po.put(TOTAL_RECORDS, 1);
break;
case NONEXISTING_PO_NUMBER:
po.put(TOTAL_RECORDS, 0);
break;
case EMPTY:
po.put(TOTAL_RECORDS, 0);
break;
default:
// modify later as needed
po.put(TOTAL_RECORDS, 0);
}
}
}
serverResponse(ctx, 200, APPLICATION_JSON, po.encodePrettily());
}
Aggregations