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-customer.git

commit a8fa2be1cc77767cd5590f736f6d7977534e99a8
Author: Myrle Krantz <[email protected]>
AuthorDate: Mon Aug 14 12:49:49 2017 +0200

    Added helper function to feign client isCustomerInGoodStanding.
---
 .../customer/api/v1/client/CustomerManager.java    | 13 +++++++++-
 .../main/java/io/mifos/customer/TestCustomer.java  | 30 ++++++++++++++++++++++
 2 files changed, 42 insertions(+), 1 deletion(-)

diff --git 
a/api/src/main/java/io/mifos/customer/api/v1/client/CustomerManager.java 
b/api/src/main/java/io/mifos/customer/api/v1/client/CustomerManager.java
index bac6bcb..281ce1c 100644
--- a/api/src/main/java/io/mifos/customer/api/v1/client/CustomerManager.java
+++ b/api/src/main/java/io/mifos/customer/api/v1/client/CustomerManager.java
@@ -17,7 +17,6 @@ package io.mifos.customer.api.v1.client;
 
 import io.mifos.core.api.annotation.ThrowsException;
 import io.mifos.core.api.annotation.ThrowsExceptions;
-import io.mifos.core.api.util.CustomFeignClientsConfiguration;
 import io.mifos.customer.api.v1.config.CustomerFeignClientConfig;
 import io.mifos.customer.api.v1.domain.Address;
 import io.mifos.customer.api.v1.domain.Command;
