Skip to content

Commit

Permalink
Feat: add discarder for anonym debtor (#77)
Browse files Browse the repository at this point in the history
* fix: attempting to use configurations and enviornment variables to avoid classloading issue on opentelemetry agent

* feat: add discarder check for anonymous or missing debtor

---------

Co-authored-by: acialini <[email protected]>
  • Loading branch information
alessio-cialini and alexyey authored Oct 13, 2023
1 parent e2875d9 commit 0f5b8c3
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,13 @@ private boolean isBizEventInvalid(BizEvent bizEvent, ExecutionContext context) {
return true;
}

if (bizEvent.getDebtor().getEntityUniqueIdentifierValue() == null ||
bizEvent.getDebtor().getEntityUniqueIdentifierValue().equals("ANONIMO")) {
logger.debug("[{}] event with id {} discarded because debtor identifier is missing or ANONIMO",
context.getFunctionName(), bizEvent.getId());
return true;
}

if (bizEvent.getPaymentInfo() != null) {
String totalNotice = bizEvent.getPaymentInfo().getTotalNotice();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,20 @@ void runDiscardedWithEventNotDONE() {
verify(documentdb, never()).setValue(any());
}

@Test
void runDiscardedWithAnonymousDebtor() {
List<BizEvent> bizEventItems = new ArrayList<>();
bizEventItems.add(generateAnonymDebtorBizEvent("1"));

@SuppressWarnings("unchecked")
OutputBinding<List<Receipt>> documentdb = (OutputBinding<List<Receipt>>) spy(OutputBinding.class);

// test execution
assertDoesNotThrow(() -> function.processBizEventToReceipt(bizEventItems, documentdb, context));

verify(documentdb, never()).setValue(any());
}

@Test
void runDiscardedWithEventNull() {
List<BizEvent> bizEventItems = new ArrayList<>();
Expand Down Expand Up @@ -259,6 +273,33 @@ private BizEvent generateValidBizEvent(String totalNotice){
return item;
}

private BizEvent generateAnonymDebtorBizEvent(String totalNotice){
BizEvent item = new BizEvent();

Payer payer = new Payer();
payer.setEntityUniqueIdentifierValue(PAYER_FISCAL_CODE);
Debtor debtor = new Debtor();
debtor.setEntityUniqueIdentifierValue("ANONIMO");

TransactionDetails transactionDetails = new TransactionDetails();
Transaction transaction = new Transaction();
transaction.setCreationDate(String.valueOf(LocalDateTime.now()));
transactionDetails.setTransaction(transaction);

PaymentInfo paymentInfo = new PaymentInfo();
paymentInfo.setTotalNotice(totalNotice);

item.setEventStatus(BizEventStatusType.DONE);
item.setId(EVENT_ID);
item.setPayer(payer);
item.setDebtor(debtor);
item.setTransactionDetails(transactionDetails);
item.setPaymentInfo(paymentInfo);

return item;
}


private BizEvent generateNotDoneBizEvent(){
BizEvent item = new BizEvent();

Expand Down

0 comments on commit 0f5b8c3

Please sign in to comment.