From 2a60b05bf6271ceea95c6354da38ab517338febe Mon Sep 17 00:00:00 2001 From: Vishwas Babu A J Date: Mon, 16 Jun 2014 18:02:26 -0700 Subject: [PATCH] modifying test cases for account transfers --- .../integrationtests/AccountTransferTest.java | 28 +++++------------ .../FinancialActivityAccountsTest.java | 29 ++++++++++------- .../integrationtests/common/Utils.java | 5 --- .../FinancialActivityAccountHelper.java | 31 ++++++++----------- 4 files changed, 38 insertions(+), 55 deletions(-) diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/AccountTransferTest.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/AccountTransferTest.java index 07e4adbaa..10276d03a 100644 --- a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/AccountTransferTest.java +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/AccountTransferTest.java @@ -64,6 +64,7 @@ public class AccountTransferTest { private FinancialActivityAccountHelper financialActivityAccountHelper; private Integer financialActivityAccountId; + private Account liabilityTransferAccount; @Before public void setup() { @@ -73,16 +74,16 @@ public class AccountTransferTest { this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build(); this.accountHelper = new AccountHelper(this.requestSpec, this.responseSpec); this.journalEntryHelper = new JournalEntryHelper(this.requestSpec, this.responseSpec); - this.financialActivityAccountHelper = new FinancialActivityAccountHelper(this.requestSpec, this.responseSpec); + this.financialActivityAccountHelper = new FinancialActivityAccountHelper(this.requestSpec); /** Setup liability transfer account **/ /** Create a Liability and an Asset Transfer Account **/ - Account liabilityTransferAccount = accountHelper.createLiabilityAccount(); + liabilityTransferAccount = accountHelper.createLiabilityAccount(); Assert.assertNotNull(liabilityTransferAccount); /*** Create A Financial Activity to Account Mapping **/ financialActivityAccountId = (Integer) financialActivityAccountHelper.createFinancialActivityAccount( - FinancialActivityAccountsTest.liabilityTransferFinancialActivityId, liabilityTransferAccount.getAccountID(), + FinancialActivityAccountsTest.liabilityTransferFinancialActivityId, liabilityTransferAccount.getAccountID(), responseSpec, CommonConstants.RESPONSE_RESOURCE_ID); Assert.assertNotNull(financialActivityAccountId); } @@ -93,7 +94,7 @@ public class AccountTransferTest { @After public void tearDown() { Integer deletedFinancialActivityAccountId = financialActivityAccountHelper.deleteFinancialActivityAccount( - financialActivityAccountId, CommonConstants.RESPONSE_RESOURCE_ID); + financialActivityAccountId, responseSpec, CommonConstants.RESPONSE_RESOURCE_ID); Assert.assertNotNull(deletedFinancialActivityAccountId); Assert.assertEquals(financialActivityAccountId, deletedFinancialActivityAccountId); } @@ -117,12 +118,6 @@ public class AccountTransferTest { String.valueOf(toOfficeId)); Assert.assertNotNull(toClientID); - Account toTransferAccount = accountHelper.createLiabilityAccount(); - Assert.assertNotNull(toTransferAccount); - - FinancialActivityAccountHelper accountMappingHelper = new FinancialActivityAccountHelper(this.requestSpec, - new ResponseSpecBuilder().build()); - final Integer toSavingsProductID = createSavingsProduct(this.requestSpec, this.responseSpec, MINIMUM_OPENING_BALANCE, assetAccount, incomeAccount, expenseAccount, liabilityAccount); Assert.assertNotNull(toSavingsProductID); @@ -195,7 +190,7 @@ public class AccountTransferTest { this.journalEntryHelper.checkJournalEntryForAssetAccount(fromTransferAccount, AccountTransferHelper.ACCOUNT_TRANSFER_DATE, office1LiabilityEntries); - this.journalEntryHelper.checkJournalEntryForAssetAccount(toTransferAccount, AccountTransferHelper.ACCOUNT_TRANSFER_DATE, + this.journalEntryHelper.checkJournalEntryForAssetAccount(liabilityTransferAccount, AccountTransferHelper.ACCOUNT_TRANSFER_DATE, office2LiabilityEntries); } @@ -228,9 +223,6 @@ public class AccountTransferTest { Account toTransferAccount = accountHelper.createLiabilityAccount(); Assert.assertNotNull(toTransferAccount); - FinancialActivityAccountHelper accountMappingHelper = new FinancialActivityAccountHelper(this.requestSpec, - new ResponseSpecBuilder().build()); - final Integer toLoanProductID = createLoanProduct(loanAssetAccount, loanIncomeAccount, loanExpenseAccount, overpaymentAccount); Assert.assertNotNull(toLoanProductID); @@ -327,12 +319,6 @@ public class AccountTransferTest { String.valueOf(toOfficeId)); Assert.assertNotNull(toClientID); - Account toTransferAccount = accountHelper.createLiabilityAccount(); - Assert.assertNotNull(toTransferAccount); - - FinancialActivityAccountHelper accountMappingHelper = new FinancialActivityAccountHelper(this.requestSpec, - new ResponseSpecBuilder().build()); - final Integer toSavingsProductID = createSavingsProduct(this.requestSpec, this.responseSpec, MINIMUM_OPENING_BALANCE, assetAccount, incomeAccount, expenseAccount, liabilityAccount); Assert.assertNotNull(toSavingsProductID); @@ -428,7 +414,7 @@ public class AccountTransferTest { this.journalEntryHelper.checkJournalEntryForAssetAccount(fromTransferAccount, AccountTransferHelper.ACCOUNT_TRANSFER_DATE, office1LiabilityEntries); - this.journalEntryHelper.checkJournalEntryForAssetAccount(toTransferAccount, AccountTransferHelper.ACCOUNT_TRANSFER_DATE, + this.journalEntryHelper.checkJournalEntryForAssetAccount(liabilityTransferAccount, AccountTransferHelper.ACCOUNT_TRANSFER_DATE, office2LiabilityEntries); } diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/FinancialActivityAccountsTest.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/FinancialActivityAccountsTest.java index f950d16c1..b9997e005 100755 --- a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/FinancialActivityAccountsTest.java +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/FinancialActivityAccountsTest.java @@ -28,6 +28,8 @@ import com.jayway.restassured.specification.ResponseSpecification; public class FinancialActivityAccountsTest { private ResponseSpecification responseSpec; + private ResponseSpecification responseSpecForValidationError; + private ResponseSpecification responseSpecForResourceNotFoundError; private RequestSpecification requestSpec; private AccountHelper accountHelper; private FinancialActivityAccountHelper financialActivityAccountHelper; @@ -41,8 +43,10 @@ public class FinancialActivityAccountsTest { this.requestSpec = new RequestSpecBuilder().setContentType(ContentType.JSON).build(); this.requestSpec.header("Authorization", "Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey()); this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build(); + this.responseSpecForValidationError = new ResponseSpecBuilder().expectStatusCode(400).build(); + this.responseSpecForResourceNotFoundError = new ResponseSpecBuilder().expectStatusCode(404).build(); this.accountHelper = new AccountHelper(this.requestSpec, this.responseSpec); - this.financialActivityAccountHelper = new FinancialActivityAccountHelper(this.requestSpec, this.responseSpec); + this.financialActivityAccountHelper = new FinancialActivityAccountHelper(this.requestSpec); } @SuppressWarnings("unchecked") @@ -57,7 +61,8 @@ public class FinancialActivityAccountsTest { /*** Create A Financial Activity to Account Mapping **/ Integer financialActivityAccountId = (Integer) financialActivityAccountHelper.createFinancialActivityAccount( - liabilityTransferFinancialActivityId, liabilityTransferAccount.getAccountID(), CommonConstants.RESPONSE_RESOURCE_ID); + liabilityTransferFinancialActivityId, liabilityTransferAccount.getAccountID(), responseSpec, + CommonConstants.RESPONSE_RESOURCE_ID); Assert.assertNotNull(financialActivityAccountId); /*** @@ -74,7 +79,8 @@ public class FinancialActivityAccountsTest { Assert.assertNotNull(newLiabilityTransferAccount); HashMap changes = (HashMap) financialActivityAccountHelper.updateFinancialActivityAccount(financialActivityAccountId, - liabilityTransferFinancialActivityId, newLiabilityTransferAccount.getAccountID(), CommonConstants.RESPONSE_CHANGES); + liabilityTransferFinancialActivityId, newLiabilityTransferAccount.getAccountID(), responseSpec, + CommonConstants.RESPONSE_CHANGES); Assert.assertEquals(newLiabilityTransferAccount.getAccountID(), changes.get("glAccountId")); /** Validate update works correctly **/ @@ -83,13 +89,14 @@ public class FinancialActivityAccountsTest { /** Update with Invalid Financial Activity should fail **/ List invalidFinancialActivityUpdateError = (List) financialActivityAccountHelper.updateFinancialActivityAccount( - financialActivityAccountId, 232, newLiabilityTransferAccount.getAccountID(), CommonConstants.RESPONSE_ERROR); - assertEquals("error.msg.officeToAccountMapping.update.of.officeId.is.not.supported", invalidFinancialActivityUpdateError.get(0) - .get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE)); + financialActivityAccountId, 232, newLiabilityTransferAccount.getAccountID(), responseSpecForValidationError, + CommonConstants.RESPONSE_ERROR); + assertEquals("validation.msg.financialactivityaccount.financialActivityId.is.not.one.of.expected.enumerations", + invalidFinancialActivityUpdateError.get(0).get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE)); /** Creating Duplicate Financial Activity should fail **/ List duplicateFinancialActivityAccountError = (List) financialActivityAccountHelper - .createFinancialActivityAccount(financialActivityAccountId, liabilityTransferAccount.getAccountID(), + .createFinancialActivityAccount(financialActivityAccountId, liabilityTransferAccount.getAccountID(), responseSpec, CommonConstants.RESPONSE_ERROR); assertEquals(DuplicateFinancialActivityAccountFoundException.getErrorcode(), duplicateFinancialActivityAccountError.get(0).get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE)); @@ -99,23 +106,23 @@ public class FinancialActivityAccountsTest { * should fail **/ List invalidFinancialActivityAccountError = (List) financialActivityAccountHelper.updateFinancialActivityAccount( - financialActivityAccountId, liabilityTransferFinancialActivityId, newLiabilityTransferAccount.getAccountID(), + financialActivityAccountId, liabilityTransferFinancialActivityId, newLiabilityTransferAccount.getAccountID(), responseSpec, CommonConstants.RESPONSE_ERROR); assertEquals(FinancialActivityAccountInvalidException.getErrorcode(), invalidFinancialActivityAccountError.get(0).get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE)); /** Should be able to delete a Financial Activity to Account Mapping **/ Integer deletedFinancialActivityAccountId = financialActivityAccountHelper.deleteFinancialActivityAccount( - financialActivityAccountId, CommonConstants.RESPONSE_RESOURCE_ID); + financialActivityAccountId, responseSpec, CommonConstants.RESPONSE_RESOURCE_ID); Assert.assertNotNull(deletedFinancialActivityAccountId); Assert.assertEquals(financialActivityAccountId, deletedFinancialActivityAccountId); /*** Trying to fetch a Deleted Account Mapping should give me a 404 **/ - financialActivityAccountHelper.getFinancialActivityAccountAndValidateResouceNotFound(financialActivityAccountId); + financialActivityAccountHelper.getFinancialActivityAccount(deletedFinancialActivityAccountId, responseSpecForResourceNotFoundError); } private void assertFinancialActivityAccountCreation(Integer financialActivityAccountId, Integer financialActivityId, Account glAccount) { - HashMap mappingDetails = financialActivityAccountHelper.getFinancialActivityAccount(financialActivityAccountId); + HashMap mappingDetails = financialActivityAccountHelper.getFinancialActivityAccount(financialActivityAccountId, responseSpec); Assert.assertEquals(financialActivityId, ((HashMap) mappingDetails.get("financialActivityData")).get("id")); Assert.assertEquals(glAccount.getAccountID(), ((HashMap) mappingDetails.get("glAccountData")).get("id")); } diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/Utils.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/Utils.java index 03b9e77d2..4f82183c8 100644 --- a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/Utils.java +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/Utils.java @@ -1,6 +1,5 @@ package org.mifosplatform.integrationtests.common; -import static com.jayway.restassured.RestAssured.expect; import static com.jayway.restassured.RestAssured.given; import static com.jayway.restassured.path.json.JsonPath.from; import static org.hamcrest.Matchers.is; @@ -54,10 +53,6 @@ public class Utils { return (T) from(json).get(jsonAttributeToGetBack); } - public static void performServerGetAndValidateResourceNotFound(final String getURL) { - expect().statusCode(404).when().get(getURL); - } - public static T performServerPost(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, final String postURL, final String jsonBodyToSend, final String jsonAttributeToGetBack) { final String json = given().spec(requestSpec).body(jsonBodyToSend).expect().spec(responseSpec).log().ifError().when().post(postURL) diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/accounting/FinancialActivityAccountHelper.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/accounting/FinancialActivityAccountHelper.java index b8352437d..4e7bed114 100755 --- a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/accounting/FinancialActivityAccountHelper.java +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/accounting/FinancialActivityAccountHelper.java @@ -12,44 +12,39 @@ public class FinancialActivityAccountHelper { private static final String FINANCIAL_ACTIVITY_ACCOUNT_MAPPING_URL = "/mifosng-provider/api/v1/financialactivityaccounts"; private final RequestSpecification requestSpec; - private final ResponseSpecification responseSpec; - public FinancialActivityAccountHelper(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) { + public FinancialActivityAccountHelper(final RequestSpecification requestSpec) { this.requestSpec = requestSpec; - this.responseSpec = responseSpec; } - public Object createFinancialActivityAccount(Integer financialActivityId, Integer glAccountId, String jsonBack) { + public Object createFinancialActivityAccount(Integer financialActivityId, Integer glAccountId, + final ResponseSpecification responseSpecification, String jsonBack) { String json = FinancialActivityAccountsMappingBuilder.build(financialActivityId, glAccountId); - return Utils.performServerPost(this.requestSpec, this.responseSpec, FINANCIAL_ACTIVITY_ACCOUNT_MAPPING_URL + "?" + return Utils.performServerPost(this.requestSpec, responseSpecification, FINANCIAL_ACTIVITY_ACCOUNT_MAPPING_URL + "?" + Utils.TENANT_IDENTIFIER, json, jsonBack); } public Object updateFinancialActivityAccount(Integer financialActivityAccountId, Integer financialActivityId, Integer glAccountId, - String jsonBack) { + final ResponseSpecification responseSpecification, String jsonBack) { String json = FinancialActivityAccountsMappingBuilder.build(financialActivityId, glAccountId); - return Utils.performServerPut(this.requestSpec, this.responseSpec, FINANCIAL_ACTIVITY_ACCOUNT_MAPPING_URL + "/" + return Utils.performServerPut(this.requestSpec, responseSpecification, FINANCIAL_ACTIVITY_ACCOUNT_MAPPING_URL + "/" + financialActivityAccountId + "?" + Utils.TENANT_IDENTIFIER, json, jsonBack); } - public HashMap getFinancialActivityAccount(final Integer financialActivityAccountId) { + public HashMap getFinancialActivityAccount(final Integer financialActivityAccountId, final ResponseSpecification responseSpecification) { final String url = FINANCIAL_ACTIVITY_ACCOUNT_MAPPING_URL + "/" + financialActivityAccountId + "?" + Utils.TENANT_IDENTIFIER; - return Utils.performServerGet(requestSpec, responseSpec, url, ""); + return Utils.performServerGet(requestSpec, responseSpecification, url, ""); } - public void getFinancialActivityAccountAndValidateResouceNotFound(final Integer financialActivityAccountId) { - final String url = FINANCIAL_ACTIVITY_ACCOUNT_MAPPING_URL + "/" + financialActivityAccountId + "?" + Utils.TENANT_IDENTIFIER; - Utils.performServerGetAndValidateResourceNotFound(url); - } - - public HashMap getAllFinancialActivityAccounts() { + public HashMap getAllFinancialActivityAccounts(final ResponseSpecification responseSpecification) { final String url = FINANCIAL_ACTIVITY_ACCOUNT_MAPPING_URL + "?" + Utils.TENANT_IDENTIFIER; - return Utils.performServerGet(this.requestSpec, this.responseSpec, url, ""); + return Utils.performServerGet(this.requestSpec, responseSpecification, url, ""); } - public Integer deleteFinancialActivityAccount(final Integer financialActivityAccountId, String jsonBack) { + public Integer deleteFinancialActivityAccount(final Integer financialActivityAccountId, + final ResponseSpecification responseSpecification, String jsonBack) { final String url = FINANCIAL_ACTIVITY_ACCOUNT_MAPPING_URL + "/" + financialActivityAccountId + "?" + Utils.TENANT_IDENTIFIER; - return Utils.performServerDelete(this.requestSpec, this.responseSpec, url, jsonBack); + return Utils.performServerDelete(this.requestSpec, responseSpecification, url, jsonBack); } }