From d05dd0e9b6ba175474733a8eb87a352e4d5ee1a2 Mon Sep 17 00:00:00 2001 From: Vishwa1311 Date: Mon, 17 Mar 2014 11:41:01 +0530 Subject: [PATCH] [MIFOSX-993] JUnit Integration Test Cases for GroupSavings --- .../ClientSavingsIntegrationTest.java | 28 +- .../GroupSavingsIntegrationTest.java | 447 ++++++++++++++++++ .../common/savings/SavingsAccountHelper.java | 10 +- .../SavingsApplicationTestBuilder.java | 8 +- 4 files changed, 473 insertions(+), 20 deletions(-) create mode 100644 mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/GroupSavingsIntegrationTest.java diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/ClientSavingsIntegrationTest.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/ClientSavingsIntegrationTest.java index bc7b72d88..7e97db0f9 100755 --- a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/ClientSavingsIntegrationTest.java +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/ClientSavingsIntegrationTest.java @@ -35,6 +35,7 @@ public class ClientSavingsIntegrationTest { public static final String WITHDRAW_AMOUNT = "1000"; public static final String WITHDRAW_AMOUNT_ADJUSTED = "500"; public static final String MINIMUM_OPENING_BALANCE = "1000.0"; + public static final String ACCOUNT_TYPE_INDIVIDUAL = "INDIVIDUAL"; private ResponseSpecification responseSpec; private RequestSpecification requestSpec; @@ -58,10 +59,11 @@ public class ClientSavingsIntegrationTest { final Integer savingsProductID = createSavingsProduct(this.requestSpec, this.responseSpec, MINIMUM_OPENING_BALANCE); Assert.assertNotNull(savingsProductID); - final Integer savingsId = this.savingsAccountHelper.applyForSavingsApplication(clientID, savingsProductID); + final Integer savingsId = this.savingsAccountHelper.applyForSavingsApplication(clientID, savingsProductID, ACCOUNT_TYPE_INDIVIDUAL); Assert.assertNotNull(savingsProductID); - HashMap modifications = this.savingsAccountHelper.updateSavingsAccount(clientID, savingsProductID, savingsId); + HashMap modifications = this.savingsAccountHelper.updateSavingsAccount(clientID, savingsProductID, savingsId, + ACCOUNT_TYPE_INDIVIDUAL); Assert.assertTrue(modifications.containsKey("submittedOnDate")); HashMap savingsStatusHashMap = SavingsStatusChecker.getStatusOfSavings(this.requestSpec, this.responseSpec, savingsId); @@ -97,7 +99,7 @@ public class ClientSavingsIntegrationTest { final Integer savingsProductID = createSavingsProduct(this.requestSpec, this.responseSpec, null); Assert.assertNotNull(savingsProductID); - final Integer savingsId = this.savingsAccountHelper.applyForSavingsApplication(clientID, savingsProductID); + final Integer savingsId = this.savingsAccountHelper.applyForSavingsApplication(clientID, savingsProductID, ACCOUNT_TYPE_INDIVIDUAL); Assert.assertNotNull(savingsProductID); HashMap savingsStatusHashMap = SavingsStatusChecker.getStatusOfSavings(this.requestSpec, this.responseSpec, savingsId); @@ -127,7 +129,7 @@ public class ClientSavingsIntegrationTest { final Integer savingsProductID = createSavingsProduct(this.requestSpec, this.responseSpec, null); Assert.assertNotNull(savingsProductID); - final Integer savingsId = this.savingsAccountHelper.applyForSavingsApplication(clientID, savingsProductID); + final Integer savingsId = this.savingsAccountHelper.applyForSavingsApplication(clientID, savingsProductID, ACCOUNT_TYPE_INDIVIDUAL); Assert.assertNotNull(savingsProductID); HashMap savingsStatusHashMap = SavingsStatusChecker.getStatusOfSavings(this.requestSpec, this.responseSpec, savingsId); @@ -166,7 +168,7 @@ public class ClientSavingsIntegrationTest { final Integer savingsProductID = createSavingsProduct(this.requestSpec, this.responseSpec, MINIMUM_OPENING_BALANCE); Assert.assertNotNull(savingsProductID); - final Integer savingsId = this.savingsAccountHelper.applyForSavingsApplication(clientID, savingsProductID); + final Integer savingsId = this.savingsAccountHelper.applyForSavingsApplication(clientID, savingsProductID, ACCOUNT_TYPE_INDIVIDUAL); Assert.assertNotNull(savingsProductID); HashMap savingsStatusHashMap = SavingsStatusChecker.getStatusOfSavings(this.requestSpec, this.responseSpec, savingsId); @@ -207,7 +209,7 @@ public class ClientSavingsIntegrationTest { final Integer savingsProductID = createSavingsProduct(this.requestSpec, this.responseSpec, MINIMUM_OPENING_BALANCE); Assert.assertNotNull(savingsProductID); - final Integer savingsId = this.savingsAccountHelper.applyForSavingsApplication(clientID, savingsProductID); + final Integer savingsId = this.savingsAccountHelper.applyForSavingsApplication(clientID, savingsProductID, ACCOUNT_TYPE_INDIVIDUAL); Assert.assertNotNull(savingsProductID); HashMap savingsStatusHashMap = SavingsStatusChecker.getStatusOfSavings(this.requestSpec, this.responseSpec, savingsId); @@ -231,7 +233,7 @@ public class ClientSavingsIntegrationTest { final Integer savingsProductID = createSavingsProduct(this.requestSpec, this.responseSpec, MINIMUM_OPENING_BALANCE); Assert.assertNotNull(savingsProductID); - final Integer savingsId = this.savingsAccountHelper.applyForSavingsApplication(clientID, savingsProductID); + final Integer savingsId = this.savingsAccountHelper.applyForSavingsApplication(clientID, savingsProductID, ACCOUNT_TYPE_INDIVIDUAL); Assert.assertNotNull(savingsProductID); HashMap savingsStatusHashMap = SavingsStatusChecker.getStatusOfSavings(this.requestSpec, this.responseSpec, savingsId); @@ -325,7 +327,7 @@ public class ClientSavingsIntegrationTest { final Integer savingsProductID = createSavingsProduct(this.requestSpec, this.responseSpec, MINIMUM_OPENING_BALANCE); Assert.assertNotNull(savingsProductID); - final Integer savingsId = this.savingsAccountHelper.applyForSavingsApplication(clientID, savingsProductID); + final Integer savingsId = this.savingsAccountHelper.applyForSavingsApplication(clientID, savingsProductID, ACCOUNT_TYPE_INDIVIDUAL); Assert.assertNotNull(savingsProductID); HashMap savingsStatusHashMap = SavingsStatusChecker.getStatusOfSavings(this.requestSpec, this.responseSpec, savingsId); @@ -336,7 +338,7 @@ public class ClientSavingsIntegrationTest { Assert.assertNotNull(withdrawalChargeId); this.savingsAccountHelper.addChargesForSavings(savingsId, withdrawalChargeId); - ArrayList chargesPendingState = this.savingsAccountHelper.getSavingsChanrges(savingsId); + ArrayList chargesPendingState = this.savingsAccountHelper.getSavingsCharges(savingsId); Assert.assertEquals(1, chargesPendingState.size()); Integer savingsChargeId = (Integer) chargesPendingState.get(0).get("id"); @@ -346,7 +348,7 @@ public class ClientSavingsIntegrationTest { Integer deletedChargeId = this.savingsAccountHelper.deleteCharge(savingsChargeId, savingsId); assertEquals(savingsChargeId, deletedChargeId); - chargesPendingState = this.savingsAccountHelper.getSavingsChanrges(savingsId); + chargesPendingState = this.savingsAccountHelper.getSavingsCharges(savingsId); Assert.assertTrue(chargesPendingState == null || chargesPendingState.size() == 0); savingsStatusHashMap = this.savingsAccountHelper.approveSavings(savingsId); @@ -358,11 +360,11 @@ public class ClientSavingsIntegrationTest { final Integer chargeId = ChargesHelper.createCharges(this.requestSpec, this.responseSpec, ChargesHelper.getSavingsAnnualFeeJSON()); Assert.assertNotNull(chargeId); - ArrayList charges = this.savingsAccountHelper.getSavingsChanrges(savingsId); + ArrayList charges = this.savingsAccountHelper.getSavingsCharges(savingsId); Assert.assertTrue(charges == null || charges.size() == 0); this.savingsAccountHelper.addChargesForSavings(savingsId, chargeId); - charges = this.savingsAccountHelper.getSavingsChanrges(savingsId); + charges = this.savingsAccountHelper.getSavingsCharges(savingsId); Assert.assertEquals(1, charges.size()); HashMap savingsChargeForPay = charges.get(0); @@ -383,7 +385,7 @@ public class ClientSavingsIntegrationTest { Assert.assertNotNull(monthlyFeechargeId); this.savingsAccountHelper.addChargesForSavings(savingsId, monthlyFeechargeId); - charges = this.savingsAccountHelper.getSavingsChanrges(savingsId); + charges = this.savingsAccountHelper.getSavingsCharges(savingsId); Assert.assertEquals(2, charges.size()); HashMap savingsChargeForWaive = charges.get(1); diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/GroupSavingsIntegrationTest.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/GroupSavingsIntegrationTest.java new file mode 100644 index 000000000..bb2e6488a --- /dev/null +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/GroupSavingsIntegrationTest.java @@ -0,0 +1,447 @@ +package org.mifosplatform.integrationtests; + +import static org.junit.Assert.assertEquals; + +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.HashMap; +import java.util.List; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.mifosplatform.integrationtests.common.ClientHelper; +import org.mifosplatform.integrationtests.common.CommonConstants; +import org.mifosplatform.integrationtests.common.GroupHelper; +import org.mifosplatform.integrationtests.common.Utils; +import org.mifosplatform.integrationtests.common.charges.ChargesHelper; +import org.mifosplatform.integrationtests.common.savings.SavingsAccountHelper; +import org.mifosplatform.integrationtests.common.savings.SavingsProductHelper; +import org.mifosplatform.integrationtests.common.savings.SavingsStatusChecker; + +import com.jayway.restassured.builder.RequestSpecBuilder; +import com.jayway.restassured.builder.ResponseSpecBuilder; +import com.jayway.restassured.http.ContentType; +import com.jayway.restassured.specification.RequestSpecification; +import com.jayway.restassured.specification.ResponseSpecification; + +/** + * Group Savings Integration Test for checking Savings Application. + */ +@SuppressWarnings({ "rawtypes", "unused" }) +public class GroupSavingsIntegrationTest { + + public static final String DEPOSIT_AMOUNT = "2000"; + public static final String WITHDRAW_AMOUNT = "1000"; + public static final String WITHDRAW_AMOUNT_ADJUSTED = "500"; + public static final String MINIMUM_OPENING_BALANCE = "1000.0"; + public static final String ACCOUNT_TYPE_GROUP = "GROUP"; + + private ResponseSpecification responseSpec; + private RequestSpecification requestSpec; + private SavingsAccountHelper savingsAccountHelper; + + @Before + public void setup() { + Utils.initializeRESTAssured(); + this.requestSpec = new RequestSpecBuilder().setContentType(ContentType.JSON).build(); + this.requestSpec.header("Authorization", "Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey()); + this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build(); + } + + @Test + public void testSavingsAccount() { + this.savingsAccountHelper = new SavingsAccountHelper(requestSpec, responseSpec); + + final Integer clientID = ClientHelper.createClient(this.requestSpec, this.responseSpec); + Assert.assertNotNull(clientID); + + Integer groupID = GroupHelper.createGroup(this.requestSpec, this.responseSpec, true); + Assert.assertNotNull(groupID); + + groupID = GroupHelper.associateClient(this.requestSpec, this.responseSpec, groupID.toString(), clientID.toString()); + Assert.assertNotNull(groupID); + + final Integer savingsProductID = createSavingsProduct(this.requestSpec, this.responseSpec, MINIMUM_OPENING_BALANCE); + Assert.assertNotNull(savingsProductID); + + final Integer savingsId = this.savingsAccountHelper.applyForSavingsApplication(groupID, savingsProductID, ACCOUNT_TYPE_GROUP); + Assert.assertNotNull(savingsId); + + HashMap modifications = this.savingsAccountHelper.updateSavingsAccount(groupID, savingsProductID, savingsId, ACCOUNT_TYPE_GROUP); + Assert.assertTrue(modifications.containsKey("submittedOnDate")); + + HashMap savingsStatusHashMap = SavingsStatusChecker.getStatusOfSavings(this.requestSpec, this.responseSpec, savingsId); + SavingsStatusChecker.verifySavingsIsPending(savingsStatusHashMap); + + savingsStatusHashMap = this.savingsAccountHelper.approveSavings(savingsId); + SavingsStatusChecker.verifySavingsIsApproved(savingsStatusHashMap); + + savingsStatusHashMap = this.savingsAccountHelper.activateSavings(savingsId); + SavingsStatusChecker.verifySavingsIsActive(savingsStatusHashMap); + + final HashMap summaryBefore = this.savingsAccountHelper.getSavingsSummary(savingsId); + this.savingsAccountHelper.calculateInterestForSavings(savingsId); + HashMap summary = this.savingsAccountHelper.getSavingsSummary(savingsId); + assertEquals(summaryBefore, summary); + + this.savingsAccountHelper.postInterestForSavings(savingsId); + summary = this.savingsAccountHelper.getSavingsSummary(savingsId); + Assert.assertFalse(summaryBefore.equals(summary)); + + final Object savingsInterest = this.savingsAccountHelper.getSavingsInterest(savingsId); + } + + @Test + public void testSavingsAccount_CLOSE_APPLICATION() { + this.savingsAccountHelper = new SavingsAccountHelper(this.requestSpec, this.responseSpec); + + final Integer clientID = ClientHelper.createClient(this.requestSpec, this.responseSpec); + Assert.assertNotNull(clientID); + + Integer groupID = GroupHelper.createGroup(this.requestSpec, this.responseSpec, true); + Assert.assertNotNull(groupID); + + groupID = GroupHelper.associateClient(this.requestSpec, this.responseSpec, groupID.toString(), clientID.toString()); + Assert.assertNotNull(groupID); + + final Integer savingsProductID = createSavingsProduct(this.requestSpec, this.responseSpec, null); + Assert.assertNotNull(savingsProductID); + + final Integer savingsId = this.savingsAccountHelper.applyForSavingsApplication(groupID, savingsProductID, ACCOUNT_TYPE_GROUP); + Assert.assertNotNull(savingsId); + + HashMap savingsStatusHashMap = SavingsStatusChecker.getStatusOfSavings(this.requestSpec, this.responseSpec, savingsId); + SavingsStatusChecker.verifySavingsIsPending(savingsStatusHashMap); + + savingsStatusHashMap = this.savingsAccountHelper.approveSavings(savingsId); + SavingsStatusChecker.verifySavingsIsApproved(savingsStatusHashMap); + + savingsStatusHashMap = this.savingsAccountHelper.activateSavings(savingsId); + SavingsStatusChecker.verifySavingsIsActive(savingsStatusHashMap); + + savingsStatusHashMap = this.savingsAccountHelper.closeSavingsAccount(savingsId); + SavingsStatusChecker.verifySavingsAccountIsClosed(savingsStatusHashMap); + } + + @SuppressWarnings("unchecked") + @Test + public void testSavingsAccount_DELETE_APPLICATION() { + this.savingsAccountHelper = new SavingsAccountHelper(this.requestSpec, this.responseSpec); + + SavingsAccountHelper savingsAccountHelperValidationError = new SavingsAccountHelper(this.requestSpec, + new ResponseSpecBuilder().build()); + + final Integer clientID = ClientHelper.createClient(this.requestSpec, this.responseSpec); + Assert.assertNotNull(clientID); + + Integer groupID = GroupHelper.createGroup(this.requestSpec, this.responseSpec, true); + Assert.assertNotNull(groupID); + + groupID = GroupHelper.associateClient(this.requestSpec, this.responseSpec, groupID.toString(), clientID.toString()); + Assert.assertNotNull(groupID); + + final Integer savingsProductID = createSavingsProduct(this.requestSpec, this.responseSpec, null); + Assert.assertNotNull(savingsProductID); + + final Integer savingsId = this.savingsAccountHelper.applyForSavingsApplication(groupID, savingsProductID, ACCOUNT_TYPE_GROUP); + Assert.assertNotNull(savingsId); + + HashMap savingsStatusHashMap = SavingsStatusChecker.getStatusOfSavings(this.requestSpec, this.responseSpec, savingsId); + SavingsStatusChecker.verifySavingsIsPending(savingsStatusHashMap); + + savingsStatusHashMap = this.savingsAccountHelper.approveSavings(savingsId); + SavingsStatusChecker.verifySavingsIsApproved(savingsStatusHashMap); + + List error1 = (List) savingsAccountHelperValidationError.deleteSavingsApplication(savingsId, + CommonConstants.RESPONSE_ERROR); + assertEquals("validation.msg.savingsaccount.delete.not.in.submittedandpendingapproval.state", + error1.get(0).get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE)); + + savingsStatusHashMap = this.savingsAccountHelper.undoApproval(savingsId); + SavingsStatusChecker.verifySavingsIsPending(savingsStatusHashMap); + + this.savingsAccountHelper.deleteSavingsApplication(savingsId, CommonConstants.RESPONSE_RESOURCE_ID); + + List error = savingsAccountHelperValidationError.getSavingsCollectionAttribute(savingsId, CommonConstants.RESPONSE_ERROR); + assertEquals("error.msg.saving.account.id.invalid", error.get(0).get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE)); + + } + + @SuppressWarnings("unchecked") + @Test + public void testSavingsAccount_REJECT_APPLICATION() { + + this.savingsAccountHelper = new SavingsAccountHelper(this.requestSpec, this.responseSpec); + + SavingsAccountHelper savingsAccountHelperValidationError = new SavingsAccountHelper(this.requestSpec, + new ResponseSpecBuilder().build()); + + final Integer clientID = ClientHelper.createClient(this.requestSpec, this.responseSpec); + Assert.assertNotNull(clientID); + + Integer groupID = GroupHelper.createGroup(this.requestSpec, this.responseSpec, true); + Assert.assertNotNull(groupID); + + groupID = GroupHelper.associateClient(this.requestSpec, this.responseSpec, groupID.toString(), clientID.toString()); + Assert.assertNotNull(groupID); + + final Integer savingsProductID = createSavingsProduct(this.requestSpec, this.responseSpec, MINIMUM_OPENING_BALANCE); + Assert.assertNotNull(savingsProductID); + + final Integer savingsId = this.savingsAccountHelper.applyForSavingsApplication(groupID, savingsProductID, ACCOUNT_TYPE_GROUP); + Assert.assertNotNull(savingsId); + + HashMap savingsStatusHashMap = SavingsStatusChecker.getStatusOfSavings(this.requestSpec, this.responseSpec, savingsId); + SavingsStatusChecker.verifySavingsIsPending(savingsStatusHashMap); + + savingsStatusHashMap = this.savingsAccountHelper.approveSavings(savingsId); + SavingsStatusChecker.verifySavingsIsApproved(savingsStatusHashMap); + + List error1 = savingsAccountHelperValidationError.rejectApplicationWithErrorCode(savingsId, + SavingsAccountHelper.CREATED_DATE_PLUS_ONE); + assertEquals("validation.msg.savingsaccount.reject.not.in.submittedandpendingapproval.state", + error1.get(0).get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE)); + + savingsStatusHashMap = this.savingsAccountHelper.undoApproval(savingsId); + SavingsStatusChecker.verifySavingsIsPending(savingsStatusHashMap); + + error1 = savingsAccountHelperValidationError.rejectApplicationWithErrorCode(savingsId, SavingsAccountHelper.getFutureDate()); + assertEquals("validation.msg.savingsaccount.reject.cannot.be.a.future.date", + error1.get(0).get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE)); + + error1 = savingsAccountHelperValidationError.rejectApplicationWithErrorCode(savingsId, SavingsAccountHelper.CREATED_DATE_MINUS_ONE); + assertEquals("validation.msg.savingsaccount.reject.cannot.be.before.submittal.date", + error1.get(0).get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE)); + + savingsStatusHashMap = this.savingsAccountHelper.rejectApplication(savingsId); + SavingsStatusChecker.verifySavingsIsRejected(savingsStatusHashMap); + } + + @Test + public void testSavingsAccount_WITHDRAW_APPLICATION() { + + this.savingsAccountHelper = new SavingsAccountHelper(this.requestSpec, this.responseSpec); + + final Integer clientID = ClientHelper.createClient(this.requestSpec, this.responseSpec); + Assert.assertNotNull(clientID); + + Integer groupID = GroupHelper.createGroup(this.requestSpec, this.responseSpec, true); + Assert.assertNotNull(groupID); + + groupID = GroupHelper.associateClient(this.requestSpec, this.responseSpec, groupID.toString(), clientID.toString()); + Assert.assertNotNull(groupID); + + final Integer savingsProductID = createSavingsProduct(this.requestSpec, this.responseSpec, MINIMUM_OPENING_BALANCE); + Assert.assertNotNull(savingsProductID); + + final Integer savingsId = this.savingsAccountHelper.applyForSavingsApplication(groupID, savingsProductID, ACCOUNT_TYPE_GROUP); + Assert.assertNotNull(savingsId); + + HashMap savingsStatusHashMap = SavingsStatusChecker.getStatusOfSavings(this.requestSpec, this.responseSpec, savingsId); + SavingsStatusChecker.verifySavingsIsPending(savingsStatusHashMap); + + savingsStatusHashMap = this.savingsAccountHelper.withdrawApplication(savingsId); + SavingsStatusChecker.verifySavingsIsWithdrawn(savingsStatusHashMap); + + } + + @SuppressWarnings("unchecked") + @Test + public void testSavingsAccountTransactions() { + this.savingsAccountHelper = new SavingsAccountHelper(this.requestSpec, this.responseSpec); + SavingsAccountHelper savingsAccountHelperValidationError = new SavingsAccountHelper(this.requestSpec, + new ResponseSpecBuilder().build()); + + final Integer clientID = ClientHelper.createClient(this.requestSpec, this.responseSpec); + Assert.assertNotNull(clientID); + + Integer groupID = GroupHelper.createGroup(this.requestSpec, this.responseSpec, true); + Assert.assertNotNull(groupID); + + groupID = GroupHelper.associateClient(this.requestSpec, this.responseSpec, groupID.toString(), clientID.toString()); + Assert.assertNotNull(groupID); + + final Integer savingsProductID = createSavingsProduct(this.requestSpec, this.responseSpec, MINIMUM_OPENING_BALANCE); + Assert.assertNotNull(savingsProductID); + + final Integer savingsId = this.savingsAccountHelper.applyForSavingsApplication(groupID, savingsProductID, ACCOUNT_TYPE_GROUP); + Assert.assertNotNull(savingsId); + + HashMap savingsStatusHashMap = SavingsStatusChecker.getStatusOfSavings(this.requestSpec, this.responseSpec, savingsId); + SavingsStatusChecker.verifySavingsIsPending(savingsStatusHashMap); + + savingsStatusHashMap = this.savingsAccountHelper.approveSavings(savingsId); + SavingsStatusChecker.verifySavingsIsApproved(savingsStatusHashMap); + + List error = (List) savingsAccountHelperValidationError.withdrawalFromSavingsAccount(savingsId, "100", + SavingsAccountHelper.TRANSACTION_DATE, CommonConstants.RESPONSE_ERROR); + assertEquals("error.msg.savingsaccount.transaction.account.is.not.active", + error.get(0).get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE)); + + error = (List) savingsAccountHelperValidationError.depositToSavingsAccount(savingsId, "100", SavingsAccountHelper.TRANSACTION_DATE, + CommonConstants.RESPONSE_ERROR); + assertEquals("error.msg.savingsaccount.transaction.account.is.not.active", + error.get(0).get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE)); + + savingsStatusHashMap = this.savingsAccountHelper.activateSavings(savingsId); + SavingsStatusChecker.verifySavingsIsActive(savingsStatusHashMap); + + HashMap summary = this.savingsAccountHelper.getSavingsSummary(savingsId); + Float balance = new Float(MINIMUM_OPENING_BALANCE); + assertEquals("Verifying opening Balance", balance, summary.get("accountBalance")); + + Integer depositTransactionId = (Integer) this.savingsAccountHelper.depositToSavingsAccount(savingsId, DEPOSIT_AMOUNT, + SavingsAccountHelper.TRANSACTION_DATE, CommonConstants.RESPONSE_RESOURCE_ID); + HashMap depositTransaction = this.savingsAccountHelper.getSavingsTransaction(savingsId, depositTransactionId); + balance += new Float(DEPOSIT_AMOUNT); + assertEquals("Verifying Deposit Amount", new Float(DEPOSIT_AMOUNT), depositTransaction.get("amount")); + assertEquals("Verifying Balance after Deposit", balance, depositTransaction.get("runningBalance")); + + Integer withdrawTransactionId = (Integer) this.savingsAccountHelper.withdrawalFromSavingsAccount(savingsId, WITHDRAW_AMOUNT, + SavingsAccountHelper.TRANSACTION_DATE, CommonConstants.RESPONSE_RESOURCE_ID); + HashMap withdrawTransaction = this.savingsAccountHelper.getSavingsTransaction(savingsId, withdrawTransactionId); + balance -= new Float(WITHDRAW_AMOUNT); + assertEquals("Verifying Withdrawal Amount", new Float(WITHDRAW_AMOUNT), withdrawTransaction.get("amount")); + assertEquals("Verifying Balance after Withdrawal", balance, withdrawTransaction.get("runningBalance")); + + Integer newWithdrawTransactionId = this.savingsAccountHelper.updateSavingsAccountTransaction(savingsId, withdrawTransactionId, + WITHDRAW_AMOUNT_ADJUSTED); + HashMap newWithdrawTransaction = this.savingsAccountHelper.getSavingsTransaction(savingsId, newWithdrawTransactionId); + balance = balance + new Float(WITHDRAW_AMOUNT) - new Float(WITHDRAW_AMOUNT_ADJUSTED); + assertEquals("Verifying adjusted Amount", new Float(WITHDRAW_AMOUNT_ADJUSTED), newWithdrawTransaction.get("amount")); + assertEquals("Verifying Balance after adjust", balance, newWithdrawTransaction.get("runningBalance")); + summary = this.savingsAccountHelper.getSavingsSummary(savingsId); + assertEquals("Verifying Adjusted Balance", balance, summary.get("accountBalance")); + withdrawTransaction = this.savingsAccountHelper.getSavingsTransaction(savingsId, withdrawTransactionId); + Assert.assertTrue((Boolean) withdrawTransaction.get("reversed")); + + this.savingsAccountHelper.undoSavingsAccountTransaction(savingsId, newWithdrawTransactionId); + newWithdrawTransaction = this.savingsAccountHelper.getSavingsTransaction(savingsId, withdrawTransactionId); + Assert.assertTrue((Boolean) newWithdrawTransaction.get("reversed")); + summary = this.savingsAccountHelper.getSavingsSummary(savingsId); + balance += new Float(WITHDRAW_AMOUNT_ADJUSTED); + assertEquals("Verifying Balance After Undo Transaction", balance, summary.get("accountBalance")); + + error = (List) savingsAccountHelperValidationError.withdrawalFromSavingsAccount(savingsId, "5000", + SavingsAccountHelper.TRANSACTION_DATE, CommonConstants.RESPONSE_ERROR); + assertEquals("error.msg.savingsaccount.transaction.insufficient.account.balance", + error.get(0).get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE)); + + error = (List) savingsAccountHelperValidationError.withdrawalFromSavingsAccount(savingsId, "5000", + SavingsAccountHelper.getFutureDate(), CommonConstants.RESPONSE_ERROR); + assertEquals("error.msg.savingsaccount.transaction.in.the.future", error.get(0).get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE)); + + error = (List) savingsAccountHelperValidationError.depositToSavingsAccount(savingsId, "5000", SavingsAccountHelper.getFutureDate(), + CommonConstants.RESPONSE_ERROR); + assertEquals("error.msg.savingsaccount.transaction.in.the.future", error.get(0).get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE)); + + error = (List) savingsAccountHelperValidationError.withdrawalFromSavingsAccount(savingsId, "5000", + SavingsAccountHelper.CREATED_DATE_MINUS_ONE, CommonConstants.RESPONSE_ERROR); + assertEquals("error.msg.savingsaccount.transaction.before.activation.date", + error.get(0).get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE)); + + error = (List) savingsAccountHelperValidationError.depositToSavingsAccount(savingsId, "5000", + SavingsAccountHelper.CREATED_DATE_MINUS_ONE, CommonConstants.RESPONSE_ERROR); + assertEquals("error.msg.savingsaccount.transaction.before.activation.date", + error.get(0).get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE)); + + } + + @SuppressWarnings("unchecked") + @Test + public void testSavingsAccountCharges() { + this.savingsAccountHelper = new SavingsAccountHelper(this.requestSpec, this.responseSpec); + + final Integer clientID = ClientHelper.createClient(this.requestSpec, this.responseSpec); + Assert.assertNotNull(clientID); + + Integer groupID = GroupHelper.createGroup(this.requestSpec, this.responseSpec, true); + Assert.assertNotNull(groupID); + + groupID = GroupHelper.associateClient(this.requestSpec, this.responseSpec, groupID.toString(), clientID.toString()); + Assert.assertNotNull(groupID); + + final Integer savingsProductID = createSavingsProduct(this.requestSpec, this.responseSpec, MINIMUM_OPENING_BALANCE); + Assert.assertNotNull(savingsProductID); + + final Integer savingsId = this.savingsAccountHelper.applyForSavingsApplication(groupID, savingsProductID, ACCOUNT_TYPE_GROUP); + Assert.assertNotNull(savingsId); + + HashMap savingsStatusHashMap = SavingsStatusChecker.getStatusOfSavings(this.requestSpec, this.responseSpec, savingsId); + SavingsStatusChecker.verifySavingsIsPending(savingsStatusHashMap); + + final Integer withdrawalChargeId = ChargesHelper.createCharges(this.requestSpec, this.responseSpec, + ChargesHelper.getSavingsWithdrawalFeeJSON()); + Assert.assertNotNull(withdrawalChargeId); + + this.savingsAccountHelper.addChargesForSavings(savingsId, withdrawalChargeId); + ArrayList chargesPendingState = this.savingsAccountHelper.getSavingsCharges(savingsId); + Assert.assertEquals(1, chargesPendingState.size()); + + Integer savingsChargeId = (Integer) chargesPendingState.get(0).get("id"); + HashMap chargeChanges = this.savingsAccountHelper.updateCharges(savingsChargeId, savingsId); + Assert.assertTrue(chargeChanges.containsKey("amount")); + + Integer deletedChargeId = this.savingsAccountHelper.deleteCharge(savingsChargeId, savingsId); + assertEquals(savingsChargeId, deletedChargeId); + + chargesPendingState = this.savingsAccountHelper.getSavingsCharges(savingsId); + Assert.assertTrue(chargesPendingState == null || chargesPendingState.size() == 0); + + savingsStatusHashMap = this.savingsAccountHelper.approveSavings(savingsId); + SavingsStatusChecker.verifySavingsIsApproved(savingsStatusHashMap); + + savingsStatusHashMap = this.savingsAccountHelper.activateSavings(savingsId); + SavingsStatusChecker.verifySavingsIsActive(savingsStatusHashMap); + + final Integer chargeId = ChargesHelper.createCharges(this.requestSpec, this.responseSpec, ChargesHelper.getSavingsAnnualFeeJSON()); + Assert.assertNotNull(chargeId); + + ArrayList charges = this.savingsAccountHelper.getSavingsCharges(savingsId); + Assert.assertTrue(charges == null || charges.size() == 0); + + this.savingsAccountHelper.addChargesForSavings(savingsId, chargeId); + charges = this.savingsAccountHelper.getSavingsCharges(savingsId); + Assert.assertEquals(1, charges.size()); + + HashMap savingsChargeForPay = charges.get(0); + SimpleDateFormat sdf = new SimpleDateFormat(CommonConstants.dateFormat); + Calendar cal = Calendar.getInstance(); + List dates = (List) savingsChargeForPay.get("dueDate"); + cal.set(Calendar.YEAR, (Integer) dates.get(0)); + cal.set(Calendar.MONTH, (Integer) dates.get(1) - 1); + cal.set(Calendar.DAY_OF_MONTH, (Integer) dates.get(2)); + + this.savingsAccountHelper.payCharge((Integer) savingsChargeForPay.get("id"), savingsId, + ((Float) savingsChargeForPay.get("amount")).toString(), sdf.format(cal.getTime())); + HashMap paidCharge = this.savingsAccountHelper.getSavingsChanrge(savingsId, (Integer) savingsChargeForPay.get("id")); + assertEquals(savingsChargeForPay.get("amount"), paidCharge.get("amountPaid")); + + final Integer monthlyFeechargeId = ChargesHelper.createCharges(this.requestSpec, this.responseSpec, + ChargesHelper.getSavingsMonthlyFeeJSON()); + Assert.assertNotNull(monthlyFeechargeId); + + this.savingsAccountHelper.addChargesForSavings(savingsId, monthlyFeechargeId); + charges = this.savingsAccountHelper.getSavingsCharges(savingsId); + Assert.assertEquals(2, charges.size()); + + HashMap savingsChargeForWaive = charges.get(1); + this.savingsAccountHelper.waiveCharge((Integer) savingsChargeForWaive.get("id"), savingsId); + HashMap waiveCharge = this.savingsAccountHelper.getSavingsChanrge(savingsId, (Integer) savingsChargeForWaive.get("id")); + assertEquals(savingsChargeForWaive.get("amount"), waiveCharge.get("amountWaived")); + } + + public static Integer createSavingsProduct(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, + final String minOpenningBalance) { + System.out.println("------------------------------CREATING NEW SAVINGS PRODUCT ---------------------------------------"); + SavingsProductHelper savingsProductHelper = new SavingsProductHelper(); + final String savingsProductJSON = savingsProductHelper // + .withInterestCompoundingPeriodTypeAsDaily() // + .withInterestPostingPeriodTypeAsMonthly() // + .withInterestCalculationPeriodTypeAsDailyBalance() // + .withMinimumOpenningBalance(minOpenningBalance).build(); + return SavingsProductHelper.createSavingsProduct(savingsProductJSON, requestSpec, responseSpec); + } +} \ No newline at end of file diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/savings/SavingsAccountHelper.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/savings/SavingsAccountHelper.java index 6ceee9a5b..31872062a 100644 --- a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/savings/SavingsAccountHelper.java +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/savings/SavingsAccountHelper.java @@ -52,19 +52,19 @@ public class SavingsAccountHelper { return sdf.format(calendar.getTime()); } - public Integer applyForSavingsApplication(final Integer clientID, final Integer savingsProductID) { + public Integer applyForSavingsApplication(final Integer ID, final Integer savingsProductID, final String accountType) { System.out.println("--------------------------------APPLYING FOR SAVINGS APPLICATION--------------------------------"); final String savingsApplicationJSON = new SavingsApplicationTestBuilder() // .withSubmittedOnDate(CREATED_DATE) // - .build(clientID.toString(), savingsProductID.toString()); + .build(ID.toString(), savingsProductID.toString(), accountType); return Utils.performServerPost(this.requestSpec, this.responseSpec, SAVINGS_ACCOUNT_URL + "?" + Utils.TENANT_IDENTIFIER, savingsApplicationJSON, "savingsId"); } - public HashMap updateSavingsAccount(final Integer clientID, final Integer savingsProductID, final Integer savingsId) { + public HashMap updateSavingsAccount(final Integer ID, final Integer savingsProductID, final Integer savingsId, final String accountType) { final String savingsApplicationJSON = new SavingsApplicationTestBuilder() // .withSubmittedOnDate(CREATED_DATE_PLUS_ONE) // - .build(clientID.toString(), savingsProductID.toString()); + .build(ID.toString(), savingsProductID.toString(), accountType); return Utils.performServerPut(this.requestSpec, this.responseSpec, SAVINGS_ACCOUNT_URL + "/" + savingsId + "?" + Utils.TENANT_IDENTIFIER, savingsApplicationJSON, CommonConstants.RESPONSE_CHANGES); @@ -302,7 +302,7 @@ public class SavingsAccountHelper { return response; } - public ArrayList getSavingsChanrges(final Integer savingsID) { + public ArrayList getSavingsCharges(final Integer savingsID) { final String URL = SAVINGS_ACCOUNT_URL + "/" + savingsID + "/charges?" + Utils.TENANT_IDENTIFIER; return Utils.performServerGet(requestSpec, responseSpec, URL, ""); } diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/savings/SavingsApplicationTestBuilder.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/savings/SavingsApplicationTestBuilder.java index 818e87d4e..a060f9a0a 100755 --- a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/savings/SavingsApplicationTestBuilder.java +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/savings/SavingsApplicationTestBuilder.java @@ -10,11 +10,15 @@ public class SavingsApplicationTestBuilder { private String submittedOnDate = ""; - public String build(final String ID, final String savingsProductId) { + public String build(final String ID, final String savingsProductId, final String accountType) { final HashMap map = new HashMap(); map.put("dateFormat", "dd MMMM yyyy"); - map.put("clientId", ID); + if (accountType == "GROUP") { + map.put("groupId", ID); + } else { + map.put("clientId", ID); + } map.put("productId", savingsProductId); map.put("locale", LOCALE); map.put("submittedOnDate", this.submittedOnDate);