Merge pull request #955 from vishwasbabu/develop

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