From c6d39fa737e89721e132c8d929073943805ab165 Mon Sep 17 00:00:00 2001 From: Vishwas Babu A J Date: Mon, 16 Jun 2014 16:33:07 -0700 Subject: [PATCH] updating test cases for financial activity accounts and accounts transfers --- .../integrationtests/AccountTransferTest.java | 36 +- .../FinancialActivityAccountsTest.java | 122 ++++ .../OfficeAccountingMappingsTest.java | 87 --- .../integrationtests/SystemCodeTest.java | 549 ++++++++---------- .../{surveyHelper.java => SurveyHelper.java} | 2 +- .../integrationtests/common/Utils.java | 5 + .../common/accounting/AccountHelper.java | 4 +- .../FinancialActivityAccountHelper.java | 55 ++ .../FinancialActivityAccountsHelper.java | 44 -- ...nancialActivityAccountsMappingBuilder.java | 15 + .../OfficeAccountMappingBuilder.java | 15 - .../common/system/CodeHelper.java | 193 +++--- ...inancialActivityAccountFoundException.java | 9 +- ...ancialActivityAccountInvalidException.java | 16 +- 14 files changed, 559 insertions(+), 593 deletions(-) create mode 100755 mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/FinancialActivityAccountsTest.java delete mode 100755 mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/OfficeAccountingMappingsTest.java rename mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/{surveyHelper.java => SurveyHelper.java} (98%) create mode 100755 mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/accounting/FinancialActivityAccountHelper.java delete mode 100755 mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/accounting/FinancialActivityAccountsHelper.java create mode 100755 mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/accounting/FinancialActivityAccountsMappingBuilder.java delete mode 100755 mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/accounting/OfficeAccountMappingBuilder.java 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 0ed4a31c6..07e4adbaa 100644 --- a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/AccountTransferTest.java +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/AccountTransferTest.java @@ -4,15 +4,17 @@ import static org.junit.Assert.assertEquals; import java.util.HashMap; +import org.junit.After; 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.OfficeHelper; import org.mifosplatform.integrationtests.common.Utils; import org.mifosplatform.integrationtests.common.accounting.Account; import org.mifosplatform.integrationtests.common.accounting.AccountHelper; -import org.mifosplatform.integrationtests.common.accounting.FinancialActivityAccountsHelper; +import org.mifosplatform.integrationtests.common.accounting.FinancialActivityAccountHelper; import org.mifosplatform.integrationtests.common.accounting.JournalEntry; import org.mifosplatform.integrationtests.common.accounting.JournalEntryHelper; import org.mifosplatform.integrationtests.common.loans.LoanApplicationTestBuilder; @@ -60,6 +62,9 @@ public class AccountTransferTest { Float TRANSFER_AMOUNT = new Float(ACCOUNT_TRANSFER_AMOUNT); Float TRANSFER_AMOUNT_ADJUST = new Float(ACCOUNT_TRANSFER_AMOUNT_ADJUST); + private FinancialActivityAccountHelper financialActivityAccountHelper; + private Integer financialActivityAccountId; + @Before public void setup() { Utils.initializeRESTAssured(); @@ -68,6 +73,29 @@ 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); + + /** Setup liability transfer account **/ + /** Create a Liability and an Asset Transfer Account **/ + Account liabilityTransferAccount = accountHelper.createLiabilityAccount(); + Assert.assertNotNull(liabilityTransferAccount); + + /*** Create A Financial Activity to Account Mapping **/ + financialActivityAccountId = (Integer) financialActivityAccountHelper.createFinancialActivityAccount( + FinancialActivityAccountsTest.liabilityTransferFinancialActivityId, liabilityTransferAccount.getAccountID(), + CommonConstants.RESPONSE_RESOURCE_ID); + Assert.assertNotNull(financialActivityAccountId); + } + + /** + * Delete the Liability transfer account + */ + @After + public void tearDown() { + Integer deletedFinancialActivityAccountId = financialActivityAccountHelper.deleteFinancialActivityAccount( + financialActivityAccountId, CommonConstants.RESPONSE_RESOURCE_ID); + Assert.assertNotNull(deletedFinancialActivityAccountId); + Assert.assertEquals(financialActivityAccountId, deletedFinancialActivityAccountId); } @Test @@ -92,7 +120,7 @@ public class AccountTransferTest { Account toTransferAccount = accountHelper.createLiabilityAccount(); Assert.assertNotNull(toTransferAccount); - FinancialActivityAccountsHelper accountMappingHelper = new FinancialActivityAccountsHelper(this.requestSpec, + FinancialActivityAccountHelper accountMappingHelper = new FinancialActivityAccountHelper(this.requestSpec, new ResponseSpecBuilder().build()); final Integer toSavingsProductID = createSavingsProduct(this.requestSpec, this.responseSpec, MINIMUM_OPENING_BALANCE, assetAccount, @@ -200,7 +228,7 @@ public class AccountTransferTest { Account toTransferAccount = accountHelper.createLiabilityAccount(); Assert.assertNotNull(toTransferAccount); - FinancialActivityAccountsHelper accountMappingHelper = new FinancialActivityAccountsHelper(this.requestSpec, + FinancialActivityAccountHelper accountMappingHelper = new FinancialActivityAccountHelper(this.requestSpec, new ResponseSpecBuilder().build()); final Integer toLoanProductID = createLoanProduct(loanAssetAccount, loanIncomeAccount, loanExpenseAccount, overpaymentAccount); @@ -302,7 +330,7 @@ public class AccountTransferTest { Account toTransferAccount = accountHelper.createLiabilityAccount(); Assert.assertNotNull(toTransferAccount); - FinancialActivityAccountsHelper accountMappingHelper = new FinancialActivityAccountsHelper(this.requestSpec, + FinancialActivityAccountHelper accountMappingHelper = new FinancialActivityAccountHelper(this.requestSpec, new ResponseSpecBuilder().build()); final Integer toSavingsProductID = createSavingsProduct(this.requestSpec, this.responseSpec, MINIMUM_OPENING_BALANCE, assetAccount, diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/FinancialActivityAccountsTest.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/FinancialActivityAccountsTest.java new file mode 100755 index 000000000..63224c104 --- /dev/null +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/FinancialActivityAccountsTest.java @@ -0,0 +1,122 @@ +package org.mifosplatform.integrationtests; + +import static org.junit.Assert.assertEquals; + +import java.util.HashMap; +import java.util.List; + +import junit.framework.Assert; + +import org.junit.Before; +import org.junit.Test; +import org.mifosplatform.accounting.common.AccountingConstants.FINANCIAL_ACTIVITY; +import org.mifosplatform.accounting.financialactivityaccount.exception.DuplicateFinancialActivityAccountFoundException; +import org.mifosplatform.accounting.financialactivityaccount.exception.FinancialActivityAccountInvalidException; +import org.mifosplatform.integrationtests.common.CommonConstants; +import org.mifosplatform.integrationtests.common.Utils; +import org.mifosplatform.integrationtests.common.accounting.Account; +import org.mifosplatform.integrationtests.common.accounting.AccountHelper; +import org.mifosplatform.integrationtests.common.accounting.FinancialActivityAccountHelper; + +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; + +@SuppressWarnings("rawtypes") +public class FinancialActivityAccountsTest { + + private ResponseSpecification responseSpec; + private RequestSpecification requestSpec; + private AccountHelper accountHelper; + private FinancialActivityAccountHelper financialActivityAccountHelper; + // private final Integer assetTransferFinancialActivityId = + // FINANCIAL_ACTIVITY.ASSET_TRANSFER.getValue(); + public static final Integer liabilityTransferFinancialActivityId = FINANCIAL_ACTIVITY.LIABILITY_TRANSFER.getValue(); + + @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(); + this.accountHelper = new AccountHelper(this.requestSpec, this.responseSpec); + this.financialActivityAccountHelper = new FinancialActivityAccountHelper(this.requestSpec, this.responseSpec); + } + + @SuppressWarnings("unchecked") + @Test + public void testFinancialActivityAccounts() { + + /** Create a Liability and an Asset Transfer Account **/ + Account liabilityTransferAccount = accountHelper.createLiabilityAccount(); + Account assetTransferAccount = accountHelper.createAssetAccount(); + Assert.assertNotNull(assetTransferAccount); + Assert.assertNotNull(liabilityTransferAccount); + + /*** Create A Financial Activity to Account Mapping **/ + Integer financialActivityAccountId = (Integer) financialActivityAccountHelper.createFinancialActivityAccount( + liabilityTransferFinancialActivityId, liabilityTransferAccount.getAccountID(), CommonConstants.RESPONSE_RESOURCE_ID); + Assert.assertNotNull(financialActivityAccountId); + + /*** + * Fetch Created Financial Activity to Account Mapping and validate + * created values + **/ + assertFinancialActivityAccountCreation(financialActivityAccountId, liabilityTransferFinancialActivityId, liabilityTransferAccount); + + /** + * Update Existing Financial Activity to Account Mapping and assert + * changes + **/ + Account newLiabilityTransferAccount = accountHelper.createLiabilityAccount(); + Assert.assertNotNull(newLiabilityTransferAccount); + + HashMap changes = (HashMap) financialActivityAccountHelper.updateFinancialActivityAccount(financialActivityAccountId, + liabilityTransferFinancialActivityId, newLiabilityTransferAccount.getAccountID(), CommonConstants.RESPONSE_CHANGES); + Assert.assertEquals(newLiabilityTransferAccount.getAccountID(), changes.get("liabilityTransferInSuspenseAccountId")); + + /** Validate update works correctly **/ + assertFinancialActivityAccountCreation(financialActivityAccountId, liabilityTransferFinancialActivityId, + newLiabilityTransferAccount); + + /** 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)); + + /** Creating Duplicate Financial Activity should fail **/ + List duplicateFinancialActivityAccountError = (List) financialActivityAccountHelper + .createFinancialActivityAccount(financialActivityAccountId, liabilityTransferAccount.getAccountID(), + CommonConstants.RESPONSE_ERROR); + assertEquals(DuplicateFinancialActivityAccountFoundException.getErrorcode(), + duplicateFinancialActivityAccountError.get(0).get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE)); + + /** + * Associating incorrect GL account types with a financial activity + * should fail + **/ + List invalidFinancialActivityAccountError = (List) financialActivityAccountHelper.updateFinancialActivityAccount( + financialActivityAccountId, liabilityTransferFinancialActivityId, newLiabilityTransferAccount.getAccountID(), + 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); + Assert.assertNotNull(deletedFinancialActivityAccountId); + Assert.assertEquals(financialActivityAccountId, deletedFinancialActivityAccountId); + + /*** Trying to fetch a Deleted Account Mapping should give me a 404 **/ + financialActivityAccountHelper.getFinancialActivityAccountAndValidateResouceNotFound(financialActivityAccountId); + } + + private void assertFinancialActivityAccountCreation(Integer financialActivityAccountId, Integer financialActivityId, Account glAccount) { + HashMap mappingDetails = financialActivityAccountHelper.getFinancialActivityAccount(financialActivityAccountId); + 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/OfficeAccountingMappingsTest.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/OfficeAccountingMappingsTest.java deleted file mode 100755 index 6d01dac80..000000000 --- a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/OfficeAccountingMappingsTest.java +++ /dev/null @@ -1,87 +0,0 @@ -package org.mifosplatform.integrationtests; - -import static org.junit.Assert.assertEquals; - -import java.util.HashMap; -import java.util.List; - -import junit.framework.Assert; - -import org.junit.Before; -import org.junit.Test; -import org.mifosplatform.integrationtests.common.CommonConstants; -import org.mifosplatform.integrationtests.common.Utils; -import org.mifosplatform.integrationtests.common.accounting.Account; -import org.mifosplatform.integrationtests.common.accounting.AccountHelper; -import org.mifosplatform.integrationtests.common.accounting.FinancialActivityAccountsHelper; - -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; - -@SuppressWarnings("rawtypes") -public class OfficeAccountingMappingsTest { - - private ResponseSpecification responseSpec; - private RequestSpecification requestSpec; - - @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(); - } - - /** - @SuppressWarnings("unchecked") - @Test - public void testFinancialActivityAccounts() { - - AccountHelper accountHelper = new AccountHelper(this.requestSpec, this.responseSpec); - Account transferAccount = accountHelper.createLiabilityAccount(); - Assert.assertNotNull(transferAccount); - - FinancialActivityAccountsHelper accountMappingHelper = new FinancialActivityAccountsHelper(this.requestSpec, - new ResponseSpecBuilder().build()); - Integer transferAccountMappingId = (Integer) accountMappingHelper.createOfficeAccountMapping(officeId, - transferAccount.getAccountID(), CommonConstants.RESPONSE_RESOURCE_ID); - Assert.assertNotNull(transferAccountMappingId); - - HashMap mappingDetails = accountMappingHelper.getOfficeAccountMapping(transferAccountMappingId); - Assert.assertEquals(officeId, ((HashMap) mappingDetails.get("officeData")).get("id")); - Assert.assertEquals(transferAccount.getAccountID(), ((HashMap) mappingDetails.get("glAccountData")).get("id")); - - Account transferAccount2 = accountHelper.createLiabilityAccount(); - Assert.assertNotNull(transferAccount2); - - HashMap changes = (HashMap) accountMappingHelper.updateOfficeAccountMapping(transferAccountMappingId, officeId, - transferAccount2.getAccountID(), CommonConstants.RESPONSE_CHANGES); - Assert.assertEquals(transferAccount2.getAccountID(), changes.get("liabilityTransferInSuspenseAccountId")); - - mappingDetails = accountMappingHelper.getOfficeAccountMapping(transferAccountMappingId); - Assert.assertEquals(officeId, ((HashMap) mappingDetails.get("officeData")).get("id")); - Assert.assertEquals(transferAccount2.getAccountID(), ((HashMap) mappingDetails.get("glAccountData")).get("id")); - - List error1 = (List) accountMappingHelper.updateOfficeAccountMapping(transferAccountMappingId, officeId2, - transferAccount2.getAccountID(), CommonConstants.RESPONSE_ERROR); - assertEquals("error.msg.officeToAccountMapping.update.of.officeId.is.not.supported", - error1.get(0).get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE)); - - List error2 = (List) accountMappingHelper.createOfficeAccountMapping(officeId, transferAccount.getAccountID(), - CommonConstants.RESPONSE_ERROR); - assertEquals("error.msg.officeToAccountMapping.exists.for.office", error2.get(0).get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE)); - - Account fundAccount = accountHelper.createAssetAccount(); - Assert.assertNotNull(fundAccount); - - List error3 = (List) accountMappingHelper.createOfficeAccountMapping(officeId2, fundAccount.getAccountID(), - CommonConstants.RESPONSE_ERROR); - assertEquals("error.msg.liabilityTransferInSuspenseAccountId.invalid.account.type", - error3.get(0).get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE)); - - }**/ - -} diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/SystemCodeTest.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/SystemCodeTest.java index 965ccabc9..de4060e9a 100644 --- a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/SystemCodeTest.java +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/SystemCodeTest.java @@ -24,336 +24,249 @@ import com.jayway.restassured.specification.ResponseSpecification; * Test for creating, updating, deleting codes and code values * */ +@SuppressWarnings({ "rawtypes", "unchecked" }) public class SystemCodeTest { - private ResponseSpecification responseSpec; - private ResponseSpecification generalResponseSpec; - private RequestSpecification requestSpec; - - @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(); - - this.generalResponseSpec = new ResponseSpecBuilder().build(); - - } - - // @Ignore() - @Test - // scenario 57, 58, 59, 60 - public void testCreateCode() { - final String codeName = "Client Marital Status"; - - final Integer createResponseId = (Integer) CodeHelper.createCode( - this.requestSpec, this.responseSpec, codeName, - CodeHelper.RESPONSE_ID_ATTRIBUTE_NAME); - - // verify code created - final HashMap newCodeAttributes = (HashMap) CodeHelper.getCodeById( - this.requestSpec, this.responseSpec, createResponseId, ""); - - Assert.assertNotNull(newCodeAttributes); - assertEquals("Verify value of codeId", createResponseId, - newCodeAttributes.get(CodeHelper.CODE_ID_ATTRIBUTE_NAME)); - - assertEquals("Verify code name", codeName, - newCodeAttributes.get(CodeHelper.CODE_NAME_ATTRIBUTE_NAME)); - assertEquals("Verify system defined is false", false, - newCodeAttributes - .get(CodeHelper.CODE_SYSTEM_DEFINED_ATTRIBUTE_NAME)); - - // update code - final HashMap updateChangeResponse = (HashMap) CodeHelper.updateCode( - this.requestSpec, this.responseSpec, createResponseId, codeName - + "(CHANGE)", "changes"); - - assertEquals("Verify code name updated", codeName + "(CHANGE)", - updateChangeResponse.get(CodeHelper.CODE_NAME_ATTRIBUTE_NAME)); - - // delete code - final Integer deleteResponseId = (Integer) CodeHelper.deleteCodeById( - this.requestSpec, this.responseSpec, createResponseId, - CodeHelper.RESPONSE_ID_ATTRIBUTE_NAME); - assertEquals("Verify code deleted", createResponseId, deleteResponseId); - - // verify code deleted - final HashMap deletedCodeValues = (HashMap) CodeHelper.getCodeById( - this.requestSpec, this.generalResponseSpec, deleteResponseId, - ""); - - Assert.assertNotNull(deletedCodeValues); - assertNull("Verify value of codeId", - deletedCodeValues.get(CodeHelper.CODE_ID_ATTRIBUTE_NAME)); - - assertNull("Verify code name", - deletedCodeValues.get(CodeHelper.CODE_NAME_ATTRIBUTE_NAME)); - assertNull("Verify system defined is false", - deletedCodeValues - .get(CodeHelper.CODE_SYSTEM_DEFINED_ATTRIBUTE_NAME)); - } - - // @Ignore() - @Test - // scenario 57, 60 - public void testPreventCreateDuplicateCode() { - final String codeName = "Client Marital Status"; - - // create code - final Integer createResponseId = (Integer) CodeHelper.createCode( - this.requestSpec, this.responseSpec, codeName, - CodeHelper.RESPONSE_ID_ATTRIBUTE_NAME); - - // verify code created - final HashMap newCodeAttributes = (HashMap) CodeHelper.getCodeById( - this.requestSpec, this.responseSpec, createResponseId, ""); - - Assert.assertNotNull(newCodeAttributes); - assertEquals("Verify value of codeId", createResponseId, - newCodeAttributes.get(CodeHelper.CODE_ID_ATTRIBUTE_NAME)); - - assertEquals("Verify code name", codeName, - newCodeAttributes.get(CodeHelper.CODE_NAME_ATTRIBUTE_NAME)); - assertEquals("Verify system defined is false", false, - newCodeAttributes - .get(CodeHelper.CODE_SYSTEM_DEFINED_ATTRIBUTE_NAME)); - - // try to create duplicate-- should fail - final List error = (List) CodeHelper.createCode( - this.requestSpec, this.generalResponseSpec, codeName, - CommonConstants.RESPONSE_ERROR); - - assertEquals("Verify duplication error", - "error.msg.code.duplicate.name", - error.get(0).get("userMessageGlobalisationCode")); - - // delete code that was just created - - final Integer deleteResponseId = (Integer) CodeHelper.deleteCodeById( - this.requestSpec, this.responseSpec, createResponseId, - CodeHelper.RESPONSE_ID_ATTRIBUTE_NAME); - assertEquals("Verify code deleted", createResponseId, deleteResponseId); - - // verify code deleted - final HashMap deletedCodeAttributes = (HashMap) CodeHelper.getCodeById( - this.requestSpec, this.generalResponseSpec, deleteResponseId, - ""); - - Assert.assertNotNull(deletedCodeAttributes); - assertNull("Verify value of codeId", - deletedCodeAttributes.get(CodeHelper.CODE_ID_ATTRIBUTE_NAME)); - - assertNull("Verify code name", - deletedCodeAttributes.get(CodeHelper.CODE_NAME_ATTRIBUTE_NAME)); - assertNull("Verify system defined is false", - deletedCodeAttributes - .get(CodeHelper.CODE_SYSTEM_DEFINED_ATTRIBUTE_NAME)); - - } - - // @Ignore - @Test - public void testUpdateDeleteSystemDefinedCode() { - - // get any systemDefined code - final HashMap systemDefinedCode = (HashMap) CodeHelper - .getSystemDefinedCodes(this.requestSpec, this.responseSpec); - - // delete system-defined code should fail - final List error = (List) CodeHelper.deleteCodeById( - this.requestSpec, this.generalResponseSpec, - (Integer) systemDefinedCode - .get(CodeHelper.CODE_ID_ATTRIBUTE_NAME), - CommonConstants.RESPONSE_ERROR); - - assertEquals("Cannot delete system-defined code", - "error.msg.code.systemdefined", - error.get(0).get("userMessageGlobalisationCode")); - - // update system-defined code should fail - final List updateError = (List) CodeHelper.updateCode( - this.requestSpec, this.generalResponseSpec, - (Integer) systemDefinedCode - .get(CodeHelper.CODE_ID_ATTRIBUTE_NAME), - systemDefinedCode.get(CodeHelper.CODE_NAME_ATTRIBUTE_NAME) - + "CHANGE", CommonConstants.RESPONSE_ERROR); - - assertEquals("Cannot update system-defined code", - "error.msg.code.systemdefined", - error.get(0).get("userMessageGlobalisationCode")); - - } - - // @Ignore - @Test - public void testCodeValuesNotAssignedToTable() { - - final String codeName = "Client Marital Status"; - - final String codeValue1 = "Married"; - final String codeValue2 = "Unmarried"; - - final int codeValue1Position = 1; - final int codeValue2Position = 2; - - // create code - final Integer createCodeResponseId = (Integer) CodeHelper.createCode( - this.requestSpec, this.responseSpec, codeName, - CodeHelper.RESPONSE_ID_ATTRIBUTE_NAME); - - // create first code value - final Integer createCodeValueResponseId1 = (Integer) CodeHelper - .createCodeValue(this.requestSpec, this.responseSpec, - createCodeResponseId, codeValue1, codeValue1Position, - CodeHelper.SUBRESPONSE_ID_ATTRIBUTE_NAME); - - // create second code value - final Integer createCodeValueResponseId2 = (Integer) CodeHelper - .createCodeValue(this.requestSpec, this.responseSpec, - createCodeResponseId, codeValue2, codeValue2Position, - CodeHelper.SUBRESPONSE_ID_ATTRIBUTE_NAME); - - // verify two code values created - - final List codeValuesList = (List) CodeHelper - .getCodeValuesForCode(this.requestSpec, this.responseSpec, - createCodeResponseId, ""); - - assertEquals("Number of code values returned matches number created", - 2, codeValuesList.size()); - - // verify values of first code value - final HashMap codeValuesAttributes1 = (HashMap) CodeHelper - .getCodeValueById(this.requestSpec, this.responseSpec, - createCodeResponseId, createCodeValueResponseId1, ""); - - Assert.assertNotNull(codeValuesAttributes1); - assertEquals("Verify value of codeValueId", createCodeValueResponseId1, - codeValuesAttributes1 - .get(CodeHelper.CODE_VALUE_ID_ATTRIBUTE_NAME)); - - assertEquals("Verify value of code name", codeValue1, - codeValuesAttributes1 - .get(CodeHelper.CODE_VALUE_NAME_ATTRIBUTE_NAME)); - - assertEquals("Verify position of code value", codeValue1Position, - codeValuesAttributes1 - .get(CodeHelper.CODE_VALUE_POSITION_ATTRIBUTE_NAME)); - - // verify values of second code value - final HashMap codeValuesAttributes2 = (HashMap) CodeHelper - .getCodeValueById(this.requestSpec, this.responseSpec, - createCodeResponseId, createCodeValueResponseId2, ""); - - Assert.assertNotNull(codeValuesAttributes2); - assertEquals("Verify value of codeValueId", createCodeValueResponseId2, - codeValuesAttributes2 - .get(CodeHelper.CODE_VALUE_ID_ATTRIBUTE_NAME)); - - assertEquals("Verify value of code name", codeValue2, - codeValuesAttributes2 - .get(CodeHelper.CODE_VALUE_NAME_ATTRIBUTE_NAME)); - - assertEquals("Verify position of code value", codeValue2Position, - codeValuesAttributes2 - .get(CodeHelper.CODE_VALUE_POSITION_ATTRIBUTE_NAME)); - - // update code value 1 - - final HashMap codeValueChanges = (HashMap) CodeHelper - .updateCodeValue(this.requestSpec, this.responseSpec, - createCodeResponseId, createCodeValueResponseId1, - codeValue1 + "CHANGE", 4, "changes"); - - assertEquals("Verify changed code value name", - codeValueChanges.get("name"), codeValue1 + "CHANGE"); - - // delete code value - final Integer deletedCodeValueResponseId1 = (Integer) CodeHelper - .deleteCodeValueById(this.requestSpec, - this.generalResponseSpec, createCodeResponseId, - createCodeValueResponseId1, - CodeHelper.RESPONSE_ID_ATTRIBUTE_NAME); + private ResponseSpecification responseSpec; + private ResponseSpecification generalResponseSpec; + private RequestSpecification requestSpec; - // Verify code value deleted + @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(); - final HashMap deletedCodeValueAttributes1 = (HashMap) CodeHelper - .getCodeValueById(this.requestSpec, this.generalResponseSpec, - createCodeResponseId, deletedCodeValueResponseId1, ""); + this.generalResponseSpec = new ResponseSpecBuilder().build(); - // Assert.assertNotNull(deletedCodeValueAttributes1); - assertNull("Verify value of codeValueId", - deletedCodeValueAttributes1 - .get(CodeHelper.CODE_VALUE_ID_ATTRIBUTE_NAME)); + } - assertNull("Verify value of code name", - deletedCodeValueAttributes1 - .get(CodeHelper.CODE_VALUE_NAME_ATTRIBUTE_NAME)); + // @Ignore() + @Test + // scenario 57, 58, 59, 60 + public void testCreateCode() { + final String codeName = "Client Marital Status"; - assertNull("Verify position of code value", - deletedCodeValueAttributes1 - .get(CodeHelper.CODE_VALUE_POSITION_ATTRIBUTE_NAME)); - - final List deletedCodeValuesList = (List) CodeHelper - .getCodeValuesForCode(this.requestSpec, this.responseSpec, - createCodeResponseId, ""); - - assertEquals("Number of code values is 1", 1, - deletedCodeValuesList.size()); - - // delete code, remaining code values automatically deleted - - final Integer deleteCodeResponseId = (Integer) CodeHelper - .deleteCodeById(this.requestSpec, this.generalResponseSpec, - createCodeResponseId, - CodeHelper.RESPONSE_ID_ATTRIBUTE_NAME); - assertEquals("Verify code deleted", createCodeResponseId, - deleteCodeResponseId); + final Integer createResponseId = (Integer) CodeHelper.createCode(this.requestSpec, this.responseSpec, codeName, + CodeHelper.RESPONSE_ID_ATTRIBUTE_NAME); - // verify code deleted - final HashMap deletedCodeAttributes = (HashMap) CodeHelper.getCodeById( - this.requestSpec, this.generalResponseSpec, - createCodeResponseId, ""); + // verify code created - Assert.assertNotNull(deletedCodeAttributes); - assertNull("Verify value of codeId is null", - deletedCodeAttributes.get(CodeHelper.CODE_ID_ATTRIBUTE_NAME)); + final HashMap newCodeAttributes = (HashMap) CodeHelper.getCodeById(this.requestSpec, this.responseSpec, createResponseId, ""); - assertNull("Verify code name is null", - deletedCodeAttributes.get(CodeHelper.CODE_NAME_ATTRIBUTE_NAME)); - assertNull("Verify system defined is null", - deletedCodeAttributes - .get(CodeHelper.CODE_SYSTEM_DEFINED_ATTRIBUTE_NAME)); - - // Verify remaining code value deleted - final HashMap deletedCodeValues2 = (HashMap) CodeHelper - .getCodeValueById(this.requestSpec, this.generalResponseSpec, - createCodeResponseId, createCodeValueResponseId2, ""); + Assert.assertNotNull(newCodeAttributes); + assertEquals("Verify value of codeId", createResponseId, newCodeAttributes.get(CodeHelper.CODE_ID_ATTRIBUTE_NAME)); - assertNull("Verify value of codeValueId is null", - deletedCodeValues2.get(CodeHelper.CODE_VALUE_ID_ATTRIBUTE_NAME)); - - assertNull("Verify value of code name is null", - deletedCodeValues2 - .get(CodeHelper.CODE_VALUE_NAME_ATTRIBUTE_NAME)); - - assertNull("Verify position of code value null", - deletedCodeValues2 - .get(CodeHelper.CODE_VALUE_POSITION_ATTRIBUTE_NAME)); - - } + assertEquals("Verify code name", codeName, newCodeAttributes.get(CodeHelper.CODE_NAME_ATTRIBUTE_NAME)); + assertEquals("Verify system defined is false", false, newCodeAttributes.get(CodeHelper.CODE_SYSTEM_DEFINED_ATTRIBUTE_NAME)); - @Ignore - @Test - public void testCodeValuesAssignedToTable() { + // update code + final HashMap updateChangeResponse = (HashMap) CodeHelper.updateCode(this.requestSpec, this.responseSpec, createResponseId, + codeName + "(CHANGE)", "changes"); - } + assertEquals("Verify code name updated", codeName + "(CHANGE)", updateChangeResponse.get(CodeHelper.CODE_NAME_ATTRIBUTE_NAME)); + + // delete code + final Integer deleteResponseId = (Integer) CodeHelper.deleteCodeById(this.requestSpec, this.responseSpec, createResponseId, + CodeHelper.RESPONSE_ID_ATTRIBUTE_NAME); + assertEquals("Verify code deleted", createResponseId, deleteResponseId); + + // verify code deleted + final HashMap deletedCodeValues = (HashMap) CodeHelper + .getCodeById(this.requestSpec, this.generalResponseSpec, deleteResponseId, ""); + + Assert.assertNotNull(deletedCodeValues); + assertNull("Verify value of codeId", deletedCodeValues.get(CodeHelper.CODE_ID_ATTRIBUTE_NAME)); + + assertNull("Verify code name", deletedCodeValues.get(CodeHelper.CODE_NAME_ATTRIBUTE_NAME)); + assertNull("Verify system defined is false", deletedCodeValues.get(CodeHelper.CODE_SYSTEM_DEFINED_ATTRIBUTE_NAME)); + } + + // @Ignore() + @Test + // scenario 57, 60 + public void testPreventCreateDuplicateCode() { + final String codeName = "Client Marital Status"; + + // create code + final Integer createResponseId = (Integer) CodeHelper.createCode(this.requestSpec, this.responseSpec, codeName, + CodeHelper.RESPONSE_ID_ATTRIBUTE_NAME); + + // verify code created + final HashMap newCodeAttributes = (HashMap) CodeHelper.getCodeById(this.requestSpec, this.responseSpec, createResponseId, ""); + + Assert.assertNotNull(newCodeAttributes); + assertEquals("Verify value of codeId", createResponseId, newCodeAttributes.get(CodeHelper.CODE_ID_ATTRIBUTE_NAME)); + + assertEquals("Verify code name", codeName, newCodeAttributes.get(CodeHelper.CODE_NAME_ATTRIBUTE_NAME)); + assertEquals("Verify system defined is false", false, newCodeAttributes.get(CodeHelper.CODE_SYSTEM_DEFINED_ATTRIBUTE_NAME)); + + // try to create duplicate-- should fail + final List error = (List) CodeHelper.createCode(this.requestSpec, this.generalResponseSpec, codeName, + CommonConstants.RESPONSE_ERROR); + + assertEquals("Verify duplication error", "error.msg.code.duplicate.name", error.get(0).get("userMessageGlobalisationCode")); + + // delete code that was just created + + final Integer deleteResponseId = (Integer) CodeHelper.deleteCodeById(this.requestSpec, this.responseSpec, createResponseId, + CodeHelper.RESPONSE_ID_ATTRIBUTE_NAME); + assertEquals("Verify code deleted", createResponseId, deleteResponseId); + + // verify code deleted + final HashMap deletedCodeAttributes = (HashMap) CodeHelper.getCodeById(this.requestSpec, this.generalResponseSpec, + deleteResponseId, ""); + + Assert.assertNotNull(deletedCodeAttributes); + assertNull("Verify value of codeId", deletedCodeAttributes.get(CodeHelper.CODE_ID_ATTRIBUTE_NAME)); + + assertNull("Verify code name", deletedCodeAttributes.get(CodeHelper.CODE_NAME_ATTRIBUTE_NAME)); + assertNull("Verify system defined is false", deletedCodeAttributes.get(CodeHelper.CODE_SYSTEM_DEFINED_ATTRIBUTE_NAME)); + + } + + // @Ignore + @Test + public void testUpdateDeleteSystemDefinedCode() { + + // get any systemDefined code + final HashMap systemDefinedCode = (HashMap) CodeHelper.getSystemDefinedCodes(this.requestSpec, this.responseSpec); + + // delete system-defined code should fail + final List error = (List) CodeHelper.deleteCodeById(this.requestSpec, this.generalResponseSpec, + (Integer) systemDefinedCode.get(CodeHelper.CODE_ID_ATTRIBUTE_NAME), CommonConstants.RESPONSE_ERROR); + + assertEquals("Cannot delete system-defined code", "error.msg.code.systemdefined", error.get(0).get("userMessageGlobalisationCode")); + + // update system-defined code should fail + + final List updateError = (List) CodeHelper.updateCode(this.requestSpec, this.generalResponseSpec, + (Integer) systemDefinedCode.get(CodeHelper.CODE_ID_ATTRIBUTE_NAME), + systemDefinedCode.get(CodeHelper.CODE_NAME_ATTRIBUTE_NAME) + "CHANGE", CommonConstants.RESPONSE_ERROR); + + assertEquals("Cannot update system-defined code", "error.msg.code.systemdefined", + updateError.get(0).get("userMessageGlobalisationCode")); + + } + + // @Ignore + @Test + public void testCodeValuesNotAssignedToTable() { + + final String codeName = "Client Marital Status"; + + final String codeValue1 = "Married"; + final String codeValue2 = "Unmarried"; + + final int codeValue1Position = 1; + final int codeValue2Position = 2; + + // create code + final Integer createCodeResponseId = (Integer) CodeHelper.createCode(this.requestSpec, this.responseSpec, codeName, + CodeHelper.RESPONSE_ID_ATTRIBUTE_NAME); + + // create first code value + final Integer createCodeValueResponseId1 = (Integer) CodeHelper.createCodeValue(this.requestSpec, this.responseSpec, + createCodeResponseId, codeValue1, codeValue1Position, CodeHelper.SUBRESPONSE_ID_ATTRIBUTE_NAME); + + // create second code value + final Integer createCodeValueResponseId2 = (Integer) CodeHelper.createCodeValue(this.requestSpec, this.responseSpec, + createCodeResponseId, codeValue2, codeValue2Position, CodeHelper.SUBRESPONSE_ID_ATTRIBUTE_NAME); + + // verify two code values created + + final List codeValuesList = (List) CodeHelper.getCodeValuesForCode(this.requestSpec, this.responseSpec, + createCodeResponseId, ""); + + assertEquals("Number of code values returned matches number created", 2, codeValuesList.size()); + + // verify values of first code value + final HashMap codeValuesAttributes1 = (HashMap) CodeHelper.getCodeValueById(this.requestSpec, this.responseSpec, + createCodeResponseId, createCodeValueResponseId1, ""); + + Assert.assertNotNull(codeValuesAttributes1); + assertEquals("Verify value of codeValueId", createCodeValueResponseId1, + codeValuesAttributes1.get(CodeHelper.CODE_VALUE_ID_ATTRIBUTE_NAME)); + + assertEquals("Verify value of code name", codeValue1, codeValuesAttributes1.get(CodeHelper.CODE_VALUE_NAME_ATTRIBUTE_NAME)); + + assertEquals("Verify position of code value", codeValue1Position, + codeValuesAttributes1.get(CodeHelper.CODE_VALUE_POSITION_ATTRIBUTE_NAME)); + + // verify values of second code value + final HashMap codeValuesAttributes2 = (HashMap) CodeHelper.getCodeValueById(this.requestSpec, this.responseSpec, + createCodeResponseId, createCodeValueResponseId2, ""); + + Assert.assertNotNull(codeValuesAttributes2); + assertEquals("Verify value of codeValueId", createCodeValueResponseId2, + codeValuesAttributes2.get(CodeHelper.CODE_VALUE_ID_ATTRIBUTE_NAME)); + + assertEquals("Verify value of code name", codeValue2, codeValuesAttributes2.get(CodeHelper.CODE_VALUE_NAME_ATTRIBUTE_NAME)); + + assertEquals("Verify position of code value", codeValue2Position, + codeValuesAttributes2.get(CodeHelper.CODE_VALUE_POSITION_ATTRIBUTE_NAME)); + + // update code value 1 + + final HashMap codeValueChanges = (HashMap) CodeHelper.updateCodeValue(this.requestSpec, this.responseSpec, createCodeResponseId, + createCodeValueResponseId1, codeValue1 + "CHANGE", 4, "changes"); + + assertEquals("Verify changed code value name", codeValueChanges.get("name"), codeValue1 + "CHANGE"); + + // delete code value + final Integer deletedCodeValueResponseId1 = (Integer) CodeHelper.deleteCodeValueById(this.requestSpec, this.generalResponseSpec, + createCodeResponseId, createCodeValueResponseId1, CodeHelper.RESPONSE_ID_ATTRIBUTE_NAME); + + // Verify code value deleted + + final HashMap deletedCodeValueAttributes1 = (HashMap) CodeHelper.getCodeValueById(this.requestSpec, this.generalResponseSpec, + createCodeResponseId, deletedCodeValueResponseId1, ""); + + // Assert.assertNotNull(deletedCodeValueAttributes1); + assertNull("Verify value of codeValueId", deletedCodeValueAttributes1.get(CodeHelper.CODE_VALUE_ID_ATTRIBUTE_NAME)); + + assertNull("Verify value of code name", deletedCodeValueAttributes1.get(CodeHelper.CODE_VALUE_NAME_ATTRIBUTE_NAME)); + + assertNull("Verify position of code value", deletedCodeValueAttributes1.get(CodeHelper.CODE_VALUE_POSITION_ATTRIBUTE_NAME)); + + final List deletedCodeValuesList = (List) CodeHelper.getCodeValuesForCode(this.requestSpec, this.responseSpec, + createCodeResponseId, ""); + + assertEquals("Number of code values is 1", 1, deletedCodeValuesList.size()); + + // delete code, remaining code values automatically deleted + + final Integer deleteCodeResponseId = (Integer) CodeHelper.deleteCodeById(this.requestSpec, this.generalResponseSpec, + createCodeResponseId, CodeHelper.RESPONSE_ID_ATTRIBUTE_NAME); + assertEquals("Verify code deleted", createCodeResponseId, deleteCodeResponseId); + + // verify code deleted + final HashMap deletedCodeAttributes = (HashMap) CodeHelper.getCodeById(this.requestSpec, this.generalResponseSpec, + createCodeResponseId, ""); + + Assert.assertNotNull(deletedCodeAttributes); + assertNull("Verify value of codeId is null", deletedCodeAttributes.get(CodeHelper.CODE_ID_ATTRIBUTE_NAME)); + + assertNull("Verify code name is null", deletedCodeAttributes.get(CodeHelper.CODE_NAME_ATTRIBUTE_NAME)); + assertNull("Verify system defined is null", deletedCodeAttributes.get(CodeHelper.CODE_SYSTEM_DEFINED_ATTRIBUTE_NAME)); + + // Verify remaining code value deleted + final HashMap deletedCodeValues2 = (HashMap) CodeHelper.getCodeValueById(this.requestSpec, this.generalResponseSpec, + createCodeResponseId, createCodeValueResponseId2, ""); + + assertNull("Verify value of codeValueId is null", deletedCodeValues2.get(CodeHelper.CODE_VALUE_ID_ATTRIBUTE_NAME)); + + assertNull("Verify value of code name is null", deletedCodeValues2.get(CodeHelper.CODE_VALUE_NAME_ATTRIBUTE_NAME)); + + assertNull("Verify position of code value null", deletedCodeValues2.get(CodeHelper.CODE_VALUE_POSITION_ATTRIBUTE_NAME)); + + } + + @Ignore + @Test + public void testCodeValuesAssignedToTable() { + + } } \ No newline at end of file diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/surveyHelper.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/SurveyHelper.java similarity index 98% rename from mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/surveyHelper.java rename to mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/SurveyHelper.java index 1d7b69a35..6f9b3474f 100644 --- a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/surveyHelper.java +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/SurveyHelper.java @@ -8,7 +8,7 @@ import java.util.HashMap; import static org.junit.Assert.assertEquals; -public class surveyHelper { +public class SurveyHelper { private static final String FULFIL_SURVEY_URL = "/mifosng-provider/api/v1/survey/ppi_kenya_2009/clientId?tenantIdentifier=default"; 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 4f82183c8..03b9e77d2 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,5 +1,6 @@ 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; @@ -53,6 +54,10 @@ 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/AccountHelper.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/accounting/AccountHelper.java index c6ea3f95d..b984912cd 100644 --- a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/accounting/AccountHelper.java +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/accounting/AccountHelper.java @@ -44,9 +44,9 @@ public class AccountHelper { } public Account createLiabilityAccount() { - final String assetAccountJSON = new GLAccountBuilder().withAccountTypeAsLiability().build(); + final String liabilityAccountJSON = new GLAccountBuilder().withAccountTypeAsLiability().build(); final Integer accountID = Utils.performServerPost(this.requestSpec, this.responseSpec, this.CREATE_GL_ACCOUNT_URL, - assetAccountJSON, this.GL_ACCOUNT_ID_RESPONSE); + liabilityAccountJSON, this.GL_ACCOUNT_ID_RESPONSE); return new Account(accountID, Account.AccountType.LIABILITY); } 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 new file mode 100755 index 000000000..b8352437d --- /dev/null +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/accounting/FinancialActivityAccountHelper.java @@ -0,0 +1,55 @@ +package org.mifosplatform.integrationtests.common.accounting; + +import java.util.HashMap; + +import org.mifosplatform.integrationtests.common.Utils; + +import com.jayway.restassured.specification.RequestSpecification; +import com.jayway.restassured.specification.ResponseSpecification; + +@SuppressWarnings("rawtypes") +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) { + this.requestSpec = requestSpec; + this.responseSpec = responseSpec; + } + + public Object createFinancialActivityAccount(Integer financialActivityId, Integer glAccountId, String jsonBack) { + String json = FinancialActivityAccountsMappingBuilder.build(financialActivityId, glAccountId); + return Utils.performServerPost(this.requestSpec, this.responseSpec, FINANCIAL_ACTIVITY_ACCOUNT_MAPPING_URL + "?" + + Utils.TENANT_IDENTIFIER, json, jsonBack); + } + + public Object updateFinancialActivityAccount(Integer financialActivityAccountId, Integer financialActivityId, Integer glAccountId, + String jsonBack) { + String json = FinancialActivityAccountsMappingBuilder.build(financialActivityId, glAccountId); + return Utils.performServerPut(this.requestSpec, this.responseSpec, FINANCIAL_ACTIVITY_ACCOUNT_MAPPING_URL + "/" + + financialActivityAccountId + "?" + Utils.TENANT_IDENTIFIER, json, jsonBack); + } + + public HashMap getFinancialActivityAccount(final Integer financialActivityAccountId) { + final String url = FINANCIAL_ACTIVITY_ACCOUNT_MAPPING_URL + "/" + financialActivityAccountId + "?" + Utils.TENANT_IDENTIFIER; + return Utils.performServerGet(requestSpec, responseSpec, 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() { + final String url = FINANCIAL_ACTIVITY_ACCOUNT_MAPPING_URL + "?" + Utils.TENANT_IDENTIFIER; + return Utils.performServerGet(this.requestSpec, this.responseSpec, url, ""); + } + + public Integer deleteFinancialActivityAccount(final Integer financialActivityAccountId, String jsonBack) { + final String url = FINANCIAL_ACTIVITY_ACCOUNT_MAPPING_URL + "/" + financialActivityAccountId + "?" + Utils.TENANT_IDENTIFIER; + return Utils.performServerDelete(this.requestSpec, this.responseSpec, url, jsonBack); + } + +} diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/accounting/FinancialActivityAccountsHelper.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/accounting/FinancialActivityAccountsHelper.java deleted file mode 100755 index 6a6584e86..000000000 --- a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/accounting/FinancialActivityAccountsHelper.java +++ /dev/null @@ -1,44 +0,0 @@ -package org.mifosplatform.integrationtests.common.accounting; - -import java.util.HashMap; - -import org.mifosplatform.integrationtests.common.Utils; - -import com.jayway.restassured.specification.RequestSpecification; -import com.jayway.restassured.specification.ResponseSpecification; - -@SuppressWarnings("rawtypes") -public class FinancialActivityAccountsHelper { - - private static final String ACCOUNT_MAPPING_URL = "/mifosng-provider/api/v1/financialactivityaccounts"; - private final RequestSpecification requestSpec; - private final ResponseSpecification responseSpec; - - public FinancialActivityAccountsHelper(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) { - this.requestSpec = requestSpec; - this.responseSpec = responseSpec; - } - - public Object createFinancialactivityaccounts(Integer officeId, Integer glAccountId, String jsonBack) { - String json = OfficeAccountMappingBuilder.build(officeId, glAccountId); - return Utils.performServerPost(this.requestSpec, this.responseSpec, ACCOUNT_MAPPING_URL + "?" + Utils.TENANT_IDENTIFIER, json, - jsonBack); - } - - public Object updateFinancialactivityaccounts(Integer mappingId, Integer officeId, Integer glAccountId, String jsonBack) { - String json = OfficeAccountMappingBuilder.build(officeId, glAccountId); - return Utils.performServerPut(this.requestSpec, this.responseSpec, ACCOUNT_MAPPING_URL + "/" + mappingId + "?" - + Utils.TENANT_IDENTIFIER, json, jsonBack); - } - - public HashMap getFinancialactivityaccount(final Integer mappingId) { - final String URL = ACCOUNT_MAPPING_URL + "/" + mappingId + "?" + Utils.TENANT_IDENTIFIER; - return Utils.performServerGet(requestSpec, responseSpec, URL, ""); - } - - public HashMap getOfficeAccountMappings() { - final String URL = ACCOUNT_MAPPING_URL + "?" + Utils.TENANT_IDENTIFIER; - return Utils.performServerGet(requestSpec, responseSpec, URL, ""); - } - -} diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/accounting/FinancialActivityAccountsMappingBuilder.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/accounting/FinancialActivityAccountsMappingBuilder.java new file mode 100755 index 000000000..cb1fdfd22 --- /dev/null +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/accounting/FinancialActivityAccountsMappingBuilder.java @@ -0,0 +1,15 @@ +package org.mifosplatform.integrationtests.common.accounting; + +import java.util.HashMap; + +import com.google.gson.Gson; + +public class FinancialActivityAccountsMappingBuilder { + + public static String build(Integer financialActivityId, Integer glAccountId) { + final HashMap map = new HashMap(); + map.put("financialActivityId", financialActivityId); + map.put("glAccountId", glAccountId); + return new Gson().toJson(map); + } +} diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/accounting/OfficeAccountMappingBuilder.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/accounting/OfficeAccountMappingBuilder.java deleted file mode 100755 index 1fbdc24a8..000000000 --- a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/accounting/OfficeAccountMappingBuilder.java +++ /dev/null @@ -1,15 +0,0 @@ -package org.mifosplatform.integrationtests.common.accounting; - -import java.util.HashMap; - -import com.google.gson.Gson; - -public class OfficeAccountMappingBuilder { - - public static String build(Integer officeId, Integer glAccountId) { - final HashMap map = new HashMap(); - map.put("officeId", officeId); - map.put("liabilityTransferInSuspenseAccountId", glAccountId); - return new Gson().toJson(map); - } -} diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/system/CodeHelper.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/system/CodeHelper.java index 06b45d1f9..42c21c8a1 100644 --- a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/system/CodeHelper.java +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/system/CodeHelper.java @@ -13,151 +13,114 @@ import com.jayway.restassured.specification.ResponseSpecification; public class CodeHelper { - public static final String CODE_ID_ATTRIBUTE_NAME = "id"; - public static final String RESPONSE_ID_ATTRIBUTE_NAME = "resourceId"; - public static final String SUBRESPONSE_ID_ATTRIBUTE_NAME = "subResourceId"; - public static final String CODE_NAME_ATTRIBUTE_NAME = "name"; - public static final String CODE_SYSTEM_DEFINED_ATTRIBUTE_NAME = "systemDefined"; - public static final String CODE_URL = "/mifosng-provider/api/v1/codes"; + public static final String CODE_ID_ATTRIBUTE_NAME = "id"; + public static final String RESPONSE_ID_ATTRIBUTE_NAME = "resourceId"; + public static final String SUBRESPONSE_ID_ATTRIBUTE_NAME = "subResourceId"; + public static final String CODE_NAME_ATTRIBUTE_NAME = "name"; + public static final String CODE_SYSTEM_DEFINED_ATTRIBUTE_NAME = "systemDefined"; + public static final String CODE_URL = "/mifosng-provider/api/v1/codes"; - public static final String CODE_VALUE_ID_ATTRIBUTE_NAME = "id"; - public static final String CODE_VALUE_NAME_ATTRIBUTE_NAME = "name"; - public static final String CODE_VALUE_POSITION_ATTRIBUTE_NAME = "position"; - public static final String CODE_VALUE_URL = "/mifosng-provider/api/v1/codes/[codeId]/codevalues"; + public static final String CODE_VALUE_ID_ATTRIBUTE_NAME = "id"; + public static final String CODE_VALUE_NAME_ATTRIBUTE_NAME = "name"; + public static final String CODE_VALUE_POSITION_ATTRIBUTE_NAME = "position"; + public static final String CODE_VALUE_URL = "/mifosng-provider/api/v1/codes/[codeId]/codevalues"; - public static Object createCode(final RequestSpecification requestSpec, - final ResponseSpecification responseSpec, final String codeName, - final String jsonAttributeToGetback) { + public static Object createCode(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, + final String codeName, final String jsonAttributeToGetback) { - return Utils.performServerPost(requestSpec, responseSpec, CODE_URL - + "?" + Utils.TENANT_IDENTIFIER, getTestCodeAsJSON(codeName), - jsonAttributeToGetback); - } + return Utils.performServerPost(requestSpec, responseSpec, CODE_URL + "?" + Utils.TENANT_IDENTIFIER, getTestCodeAsJSON(codeName), + jsonAttributeToGetback); + } - public static Object updateCode(final RequestSpecification requestSpec, - final ResponseSpecification responseSpec, final Integer codeId, - final String codeName, final String jsonAttributeToGetback) { + public static Object updateCode(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, final Integer codeId, + final String codeName, final String jsonAttributeToGetback) { - return Utils.performServerPut(requestSpec, responseSpec, CODE_URL + "/" - + codeId + "?" + Utils.TENANT_IDENTIFIER, - getTestCodeAsJSON(codeName), jsonAttributeToGetback); - } + return Utils.performServerPut(requestSpec, responseSpec, CODE_URL + "/" + codeId + "?" + Utils.TENANT_IDENTIFIER, + getTestCodeAsJSON(codeName), jsonAttributeToGetback); + } - public static Object getCodeById(final RequestSpecification requestSpec, - final ResponseSpecification responseSpec, final Integer codeId, - final String jsonAttributeToGetback) { + public static Object getCodeById(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, + final Integer codeId, final String jsonAttributeToGetback) { - return Utils.performServerGet(requestSpec, responseSpec, CODE_URL + "/" - + codeId + "?" + Utils.TENANT_IDENTIFIER, - jsonAttributeToGetback); + return Utils.performServerGet(requestSpec, responseSpec, CODE_URL + "/" + codeId + "?" + Utils.TENANT_IDENTIFIER, + jsonAttributeToGetback); - } + } - public static Object getAllCodes(final RequestSpecification requestSpec, - final ResponseSpecification responseSpec) { + public static Object getAllCodes(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) { - return Utils.performServerGet(requestSpec, responseSpec, CODE_URL + "?" - + Utils.TENANT_IDENTIFIER, ""); + return Utils.performServerGet(requestSpec, responseSpec, CODE_URL + "?" + Utils.TENANT_IDENTIFIER, ""); - } + } - public static Object getSystemDefinedCodes( - final RequestSpecification requestSpec, - final ResponseSpecification responseSpec) { + public static Object getSystemDefinedCodes(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) { - final String getResponse = given().spec(requestSpec).expect() - .spec(responseSpec).when() - .get(CodeHelper.CODE_URL + "?" + Utils.TENANT_IDENTIFIER) - .asString(); + final String getResponse = given().spec(requestSpec).expect().spec(responseSpec).when() + .get(CodeHelper.CODE_URL + "?" + Utils.TENANT_IDENTIFIER).asString(); - final JsonPath getResponseJsonPath = new JsonPath(getResponse); + final JsonPath getResponseJsonPath = new JsonPath(getResponse); - // get any systemDefined code - return getResponseJsonPath.get("find { e -> e.systemDefined == true }"); + // get any systemDefined code + return getResponseJsonPath.get("find { e -> e.systemDefined == true }"); - } + } - public static String getTestCodeAsJSON(final String codeName) { - final HashMap map = new HashMap(); - map.put(CODE_NAME_ATTRIBUTE_NAME, codeName); - return new Gson().toJson(map); - } + public static String getTestCodeAsJSON(final String codeName) { + final HashMap map = new HashMap(); + map.put(CODE_NAME_ATTRIBUTE_NAME, codeName); + return new Gson().toJson(map); + } - public static String getTestCodeValueAsJSON(final String codeValueName, - final Integer position) { - final HashMap map = new HashMap(); - map.put(CODE_VALUE_NAME_ATTRIBUTE_NAME, codeValueName); - map.put(CODE_VALUE_POSITION_ATTRIBUTE_NAME, position); - return new Gson().toJson(map); - } + public static String getTestCodeValueAsJSON(final String codeValueName, final Integer position) { + final HashMap map = new HashMap(); + map.put(CODE_VALUE_NAME_ATTRIBUTE_NAME, codeValueName); + map.put(CODE_VALUE_POSITION_ATTRIBUTE_NAME, position); + return new Gson().toJson(map); + } - public static Object deleteCodeById(final RequestSpecification requestSpec, - final ResponseSpecification responseSpec, final Integer codeId, - final String jsonAttributeToGetback) { + public static Object deleteCodeById(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, + final Integer codeId, final String jsonAttributeToGetback) { - return Utils.performServerDelete(requestSpec, responseSpec, CODE_URL - + "/" + codeId + "?" + Utils.TENANT_IDENTIFIER, - jsonAttributeToGetback); + return Utils.performServerDelete(requestSpec, responseSpec, CODE_URL + "/" + codeId + "?" + Utils.TENANT_IDENTIFIER, + jsonAttributeToGetback); - } + } - public static Object createCodeValue( - final RequestSpecification requestSpec, - final ResponseSpecification responseSpec, final Integer codeId, - final String codeValueName, final Integer position, - final String jsonAttributeToGetback) { + public static Object createCodeValue(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, + final Integer codeId, final String codeValueName, final Integer position, final String jsonAttributeToGetback) { - return Utils.performServerPost(requestSpec, responseSpec, - CODE_VALUE_URL.replace("[codeId]", codeId.toString()) + "?" - + Utils.TENANT_IDENTIFIER, - getTestCodeValueAsJSON(codeValueName, position), - jsonAttributeToGetback); - } + return Utils.performServerPost(requestSpec, responseSpec, CODE_VALUE_URL.replace("[codeId]", codeId.toString()) + "?" + + Utils.TENANT_IDENTIFIER, getTestCodeValueAsJSON(codeValueName, position), jsonAttributeToGetback); + } - public static Object getCodeValuesForCode( - final RequestSpecification requestSpec, - final ResponseSpecification responseSpec, final Integer codeId, - final String jsonAttributeToGetback) { + public static Object getCodeValuesForCode(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, + final Integer codeId, final String jsonAttributeToGetback) { - return Utils.performServerGet(requestSpec, responseSpec, - CODE_VALUE_URL.replace("[codeId]", codeId.toString()) + "?" - + Utils.TENANT_IDENTIFIER, jsonAttributeToGetback); - } + return Utils.performServerGet(requestSpec, responseSpec, CODE_VALUE_URL.replace("[codeId]", codeId.toString()) + "?" + + Utils.TENANT_IDENTIFIER, jsonAttributeToGetback); + } - public static Object getCodeValueById( - final RequestSpecification requestSpec, - final ResponseSpecification responseSpec, final Integer codeId, - final Integer codeValueId, final String jsonAttributeToGetback) { + public static Object getCodeValueById(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, + final Integer codeId, final Integer codeValueId, final String jsonAttributeToGetback) { - - return Utils.performServerGet(requestSpec, responseSpec, - CODE_VALUE_URL.replace("[codeId]", codeId.toString()) + "/" - + codeValueId.toString() + "?" - + Utils.TENANT_IDENTIFIER, jsonAttributeToGetback); - } + return Utils.performServerGet(requestSpec, responseSpec, + CODE_VALUE_URL.replace("[codeId]", codeId.toString()) + "/" + codeValueId.toString() + "?" + Utils.TENANT_IDENTIFIER, + jsonAttributeToGetback); + } - public static Object deleteCodeValueById( - final RequestSpecification requestSpec, - final ResponseSpecification responseSpec, final Integer codeId, - final Integer codeValueId, final String jsonAttributeToGetback) { + public static Object deleteCodeValueById(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, + final Integer codeId, final Integer codeValueId, final String jsonAttributeToGetback) { - return Utils.performServerDelete(requestSpec, responseSpec, - CODE_VALUE_URL.replace("[codeId]", codeId.toString()) + "/" - + codeValueId.toString() + "?" - + Utils.TENANT_IDENTIFIER, jsonAttributeToGetback); - } + return Utils.performServerDelete(requestSpec, responseSpec, CODE_VALUE_URL.replace("[codeId]", codeId.toString()) + "/" + + codeValueId.toString() + "?" + Utils.TENANT_IDENTIFIER, jsonAttributeToGetback); + } - public static Object updateCodeValue( - final RequestSpecification requestSpec, - final ResponseSpecification responseSpec, final Integer codeId, - final Integer codeValueId, final String codeValueName, - final Integer position, final String jsonAttributeToGetback) { + public static Object updateCodeValue(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, + final Integer codeId, final Integer codeValueId, final String codeValueName, final Integer position, + final String jsonAttributeToGetback) { - return Utils.performServerPut(requestSpec, responseSpec, - CODE_VALUE_URL.replace("[codeId]", codeId.toString()) + "/" - + codeValueId + "?" + Utils.TENANT_IDENTIFIER, - getTestCodeValueAsJSON(codeValueName, position), - jsonAttributeToGetback); - } + return Utils.performServerPut(requestSpec, responseSpec, CODE_VALUE_URL.replace("[codeId]", codeId.toString()) + "/" + codeValueId + + "?" + Utils.TENANT_IDENTIFIER, getTestCodeValueAsJSON(codeValueName, position), jsonAttributeToGetback); + } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/accounting/financialactivityaccount/exception/DuplicateFinancialActivityAccountFoundException.java b/mifosng-provider/src/main/java/org/mifosplatform/accounting/financialactivityaccount/exception/DuplicateFinancialActivityAccountFoundException.java index 463a1696e..cae4d90dc 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/accounting/financialactivityaccount/exception/DuplicateFinancialActivityAccountFoundException.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/accounting/financialactivityaccount/exception/DuplicateFinancialActivityAccountFoundException.java @@ -13,9 +13,14 @@ import org.mifosplatform.infrastructure.core.exception.AbstractPlatformDomainRul */ public class DuplicateFinancialActivityAccountFoundException extends AbstractPlatformDomainRuleException { + private final static String errorCode = "error.msg.financialActivityAccount.exists"; + public DuplicateFinancialActivityAccountFoundException(final Integer financialActivityType) { - super("error.msg.financialActivityAccount.exists.for.office", "Mapping for activity already exists " + financialActivityType, - financialActivityType); + super(errorCode, "Mapping for activity already exists " + financialActivityType, financialActivityType); + } + + public static String getErrorcode() { + return errorCode; } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/accounting/financialactivityaccount/exception/FinancialActivityAccountInvalidException.java b/mifosng-provider/src/main/java/org/mifosplatform/accounting/financialactivityaccount/exception/FinancialActivityAccountInvalidException.java index 47562f5c9..b6081b16d 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/accounting/financialactivityaccount/exception/FinancialActivityAccountInvalidException.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/accounting/financialactivityaccount/exception/FinancialActivityAccountInvalidException.java @@ -15,11 +15,17 @@ import org.mifosplatform.infrastructure.core.exception.AbstractPlatformDomainRul */ public class FinancialActivityAccountInvalidException extends AbstractPlatformDomainRuleException { + private final static String errorCode = "error.msg.financialActivityAccount.invalid"; + public FinancialActivityAccountInvalidException(final FINANCIAL_ACTIVITY financialActivity, final GLAccount glAccount) { - super("error.msg.financialActivityAccount.invalid", "Financial Activity '" + financialActivity.getCode() + "' with Id :" - + financialActivity.getValue() + "' can only be associated with a Ledger Account of Type " - + financialActivity.getMappedGLAccountType().getCode() + " the provided Ledger Account '" + glAccount.getName() + "(" - + glAccount.getGlCode() + ")' does not of the required type", financialActivity.getCode(), financialActivity.getValue(), - financialActivity.getMappedGLAccountType().getCode(), glAccount.getName(), glAccount.getGlCode()); + super(errorCode, "Financial Activity '" + financialActivity.getCode() + "' with Id :" + financialActivity.getValue() + + "' can only be associated with a Ledger Account of Type " + financialActivity.getMappedGLAccountType().getCode() + + " the provided Ledger Account '" + glAccount.getName() + "(" + glAccount.getGlCode() + + ")' does not of the required type", financialActivity.getCode(), financialActivity.getValue(), financialActivity + .getMappedGLAccountType().getCode(), glAccount.getName(), glAccount.getGlCode()); + } + + public static String getErrorcode() { + return errorCode; } } \ No newline at end of file