Merge pull request #953 from vishwasbabu/develop

updating test cases for financial activity accounts and accounts transfe...
This commit is contained in:
Vishwas Babu A J
2014-06-16 16:34:36 -07:00
14 changed files with 559 additions and 593 deletions
@@ -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,
@@ -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<HashMap> invalidFinancialActivityUpdateError = (List<HashMap>) 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<HashMap> duplicateFinancialActivityAccountError = (List<HashMap>) 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<HashMap> invalidFinancialActivityAccountError = (List<HashMap>) 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"));
}
}
@@ -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<HashMap> error1 = (List<HashMap>) 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<HashMap> error2 = (List<HashMap>) 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<HashMap> error3 = (List<HashMap>) accountMappingHelper.createOfficeAccountMapping(officeId2, fundAccount.getAccountID(),
CommonConstants.RESPONSE_ERROR);
assertEquals("error.msg.liabilityTransferInSuspenseAccountId.invalid.account.type",
error3.get(0).get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
}**/
}
@@ -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<HashMap> 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<HashMap> 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<HashMap> 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<HashMap> 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<HashMap> 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<HashMap> 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<HashMap> 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<HashMap> 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<HashMap> 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<HashMap> 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() {
}
}
@@ -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";
@@ -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> 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)
@@ -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);
}
@@ -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);
}
}
@@ -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, "");
}
}
@@ -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<String, Object> map = new HashMap<String, Object>();
map.put("financialActivityId", financialActivityId);
map.put("glAccountId", glAccountId);
return new Gson().toJson(map);
}
}
@@ -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<String, Object> map = new HashMap<String, Object>();
map.put("officeId", officeId);
map.put("liabilityTransferInSuspenseAccountId", glAccountId);
return new Gson().toJson(map);
}
}
@@ -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<String, String> map = new HashMap<String, String>();
map.put(CODE_NAME_ATTRIBUTE_NAME, codeName);
return new Gson().toJson(map);
}
public static String getTestCodeAsJSON(final String codeName) {
final HashMap<String, String> map = new HashMap<String, String>();
map.put(CODE_NAME_ATTRIBUTE_NAME, codeName);
return new Gson().toJson(map);
}
public static String getTestCodeValueAsJSON(final String codeValueName,
final Integer position) {
final HashMap<String, Object> map = new HashMap<String, Object>();
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<String, Object> map = new HashMap<String, Object>();
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);
}
}
@@ -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;
}
}
@@ -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;
}
}