use of org.folio.rest.acq.model.orders.PoLine in project mod-invoice by folio-org.
the class InvoiceCancelServiceTest method setupUnreleaseEncumbrances.
private void setupUnreleaseEncumbrances(boolean withError) {
String orderId1 = UUID.randomUUID().toString();
String orderId2 = UUID.randomUUID().toString();
List<PurchaseOrder> orders = List.of(new PurchaseOrder().withId(orderId1).withWorkflowStatus(WorkflowStatus.PENDING), new PurchaseOrder().withId(orderId2).withWorkflowStatus(WorkflowStatus.OPEN));
List<PoLine> poLines = List.of(new PoLine().withId("2bafc9e1-9dd3-4ede-9f23-c4a03f8bb2d5").withPurchaseOrderId(orderId1), new PoLine().withId("5a34ae0e-5a11-4337-be95-1a20cfdc3161").withPurchaseOrderId(orderId2), new PoLine().withId("0610be6d-0ddd-494b-b867-19f63d8b5d6d").withPurchaseOrderId(orderId2));
List<Transaction> transactions = List.of(new Transaction().withId(UUID.randomUUID().toString()).withTransactionType(TransactionType.ENCUMBRANCE).withEncumbrance(new Encumbrance().withStatus(PENDING).withSourcePurchaseOrderId(orderId2)), new Transaction().withId(UUID.randomUUID().toString()).withTransactionType(TransactionType.ENCUMBRANCE).withEncumbrance(new Encumbrance().withStatus(RELEASED).withSourcePurchaseOrderId(orderId2)), new Transaction().withId(UUID.randomUUID().toString()).withTransactionType(TransactionType.ENCUMBRANCE).withEncumbrance(new Encumbrance().withStatus(UNRELEASED).withSourcePurchaseOrderId(orderId2)));
setupPoLineQuery(poLines);
setupOrderQuery(orders);
setupEncumbranceQuery(orders, poLines, transactions);
setupUpdateOrderTransactionSummary(orders.get(1));
if (withError)
setupEncumbrancePutWithError(transactions.get(1));
else
setupEncumbrancePut(transactions.get(1));
}
use of org.folio.rest.acq.model.orders.PoLine in project mod-invoice by folio-org.
the class CreateInvoiceEventHandlerTest method shouldNotLinkInvoiceLinesToPoLinesWhenMultiplePoLinesAreMatchedByRefNumber.
@Test
public void shouldNotLinkInvoiceLinesToPoLinesWhenMultiplePoLinesAreMatchedByRefNumber() throws IOException, InterruptedException {
// given
PoLine poLine1 = Json.decodeValue(getMockData(String.format(MOCK_DATA_PATH_PATTERN, PO_LINES_MOCK_DATA_PATH, PO_LINE_ID_1)), PoLine.class);
PoLine poLine3 = Json.decodeValue(getMockData(String.format(MOCK_DATA_PATH_PATTERN, PO_LINES_MOCK_DATA_PATH, PO_LINE_ID_3)), PoLine.class);
when(mockOrderLinesRestClient.get(any(), any(RequestContext.class), eq(PoLineCollection.class))).thenReturn(CompletableFuture.completedFuture(new PoLineCollection())).thenReturn(CompletableFuture.completedFuture(new PoLineCollection().withPoLines(List.of(poLine1, poLine3))));
ProfileSnapshotWrapper profileSnapshotWrapper = buildProfileSnapshotWrapper(jobProfile, actionProfile, mappingProfileWithPoLineSyntax);
addMockEntry(JOB_PROFILE_SNAPSHOTS_MOCK, profileSnapshotWrapper);
Record record = new Record().withParsedRecord(new ParsedRecord().withContent(EDIFACT_PARSED_CONTENT)).withId(UUID.randomUUID().toString());
HashMap<String, String> payloadContext = new HashMap<>();
payloadContext.put(EDIFACT_INVOICE.value(), Json.encode(record));
payloadContext.put(JOB_PROFILE_SNAPSHOT_ID_KEY, profileSnapshotWrapper.getId());
DataImportEventPayload dataImportEventPayload = new DataImportEventPayload().withEventType(DI_EDIFACT_RECORD_CREATED.value()).withTenant(DI_POST_INVOICE_LINES_SUCCESS_TENANT).withOkapiUrl(OKAPI_URL).withToken(TOKEN).withContext(payloadContext);
String topic = KafkaTopicNameHelper.formatTopicName(KAFKA_ENV_VALUE, getDefaultNameSpace(), DI_POST_INVOICE_LINES_SUCCESS_TENANT, dataImportEventPayload.getEventType());
Event event = new Event().withEventPayload(Json.encode(dataImportEventPayload));
KeyValue<String, String> kafkaRecord = new KeyValue<>("test-key", Json.encode(event));
kafkaRecord.addHeader(RECORD_ID_HEADER, record.getId(), UTF_8);
SendKeyValues<String, String> request = SendKeyValues.to(topic, Collections.singletonList(kafkaRecord)).useDefaults();
// when
kafkaCluster.send(request);
// then
String topicToObserve = KafkaTopicNameHelper.formatTopicName(KAFKA_ENV_VALUE, getDefaultNameSpace(), DI_POST_INVOICE_LINES_SUCCESS_TENANT, DI_COMPLETED.value());
List<String> observedValues = kafkaCluster.observeValues(ObserveKeyValues.on(topicToObserve, 1).with(ConsumerConfig.GROUP_ID_CONFIG, GROUP_ID).observeFor(30, TimeUnit.SECONDS).build());
Event obtainedEvent = Json.decodeValue(observedValues.get(0), Event.class);
DataImportEventPayload eventPayload = Json.decodeValue(obtainedEvent.getEventPayload(), DataImportEventPayload.class);
assertEquals(DI_INVOICE_CREATED.value(), eventPayload.getEventsChain().get(eventPayload.getEventsChain().size() - 1));
assertNotNull(eventPayload.getContext().get(INVOICE_LINES_KEY));
InvoiceLineCollection createdInvoiceLines = Json.decodeValue(eventPayload.getContext().get(INVOICE_LINES_KEY), InvoiceLineCollection.class);
assertEquals(3, createdInvoiceLines.getTotalRecords());
assertEquals(3, createdInvoiceLines.getInvoiceLines().size());
assertNull(createdInvoiceLines.getInvoiceLines().get(0).getPoLineId());
assertNull(createdInvoiceLines.getInvoiceLines().get(1).getPoLineId());
assertNull(createdInvoiceLines.getInvoiceLines().get(2).getPoLineId());
assertNotNull(createdInvoiceLines.getInvoiceLines().get(0).getDescription());
assertNotNull(createdInvoiceLines.getInvoiceLines().get(1).getDescription());
assertNotNull(createdInvoiceLines.getInvoiceLines().get(2).getDescription());
}
use of org.folio.rest.acq.model.orders.PoLine in project mod-invoice by folio-org.
the class CreateInvoiceEventHandlerTest method shouldMatchPoLinesByPoLineNumberAndCreateInvoiceLinesWithDescriptionFromPoLines.
@Test
public void shouldMatchPoLinesByPoLineNumberAndCreateInvoiceLinesWithDescriptionFromPoLines() throws IOException, InterruptedException {
// given
PoLine poLine1 = Json.decodeValue(getMockData(String.format(MOCK_DATA_PATH_PATTERN, PO_LINES_MOCK_DATA_PATH, PO_LINE_ID_1)), PoLine.class);
PoLine poLine3 = Json.decodeValue(getMockData(String.format(MOCK_DATA_PATH_PATTERN, PO_LINES_MOCK_DATA_PATH, PO_LINE_ID_3)), PoLine.class);
PoLineCollection poLineCollection = new PoLineCollection().withPoLines(List.of(poLine1, poLine3));
when(mockOrderLinesRestClient.get(any(), any(RequestContext.class), eq(PoLineCollection.class))).thenReturn(CompletableFuture.completedFuture(poLineCollection));
Record record = new Record().withParsedRecord(new ParsedRecord().withContent(EDIFACT_PARSED_CONTENT)).withId(UUID.randomUUID().toString());
ProfileSnapshotWrapper profileSnapshotWrapper = buildProfileSnapshotWrapper(jobProfile, actionProfile, mappingProfileWithPoLineSyntax);
addMockEntry(JOB_PROFILE_SNAPSHOTS_MOCK, profileSnapshotWrapper);
HashMap<String, String> payloadContext = new HashMap<>();
payloadContext.put(EDIFACT_INVOICE.value(), Json.encode(record));
payloadContext.put(JOB_PROFILE_SNAPSHOT_ID_KEY, profileSnapshotWrapper.getId());
payloadContext.put(DATA_IMPORT_PAYLOAD_OKAPI_PERMISSIONS, Json.encode(Collections.singletonList(AcqDesiredPermissions.ASSIGN.getPermission())));
payloadContext.put(DATA_IMPORT_PAYLOAD_OKAPI_USER_ID, USER_ID);
DataImportEventPayload dataImportEventPayload = new DataImportEventPayload().withEventType(DI_EDIFACT_RECORD_CREATED.value()).withTenant(DI_POST_INVOICE_LINES_SUCCESS_TENANT).withOkapiUrl(OKAPI_URL).withToken(TOKEN).withContext(payloadContext);
String topic = KafkaTopicNameHelper.formatTopicName(KAFKA_ENV_VALUE, getDefaultNameSpace(), DI_POST_INVOICE_LINES_SUCCESS_TENANT, dataImportEventPayload.getEventType());
Event event = new Event().withEventPayload(Json.encode(dataImportEventPayload));
KeyValue<String, String> kafkaRecord = new KeyValue<>("test-key", Json.encode(event));
kafkaRecord.addHeader(RECORD_ID_HEADER, record.getId(), UTF_8);
SendKeyValues<String, String> request = SendKeyValues.to(topic, Collections.singletonList(kafkaRecord)).useDefaults();
// when
kafkaCluster.send(request);
// then
String topicToObserve = KafkaTopicNameHelper.formatTopicName(KAFKA_ENV_VALUE, getDefaultNameSpace(), DI_POST_INVOICE_LINES_SUCCESS_TENANT, DI_COMPLETED.value());
List<String> observedValues = kafkaCluster.observeValues(ObserveKeyValues.on(topicToObserve, 1).with(ConsumerConfig.GROUP_ID_CONFIG, GROUP_ID).observeFor(30, TimeUnit.SECONDS).build());
Event obtainedEvent = Json.decodeValue(observedValues.get(0), Event.class);
DataImportEventPayload eventPayload = Json.decodeValue(obtainedEvent.getEventPayload(), DataImportEventPayload.class);
assertEquals(DI_INVOICE_CREATED.value(), eventPayload.getEventsChain().get(eventPayload.getEventsChain().size() - 1));
assertNotNull(eventPayload.getContext().get(INVOICE.value()));
Invoice createdInvoice = Json.decodeValue(eventPayload.getContext().get(INVOICE.value()), Invoice.class);
assertNotNull(eventPayload.getContext().get(INVOICE_LINES_KEY));
InvoiceLineCollection createdInvoiceLines = Json.decodeValue(eventPayload.getContext().get(INVOICE_LINES_KEY), InvoiceLineCollection.class);
assertEquals(3, createdInvoiceLines.getTotalRecords());
assertEquals(3, createdInvoiceLines.getInvoiceLines().size());
createdInvoiceLines.getInvoiceLines().forEach(invLine -> assertEquals(createdInvoice.getId(), invLine.getInvoiceId()));
assertEquals(poLine1.getId(), createdInvoiceLines.getInvoiceLines().get(0).getPoLineId());
assertEquals(poLine3.getId(), createdInvoiceLines.getInvoiceLines().get(2).getPoLineId());
assertNull(createdInvoiceLines.getInvoiceLines().get(1).getPoLineId());
assertEquals(poLine1.getTitleOrPackage(), createdInvoiceLines.getInvoiceLines().get(0).getDescription());
assertEquals(poLine3.getTitleOrPackage(), createdInvoiceLines.getInvoiceLines().get(2).getDescription());
assertEquals("ACI MATERIALS JOURNAL - ONLINE -", createdInvoiceLines.getInvoiceLines().get(1).getDescription());
}
use of org.folio.rest.acq.model.orders.PoLine in project mod-invoice by folio-org.
the class CreateInvoiceEventHandlerTest method shouldMatchPoLinesByRefNumberAndCreateInvoiceLinesWithDescriptionFromPoLines.
@Test
public void shouldMatchPoLinesByRefNumberAndCreateInvoiceLinesWithDescriptionFromPoLines() throws IOException, InterruptedException {
// given
PoLine poLine1 = Json.decodeValue(getMockData(String.format(MOCK_DATA_PATH_PATTERN, PO_LINES_MOCK_DATA_PATH, PO_LINE_ID_1)), PoLine.class);
PoLine poLine3 = Json.decodeValue(getMockData(String.format(MOCK_DATA_PATH_PATTERN, PO_LINES_MOCK_DATA_PATH, PO_LINE_ID_3)), PoLine.class);
when(mockOrderLinesRestClient.get(any(), any(RequestContext.class), eq(PoLineCollection.class))).thenReturn(CompletableFuture.completedFuture(new PoLineCollection().withPoLines(new ArrayList<>()))).thenReturn(CompletableFuture.completedFuture(new PoLineCollection().withPoLines(List.of(poLine1)))).thenReturn(CompletableFuture.completedFuture(new PoLineCollection().withPoLines(new ArrayList<>()))).thenReturn(CompletableFuture.completedFuture(new PoLineCollection().withPoLines(List.of(poLine3))));
ProfileSnapshotWrapper profileSnapshotWrapper = buildProfileSnapshotWrapper(jobProfile, actionProfile, mappingProfileWithPoLineSyntax);
addMockEntry(JOB_PROFILE_SNAPSHOTS_MOCK, profileSnapshotWrapper);
Record record = new Record().withParsedRecord(new ParsedRecord().withContent(EDIFACT_PARSED_CONTENT)).withId(UUID.randomUUID().toString());
HashMap<String, String> payloadContext = new HashMap<>();
payloadContext.put(EDIFACT_INVOICE.value(), Json.encode(record));
payloadContext.put(JOB_PROFILE_SNAPSHOT_ID_KEY, profileSnapshotWrapper.getId());
DataImportEventPayload dataImportEventPayload = new DataImportEventPayload().withEventType(DI_EDIFACT_RECORD_CREATED.value()).withTenant(DI_POST_INVOICE_LINES_SUCCESS_TENANT).withOkapiUrl(OKAPI_URL).withToken(TOKEN).withContext(payloadContext);
String topic = KafkaTopicNameHelper.formatTopicName(KAFKA_ENV_VALUE, getDefaultNameSpace(), DI_POST_INVOICE_LINES_SUCCESS_TENANT, dataImportEventPayload.getEventType());
Event event = new Event().withEventPayload(Json.encode(dataImportEventPayload));
KeyValue<String, String> kafkaRecord = new KeyValue<>("test-key", Json.encode(event));
kafkaRecord.addHeader(RECORD_ID_HEADER, record.getId(), UTF_8);
SendKeyValues<String, String> request = SendKeyValues.to(topic, Collections.singletonList(kafkaRecord)).useDefaults();
// when
kafkaCluster.send(request);
// then
String topicToObserve = KafkaTopicNameHelper.formatTopicName(KAFKA_ENV_VALUE, getDefaultNameSpace(), DI_POST_INVOICE_LINES_SUCCESS_TENANT, DI_COMPLETED.value());
List<String> observedValues = kafkaCluster.observeValues(ObserveKeyValues.on(topicToObserve, 1).with(ConsumerConfig.GROUP_ID_CONFIG, GROUP_ID).observeFor(30, TimeUnit.SECONDS).build());
Event obtainedEvent = Json.decodeValue(observedValues.get(0), Event.class);
DataImportEventPayload eventPayload = Json.decodeValue(obtainedEvent.getEventPayload(), DataImportEventPayload.class);
assertEquals(DI_INVOICE_CREATED.value(), eventPayload.getEventsChain().get(eventPayload.getEventsChain().size() - 1));
assertNotNull(eventPayload.getContext().get(INVOICE.value()));
Invoice createdInvoice = Json.decodeValue(eventPayload.getContext().get(INVOICE.value()), Invoice.class);
assertNotNull(createdInvoice.getVendorInvoiceNo());
assertNotNull(eventPayload.getContext().get(INVOICE_LINES_KEY));
InvoiceLineCollection createdInvoiceLines = Json.decodeValue(eventPayload.getContext().get(INVOICE_LINES_KEY), InvoiceLineCollection.class);
assertEquals(3, createdInvoiceLines.getTotalRecords());
assertEquals(3, createdInvoiceLines.getInvoiceLines().size());
createdInvoiceLines.getInvoiceLines().forEach(invLine -> assertEquals(createdInvoice.getId(), invLine.getInvoiceId()));
assertEquals(poLine1.getId(), createdInvoiceLines.getInvoiceLines().get(0).getPoLineId());
assertEquals(poLine3.getId(), createdInvoiceLines.getInvoiceLines().get(2).getPoLineId());
assertNull(createdInvoiceLines.getInvoiceLines().get(1).getPoLineId());
assertEquals(poLine1.getTitleOrPackage(), createdInvoiceLines.getInvoiceLines().get(0).getDescription());
assertEquals(poLine3.getTitleOrPackage(), createdInvoiceLines.getInvoiceLines().get(2).getDescription());
assertEquals("ACI MATERIALS JOURNAL - ONLINE -", createdInvoiceLines.getInvoiceLines().get(1).getDescription());
assertFalse(createdInvoiceLines.getInvoiceLines().get(0).getReferenceNumbers().isEmpty());
assertFalse(createdInvoiceLines.getInvoiceLines().get(1).getReferenceNumbers().isEmpty());
assertFalse(createdInvoiceLines.getInvoiceLines().get(2).getReferenceNumbers().isEmpty());
assertThat(poLine1.getVendorDetail().getReferenceNumbers(), hasItem(hasProperty("refNumber", is(createdInvoiceLines.getInvoiceLines().get(0).getReferenceNumbers().get(0).getRefNumber()))));
assertThat(poLine3.getVendorDetail().getReferenceNumbers(), hasItem(hasProperty("refNumber", is(createdInvoiceLines.getInvoiceLines().get(2).getReferenceNumbers().get(0).getRefNumber()))));
}
use of org.folio.rest.acq.model.orders.PoLine in project mod-invoice by folio-org.
the class InvoiceCancelServiceTest method setupPoLineQuery.
private void setupPoLineQuery(List<PoLine> poLines) {
String poLineIdsQuery = poLines.stream().map(PoLine::getId).collect(joining(" or "));
String poLineQuery = "paymentStatus==(\"Awaiting Payment\" OR \"Partially Paid\" OR \"Fully Paid\") AND id==(" + poLineIdsQuery + ")";
PoLineCollection poLineCollection = new PoLineCollection().withPoLines(poLines).withTotalRecords(poLines.size());
RequestEntry requestEntry = new RequestEntry("/orders/order-lines").withQuery(poLineQuery).withOffset(0).withLimit(Integer.MAX_VALUE);
doReturn(completedFuture(poLineCollection)).when(restClient).get(argThat(re -> sameRequestEntry(requestEntry, re)), eq(requestContextMock), eq(PoLineCollection.class));
}
Aggregations