You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@fineract.apache.org by ju...@apache.org on 2019/10/09 07:39:29 UTC

[fineract-cn-cheques] 15/41: fixed issue with processing open cheques

This is an automated email from the ASF dual-hosted git repository.

juhan pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/fineract-cn-cheques.git

commit af64ef2559252f3f32b80529ab4e520070950879
Author: mgeiss <mg...@mifos.org>
AuthorDate: Mon Sep 11 13:43:43 2017 +0200

    fixed issue with processing open cheques
---
 .../src/main/java/io/mifos/cheque/TestCheques.java | 48 +++++++++++++++++++++-
 .../internal/command/handler/ChequeAggregate.java  |  2 +-
 2 files changed, 48 insertions(+), 2 deletions(-)

diff --git a/component-test/src/main/java/io/mifos/cheque/TestCheques.java b/component-test/src/main/java/io/mifos/cheque/TestCheques.java
index 22cd88e..0acbd3b 100644
--- a/component-test/src/main/java/io/mifos/cheque/TestCheques.java
+++ b/component-test/src/main/java/io/mifos/cheque/TestCheques.java
@@ -35,7 +35,14 @@ import org.junit.Assert;
 import org.junit.Test;
 import org.mockito.Matchers;
 import org.mockito.Mockito;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.test.mock.mockito.MockBean;
+import org.springframework.validation.AbstractErrors;
+import org.springframework.validation.BeanPropertyBindingResult;
+import org.springframework.validation.BindingResult;
+import org.springframework.validation.Errors;
+import org.springframework.validation.Validator;
+import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean;
 
 import java.util.Collections;
 import java.util.UUID;
@@ -51,6 +58,9 @@ public class TestCheques extends AbstractChequeTest {
   @MockBean
   private AccountingService accountingServiceSpy;
 
+  @Autowired
+  private Validator validator;
+
   public TestCheques() {
     super();
   }
@@ -158,7 +168,6 @@ public class TestCheques extends AbstractChequeTest {
         .doAnswer(invocation -> false)
         .when(this.accountingServiceSpy).accountExists(randomCheque.getMicr().getAccountNumber());
 
-
     final ChequeTransaction chequeTransaction = new ChequeTransaction();
     chequeTransaction.setChequesReceivableAccount(RandomStringUtils.randomAlphabetic(34));
     chequeTransaction.setCheque(randomCheque);
@@ -209,4 +218,41 @@ public class TestCheques extends AbstractChequeTest {
         .verify(this.accountingServiceSpy, Mockito.times(2))
         .processJournalEntry(Matchers.any(JournalEntry.class));
   }
+
+  @Test
+  public void shouldProcessOpenCheque() throws Exception {
+      final Cheque randomCheque = Fixture.createRandomCheque();
+      randomCheque.setOpenCheque(Boolean.TRUE);
+
+      Mockito
+          .doAnswer(invocation -> false)
+          .when(this.organizationServiceSpy).officeExistsByBranchSortCode(randomCheque.getMicr().getBranchSortCode());
+
+      Mockito
+          .doAnswer(invocation -> false)
+          .when(this.accountingServiceSpy).accountExists(randomCheque.getMicr().getAccountNumber());
+
+      Mockito.doAnswer(invocation -> {
+        final JournalEntry journalEntry = invocation.getArgumentAt(0, JournalEntry.class);
+        final BeanPropertyBindingResult bindingResult = new BeanPropertyBindingResult(journalEntry, "journalEntry");
+        this.validator.validate(journalEntry, bindingResult);
+        if (bindingResult.getErrorCount() != 0) {
+          bindingResult.getAllErrors().forEach(objectError -> {
+            System.out.println(objectError.toString());
+          });
+        }
+        return invocation.getMethod().getReturnType();
+      }).when(this.accountingServiceSpy).processJournalEntry(Matchers.any(JournalEntry.class));
+
+      final ChequeTransaction chequeTransaction = new ChequeTransaction();
+      chequeTransaction.setChequesReceivableAccount(RandomStringUtils.randomAlphabetic(34));
+      chequeTransaction.setCheque(randomCheque);
+      chequeTransaction.setCreditorAccountNumber(RandomStringUtils.randomAlphanumeric(34));
+      super.chequeManager.process(chequeTransaction);
+
+      Assert.assertTrue(
+          super.eventRecorder.wait(EventConstants.CHEQUE_TRANSACTION, MICRParser.toIdentifier(randomCheque.getMicr()))
+      );
+
+    }
 }
diff --git a/service/src/main/java/io/mifos/cheque/service/internal/command/handler/ChequeAggregate.java b/service/src/main/java/io/mifos/cheque/service/internal/command/handler/ChequeAggregate.java
index a3b1762..3bb746a 100644
--- a/service/src/main/java/io/mifos/cheque/service/internal/command/handler/ChequeAggregate.java
+++ b/service/src/main/java/io/mifos/cheque/service/internal/command/handler/ChequeAggregate.java
@@ -138,7 +138,7 @@ public class ChequeAggregate {
     final JournalEntry journalEntry = new JournalEntry();
     journalEntry.setTransactionIdentifier("chq-tx-" + UUID.randomUUID().toString());
     final String transactionType =
-        chequeEntity.getOpenCheque() != null && chequeEntity.getOpenCheque() ? "OPCQ " : "ORCQ";
+        chequeEntity.getOpenCheque() != null && chequeEntity.getOpenCheque() ? "OPCQ" : "ORCQ";
     journalEntry.setTransactionType(transactionType);
     journalEntry.setTransactionDate(DateConverter.toIsoString(chequeEntity.getCreatedOn()));
     journalEntry.setMessage(transactionType);