[MIFOSX-1035] JUnit Test Cases for Charges

[MIFOSX-1035] JUnit Test Cases for Charges
This commit is contained in:
Vishwa1311
2014-03-28 19:19:38 +05:30
parent c9be118c32
commit 7c3d011db0
2 changed files with 307 additions and 23 deletions
@@ -0,0 +1,156 @@
package org.mifosplatform.integrationtests;
import java.util.HashMap;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.mifosplatform.integrationtests.common.Utils;
import org.mifosplatform.integrationtests.common.charges.ChargesHelper;
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 ChargesTest {
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();
}
@Test
public void testChargesForSavings() {
// Testing Creation, Updation and Deletion of Specified due date Charge
final Integer specifiedDueDateChargeId = ChargesHelper.createCharges(this.requestSpec, this.responseSpec,
ChargesHelper.getSavingsSpecifiedDueDateJSON());
Assert.assertNotNull(specifiedDueDateChargeId);
HashMap changes = ChargesHelper.updateCharges(this.requestSpec, this.responseSpec, specifiedDueDateChargeId,
ChargesHelper.getModifyChargeJSON());
Assert.assertNotNull(changes);
Integer chargeIdAfterDeletion = ChargesHelper.deleteCharge(this.responseSpec, this.requestSpec, specifiedDueDateChargeId);
Assert.assertEquals("Verifying Charge ID after deletion", specifiedDueDateChargeId, chargeIdAfterDeletion);
// Testing Creation, Updation and Deletion of Savings Activation Charge
final Integer savingsActivationChargeId = ChargesHelper.createCharges(this.requestSpec, this.responseSpec,
ChargesHelper.getSavingsActivationFeeJSON());
Assert.assertNotNull(savingsActivationChargeId);
changes = ChargesHelper.updateCharges(this.requestSpec, this.responseSpec, savingsActivationChargeId,
ChargesHelper.getModifyChargeJSON());
Assert.assertNotNull(changes);
chargeIdAfterDeletion = ChargesHelper.deleteCharge(this.responseSpec, this.requestSpec, savingsActivationChargeId);
Assert.assertEquals("Verifying Charge ID after deletion", savingsActivationChargeId, chargeIdAfterDeletion);
// Testing Creation, Updation and Deletion of Charge for Withdrawal Fee
final Integer withdrawalFeeChargeId = ChargesHelper.createCharges(this.requestSpec, this.responseSpec,
ChargesHelper.getSavingsWithdrawalFeeJSON());
Assert.assertNotNull(withdrawalFeeChargeId);
changes = ChargesHelper.updateCharges(this.requestSpec, this.responseSpec, withdrawalFeeChargeId,
ChargesHelper.getModifyWithdrawalFeeChargeJSON());
Assert.assertNotNull(changes);
chargeIdAfterDeletion = ChargesHelper.deleteCharge(this.responseSpec, this.requestSpec, withdrawalFeeChargeId);
Assert.assertEquals("Verifying Charge ID after deletion", withdrawalFeeChargeId, chargeIdAfterDeletion);
// Testing Creation, Updation and Deletion of Charge for Annual Fee
final Integer annualFeeChargeId = ChargesHelper.createCharges(this.requestSpec, this.responseSpec,
ChargesHelper.getSavingsAnnualFeeJSON());
Assert.assertNotNull(annualFeeChargeId);
changes = ChargesHelper.updateCharges(this.requestSpec, this.responseSpec, annualFeeChargeId, ChargesHelper.getModifyChargeJSON());
Assert.assertNotNull(changes);
chargeIdAfterDeletion = ChargesHelper.deleteCharge(this.responseSpec, this.requestSpec, annualFeeChargeId);
Assert.assertEquals("Verifying Charge ID after deletion", annualFeeChargeId, chargeIdAfterDeletion);
// Testing Creation, Updation and Deletion of Charge for Monthly Fee
final Integer monthlyFeeChargeId = ChargesHelper.createCharges(this.requestSpec, this.responseSpec,
ChargesHelper.getSavingsMonthlyFeeJSON());
Assert.assertNotNull(monthlyFeeChargeId);
changes = ChargesHelper.updateCharges(this.requestSpec, this.responseSpec, monthlyFeeChargeId, ChargesHelper.getModifyChargeJSON());
Assert.assertNotNull(changes);
chargeIdAfterDeletion = ChargesHelper.deleteCharge(this.responseSpec, this.requestSpec, monthlyFeeChargeId);
Assert.assertEquals("Verifying Charge ID after deletion", monthlyFeeChargeId, chargeIdAfterDeletion);
// Testing Creation, Updation and Deletion of Charge for Overdraft Fee
final Integer overdraftFeeChargeId = ChargesHelper.createCharges(this.requestSpec, this.responseSpec,
ChargesHelper.getSavingsOverdraftFeeJSON());
Assert.assertNotNull(overdraftFeeChargeId);
changes = ChargesHelper.updateCharges(this.requestSpec, this.responseSpec, overdraftFeeChargeId,
ChargesHelper.getModifyChargeJSON());
Assert.assertNotNull(changes);
chargeIdAfterDeletion = ChargesHelper.deleteCharge(this.responseSpec, this.requestSpec, overdraftFeeChargeId);
Assert.assertEquals("Verifying Charge ID after deletion", overdraftFeeChargeId, chargeIdAfterDeletion);
}
@Test
public void testChargesForLoans() {
// Testing Creation, Updation and Deletion of Disbursement Charge
final Integer disbursementChargeId = ChargesHelper.createCharges(this.requestSpec, this.responseSpec,
ChargesHelper.getLoanDisbursementJSON());
Assert.assertNotNull(disbursementChargeId);
HashMap changes = ChargesHelper.updateCharges(this.requestSpec, this.responseSpec, disbursementChargeId,
ChargesHelper.getModifyChargeJSON());
Assert.assertNotNull(changes);
Integer chargeIdAfterDeletion = ChargesHelper.deleteCharge(this.responseSpec, this.requestSpec, disbursementChargeId);
Assert.assertEquals("Verifying Charge ID after deletion", disbursementChargeId, chargeIdAfterDeletion);
// Testing Creation, Updation and Deletion of Specified due date Charge
final Integer specifiedDueDateChargeId = ChargesHelper.createCharges(this.requestSpec, this.responseSpec,
ChargesHelper.getLoanSpecifiedDueDateJSON());
Assert.assertNotNull(specifiedDueDateChargeId);
changes = ChargesHelper.updateCharges(this.requestSpec, this.responseSpec, specifiedDueDateChargeId,
ChargesHelper.getModifyChargeJSON());
Assert.assertNotNull(changes);
chargeIdAfterDeletion = ChargesHelper.deleteCharge(this.responseSpec, this.requestSpec, specifiedDueDateChargeId);
Assert.assertEquals("Verifying Charge ID after deletion", specifiedDueDateChargeId, chargeIdAfterDeletion);
// Testing Creation, Updation and Deletion of Installment Fee Charge
final Integer installmentFeeChargeId = ChargesHelper.createCharges(this.requestSpec, this.responseSpec,
ChargesHelper.getLoanInstallmentFeeJSON());
Assert.assertNotNull(installmentFeeChargeId);
changes = ChargesHelper.updateCharges(this.requestSpec, this.responseSpec, installmentFeeChargeId,
ChargesHelper.getModifyChargeJSON());
Assert.assertNotNull(changes);
chargeIdAfterDeletion = ChargesHelper.deleteCharge(this.responseSpec, this.requestSpec, installmentFeeChargeId);
Assert.assertEquals("Verifying Charge ID after deletion", installmentFeeChargeId, chargeIdAfterDeletion);
// Testing Creation, Updation and Deletion of Overdue Installment Fee Charge
final Integer overdueFeeChargeId = ChargesHelper.createCharges(this.requestSpec, this.responseSpec,
ChargesHelper.getLoanOverdueFeeJSON());
Assert.assertNotNull(overdueFeeChargeId);
changes = ChargesHelper.updateCharges(this.requestSpec, this.responseSpec, overdueFeeChargeId,
ChargesHelper.getModifyChargeJSON());
Assert.assertNotNull(changes);
chargeIdAfterDeletion = ChargesHelper.deleteCharge(this.responseSpec, this.requestSpec, overdueFeeChargeId);
Assert.assertEquals("Verifying Charge ID after deletion", overdueFeeChargeId, chargeIdAfterDeletion);
}
}
@@ -9,62 +9,160 @@ import com.google.gson.Gson;
import com.jayway.restassured.specification.RequestSpecification;
import com.jayway.restassured.specification.ResponseSpecification;
@SuppressWarnings({ "unused", "rawtypes" })
public class ChargesHelper {
private static final String CHARGES_URL = "/mifosng-provider/api/v1/charges";
private static final String CREATE_CHARGES_URL = CHARGES_URL + "?" + Utils.TENANT_IDENTIFIER;
private static final Integer CHARGE_APPLIES_TO_LOAN = 1;
private static final Integer CHARGE_APPLIES_TO_SAVINGS = 2;
private static final Integer CHARGE_CALCULATION_TYPE_FLAT = 1;
private static final Integer CHARGE_MONTHLY_FEE = 7;
private static final Integer CHARGE_ANNUAL_FEE = 6;
private static final Integer CHARGE_DISBURSEMENT_FEE = 1;
private static final Integer CHARGE_SPECIFIED_DUE_DATE = 2;
private static final Integer CHARGE_SAVINGS_ACTIVATION_FEE = 3;
private static final Integer CHARGE_WITHDRAWAL_FEE = 5;
private static final Integer CHARGE_ANNUAL_FEE = 6;
private static final Integer CHARGE_MONTHLY_FEE = 7;
private static final Integer CHARGE_INSTALLMENT_FEE = 8;
private static final Integer CHARGE_OVERDUE_INSTALLMENT_FEE = 9;
private static final Integer CHARGE_OVERDRAFT_FEE = 10;
private static final Integer CHARGE_CALCULATION_TYPE_FLAT = 1;
private static final Integer CHARGE_CALCULATION_TYPE_PERCENTAGE_AMOUNT = 2;
private static final Integer CHARGE_CALCULATION_TYPE_PERCENTAGE_AMOUNT_AND_INTEREST = 3;
private static final Integer CHARGE_CALCULATION_TYPE_PERCENTAGE_INTEREST = 4;
private static final Integer CHARGE_PAYMENT_MODE_REGULAR = 0;
private static final Integer CHARGE_PAYMENT_MODE_ACCOUNT_TRANSFER = 1;
private static final Integer CHARGE_FEE_FREQUENCY_DAYS = 0;
private static final Integer CHARGE_FEE_FREQUENCY_WEEKS = 1;
private static final Integer CHARGE_FEE_FREQUENCY_MONTHS = 2;
private static final Integer CHARGE_FEE_FREQUENCY_YEARS = 3;
private final static boolean active = true;
private final static boolean penalty = false;
private final static boolean addfeefrequency = true;
private final static String amount = "100";
private final static Integer chargeAppliesTo = CHARGE_APPLIES_TO_SAVINGS;
private final static Integer chargeCalculationType = CHARGE_CALCULATION_TYPE_FLAT;
private final static String currencyCode = "USD";
public final static String feeOnMonthDay = "04 March";
private final static String monthDayFormat = "dd MMM";
private static String getChargeName() {
return Utils.randomNameGenerator("Charge_", 6);
}
public static String getSavingsAnnualFeeJSON() {
final HashMap<String, Object> map = populateDefaults();
map.put("feeOnMonthDay", ChargesHelper.feeOnMonthDay);
map.put("chargeTimeType", CHARGE_ANNUAL_FEE);
public static String getSavingsSpecifiedDueDateJSON() {
final HashMap<String, Object> map = populateDefaultsForSavings();
map.put("chargeTimeType", CHARGE_SPECIFIED_DUE_DATE);
map.put("feeInterval", 2);
String chargesCreateJson = new Gson().toJson(map);
System.out.println(chargesCreateJson);
return chargesCreateJson;
}
public static String getSavingsMonthlyFeeJSON() {
final HashMap<String, Object> map = populateDefaults();
map.put("feeOnMonthDay", ChargesHelper.feeOnMonthDay);
map.put("chargeTimeType", CHARGE_MONTHLY_FEE);
map.put("feeInterval", 2);
public static String getSavingsActivationFeeJSON() {
final HashMap<String, Object> map = populateDefaultsForSavings();
map.put("chargeTimeType", CHARGE_SAVINGS_ACTIVATION_FEE);
String chargesCreateJson = new Gson().toJson(map);
System.out.println(chargesCreateJson);
return chargesCreateJson;
}
public static String getSavingsWithdrawalFeeJSON() {
final HashMap<String, Object> map = populateDefaults();
final HashMap<String, Object> map = populateDefaultsForSavings();
map.put("chargeTimeType", CHARGE_WITHDRAWAL_FEE);
String chargesCreateJson = new Gson().toJson(map);
System.out.println(chargesCreateJson);
return chargesCreateJson;
}
public static HashMap<String, Object> populateDefaults() {
public static String getSavingsAnnualFeeJSON() {
final HashMap<String, Object> map = populateDefaultsForSavings();
map.put("feeOnMonthDay", ChargesHelper.feeOnMonthDay);
map.put("chargeTimeType", CHARGE_ANNUAL_FEE);
String chargesCreateJson = new Gson().toJson(map);
System.out.println(chargesCreateJson);
return chargesCreateJson;
}
public static String getSavingsMonthlyFeeJSON() {
final HashMap<String, Object> map = populateDefaultsForSavings();
map.put("feeOnMonthDay", ChargesHelper.feeOnMonthDay);
map.put("chargeTimeType", CHARGE_MONTHLY_FEE);
map.put("feeInterval", 2);
String chargesCreateJson = new Gson().toJson(map);
System.out.println(chargesCreateJson);
return chargesCreateJson;
}
public static String getSavingsOverdraftFeeJSON() {
final HashMap<String, Object> map = populateDefaultsForSavings();
map.put("chargeTimeType", CHARGE_OVERDRAFT_FEE);
String chargesCreateJson = new Gson().toJson(map);
System.out.println(chargesCreateJson);
return chargesCreateJson;
}
public static HashMap<String, Object> populateDefaultsForSavings() {
final HashMap<String, Object> map = new HashMap<String, Object>();
map.put("active", ChargesHelper.active);
map.put("amount", ChargesHelper.amount);
map.put("chargeAppliesTo", ChargesHelper.chargeAppliesTo);
map.put("chargeCalculationType", ChargesHelper.chargeCalculationType);
map.put("chargeAppliesTo", ChargesHelper.CHARGE_APPLIES_TO_SAVINGS);
map.put("chargeCalculationType", ChargesHelper.CHARGE_CALCULATION_TYPE_FLAT);
map.put("currencyCode", ChargesHelper.currencyCode);
map.put("locale", CommonConstants.locale);
map.put("monthDayFormat", ChargesHelper.monthDayFormat);
map.put("name", ChargesHelper.getChargeName());
map.put("name", Utils.randomNameGenerator("Charge_Savings_", 6));
return map;
}
public static String getLoanDisbursementJSON() {
final HashMap<String, Object> map = populateDefaultsForLoan();
map.put("chargeTimeType", CHARGE_DISBURSEMENT_FEE);
String chargesCreateJson = new Gson().toJson(map);
System.out.println(chargesCreateJson);
return chargesCreateJson;
}
public static String getLoanSpecifiedDueDateJSON() {
final HashMap<String, Object> map = populateDefaultsForLoan();
map.put("chargeTimeType", CHARGE_SPECIFIED_DUE_DATE);
String chargesCreateJson = new Gson().toJson(map);
System.out.println(chargesCreateJson);
return chargesCreateJson;
}
public static String getLoanInstallmentFeeJSON() {
final HashMap<String, Object> map = populateDefaultsForLoan();
map.put("chargeTimeType", CHARGE_INSTALLMENT_FEE);
String chargesCreateJson = new Gson().toJson(map);
System.out.println(chargesCreateJson);
return chargesCreateJson;
}
public static String getLoanOverdueFeeJSON() {
final HashMap<String, Object> map = populateDefaultsForLoan();
map.put("penalty", true);
map.put("chargeTimeType", CHARGE_OVERDUE_INSTALLMENT_FEE);
String chargesCreateJson = new Gson().toJson(map);
System.out.println(chargesCreateJson);
return chargesCreateJson;
}
public static HashMap<String, Object> populateDefaultsForLoan() {
final HashMap<String, Object> map = new HashMap<String, Object>();
map.put("active", ChargesHelper.active);
map.put("penalty", ChargesHelper.penalty);
map.put("amount", ChargesHelper.amount);
map.put("chargeAppliesTo", ChargesHelper.CHARGE_APPLIES_TO_LOAN);
map.put("chargeCalculationType", ChargesHelper.CHARGE_CALCULATION_TYPE_FLAT);
map.put("chargePaymentMode", ChargesHelper.CHARGE_PAYMENT_MODE_REGULAR);
map.put("currencyCode", ChargesHelper.currencyCode);
map.put("locale", CommonConstants.locale);
map.put("monthDayFormat", ChargesHelper.monthDayFormat);
map.put("name", Utils.randomNameGenerator("Charge_Loans_", 6));
if (ChargesHelper.addfeefrequency) {
map.put("feeFrequency", ChargesHelper.CHARGE_FEE_FREQUENCY_MONTHS);
map.put("feeInterval", 2);
}
return map;
}
@@ -73,4 +171,34 @@ public class ChargesHelper {
return Utils.performServerPost(requestSpec, responseSpec, CREATE_CHARGES_URL, request, "resourceId");
}
public static HashMap updateCharges(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
final Integer chargeId, final String request) {
return Utils.performServerPut(requestSpec, responseSpec, CHARGES_URL + "/" + chargeId + "?" + Utils.TENANT_IDENTIFIER, request,
CommonConstants.RESPONSE_CHANGES);
}
public static Integer deleteCharge(final ResponseSpecification responseSpec, final RequestSpecification requestSpec,
final Integer chargeId) {
return Utils.performServerDelete(requestSpec, responseSpec, CHARGES_URL + "/" + chargeId + "?" + Utils.TENANT_IDENTIFIER,
CommonConstants.RESPONSE_RESOURCE_ID);
}
public static String getModifyChargeJSON() {
final HashMap<String, Object> map = new HashMap<String, Object>();
map.put("locale", CommonConstants.locale);
map.put("amount", "200");
String json = new Gson().toJson(map);
System.out.println(json);
return json;
}
public static String getModifyWithdrawalFeeChargeJSON() {
final HashMap<String, Object> map = new HashMap<String, Object>();
map.put("locale", CommonConstants.locale);
map.put("chargeCalculationType", CHARGE_CALCULATION_TYPE_PERCENTAGE_AMOUNT);
String json = new Gson().toJson(map);
System.out.println(json);
return json;
}
}