use of org.folio.rest.acq.model.orders.CompositePoLine in project mod-invoice by folio-org.
the class MockServer method handleGetPoLineById.
private void handleGetPoLineById(RoutingContext ctx) {
logger.info("got: " + ctx.request().path());
String id = ctx.request().getParam(AbstractHelper.ID);
logger.info("id: " + id);
addServerRqRsData(HttpMethod.GET, ResourcePathResolver.ORDER_LINES, new JsonObject().put(AbstractHelper.ID, id));
if (ID_FOR_INTERNAL_SERVER_ERROR.equals(id)) {
serverResponse(ctx, 500, APPLICATION_JSON, INTERNAL_SERVER_ERROR.getReasonPhrase());
} else if (ID_FOR_INTERNAL_SERVER_ERROR_PUT.equals(id)) {
CompositePoLine poLine = new CompositePoLine();
poLine.setId(ID_FOR_INTERNAL_SERVER_ERROR_PUT);
serverResponse(ctx, 200, APPLICATION_JSON, JsonObject.mapFrom(poLine).encodePrettily());
} else {
Supplier<JsonObject> getFromFile = () -> {
String filePath = String.format(MOCK_DATA_PATH_PATTERN, PO_LINES_MOCK_DATA_PATH, id);
try {
return new JsonObject(getMockData(filePath));
} catch (IOException e) {
return null;
}
};
// Attempt to find POLine in mock server memory
JsonObject poLine = getMockEntry(ResourcePathResolver.ORDER_LINES, id).orElseGet(getFromFile);
if (poLine == null) {
ctx.response().setStatusCode(404).end(id);
} else {
// validate content against schema
CompositePoLine poLineSchema = poLine.mapTo(CompositePoLine.class);
poLineSchema.setId(id);
poLine = JsonObject.mapFrom(poLineSchema);
serverResponse(ctx, 200, APPLICATION_JSON, poLine.encodePrettily());
}
}
}
use of org.folio.rest.acq.model.orders.CompositePoLine in project mod-invoice by folio-org.
the class InvoicesApiTest method validatePoLinesPaymentStatus.
private void validatePoLinesPaymentStatus() {
final List<CompositePoLine> updatedPoLines = getRqRsEntries(HttpMethod.PUT, ORDER_LINES).stream().map(poLine -> poLine.mapTo(CompositePoLine.class)).collect(Collectors.toList());
assertThat(updatedPoLines, not(empty()));
Map<String, List<InvoiceLine>> invoiceLines = getRqRsEntries(HttpMethod.GET, INVOICE_LINES).get(0).mapTo(InvoiceLineCollection.class).getInvoiceLines().stream().collect(groupingBy(InvoiceLine::getPoLineId));
assertThat(invoiceLines.size(), equalTo(updatedPoLines.size()));
for (Map.Entry<String, List<InvoiceLine>> poLineIdWithInvoiceLines : invoiceLines.entrySet()) {
CompositePoLine poLine = updatedPoLines.stream().filter(compositePoLine -> compositePoLine.getId().equals(poLineIdWithInvoiceLines.getKey())).findFirst().orElseThrow(NullPointerException::new);
CompositePoLine.PaymentStatus expectedStatus = poLineIdWithInvoiceLines.getValue().stream().anyMatch(InvoiceLine::getReleaseEncumbrance) ? CompositePoLine.PaymentStatus.FULLY_PAID : CompositePoLine.PaymentStatus.PARTIALLY_PAID;
assertThat(expectedStatus, is(poLine.getPaymentStatus()));
}
}
use of org.folio.rest.acq.model.orders.CompositePoLine in project mod-invoice by folio-org.
the class InvoiceHelperTest method shouldReturnTrueWhenCompositeCheckingForUpdatePoLinePaymentStatusIsDifferentValues.
@Test
@DisplayName("decide to update status of POLines with different statuses")
void shouldReturnTrueWhenCompositeCheckingForUpdatePoLinePaymentStatusIsDifferentValues() {
InvoiceHelper invoiceHelper = new InvoiceHelper(okapiHeaders, context, "en");
CompositePoLine ongoingCompositePoLine = getMockAsJson(String.format("%s%s.json", PO_LINE_MOCK_DATA_PATH, EXISTING_PO_LINE_ID)).mapTo(CompositePoLine.class).withPaymentStatus(CompositePoLine.PaymentStatus.ONGOING);
CompositePoLine fullyPaidCompositePoLine = getMockAsJson(String.format("%s%s.json", PO_LINE_MOCK_DATA_PATH, EXISTING_PO_LINE_ID)).mapTo(CompositePoLine.class).withPaymentStatus(CompositePoLine.PaymentStatus.FULLY_PAID);
Map<CompositePoLine, CompositePoLine.PaymentStatus> compositePoLinesWithStatus = new HashMap<>() {
{
put(ongoingCompositePoLine, CompositePoLine.PaymentStatus.ONGOING);
put(fullyPaidCompositePoLine, CompositePoLine.PaymentStatus.PENDING);
}
};
assertTrue(invoiceHelper.isPaymentStatusUpdateRequired(compositePoLinesWithStatus, fullyPaidCompositePoLine));
}
use of org.folio.rest.acq.model.orders.CompositePoLine in project mod-invoice by folio-org.
the class OrderServiceTest method shouldSkipDeletionOrderInvoiceRelationshipByInvoiceIdAndLineIdIfRelationNotExist.
@Test
void shouldSkipDeletionOrderInvoiceRelationshipByInvoiceIdAndLineIdIfRelationNotExist() {
String invoiceId = UUID.randomUUID().toString();
String poLineId = UUID.randomUUID().toString();
String orderId = UUID.randomUUID().toString();
CompositePoLine poLine = new CompositePoLine().withId(poLineId).withPurchaseOrderId(orderId);
OrderInvoiceRelationshipCollection relationships = new OrderInvoiceRelationshipCollection().withOrderInvoiceRelationships(Collections.EMPTY_LIST).withTotalRecords(0);
doReturn(completedFuture(poLine)).when(restClient).get(any(RequestEntry.class), eq(requestContextMock), eq(CompositePoLine.class));
doReturn(completedFuture(relationships)).when(restClient).get(any(RequestEntry.class), eq(requestContextMock), eq(OrderInvoiceRelationshipCollection.class));
doReturn(completedFuture(poLine)).when(orderLineService).getPoLine(poLineId, requestContextMock);
orderService.deleteOrderInvoiceRelationshipByInvoiceIdAndLineId(invoiceId, poLineId, requestContextMock).join();
verify(restClient, times(0)).delete(any(RequestEntry.class), eq(requestContextMock));
}
Aggregations