@@ -77,6 +76,18 @@ public interface CustomerManager {
   @ThrowsException(status = HttpStatus.NOT_FOUND, exception = 
CustomerNotFoundException.class)
   Customer findCustomer(@PathVariable("identifier") final String identifier);
 
+  default boolean isCustomerInGoodStanding(final String customerIdentifier) {
+    final Customer customer;
+    try {
+      customer = this.findCustomer(customerIdentifier);
+    }
+    catch (CustomerNotFoundException e) {
+      return false;
+    }
+    final Customer.State state = 
Customer.State.valueOf(customer.getCurrentState());
+    return (state == Customer.State.ACTIVE);
+  }
+
   @RequestMapping(
       value = "/customers/{identifier}",
       method = RequestMethod.PUT,
diff --git a/component-test/src/main/java/io/mifos/customer/TestCustomer.java 
b/component-test/src/main/java/io/mifos/customer/TestCustomer.java
index 7ddf59e..0df8a02 100644
--- a/component-test/src/main/java/io/mifos/customer/TestCustomer.java
+++ b/component-test/src/main/java/io/mifos/customer/TestCustomer.java
@@ -38,6 +38,9 @@ public class TestCustomer extends AbstractCustomerTest {
 
     this.eventRecorder.wait(CustomerEventConstants.POST_CUSTOMER, 
customer.getIdentifier());
 
+    //Pending customer is not in good standing.
+    
Assert.assertFalse(this.customerManager.isCustomerInGoodStanding(customer.getIdentifier()));
+
     final Customer createdCustomer = 
this.customerManager.findCustomer(customer.getIdentifier());
     Assert.assertNotNull(createdCustomer);
   }
@@ -97,6 +100,11 @@ public class TestCustomer extends AbstractCustomerTest {
   }
 
   @Test
+  public void shouldFindNonExistentCustomerIsNotInGoodStanding() throws 
Exception {
+    
Assert.assertFalse(this.customerManager.isCustomerInGoodStanding(testEnvironment.generateUniqueIdentifer("don")));
+  }
+
+  @Test
   public void shouldFetchCustomers() throws Exception {
     Stream.of(
         CustomerGenerator.createRandomCustomer(),
@@ -164,6 +172,8 @@ public class TestCustomer extends AbstractCustomerTest {
     this.customerManager.customerCommand(customer.getIdentifier(), 
CommandGenerator.create(Command.Action.ACTIVATE, "Test"));
     this.eventRecorder.wait(CustomerEventConstants.ACTIVATE_CUSTOMER, 
customer.getIdentifier());
 
+    
Assert.assertTrue(this.customerManager.isCustomerInGoodStanding(customer.getIdentifier()));
+
     final Customer activatedCustomer = 
this.customerManager.findCustomer(customer.getIdentifier());
     Assert.assertEquals(Customer.State.ACTIVE.name(), 
activatedCustomer.getCurrentState());
   }
@@ -178,9 +188,13 @@ public class TestCustomer extends AbstractCustomerTest {
     this.customerManager.customerCommand(customer.getIdentifier(), 
CommandGenerator.create(Command.Action.ACTIVATE, "Test"));
     this.eventRecorder.wait(CustomerEventConstants.ACTIVATE_CUSTOMER, 
customer.getIdentifier());
 
+    
Assert.assertTrue(this.customerManager.isCustomerInGoodStanding(customer.getIdentifier()));
+
     this.customerManager.customerCommand(customer.getIdentifier(), 
CommandGenerator.create(Command.Action.LOCK, "Test"));
     this.eventRecorder.wait(CustomerEventConstants.LOCK_CUSTOMER, 
customer.getIdentifier());
 
+    
Assert.assertFalse(this.customerManager.isCustomerInGoodStanding(customer.getIdentifier()));
+
     final Customer lockedCustomer = 
this.customerManager.findCustomer(customer.getIdentifier());
     Assert.assertEquals(Customer.State.LOCKED.name(), 
lockedCustomer.getCurrentState());
   }
@@ -195,12 +209,18 @@ public class TestCustomer extends AbstractCustomerTest {
     this.customerManager.customerCommand(customer.getIdentifier(), 
CommandGenerator.create(Command.Action.ACTIVATE, "Test"));
     this.eventRecorder.wait(CustomerEventConstants.ACTIVATE_CUSTOMER, 
customer.getIdentifier());
 
+    
Assert.assertTrue(this.customerManager.isCustomerInGoodStanding(customer.getIdentifier()));
+
     this.customerManager.customerCommand(customer.getIdentifier(), 
CommandGenerator.create(Command.Action.LOCK, "Test"));
     this.eventRecorder.wait(CustomerEventConstants.LOCK_CUSTOMER, 
customer.getIdentifier());
 
+    
Assert.assertFalse(this.customerManager.isCustomerInGoodStanding(customer.getIdentifier()));
+
     this.customerManager.customerCommand(customer.getIdentifier(), 
CommandGenerator.create(Command.Action.UNLOCK, "Test"));
     this.eventRecorder.wait(CustomerEventConstants.UNLOCK_CUSTOMER, 
customer.getIdentifier());
 
+    
Assert.assertTrue(this.customerManager.isCustomerInGoodStanding(customer.getIdentifier()));
+
     final Customer unlockedCustomer = 
this.customerManager.findCustomer(customer.getIdentifier());
     Assert.assertEquals(Customer.State.ACTIVE.name(), 
unlockedCustomer.getCurrentState());
   }
@@ -215,9 +235,13 @@ public class TestCustomer extends AbstractCustomerTest {
     this.customerManager.customerCommand(customer.getIdentifier(), 
CommandGenerator.create(Command.Action.ACTIVATE, "Test"));
     this.eventRecorder.wait(CustomerEventConstants.ACTIVATE_CUSTOMER, 
customer.getIdentifier());
 
+    
Assert.assertTrue(this.customerManager.isCustomerInGoodStanding(customer.getIdentifier()));
+
     this.customerManager.customerCommand(customer.getIdentifier(), 
CommandGenerator.create(Command.Action.CLOSE, "Test"));
     this.eventRecorder.wait(CustomerEventConstants.CLOSE_CUSTOMER, 
customer.getIdentifier());
 
+    
Assert.assertFalse(this.customerManager.isCustomerInGoodStanding(customer.getIdentifier()));
+
     final Customer closedCustomer = 
this.customerManager.findCustomer(customer.getIdentifier());
     Assert.assertEquals(Customer.State.CLOSED.name(), 
closedCustomer.getCurrentState());
   }
@@ -232,12 +256,18 @@ public class TestCustomer extends AbstractCustomerTest {
     this.customerManager.customerCommand(customer.getIdentifier(), 
CommandGenerator.create(Command.Action.ACTIVATE, "Test"));
     this.eventRecorder.wait(CustomerEventConstants.ACTIVATE_CUSTOMER, 
customer.getIdentifier());
 
+    
Assert.assertTrue(this.customerManager.isCustomerInGoodStanding(customer.getIdentifier()));
+
     this.customerManager.customerCommand(customer.getIdentifier(), 
CommandGenerator.create(Command.Action.CLOSE, "Test"));
     this.eventRecorder.wait(CustomerEventConstants.CLOSE_CUSTOMER, 
customer.getIdentifier());
 
+    
Assert.assertFalse(this.customerManager.isCustomerInGoodStanding(customer.getIdentifier()));
+
     this.customerManager.customerCommand(customer.getIdentifier(), 
CommandGenerator.create(Command.Action.REOPEN, "Test"));
     this.eventRecorder.wait(CustomerEventConstants.REOPEN_CUSTOMER, 
customer.getIdentifier());
 
+    
Assert.assertTrue(this.customerManager.isCustomerInGoodStanding(customer.getIdentifier()));
+
     final Customer reopenedCustomer = 
this.customerManager.findCustomer(customer.getIdentifier());
     Assert.assertEquals(Customer.State.ACTIVE.name(), 
reopenedCustomer.getCurrentState());
   }

-- 
To stop receiving notification emails like this one, please contact
[email protected].

Reply via email to