fineract-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From my...@apache.org
Subject [fineract-cn-teller] 19/30: added verification for balance and cash draw limit
Date Mon, 22 Jan 2018 15:32:17 GMT
This is an automated email from the ASF dual-hosted git repository.

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

commit 71839a17fb6e181e6a3af0f44e5dce6418433b25
Author: mgeiss <mgeiss@mifos.org>
AuthorDate: Sun Jun 25 19:10:20 2017 +0200

    added verification for balance and cash draw limit
---
 .../mifos/teller/api/v1/client/TellerManager.java  |   5 +-
 .../v1/client/TransactionProcessingException.java  |  19 +++
 .../java/io/mifos/teller/TestTellerManagement.java | 122 ++++++++++----------
 .../java/io/mifos/teller/TestTellerOperation.java  | 128 ++++++++++++++++-----
 .../internal/command/handler/TellerAggregate.java  |   8 +-
 .../processor/TellerTransactionProcessor.java      |  22 ++--
 .../internal/service/helper/AccountingService.java |  10 +-
 .../helper/DepositAccountManagementService.java    |  10 +-
 .../rest/TellerManagementRestController.java       |   2 +-
 .../rest/TellerOperationRestController.java        |  30 ++++-
 10 files changed, 244 insertions(+), 112 deletions(-)

diff --git a/api/src/main/java/io/mifos/teller/api/v1/client/TellerManager.java b/api/src/main/java/io/mifos/teller/api/v1/client/TellerManager.java
index 3f3a9b2..6a965e6 100644
--- a/api/src/main/java/io/mifos/teller/api/v1/client/TellerManager.java
+++ b/api/src/main/java/io/mifos/teller/api/v1/client/TellerManager.java
@@ -19,11 +19,11 @@ import io.mifos.core.api.annotation.ThrowsException;
 import io.mifos.core.api.annotation.ThrowsExceptions;
 import io.mifos.core.api.util.CustomFeignClientsConfiguration;
 import io.mifos.teller.api.v1.domain.Teller;
-import io.mifos.teller.api.v1.domain.UnlockDrawerCommand;
 import io.mifos.teller.api.v1.domain.TellerBalanceSheet;
 import io.mifos.teller.api.v1.domain.TellerManagementCommand;
 import io.mifos.teller.api.v1.domain.TellerTransaction;
 import io.mifos.teller.api.v1.domain.TellerTransactionCosts;
+import io.mifos.teller.api.v1.domain.UnlockDrawerCommand;
 import org.springframework.cloud.netflix.feign.FeignClient;
 import org.springframework.http.HttpStatus;
 import org.springframework.http.MediaType;
@@ -152,7 +152,8 @@ public interface TellerManager {
   )
   @ThrowsExceptions({
       @ThrowsException(status = HttpStatus.NOT_FOUND, exception = TellerNotFoundException.class),
-      @ThrowsException(status = HttpStatus.BAD_REQUEST, exception = TellerTransactionValidationException.class)
+      @ThrowsException(status = HttpStatus.BAD_REQUEST, exception = TellerTransactionValidationException.class),
+      @ThrowsException(status = HttpStatus.CONFLICT, exception = TransactionProcessingException.class)
   })
   TellerTransactionCosts post(@PathVariable("tellerCode") final String tellerCode,
                               @RequestBody @Valid final TellerTransaction tellerTransaction);
diff --git a/api/src/main/java/io/mifos/teller/api/v1/client/TransactionProcessingException.java
b/api/src/main/java/io/mifos/teller/api/v1/client/TransactionProcessingException.java
new file mode 100644
index 0000000..f36274f
--- /dev/null
+++ b/api/src/main/java/io/mifos/teller/api/v1/client/TransactionProcessingException.java
@@ -0,0 +1,19 @@
+/*
+ * Copyright 2017 The Mifos Initiative.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package io.mifos.teller.api.v1.client;
+
+public class TransactionProcessingException extends RuntimeException {
+}
diff --git a/component-test/src/main/java/io/mifos/teller/TestTellerManagement.java b/component-test/src/main/java/io/mifos/teller/TestTellerManagement.java
index ca28069..83611e2 100644
--- a/component-test/src/main/java/io/mifos/teller/TestTellerManagement.java
+++ b/component-test/src/main/java/io/mifos/teller/TestTellerManagement.java
@@ -15,6 +15,7 @@
  */
 package io.mifos.teller;
 
+import io.mifos.accounting.api.v1.domain.Account;
 import io.mifos.teller.api.v1.EventConstants;
 import io.mifos.teller.api.v1.client.TellerAlreadyExistsException;
 import io.mifos.teller.api.v1.client.TellerNotFoundException;
@@ -30,6 +31,7 @@ import org.mockito.Mockito;
 
 import java.util.Arrays;
 import java.util.List;
+import java.util.Optional;
 
 public class TestTellerManagement extends AbstractTellerTest {
 
@@ -45,11 +47,11 @@ public class TestTellerManagement extends AbstractTellerTest {
     Mockito.doAnswer(invocation -> true)
         .when(super.organizationServiceSpy).officeExists(Matchers.eq(officeIdentifier));
 
-    Mockito.doAnswer(invocation -> true)
-        .when(super.accountingServiceSpy).accountExists(Matchers.eq(teller.getTellerAccountIdentifier()));
+    Mockito.doAnswer(invocation -> Optional.of(new Account()))
+        .when(super.accountingServiceSpy).findAccount(Matchers.eq(teller.getTellerAccountIdentifier()));
 
-    Mockito.doAnswer(invocation -> true)
-        .when(super.accountingServiceSpy).accountExists(Matchers.eq(teller.getVaultAccountIdentifier()));
+    Mockito.doAnswer(invocation -> Optional.of(new Account()))
+        .when(super.accountingServiceSpy).findAccount(Matchers.eq(teller.getVaultAccountIdentifier()));
 
     super.testSubject.create(officeIdentifier, teller);
 
@@ -72,8 +74,8 @@ public class TestTellerManagement extends AbstractTellerTest {
     final String officeIdentifier = RandomStringUtils.randomAlphabetic(32);
     final Teller teller = TellerGenerator.createRandomTeller();
 
-    Mockito.doAnswer(invocation -> false)
-        .when(super.accountingServiceSpy).accountExists(Matchers.eq(teller.getTellerAccountIdentifier()));
+    Mockito.doAnswer(invocation -> Optional.empty())
+        .when(super.accountingServiceSpy).findAccount(Matchers.eq(teller.getTellerAccountIdentifier()));
 
     super.testSubject.create(officeIdentifier, teller);
   }
@@ -83,8 +85,8 @@ public class TestTellerManagement extends AbstractTellerTest {
     final String officeIdentifier = RandomStringUtils.randomAlphabetic(32);
     final Teller teller = TellerGenerator.createRandomTeller();
 
-    Mockito.doAnswer(invocation -> false)
-        .when(super.accountingServiceSpy).accountExists(Matchers.eq(teller.getVaultAccountIdentifier()));
+    Mockito.doAnswer(invocation -> Optional.empty())
+        .when(super.accountingServiceSpy).findAccount(Matchers.eq(teller.getVaultAccountIdentifier()));
 
     super.testSubject.create(officeIdentifier, teller);
   }
@@ -98,11 +100,11 @@ public class TestTellerManagement extends AbstractTellerTest {
     Mockito.doAnswer(invocation -> true)
         .when(super.organizationServiceSpy).officeExists(Matchers.eq(officeIdentifier));
 
-    Mockito.doAnswer(invocation -> true)
-        .when(super.accountingServiceSpy).accountExists(Matchers.eq(teller.getTellerAccountIdentifier()));
+    Mockito.doAnswer(invocation -> Optional.of(new Account()))
+        .when(super.accountingServiceSpy).findAccount(Matchers.eq(teller.getTellerAccountIdentifier()));
 
-    Mockito.doAnswer(invocation -> true)
-        .when(super.accountingServiceSpy).accountExists(Matchers.eq(teller.getVaultAccountIdentifier()));
+    Mockito.doAnswer(invocation -> Optional.of(new Account()))
+        .when(super.accountingServiceSpy).findAccount(Matchers.eq(teller.getVaultAccountIdentifier()));
 
     super.testSubject.create(officeIdentifier, teller);
 
@@ -119,11 +121,11 @@ public class TestTellerManagement extends AbstractTellerTest {
     Mockito.doAnswer(invocation -> true)
         .when(super.organizationServiceSpy).officeExists(Matchers.eq(officeIdentifier));
 
-    Mockito.doAnswer(invocation -> true)
-        .when(super.accountingServiceSpy).accountExists(Matchers.eq(teller.getTellerAccountIdentifier()));
+    Mockito.doAnswer(invocation -> Optional.of(new Account()))
+        .when(super.accountingServiceSpy).findAccount(Matchers.eq(teller.getTellerAccountIdentifier()));
 
-    Mockito.doAnswer(invocation -> true)
-        .when(super.accountingServiceSpy).accountExists(Matchers.eq(teller.getVaultAccountIdentifier()));
+    Mockito.doAnswer(invocation -> Optional.of(new Account()))
+        .when(super.accountingServiceSpy).findAccount(Matchers.eq(teller.getVaultAccountIdentifier()));
 
     super.testSubject.create(officeIdentifier, teller);
 
@@ -172,11 +174,11 @@ public class TestTellerManagement extends AbstractTellerTest {
         .when(super.organizationServiceSpy).officeExists(Matchers.eq(officeIdentifier));
 
     tellerToCreate.forEach(teller -> {
-      Mockito.doAnswer(invocation -> true)
-          .when(super.accountingServiceSpy).accountExists(Matchers.eq(teller.getTellerAccountIdentifier()));
+      Mockito.doAnswer(invocation -> Optional.of(new Account()))
+          .when(super.accountingServiceSpy).findAccount(Matchers.eq(teller.getTellerAccountIdentifier()));
 
-      Mockito.doAnswer(invocation -> true)
-          .when(super.accountingServiceSpy).accountExists(Matchers.eq(teller.getVaultAccountIdentifier()));
+      Mockito.doAnswer(invocation -> Optional.of(new Account()))
+          .when(super.accountingServiceSpy).findAccount(Matchers.eq(teller.getVaultAccountIdentifier()));
 
       super.testSubject.create(officeIdentifier, teller);
 
@@ -210,11 +212,11 @@ public class TestTellerManagement extends AbstractTellerTest {
     Mockito.doAnswer(invocation -> true)
         .when(super.organizationServiceSpy).officeExists(Matchers.eq(officeIdentifier));
 
-    Mockito.doAnswer(invocation -> true)
-        .when(super.accountingServiceSpy).accountExists(Matchers.eq(teller.getTellerAccountIdentifier()));
+    Mockito.doAnswer(invocation -> Optional.of(new Account()))
+        .when(super.accountingServiceSpy).findAccount(Matchers.eq(teller.getTellerAccountIdentifier()));
 
-    Mockito.doAnswer(invocation -> true)
-        .when(super.accountingServiceSpy).accountExists(Matchers.eq(teller.getVaultAccountIdentifier()));
+    Mockito.doAnswer(invocation -> Optional.of(new Account()))
+        .when(super.accountingServiceSpy).findAccount(Matchers.eq(teller.getVaultAccountIdentifier()));
 
     super.testSubject.create(officeIdentifier, teller);
 
@@ -240,11 +242,11 @@ public class TestTellerManagement extends AbstractTellerTest {
     Mockito.doAnswer(invocation -> true)
         .when(super.organizationServiceSpy).officeExists(Matchers.eq(officeIdentifier));
 
-    Mockito.doAnswer(invocation -> true)
-        .when(super.accountingServiceSpy).accountExists(Matchers.eq(teller.getTellerAccountIdentifier()));
+    Mockito.doAnswer(invocation -> Optional.of(new Account()))
+        .when(super.accountingServiceSpy).findAccount(Matchers.eq(teller.getTellerAccountIdentifier()));
 
-    Mockito.doAnswer(invocation -> true)
-        .when(super.accountingServiceSpy).accountExists(Matchers.eq(teller.getVaultAccountIdentifier()));
+    Mockito.doAnswer(invocation -> Optional.of(new Account()))
+        .when(super.accountingServiceSpy).findAccount(Matchers.eq(teller.getVaultAccountIdentifier()));
 
     super.testSubject.create(officeIdentifier, teller);
 
@@ -264,11 +266,11 @@ public class TestTellerManagement extends AbstractTellerTest {
     Mockito.doAnswer(invocation -> true)
         .when(super.organizationServiceSpy).officeExists(Matchers.eq(officeIdentifier));
 
-    Mockito.doAnswer(invocation -> true)
-        .when(super.accountingServiceSpy).accountExists(Matchers.eq(teller.getTellerAccountIdentifier()));
+    Mockito.doAnswer(invocation -> Optional.of(new Account()))
+        .when(super.accountingServiceSpy).findAccount(Matchers.eq(teller.getTellerAccountIdentifier()));
 
-    Mockito.doAnswer(invocation -> true)
-        .when(super.accountingServiceSpy).accountExists(Matchers.eq(teller.getVaultAccountIdentifier()));
+    Mockito.doAnswer(invocation -> Optional.of(new Account()))
+        .when(super.accountingServiceSpy).findAccount(Matchers.eq(teller.getVaultAccountIdentifier()));
 
     super.testSubject.create(officeIdentifier, teller);
 
@@ -276,8 +278,8 @@ public class TestTellerManagement extends AbstractTellerTest {
 
     teller.setTellerAccountIdentifier(RandomStringUtils.randomAlphanumeric(32));
 
-    Mockito.doAnswer(invocation -> false)
-        .when(super.accountingServiceSpy).accountExists(Matchers.eq(teller.getTellerAccountIdentifier()));
+    Mockito.doAnswer(invocation -> Optional.empty())
+        .when(super.accountingServiceSpy).findAccount(Matchers.eq(teller.getTellerAccountIdentifier()));
 
     super.testSubject.change(officeIdentifier, teller.getCode(), teller);
   }
@@ -290,11 +292,11 @@ public class TestTellerManagement extends AbstractTellerTest {
     Mockito.doAnswer(invocation -> true)
         .when(super.organizationServiceSpy).officeExists(Matchers.eq(officeIdentifier));
 
-    Mockito.doAnswer(invocation -> true)
-        .when(super.accountingServiceSpy).accountExists(Matchers.eq(teller.getTellerAccountIdentifier()));
+    Mockito.doAnswer(invocation -> Optional.of(new Account()))
+        .when(super.accountingServiceSpy).findAccount(Matchers.eq(teller.getTellerAccountIdentifier()));
 
-    Mockito.doAnswer(invocation -> true)
-        .when(super.accountingServiceSpy).accountExists(Matchers.eq(teller.getVaultAccountIdentifier()));
+    Mockito.doAnswer(invocation -> Optional.of(new Account()))
+        .when(super.accountingServiceSpy).findAccount(Matchers.eq(teller.getVaultAccountIdentifier()));
 
     super.testSubject.create(officeIdentifier, teller);
 
@@ -302,8 +304,8 @@ public class TestTellerManagement extends AbstractTellerTest {
 
     teller.setVaultAccountIdentifier(RandomStringUtils.randomAlphanumeric(32));
 
-    Mockito.doAnswer(invocation -> false)
-        .when(super.accountingServiceSpy).accountExists(Matchers.eq(teller.getVaultAccountIdentifier()));
+    Mockito.doAnswer(invocation -> Optional.empty())
+        .when(super.accountingServiceSpy).findAccount(Matchers.eq(teller.getVaultAccountIdentifier()));
 
     super.testSubject.change(officeIdentifier, teller.getCode(), teller);
   }
@@ -318,11 +320,11 @@ public class TestTellerManagement extends AbstractTellerTest {
     Mockito.doAnswer(invocation -> true)
         .when(super.organizationServiceSpy).officeExists(Matchers.eq(officeIdentifier));
 
-    Mockito.doAnswer(invocation -> true)
-        .when(super.accountingServiceSpy).accountExists(Matchers.eq(teller.getTellerAccountIdentifier()));
+    Mockito.doAnswer(invocation -> Optional.of(new Account()))
+        .when(super.accountingServiceSpy).findAccount(Matchers.eq(teller.getTellerAccountIdentifier()));
 
-    Mockito.doAnswer(invocation -> true)
-        .when(super.accountingServiceSpy).accountExists(Matchers.eq(teller.getVaultAccountIdentifier()));
+    Mockito.doAnswer(invocation -> Optional.of(new Account()))
+        .when(super.accountingServiceSpy).findAccount(Matchers.eq(teller.getVaultAccountIdentifier()));
 
     super.testSubject.create(officeIdentifier, teller);
 
@@ -349,11 +351,11 @@ public class TestTellerManagement extends AbstractTellerTest {
     Mockito.doAnswer(invocation -> true)
         .when(super.organizationServiceSpy).officeExists(Matchers.eq(officeIdentifier));
 
-    Mockito.doAnswer(invocation -> true)
-        .when(super.accountingServiceSpy).accountExists(Matchers.eq(teller.getTellerAccountIdentifier()));
+    Mockito.doAnswer(invocation -> Optional.of(new Account()))
+        .when(super.accountingServiceSpy).findAccount(Matchers.eq(teller.getTellerAccountIdentifier()));
 
-    Mockito.doAnswer(invocation -> true)
-        .when(super.accountingServiceSpy).accountExists(Matchers.eq(teller.getVaultAccountIdentifier()));
+    Mockito.doAnswer(invocation -> Optional.of(new Account()))
+        .when(super.accountingServiceSpy).findAccount(Matchers.eq(teller.getVaultAccountIdentifier()));
 
     super.testSubject.create(officeIdentifier, teller);
 
@@ -384,11 +386,11 @@ public class TestTellerManagement extends AbstractTellerTest {
     Mockito.doAnswer(invocation -> true)
         .when(super.organizationServiceSpy).officeExists(Matchers.eq(officeIdentifier));
 
-    Mockito.doAnswer(invocation -> true)
-        .when(super.accountingServiceSpy).accountExists(Matchers.eq(teller.getTellerAccountIdentifier()));
+    Mockito.doAnswer(invocation -> Optional.of(new Account()))
+        .when(super.accountingServiceSpy).findAccount(Matchers.eq(teller.getTellerAccountIdentifier()));
 
-    Mockito.doAnswer(invocation -> true)
-        .when(super.accountingServiceSpy).accountExists(Matchers.eq(teller.getVaultAccountIdentifier()));
+    Mockito.doAnswer(invocation -> Optional.of(new Account()))
+        .when(super.accountingServiceSpy).findAccount(Matchers.eq(teller.getVaultAccountIdentifier()));
 
     super.testSubject.create(officeIdentifier, teller);
 
@@ -425,11 +427,11 @@ public class TestTellerManagement extends AbstractTellerTest {
     Mockito.doAnswer(invocation -> true)
         .when(super.organizationServiceSpy).officeExists(Matchers.eq(officeIdentifier));
 
-    Mockito.doAnswer(invocation -> true)
-        .when(super.accountingServiceSpy).accountExists(Matchers.eq(teller.getTellerAccountIdentifier()));
+    Mockito.doAnswer(invocation -> Optional.of(new Account()))
+        .when(super.accountingServiceSpy).findAccount(Matchers.eq(teller.getTellerAccountIdentifier()));
 
-    Mockito.doAnswer(invocation -> true)
-        .when(super.accountingServiceSpy).accountExists(Matchers.eq(teller.getVaultAccountIdentifier()));
+    Mockito.doAnswer(invocation -> Optional.of(new Account()))
+        .when(super.accountingServiceSpy).findAccount(Matchers.eq(teller.getVaultAccountIdentifier()));
 
     super.testSubject.create(officeIdentifier, teller);
 
@@ -450,11 +452,11 @@ public class TestTellerManagement extends AbstractTellerTest {
     Mockito.doAnswer(invocation -> true)
         .when(super.organizationServiceSpy).officeExists(Matchers.eq(officeIdentifier));
 
-    Mockito.doAnswer(invocation -> true)
-        .when(super.accountingServiceSpy).accountExists(Matchers.eq(teller.getTellerAccountIdentifier()));
+    Mockito.doAnswer(invocation -> Optional.of(new Account()))
+        .when(super.accountingServiceSpy).findAccount(Matchers.eq(teller.getTellerAccountIdentifier()));
 
-    Mockito.doAnswer(invocation -> true)
-        .when(super.accountingServiceSpy).accountExists(Matchers.eq(teller.getVaultAccountIdentifier()));
+    Mockito.doAnswer(invocation -> Optional.of(new Account()))
+        .when(super.accountingServiceSpy).findAccount(Matchers.eq(teller.getVaultAccountIdentifier()));
 
     super.testSubject.create(officeIdentifier, teller);
 
diff --git a/component-test/src/main/java/io/mifos/teller/TestTellerOperation.java b/component-test/src/main/java/io/mifos/teller/TestTellerOperation.java
index 18589cf..7d3e1da 100644
--- a/component-test/src/main/java/io/mifos/teller/TestTellerOperation.java
+++ b/component-test/src/main/java/io/mifos/teller/TestTellerOperation.java
@@ -15,14 +15,16 @@
  */
 package io.mifos.teller;
 
+import io.mifos.accounting.api.v1.domain.Account;
 import io.mifos.core.lang.DateConverter;
 import io.mifos.teller.api.v1.EventConstants;
 import io.mifos.teller.api.v1.client.TellerNotFoundException;
 import io.mifos.teller.api.v1.client.TellerValidationException;
+import io.mifos.teller.api.v1.client.TransactionProcessingException;
 import io.mifos.teller.api.v1.domain.Teller;
-import io.mifos.teller.api.v1.domain.UnlockDrawerCommand;
 import io.mifos.teller.api.v1.domain.TellerManagementCommand;
 import io.mifos.teller.api.v1.domain.TellerTransaction;
+import io.mifos.teller.api.v1.domain.UnlockDrawerCommand;
 import io.mifos.teller.util.TellerGenerator;
 import org.apache.commons.lang3.RandomStringUtils;
 import org.junit.Assert;
@@ -33,6 +35,7 @@ import org.mockito.Mockito;
 import java.time.Clock;
 import java.time.LocalDateTime;
 import java.util.Collections;
+import java.util.Optional;
 
 public class TestTellerOperation extends AbstractTellerTest {
 
@@ -119,12 +122,12 @@ public class TestTellerOperation extends AbstractTellerTest {
     tellerTransaction.setClerk(AbstractTellerTest.TEST_USER);
     tellerTransaction.setAmount(1234.56D);
 
-    Mockito.doAnswer(invocation -> true)
-        .when(super.accountingServiceSpy).accountExists(tellerTransaction.getCustomerAccountIdentifier());
+    Mockito.doAnswer(invocation -> Optional.of(new Account()))
+        .when(super.accountingServiceSpy).findAccount(tellerTransaction.getCustomerAccountIdentifier());
     Mockito.doAnswer(invocation -> Collections.emptyList())
         .when(super.depositAccountManagementServiceSpy).getCharges(Matchers.eq(tellerTransaction));
     Mockito.doAnswer(invocation -> Collections.emptyList())
-        .when(super.depositAccountManagementServiceSpy).getProductInstance(tellerTransaction.getCustomerIdentifier());
+        .when(super.depositAccountManagementServiceSpy).fetchProductInstances(tellerTransaction.getCustomerIdentifier());
 
     super.testSubject.post(teller.getCode(), tellerTransaction);
   }
@@ -150,12 +153,14 @@ public class TestTellerOperation extends AbstractTellerTest {
     tellerTransaction.setClerk(AbstractTellerTest.TEST_USER);
     tellerTransaction.setAmount(1234.56D);
 
-    Mockito.doAnswer(invocation -> true)
-        .when(super.accountingServiceSpy).accountExists(tellerTransaction.getCustomerAccountIdentifier());
+    final Account account = new Account();
+    account.setBalance(2000.00D);
+    Mockito.doAnswer(invocation -> Optional.of(account))
+        .when(super.accountingServiceSpy).findAccount(tellerTransaction.getCustomerAccountIdentifier());
     Mockito.doAnswer(invocation -> Collections.emptyList())
         .when(super.depositAccountManagementServiceSpy).getCharges(Matchers.eq(tellerTransaction));
     Mockito.doAnswer(invocation -> Collections.emptyList())
-        .when(super.depositAccountManagementServiceSpy).getProductInstance(tellerTransaction.getCustomerIdentifier());
+        .when(super.depositAccountManagementServiceSpy).fetchProductInstances(tellerTransaction.getCustomerIdentifier());
 
     super.testSubject.post(teller.getCode(), tellerTransaction);
   }
@@ -182,14 +187,16 @@ public class TestTellerOperation extends AbstractTellerTest {
     tellerTransaction.setClerk(AbstractTellerTest.TEST_USER);
     tellerTransaction.setAmount(1234.56D);
 
-    Mockito.doAnswer(invocation -> true)
-        .when(super.accountingServiceSpy).accountExists(tellerTransaction.getCustomerAccountIdentifier());
-    Mockito.doAnswer(invocation -> true)
-        .when(super.accountingServiceSpy).accountExists(tellerTransaction.getTargetAccountIdentifier());
+    final Account account = new Account();
+    account.setBalance(2000.00D);
+    Mockito.doAnswer(invocation -> Optional.of(account))
+        .when(super.accountingServiceSpy).findAccount(tellerTransaction.getCustomerAccountIdentifier());
+    Mockito.doAnswer(invocation -> Optional.of(new Account()))
+        .when(super.accountingServiceSpy).findAccount(tellerTransaction.getTargetAccountIdentifier());
     Mockito.doAnswer(invocation -> Collections.emptyList())
         .when(super.depositAccountManagementServiceSpy).getCharges(Matchers.eq(tellerTransaction));
     Mockito.doAnswer(invocation -> Collections.emptyList())
-        .when(super.depositAccountManagementServiceSpy).getProductInstance(tellerTransaction.getCustomerIdentifier());
+        .when(super.depositAccountManagementServiceSpy).fetchProductInstances(tellerTransaction.getCustomerIdentifier());
 
     super.testSubject.post(teller.getCode(), tellerTransaction);
   }
@@ -215,12 +222,12 @@ public class TestTellerOperation extends AbstractTellerTest {
     tellerTransaction.setClerk(AbstractTellerTest.TEST_USER);
     tellerTransaction.setAmount(1234.56D);
 
-    Mockito.doAnswer(invocation -> true)
-        .when(super.accountingServiceSpy).accountExists(tellerTransaction.getCustomerAccountIdentifier());
+    Mockito.doAnswer(invocation -> Optional.of(new Account()))
+        .when(super.accountingServiceSpy).findAccount(tellerTransaction.getCustomerAccountIdentifier());
     Mockito.doAnswer(invocation -> Collections.emptyList())
         .when(super.depositAccountManagementServiceSpy).getCharges(Matchers.eq(tellerTransaction));
     Mockito.doAnswer(invocation -> Collections.emptyList())
-        .when(super.depositAccountManagementServiceSpy).getProductInstance(tellerTransaction.getCustomerIdentifier());
+        .when(super.depositAccountManagementServiceSpy).fetchProductInstances(tellerTransaction.getCustomerIdentifier());
 
     super.testSubject.post(teller.getCode(), tellerTransaction);
   }
@@ -246,16 +253,85 @@ public class TestTellerOperation extends AbstractTellerTest {
     tellerTransaction.setClerk(AbstractTellerTest.TEST_USER);
     tellerTransaction.setAmount(1234.56D);
 
-    Mockito.doAnswer(invocation -> true)
-        .when(super.accountingServiceSpy).accountExists(tellerTransaction.getCustomerAccountIdentifier());
+    final Account account = new Account();
+    account.setBalance(2000.00D);
+    Mockito.doAnswer(invocation -> Optional.of(account))
+        .when(super.accountingServiceSpy).findAccount(tellerTransaction.getCustomerAccountIdentifier());
     Mockito.doAnswer(invocation -> Collections.emptyList())
         .when(super.depositAccountManagementServiceSpy).getCharges(Matchers.eq(tellerTransaction));
     Mockito.doAnswer(invocation -> Collections.emptyList())
-        .when(super.depositAccountManagementServiceSpy).getProductInstance(tellerTransaction.getCustomerIdentifier());
+        .when(super.depositAccountManagementServiceSpy).fetchProductInstances(tellerTransaction.getCustomerIdentifier());
 
     super.testSubject.post(teller.getCode(), tellerTransaction);
   }
 
+  @Test(expected = TransactionProcessingException.class)
+  public void shouldNotWithdrawLackingBalance() throws Exception {
+    final Teller teller = this.prepareTeller();
+
+    final UnlockDrawerCommand unlockDrawerCommand = new UnlockDrawerCommand();
+    unlockDrawerCommand.setEmployeeIdentifier(AbstractTellerTest.TEST_USER);
+    unlockDrawerCommand.setPassword(teller.getPassword());
+
+    super.testSubject.unlockDrawer(teller.getCode(), unlockDrawerCommand);
+
+    super.eventRecorder.wait(EventConstants.AUTHENTICATE_TELLER, teller.getCode());
+
+    final TellerTransaction tellerTransaction =  new TellerTransaction();
+    tellerTransaction.setTransactionType(ServiceConstants.TX_CASH_WITHDRAWAL);
+    tellerTransaction.setTransactionDate(DateConverter.toIsoString(LocalDateTime.now(Clock.systemUTC())));
+    tellerTransaction.setProductIdentifier(RandomStringUtils.randomAlphanumeric(32));
+    tellerTransaction.setCustomerAccountIdentifier(RandomStringUtils.randomAlphanumeric(32));
+    tellerTransaction.setCustomerIdentifier(RandomStringUtils.randomAlphanumeric(32));
+    tellerTransaction.setClerk(AbstractTellerTest.TEST_USER);
+    tellerTransaction.setAmount(5000.00D);
+
+    final Account account = new Account();
+    account.setBalance(2000.00D);
+    Mockito.doAnswer(invocation -> Optional.of(account))
+        .when(super.accountingServiceSpy).findAccount(tellerTransaction.getCustomerAccountIdentifier());
+    Mockito.doAnswer(invocation -> Collections.emptyList())
+        .when(super.depositAccountManagementServiceSpy).getCharges(Matchers.eq(tellerTransaction));
+    Mockito.doAnswer(invocation -> Collections.emptyList())
+        .when(super.depositAccountManagementServiceSpy).fetchProductInstances(tellerTransaction.getCustomerIdentifier());
+
+    super.testSubject.post(teller.getCode(), tellerTransaction);
+  }
+
+  @Test(expected = TransactionProcessingException.class)
+  public void shouldNotWithdrawExceedsCashDrawLimit() throws Exception {
+    final Teller teller = this.prepareTeller();
+
+    final UnlockDrawerCommand unlockDrawerCommand = new UnlockDrawerCommand();
+    unlockDrawerCommand.setEmployeeIdentifier(AbstractTellerTest.TEST_USER);
+    unlockDrawerCommand.setPassword(teller.getPassword());
+
+    super.testSubject.unlockDrawer(teller.getCode(), unlockDrawerCommand);
+
+    super.eventRecorder.wait(EventConstants.AUTHENTICATE_TELLER, teller.getCode());
+
+    final TellerTransaction tellerTransaction =  new TellerTransaction();
+    tellerTransaction.setTransactionType(ServiceConstants.TX_CASH_WITHDRAWAL);
+    tellerTransaction.setTransactionDate(DateConverter.toIsoString(LocalDateTime.now(Clock.systemUTC())));
+    tellerTransaction.setProductIdentifier(RandomStringUtils.randomAlphanumeric(32));
+    tellerTransaction.setCustomerAccountIdentifier(RandomStringUtils.randomAlphanumeric(32));
+    tellerTransaction.setCustomerIdentifier(RandomStringUtils.randomAlphanumeric(32));
+    tellerTransaction.setClerk(AbstractTellerTest.TEST_USER);
+    tellerTransaction.setAmount(15000.00D);
+
+    final Account account = new Account();
+    account.setBalance(20000.00D);
+    Mockito.doAnswer(invocation -> Optional.of(account))
+        .when(super.accountingServiceSpy).findAccount(tellerTransaction.getCustomerAccountIdentifier());
+    Mockito.doAnswer(invocation -> Collections.emptyList())
+        .when(super.depositAccountManagementServiceSpy).getCharges(Matchers.eq(tellerTransaction));
+    Mockito.doAnswer(invocation -> Collections.emptyList())
+        .when(super.depositAccountManagementServiceSpy).fetchProductInstances(tellerTransaction.getCustomerIdentifier());
+
+    super.testSubject.post(teller.getCode(), tellerTransaction);
+  }
+
+
   private Teller prepareTeller() throws Exception {
     final String officeIdentifier = RandomStringUtils.randomAlphabetic(32);
     final Teller teller = TellerGenerator.createRandomTeller();
@@ -263,11 +339,11 @@ public class TestTellerOperation extends AbstractTellerTest {
     Mockito.doAnswer(invocation -> true)
         .when(super.organizationServiceSpy).officeExists(Matchers.eq(officeIdentifier));
 
-    Mockito.doAnswer(invocation -> true)
-        .when(super.accountingServiceSpy).accountExists(Matchers.eq(teller.getTellerAccountIdentifier()));
+    Mockito.doAnswer(invocation -> Optional.of(new Account()))
+        .when(super.accountingServiceSpy).findAccount(Matchers.eq(teller.getTellerAccountIdentifier()));
 
-    Mockito.doAnswer(invocation -> true)
-        .when(super.accountingServiceSpy).accountExists(Matchers.eq(teller.getVaultAccountIdentifier()));
+    Mockito.doAnswer(invocation -> Optional.of(new Account()))
+        .when(super.accountingServiceSpy).findAccount(Matchers.eq(teller.getVaultAccountIdentifier()));
 
     super.testSubject.create(officeIdentifier, teller);
 
@@ -296,11 +372,11 @@ public class TestTellerOperation extends AbstractTellerTest {
     Mockito.doAnswer(invocation -> true)
         .when(super.organizationServiceSpy).officeExists(Matchers.eq(officeIdentifier));
 
-    Mockito.doAnswer(invocation -> true)
-        .when(super.accountingServiceSpy).accountExists(Matchers.eq(teller.getTellerAccountIdentifier()));
+    Mockito.doAnswer(invocation -> Optional.of(new Account()))
+        .when(super.accountingServiceSpy).findAccount(Matchers.eq(teller.getTellerAccountIdentifier()));
 
-    Mockito.doAnswer(invocation -> true)
-        .when(super.accountingServiceSpy).accountExists(Matchers.eq(teller.getVaultAccountIdentifier()));
+    Mockito.doAnswer(invocation -> Optional.of(new Account()))
+        .when(super.accountingServiceSpy).findAccount(Matchers.eq(teller.getVaultAccountIdentifier()));
 
     super.testSubject.create(officeIdentifier, teller);
 
diff --git a/service/src/main/java/io/mifos/teller/service/internal/command/handler/TellerAggregate.java
b/service/src/main/java/io/mifos/teller/service/internal/command/handler/TellerAggregate.java
index fb43fbc..53e0a55 100644
--- a/service/src/main/java/io/mifos/teller/service/internal/command/handler/TellerAggregate.java
+++ b/service/src/main/java/io/mifos/teller/service/internal/command/handler/TellerAggregate.java
@@ -28,12 +28,12 @@ import io.mifos.core.lang.ServiceException;
 import io.mifos.teller.ServiceConstants;
 import io.mifos.teller.api.v1.EventConstants;
 import io.mifos.teller.api.v1.domain.Teller;
-import io.mifos.teller.api.v1.domain.UnlockDrawerCommand;
 import io.mifos.teller.api.v1.domain.TellerManagementCommand;
-import io.mifos.teller.service.internal.command.DrawerUnlockCommand;
+import io.mifos.teller.api.v1.domain.UnlockDrawerCommand;
 import io.mifos.teller.service.internal.command.ChangeTellerCommand;
 import io.mifos.teller.service.internal.command.CloseTellerCommand;
 import io.mifos.teller.service.internal.command.CreateTellerCommand;
+import io.mifos.teller.service.internal.command.DrawerUnlockCommand;
 import io.mifos.teller.service.internal.command.OpenTellerCommand;
 import io.mifos.teller.service.internal.command.PauseTellerCommand;
 import io.mifos.teller.service.internal.mapper.TellerMapper;
@@ -275,12 +275,12 @@ public class TellerAggregate {
       pass = false;
     }
 
-    if (!this.accountingService.accountExists(teller.getTellerAccountIdentifier())) {
+    if (!this.accountingService.findAccount(teller.getTellerAccountIdentifier()).isPresent())
{
       this.logger.warn("Teller account {} not found.", teller.getTellerAccountIdentifier());
       pass = false;
     }
 
-    if (!this.accountingService.accountExists(teller.getVaultAccountIdentifier())) {
+    if (!this.accountingService.findAccount(teller.getVaultAccountIdentifier()).isPresent())
{
       this.logger.warn("Vault account {} not found.", teller.getVaultAccountIdentifier());
       pass = false;
     }
diff --git a/service/src/main/java/io/mifos/teller/service/internal/processor/TellerTransactionProcessor.java
b/service/src/main/java/io/mifos/teller/service/internal/processor/TellerTransactionProcessor.java
index 105df99..f429425 100644
--- a/service/src/main/java/io/mifos/teller/service/internal/processor/TellerTransactionProcessor.java
+++ b/service/src/main/java/io/mifos/teller/service/internal/processor/TellerTransactionProcessor.java
@@ -19,6 +19,7 @@ import io.mifos.accounting.api.v1.domain.Creditor;
 import io.mifos.accounting.api.v1.domain.Debtor;
 import io.mifos.accounting.api.v1.domain.JournalEntry;
 import io.mifos.core.api.util.UserContextHolder;
+import io.mifos.deposit.api.v1.definition.domain.ProductDefinition;
 import io.mifos.deposit.api.v1.instance.domain.ProductInstance;
 import io.mifos.teller.ServiceConstants;
 import io.mifos.teller.api.v1.domain.Charge;
@@ -144,7 +145,6 @@ public class TellerTransactionProcessor {
 
     final TellerEntity tellerEntity = optionalTeller.get();
     final JournalEntry journalEntry = this.prepareJournalEntry(tellerTransaction);
-    journalEntry.setMessage(tellerTransaction.getTransactionType());
     final TellerTransactionCosts tellerTransactionCosts = this.depositAccountCosts(tellerTransaction);
 
     final HashSet<Debtor> debtors = new HashSet<>();
@@ -214,7 +214,7 @@ public class TellerTransactionProcessor {
 
   private void processDepositAccountClosing(final String tellerCode, final TellerTransaction
tellerTransaction) {
     final List<ProductInstance> productInstances =
-        this.depositAccountManagementService.getProductInstance(tellerTransaction.getCustomerIdentifier());
+        this.depositAccountManagementService.fetchProductInstances(tellerTransaction.getCustomerIdentifier());
 
     this.processCashWithdrawal(tellerCode, tellerTransaction);
 
@@ -227,17 +227,18 @@ public class TellerTransactionProcessor {
   }
 
   private void processDepositAccountOpening(final String tellerCode, final TellerTransaction
tellerTransaction) {
-    final List<ProductInstance> productInstances =
-        this.depositAccountManagementService.getProductInstance(tellerTransaction.getCustomerIdentifier());
+    final ProductInstance productInstances =
+        this.depositAccountManagementService.findProductInstance(tellerTransaction.getCustomerAccountIdentifier());
+
+    final ProductDefinition productDefinition =
+        this.depositAccountManagementService.findProductDefinition(productInstances.getProductIdentifier());
 
     this.processCashDeposit(tellerCode, tellerTransaction);
 
-    productInstances.forEach(productInstance -> {
-      if (productInstance.getAccountIdentifier().equals(tellerTransaction.getCustomerAccountIdentifier()))
{
-        this.depositAccountManagementService.activateProductInstance(tellerTransaction.getCustomerAccountIdentifier());
-        this.accountingService.openAccount(tellerTransaction.getCustomerAccountIdentifier());
-      }
-    });
+    if ((tellerTransaction.getAmount() + productInstances.getBalance()) >= productDefinition.getMinimumBalance())
{
+      this.depositAccountManagementService.activateProductInstance(tellerTransaction.getCustomerAccountIdentifier());
+      this.accountingService.openAccount(tellerTransaction.getCustomerAccountIdentifier());
+    }
   }
 
   private JournalEntry prepareJournalEntry(final TellerTransaction tellerTransaction) {
@@ -245,6 +246,7 @@ public class TellerTransactionProcessor {
     journalEntry.setTransactionIdentifier(tellerTransaction.getIdentifier());
     journalEntry.setTransactionDate(tellerTransaction.getTransactionDate());
     journalEntry.setTransactionType(tellerTransaction.getTransactionType());
+    journalEntry.setMessage(tellerTransaction.getTransactionType());
     journalEntry.setClerk(UserContextHolder.checkedGetUser());
 
     return journalEntry;
diff --git a/service/src/main/java/io/mifos/teller/service/internal/service/helper/AccountingService.java
b/service/src/main/java/io/mifos/teller/service/internal/service/helper/AccountingService.java
index 2926910..e5fce56 100644
--- a/service/src/main/java/io/mifos/teller/service/internal/service/helper/AccountingService.java
+++ b/service/src/main/java/io/mifos/teller/service/internal/service/helper/AccountingService.java
@@ -17,6 +17,7 @@ package io.mifos.teller.service.internal.service.helper;
 
 import io.mifos.accounting.api.v1.client.AccountNotFoundException;
 import io.mifos.accounting.api.v1.client.LedgerManager;
+import io.mifos.accounting.api.v1.domain.Account;
 import io.mifos.accounting.api.v1.domain.AccountCommand;
 import io.mifos.accounting.api.v1.domain.AccountEntryPage;
 import io.mifos.accounting.api.v1.domain.JournalEntry;
@@ -27,6 +28,8 @@ import org.springframework.beans.factory.annotation.Qualifier;
 import org.springframework.data.domain.Sort;
 import org.springframework.stereotype.Service;
 
+import java.util.Optional;
+
 @Service
 public class AccountingService {
 
@@ -41,13 +44,12 @@ public class AccountingService {
     this.ledgerManager = ledgerManager;
   }
 
-  public boolean accountExists(final String accountIdentifier) {
+  public Optional<Account> findAccount(final String accountIdentifier) {
     try {
-      this.ledgerManager.findAccount(accountIdentifier);
-      return true;
+      return Optional.of(this.ledgerManager.findAccount(accountIdentifier));
     } catch (final AccountNotFoundException anfex) {
       this.logger.warn("Account {} not found.", accountIdentifier);
-      return false;
+      return Optional.empty();
     }
   }
 
diff --git a/service/src/main/java/io/mifos/teller/service/internal/service/helper/DepositAccountManagementService.java
b/service/src/main/java/io/mifos/teller/service/internal/service/helper/DepositAccountManagementService.java
index 891641f..2843195 100644
--- a/service/src/main/java/io/mifos/teller/service/internal/service/helper/DepositAccountManagementService.java
+++ b/service/src/main/java/io/mifos/teller/service/internal/service/helper/DepositAccountManagementService.java
@@ -46,10 +46,14 @@ public class DepositAccountManagementService {
     this.depositAccountManager = depositAccountManager;
   }
 
-  public List<ProductInstance> getProductInstance(final String customerIdentifier)
{
+  public List<ProductInstance> fetchProductInstances(final String customerIdentifier)
{
     return this.depositAccountManager.fetchProductInstances(customerIdentifier);
   }
 
+  public ProductInstance findProductInstance(final String accountIdentifier) {
+    return this.depositAccountManager.findProductInstance(accountIdentifier);
+  }
+
   public List<Charge> getCharges(final TellerTransaction tellerTransaction) {
     final List<Charge> charges = new ArrayList<>();
     final ProductDefinition productDefinition =
@@ -87,4 +91,8 @@ public class DepositAccountManagementService {
   public void closeProductInstance(final String customerAccountIdentifier) {
     this.depositAccountManager.postProductInstanceCommand(customerAccountIdentifier, EventConstants.CLOSE_PRODUCT_INSTANCE_COMMAND);
   }
+
+  public ProductDefinition findProductDefinition(final String productIdentifier) {
+    return this.depositAccountManager.findProductDefinition(productIdentifier);
+  }
 }
diff --git a/service/src/main/java/io/mifos/teller/service/rest/TellerManagementRestController.java
b/service/src/main/java/io/mifos/teller/service/rest/TellerManagementRestController.java
index feef72a..454d02c 100644
--- a/service/src/main/java/io/mifos/teller/service/rest/TellerManagementRestController.java
+++ b/service/src/main/java/io/mifos/teller/service/rest/TellerManagementRestController.java
@@ -209,7 +209,7 @@ public class TellerManagementRestController {
   }
 
   private void verifyAccount(final String accountIdentifier) {
-    if (!this.accountingService.accountExists(accountIdentifier)) {
+    if (!this.accountingService.findAccount(accountIdentifier).isPresent()) {
       throw ServiceException.badRequest("Account {0} not found.", accountIdentifier);
     }
   }
diff --git a/service/src/main/java/io/mifos/teller/service/rest/TellerOperationRestController.java
b/service/src/main/java/io/mifos/teller/service/rest/TellerOperationRestController.java
index 68d6876..2a2ca8d 100644
--- a/service/src/main/java/io/mifos/teller/service/rest/TellerOperationRestController.java
+++ b/service/src/main/java/io/mifos/teller/service/rest/TellerOperationRestController.java
@@ -15,6 +15,7 @@
  */
 package io.mifos.teller.service.rest;
 
+import io.mifos.accounting.api.v1.domain.Account;
 import io.mifos.anubis.annotation.AcceptedTokenType;
 import io.mifos.anubis.annotation.Permittable;
 import io.mifos.core.api.util.UserContextHolder;
@@ -23,12 +24,12 @@ import io.mifos.core.lang.ServiceException;
 import io.mifos.teller.ServiceConstants;
 import io.mifos.teller.api.v1.PermittableGroupIds;
 import io.mifos.teller.api.v1.domain.Teller;
-import io.mifos.teller.api.v1.domain.UnlockDrawerCommand;
 import io.mifos.teller.api.v1.domain.TellerTransaction;
 import io.mifos.teller.api.v1.domain.TellerTransactionCosts;
-import io.mifos.teller.service.internal.command.DrawerUnlockCommand;
+import io.mifos.teller.api.v1.domain.UnlockDrawerCommand;
 import io.mifos.teller.service.internal.command.CancelTellerTransactionCommand;
 import io.mifos.teller.service.internal.command.ConfirmTellerTransactionCommand;
+import io.mifos.teller.service.internal.command.DrawerUnlockCommand;
 import io.mifos.teller.service.internal.command.InitializeTellerTransactionCommand;
 import io.mifos.teller.service.internal.command.PauseTellerCommand;
 import io.mifos.teller.service.internal.service.TellerManagementService;
@@ -155,12 +156,33 @@ public class TellerOperationRestController {
       throw ServiceException.conflict("Teller {0} ist not active.", tellerCode);
     }
 
-    if (!this.accountingService.accountExists(tellerTransaction.getCustomerAccountIdentifier()))
{
+    final String transactionType = tellerTransaction.getTransactionType();
+
+    if (transactionType.equals(ServiceConstants.TX_CASH_WITHDRAWAL)
+        || transactionType.equals(ServiceConstants.TX_CLOSE_ACCOUNT)) {
+      if (tellerTransaction.getAmount() > teller.getCashdrawLimit()) {
+        throw ServiceException.conflict("Amount exceeds cash drawl limit.");
+      }
+    }
+
+    final Optional<Account> optionalCustomerAccount =
+        this.accountingService.findAccount(tellerTransaction.getCustomerAccountIdentifier());
+    if (!optionalCustomerAccount.isPresent()) {
       throw ServiceException.badRequest("Customer account {0} not found.");
+    } else {
+      if (transactionType.equals(ServiceConstants.TX_ACCOUNT_TRANSFER)
+          || transactionType.equals(ServiceConstants.TX_CASH_WITHDRAWAL)
+          || transactionType.equals(ServiceConstants.TX_CLOSE_ACCOUNT)) {
+
+        final Account customerAccount = optionalCustomerAccount.get();
+        if (customerAccount.getBalance() < tellerTransaction.getAmount()) {
+          throw ServiceException.conflict("Not enough balance.");
+        }
+      }
     }
 
     if (tellerTransaction.getTargetAccountIdentifier() != null &&
-        !this.accountingService.accountExists(tellerTransaction.getTargetAccountIdentifier()))
{
+        !this.accountingService.findAccount(tellerTransaction.getTargetAccountIdentifier()).isPresent())
{
       throw ServiceException.badRequest("Target account {0} not found.");
     }
 

-- 
To stop receiving notification emails like this one, please contact
myrle@apache.org.

Mime
View raw message