http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/4b1ec9ef/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/accounting/JournalEntryHelper.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/accounting/JournalEntryHelper.java b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/accounting/JournalEntryHelper.java new file mode 100644 index 0000000..b549763 --- /dev/null +++ b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/accounting/JournalEntryHelper.java @@ -0,0 +1,111 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.fineract.integrationtests.common.accounting; + +import static org.hamcrest.Matchers.equalTo; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertTrue; + +import java.util.ArrayList; +import java.util.HashMap; + +import org.apache.fineract.integrationtests.common.Utils; + +import com.jayway.restassured.specification.RequestSpecification; +import com.jayway.restassured.specification.ResponseSpecification; + +@SuppressWarnings("rawtypes") +public class JournalEntryHelper { + + private final RequestSpecification requestSpec; + private final ResponseSpecification responseSpec; + + public JournalEntryHelper(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) { + this.requestSpec = requestSpec; + this.responseSpec = responseSpec; + } + + public void checkJournalEntryForExpenseAccount(final Account expenseAccount, final String date, final JournalEntry... accountEntries) { + checkJournalEntry(null, expenseAccount, date, accountEntries); + } + + public void checkJournalEntryForAssetAccount(final Account assetAccount, final String date, final JournalEntry... accountEntries) { + checkJournalEntry(null, assetAccount, date, accountEntries); + } + + public void checkJournalEntryForIncomeAccount(final Account incomeAccount, final String date, final JournalEntry... accountEntries) { + checkJournalEntry(null, incomeAccount, date, accountEntries); + } + + public void checkJournalEntryForLiabilityAccount(final Account liabilityAccount, final String date, + final JournalEntry... accountEntries) { + checkJournalEntry(null, liabilityAccount, date, accountEntries); + } + + public void checkJournalEntryForLiabilityAccount(final Integer officeId, final Account liabilityAccount, final String date, + final JournalEntry... accountEntries) { + checkJournalEntry(officeId, liabilityAccount, date, accountEntries); + } + + public void ensureNoAccountingTransactionsWithTransactionId(final String transactionId) { + ArrayList<HashMap> transactions = getJournalEntriesByTransactionId(transactionId); + assertTrue("Tranasactions are is not empty", transactions.isEmpty()); + + } + + private String getEntryValueFromJournalEntry(final ArrayList<HashMap> entryResponse, final int entryNumber) { + final HashMap map = (HashMap) entryResponse.get(entryNumber).get("entryType"); + return (String) map.get("value"); + } + + private Float getTransactionAmountFromJournalEntry(final ArrayList<HashMap> entryResponse, final int entryNumber) { + return (Float) entryResponse.get(entryNumber).get("amount"); + } + + private void checkJournalEntry(final Integer officeId, final Account account, final String date, final JournalEntry... accountEntries) { + final String url = createURLForGettingAccountEntries(account, date, officeId); + final ArrayList<HashMap> response = Utils.performServerGet(this.requestSpec, this.responseSpec, url, "pageItems"); + for (int i = 0; i < accountEntries.length; i++) { + assertThat(getEntryValueFromJournalEntry(response, i), equalTo(accountEntries[i].getTransactionType())); + assertThat(getTransactionAmountFromJournalEntry(response, i), equalTo(accountEntries[i].getTransactionAmount())); + } + } + + private String createURLForGettingAccountEntries(final Account account, final String date, final Integer officeId) { + String url = new String("/fineract-provider/api/v1/journalentries?glAccountId=" + account.getAccountID() + "&type=" + + account.getAccountType() + "&fromDate=" + date + "&toDate=" + date + "&tenantIdentifier=default" + + "&orderBy=id&sortOrder=desc&locale=en&dateFormat=dd MMMM yyyy"); + if (officeId != null) { + url = url + "&officeId=" + officeId; + } + return url; + } + + private ArrayList<HashMap> getJournalEntriesByTransactionId(final String transactionId) { + final String url = createURLForGettingAccountEntriesByTransactionId(transactionId); + final ArrayList<HashMap> response = Utils.performServerGet(this.requestSpec, this.responseSpec, url, "pageItems"); + return response; + } + + private String createURLForGettingAccountEntriesByTransactionId(final String transactionId) { + return new String("/fineract-provider/api/v1/journalentries?transactionId=" + transactionId + "&tenantIdentifier=default" + + "&orderBy=id&sortOrder=desc&locale=en&dateFormat=dd MMMM yyyy"); + } + +}
http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/4b1ec9ef/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/accounting/PeriodicAccrualAccountingHelper.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/accounting/PeriodicAccrualAccountingHelper.java b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/accounting/PeriodicAccrualAccountingHelper.java new file mode 100755 index 0000000..843f8e0 --- /dev/null +++ b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/accounting/PeriodicAccrualAccountingHelper.java @@ -0,0 +1,53 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.fineract.integrationtests.common.accounting; + +import java.util.HashMap; + +import org.apache.fineract.integrationtests.common.Utils; + +import com.google.gson.Gson; +import com.jayway.restassured.specification.RequestSpecification; +import com.jayway.restassured.specification.ResponseSpecification; + +public class PeriodicAccrualAccountingHelper { + + private static final String PERIODIC_ACCRUAL_URL = "/fineract-provider/api/v1/runaccruals"; + private final RequestSpecification requestSpec; + private final ResponseSpecification responseSpec; + + public PeriodicAccrualAccountingHelper(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) { + this.requestSpec = requestSpec; + this.responseSpec = responseSpec; + } + + public Object runPeriodicAccrualAccounting(String date) { + String json = getRunPeriodicAccrual(date); + return Utils.performServerPost(this.requestSpec, this.responseSpec, PERIODIC_ACCRUAL_URL + "?" + Utils.TENANT_IDENTIFIER, json, ""); + } + + private String getRunPeriodicAccrual(String date) { + final HashMap<String, String> map = new HashMap<>(); + map.put("dateFormat", "dd MMMM yyyy"); + map.put("locale", "en_GB"); + map.put("tillDate", date); + return new Gson().toJson(map); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/4b1ec9ef/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/charges/ChargesHelper.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/charges/ChargesHelper.java b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/charges/ChargesHelper.java new file mode 100755 index 0000000..6b17468 --- /dev/null +++ b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/charges/ChargesHelper.java @@ -0,0 +1,412 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.fineract.integrationtests.common.charges; + +import java.util.ArrayList; +import java.util.HashMap; + +import org.apache.fineract.integrationtests.common.CommonConstants; +import org.apache.fineract.integrationtests.common.Utils; + +import com.google.gson.Gson; +import com.jayway.restassured.specification.RequestSpecification; +import com.jayway.restassured.specification.ResponseSpecification; + +@SuppressWarnings({ "rawtypes", "unchecked" }) +public class ChargesHelper { + + private static final String CHARGES_URL = "/fineract-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_APPLIES_TO_CLIENT = 3; + + 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 WEEKLY_FEE = 11; + + private static final Integer CHARGE_CLIENT_SPECIFIED_DUE_DATE = 1; + + public static final Integer CHARGE_CALCULATION_TYPE_FLAT = 1; + public static final Integer CHARGE_CALCULATION_TYPE_PERCENTAGE_AMOUNT = 2; + public static final Integer CHARGE_CALCULATION_TYPE_PERCENTAGE_AMOUNT_AND_INTEREST = 3; + public 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 = true; + private final static String amount = "100"; + private final static String currencyCode = "USD"; + public final static String feeOnMonthDay = "04 March"; + private final static String monthDayFormat = "dd MMM"; + + 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 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 = populateDefaultsForSavings(); + map.put("chargeTimeType", CHARGE_WITHDRAWAL_FEE); + String chargesCreateJson = new Gson().toJson(map); + System.out.println(chargesCreateJson); + return chargesCreateJson; + } + + 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 getSavingsWeeklyFeeJSON() { + final HashMap<String, Object> map = populateDefaultsForSavings(); + map.put("chargeTimeType", WEEKLY_FEE); + map.put("feeInterval", 1); + 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<>(); + map.put("active", ChargesHelper.active); + map.put("amount", ChargesHelper.amount); + 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", Utils.randomNameGenerator("Charge_Savings_", 6)); + return map; + } + + public static String getLoanDisbursementJSON() { + return getLoanDisbursementJSON(ChargesHelper.CHARGE_CALCULATION_TYPE_FLAT, ChargesHelper.amount); + } + + public static String getLoanDisbursementJSON(final Integer chargeCalculationType, final String amount) { + return getLoanDisbursementJSON(chargeCalculationType, amount, ChargesHelper.CHARGE_PAYMENT_MODE_REGULAR); + } + + public static String getLoanDisbursementAccountTransferJSON(final Integer chargeCalculationType, final String amount) { + return getLoanDisbursementJSON(chargeCalculationType, amount, ChargesHelper.CHARGE_PAYMENT_MODE_ACCOUNT_TRANSFER); + } + + public static String getLoanDisbursementJSON(final Integer chargeCalculationType, final String amount, final Integer paymentmode) { + final HashMap<String, Object> map = populateDefaultsForLoan(); + map.put("chargeTimeType", CHARGE_DISBURSEMENT_FEE); + map.put("chargePaymentMode", paymentmode); + map.put("amount", amount); + map.put("chargeCalculationType", chargeCalculationType); + String chargesCreateJson = new Gson().toJson(map); + System.out.println(chargesCreateJson); + return chargesCreateJson; + } + + public static String getLoanSpecifiedDueDateJSON() { + return getLoanSpecifiedDueDateJSON(ChargesHelper.CHARGE_CALCULATION_TYPE_FLAT, ChargesHelper.amount, ChargesHelper.penalty); + } + + public static String getLoanSpecifiedDueDateJSON(final Integer chargeCalculationType, final String amount, boolean penalty) { + return getLoanSpecifiedDueDateJSON(chargeCalculationType, amount, penalty, ChargesHelper.CHARGE_PAYMENT_MODE_REGULAR); + } + + public static String getLoanSpecifiedDueDateJSON(final Integer chargeCalculationType, final String amount, final boolean penalty, + final Integer paymentMode) { + final HashMap<String, Object> map = populateDefaultsForLoan(); + map.put("chargeTimeType", CHARGE_SPECIFIED_DUE_DATE); + map.put("chargePaymentMode", paymentMode); + map.put("penalty", penalty); + map.put("amount", amount); + map.put("chargeCalculationType", chargeCalculationType); + + String chargesCreateJson = new Gson().toJson(map); + System.out.println(chargesCreateJson); + return chargesCreateJson; + } + + public static String getLoanSpecifiedDueDateWithAccountTransferJSON(final Integer chargeCalculationType, final String amount, + boolean penalty) { + return getLoanSpecifiedDueDateJSON(chargeCalculationType, amount, penalty, ChargesHelper.CHARGE_PAYMENT_MODE_ACCOUNT_TRANSFER); + } + + public static String getLoanSpecifiedDueDateWithAccountTransferJSON() { + return getLoanSpecifiedDueDateJSON(ChargesHelper.CHARGE_CALCULATION_TYPE_FLAT, ChargesHelper.amount, ChargesHelper.penalty, + ChargesHelper.CHARGE_PAYMENT_MODE_ACCOUNT_TRANSFER); + } + + public static String getLoanInstallmentJSON(final Integer chargeCalculationType, final String amount, boolean penalty) { + return getLoanInstallmentJSON(chargeCalculationType, amount, penalty, ChargesHelper.CHARGE_PAYMENT_MODE_REGULAR); + } + + public static String getLoanInstallmentJSON(final Integer chargeCalculationType, final String amount, final boolean penalty, + final Integer paymentMode) { + final HashMap<String, Object> map = populateDefaultsForLoan(); + map.put("chargeTimeType", CHARGE_INSTALLMENT_FEE); + map.put("chargePaymentMode", paymentMode); + map.put("penalty", penalty); + map.put("amount", amount); + map.put("chargeCalculationType", chargeCalculationType); + + String chargesCreateJson = new Gson().toJson(map); + System.out.println(chargesCreateJson); + return chargesCreateJson; + } + + public static String getLoanInstallmentWithAccountTransferJSON(final Integer chargeCalculationType, final String amount, boolean penalty) { + return getLoanInstallmentJSON(chargeCalculationType, amount, penalty, ChargesHelper.CHARGE_PAYMENT_MODE_ACCOUNT_TRANSFER); + } + + public static String getLoanInstallmentFeeJSON() { + return getLoanInstallmentJSON(ChargesHelper.CHARGE_CALCULATION_TYPE_FLAT, ChargesHelper.amount, ChargesHelper.penalty); + } + + public static String getLoanOverdueFeeJSON() { + final HashMap<String, Object> map = populateDefaultsForLoan(); + map.put("penalty", ChargesHelper.penalty); + map.put("chargePaymentMode", ChargesHelper.CHARGE_PAYMENT_MODE_REGULAR); + map.put("chargeTimeType", CHARGE_OVERDUE_INSTALLMENT_FEE); + map.put("feeFrequency", ChargesHelper.CHARGE_FEE_FREQUENCY_MONTHS); + map.put("feeOnMonthDay", ChargesHelper.feeOnMonthDay); + map.put("feeInterval", 2); + String chargesCreateJson = new Gson().toJson(map); + System.out.println(chargesCreateJson); + return chargesCreateJson; + } + + public static String getLoanOverdueFeeJSONWithCalculattionTypePercentage() { + final HashMap<String, Object> map = populateDefaultsForLoan(); + map.put("penalty", ChargesHelper.penalty); + map.put("amount", "10"); + map.put("chargePaymentMode", ChargesHelper.CHARGE_PAYMENT_MODE_REGULAR); + map.put("chargeTimeType", CHARGE_OVERDUE_INSTALLMENT_FEE); + map.put("chargeCalculationType", ChargesHelper.CHARGE_CALCULATION_TYPE_PERCENTAGE_AMOUNT_AND_INTEREST); + 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<>(); + map.put("active", ChargesHelper.active); + map.put("amount", ChargesHelper.amount); + map.put("chargeAppliesTo", ChargesHelper.CHARGE_APPLIES_TO_LOAN); + 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", Utils.randomNameGenerator("Charge_Loans_", 6)); + return map; + } + + public static HashMap<String, Object> populateDefaultsClientCharge() { + final HashMap<String, Object> map = new HashMap<>(); + map.put("active", ChargesHelper.active); + map.put("amount", ChargesHelper.amount); + map.put("chargeAppliesTo", ChargesHelper.CHARGE_APPLIES_TO_CLIENT); + map.put("chargeCalculationType", ChargesHelper.CHARGE_CALCULATION_TYPE_FLAT); + map.put("chargeTimeType",ChargesHelper.CHARGE_SPECIFIED_DUE_DATE); + map.put("currencyCode", ChargesHelper.currencyCode); + map.put("locale", CommonConstants.locale); + map.put("monthDayFormat", ChargesHelper.monthDayFormat); + map.put("name", Utils.randomNameGenerator("Charge_client_", 8)); + return map; + } + + public static Integer createCharges(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, + final String request) { + return Utils.performServerPost(requestSpec, responseSpec, CREATE_CHARGES_URL, request, "resourceId"); + } + + public static ArrayList<HashMap> getCharges(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) { + return (ArrayList) Utils.performServerGet(requestSpec, responseSpec, CHARGES_URL + "?" + Utils.TENANT_IDENTIFIER, ""); + } + + public static HashMap getChargeById(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, + final Integer chargeId) { + return Utils.performServerGet(requestSpec, responseSpec, CHARGES_URL + "/" + chargeId + "?" + Utils.TENANT_IDENTIFIER, ""); + } + + public static HashMap getChargeChanges(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, + final Integer chargeId) { + return Utils.performServerGet(requestSpec, responseSpec, CHARGES_URL + "/" + chargeId + "?" + Utils.TENANT_IDENTIFIER, + CommonConstants.RESPONSE_CHANGES); + } + + 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<>(); + map.put("locale", CommonConstants.locale); + map.put("amount", "200.0"); + String json = new Gson().toJson(map); + System.out.println(json); + return json; + } + + public static String getModifyWithdrawalFeeSavingsChargeJSON() { + final HashMap<String, Object> map = new HashMap<>(); + 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; + } + + public static String getModifyChargeAsPecentageAmountJSON() { + final HashMap<String, Object> map = new HashMap<>(); + map.put("locale", CommonConstants.locale); + map.put("chargeCalculationType", CHARGE_CALCULATION_TYPE_PERCENTAGE_AMOUNT); + map.put("chargePaymentMode", CHARGE_PAYMENT_MODE_ACCOUNT_TRANSFER); + String json = new Gson().toJson(map); + System.out.println(json); + return json; + } + + public static String getModifyChargeAsPecentageLoanAmountWithInterestJSON() { + final HashMap<String, Object> map = new HashMap<>(); + map.put("locale", CommonConstants.locale); + map.put("chargeCalculationType", CHARGE_CALCULATION_TYPE_PERCENTAGE_AMOUNT_AND_INTEREST); + map.put("chargePaymentMode", CHARGE_PAYMENT_MODE_ACCOUNT_TRANSFER); + String json = new Gson().toJson(map); + System.out.println(json); + return json; + } + + public static String getModifyChargeAsPercentageInterestJSON() { + final HashMap<String, Object> map = new HashMap<>(); + map.put("locale", CommonConstants.locale); + map.put("chargeCalculationType", CHARGE_CALCULATION_TYPE_PERCENTAGE_INTEREST); + map.put("chargePaymentMode", CHARGE_PAYMENT_MODE_ACCOUNT_TRANSFER); + String json = new Gson().toJson(map); + System.out.println(json); + return json; + } + + public static String getModifyChargeFeeFrequencyAsDaysJSON() { + final HashMap<String, Object> map = new HashMap<>(); + map.put("locale", CommonConstants.locale); + map.put("feeFrequency", ChargesHelper.CHARGE_FEE_FREQUENCY_DAYS); + map.put("feeInterval", 2); + String json = new Gson().toJson(map); + System.out.println(json); + return json; + } + + public static String getModifyChargeFeeFrequencyAsWeeksJSON() { + final HashMap<String, Object> map = new HashMap<>(); + map.put("locale", CommonConstants.locale); + map.put("feeFrequency", ChargesHelper.CHARGE_FEE_FREQUENCY_WEEKS); + map.put("feeInterval", 2); + String json = new Gson().toJson(map); + System.out.println(json); + return json; + } + + public static String getModifyChargeFeeFrequencyAsMonthsJSON() { + final HashMap<String, Object> map = new HashMap<>(); + map.put("locale", CommonConstants.locale); + map.put("feeFrequency", ChargesHelper.CHARGE_FEE_FREQUENCY_MONTHS); + map.put("feeInterval", 2); + String json = new Gson().toJson(map); + System.out.println(json); + return json; + } + + public static String getModifyChargeFeeFrequencyAsYearsJSON() { + final HashMap<String, Object> map = new HashMap<>(); + map.put("locale", CommonConstants.locale); + map.put("feeFrequency", ChargesHelper.CHARGE_FEE_FREQUENCY_YEARS); + map.put("feeInterval", 2); + String json = new Gson().toJson(map); + System.out.println(json); + return json; + } + + public static String getChargeSpecifiedDueDateJSON() { + final HashMap<String, Object> map = populateDefaultsClientCharge(); + String chargesCreateJson = new Gson().toJson(map); + System.out.println("chargesCreateJson:"+chargesCreateJson); + return chargesCreateJson; + } + + public static String applyCharge(RequestSpecification requestSpec,ResponseSpecification responseSpec, String chargeId,String json) { + return Utils.performServerPost(requestSpec, responseSpec, CHARGES_URL + "/" + chargeId + "?" + Utils.TENANT_IDENTIFIER, json,"status"); + + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/4b1ec9ef/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/fixeddeposit/FixedDepositAccountHelper.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/fixeddeposit/FixedDepositAccountHelper.java b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/fixeddeposit/FixedDepositAccountHelper.java new file mode 100644 index 0000000..fa48717 --- /dev/null +++ b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/fixeddeposit/FixedDepositAccountHelper.java @@ -0,0 +1,490 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.fineract.integrationtests.common.fixeddeposit; + +import java.util.ArrayList; +import java.util.Calendar; +import java.util.HashMap; +import java.util.List; + +import org.apache.fineract.integrationtests.common.CommonConstants; +import org.apache.fineract.integrationtests.common.Utils; + +import com.google.gson.Gson; +import com.jayway.restassured.specification.RequestSpecification; +import com.jayway.restassured.specification.ResponseSpecification; + +@SuppressWarnings({ "unused", "rawtypes" }) +public class FixedDepositAccountHelper { + + private final RequestSpecification requestSpec; + private final ResponseSpecification responseSpec; + + public FixedDepositAccountHelper(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) { + this.requestSpec = requestSpec; + this.responseSpec = responseSpec; + } + + private static final String FIXED_DEPOSIT_ACCOUNT_URL = "/fineract-provider/api/v1/fixeddepositaccounts"; + private static final String APPLY_FIXED_DEPOSIT_ACCOUNT_URL = FIXED_DEPOSIT_ACCOUNT_URL + "?" + Utils.TENANT_IDENTIFIER; + private static final String APPROVE_FIXED_DEPOSIT_COMMAND = "approve"; + private static final String UNDO_APPROVAL_FIXED_DEPOSIT_COMMAND = "undoapproval"; + private static final String REJECT_FIXED_DEPOSIT_COMMAND = "reject"; + private static final String WITHDRAWN_BY_CLIENT_FIXED_DEPOSIT_COMMAND = "withdrawnByApplicant"; + private static final String ACTIVATE_FIXED_DEPOSIT_COMMAND = "activate"; + private static final String CLOSE_FIXED_DEPOSIT_COMMAND = "close"; + private static final String POST_INTEREST_FIXED_DEPOSIT_COMMAND = "postInterest"; + private static final String CALCULATE_INTEREST_FIXED_DEPOSIT_COMMAND = "calculateInterest"; + private static final String CALCULATE_PREMATURE_AMOUNT_COMMAND = "calculatePrematureAmount"; + private static final String PREMATURE_CLOSE_COMMAND = "prematureClose"; + + private static final String LOCALE = "en_GB"; + private static final String DIGITS_AFTER_DECIMAL = "4"; + private static final String IN_MULTIPLES_OF = "100"; + private static final String USD = "USD"; + public static final String DAYS = "0"; + private static final String WEEKS = "1"; + private static final String MONTHS = "2"; + private static final String YEARS = "3"; + private static final String DAILY = "1"; + private static final String MONTHLY = "4"; + private static final String QUARTERLY = "5"; + private static final String BI_ANNUALLY = "6"; + private static final String ANNUALLY = "7"; + private static final String INTEREST_CALCULATION_USING_DAILY_BALANCE = "1"; + private static final String INTEREST_CALCULATION_USING_AVERAGE_DAILY_BALANCE = "2"; + private static final String DAYS_360 = "360"; + private static final String DAYS_365 = "365"; + public final static String depositAmount = "100000"; + + private String interestCompoundingPeriodType = MONTHLY; + private String interestPostingPeriodType = MONTHLY; + private String interestCalculationType = INTEREST_CALCULATION_USING_DAILY_BALANCE; + private String lockinPeriodFrequency = "1"; + private String lockingPeriodFrequencyType = MONTHS; + private final String minDepositTerm = "6"; + private final String minDepositTermTypeId = MONTHS; + private final String maxDepositTerm = "10"; + private final String maxDepositTermTypeId = YEARS; + private final String inMultiplesOfDepositTerm = "2"; + private final String inMultiplesOfDepositTermTypeId = MONTHS; + private final String preClosurePenalInterest = "2"; + private String interestCalculationDaysInYearType = DAYS_365; + private final boolean preClosurePenalApplicable = true; + private final boolean isActiveChart = true; + private final String currencyCode = USD; + + private final String depositPeriod = "14"; + private final String depositPeriodFrequencyId = MONTHS; + private String submittedOnDate = ""; + private String savingsId = null; + private boolean transferInterest = false; + + public String build(final String clientId, final String productId, final String validFrom, final String validTo, + final String penalInterestType) { + final HashMap<String, Object> map = new HashMap<>(); + + List<HashMap<String, String>> chartSlabs = new ArrayList<HashMap<String, String>>(); + HashMap<String, String> chartSlabsMap1 = new HashMap<>(); + chartSlabsMap1.put("description", "First"); + chartSlabsMap1.put("periodType", MONTHS); + chartSlabsMap1.put("fromPeriod", "1"); + chartSlabsMap1.put("toPeriod", "6"); + chartSlabsMap1.put("annualInterestRate", "5"); + chartSlabsMap1.put("locale", LOCALE); + chartSlabs.add(0, chartSlabsMap1); + + HashMap<String, String> chartSlabsMap2 = new HashMap<>(); + chartSlabsMap2.put("description", "Second"); + chartSlabsMap2.put("periodType", MONTHS); + chartSlabsMap2.put("fromPeriod", "7"); + chartSlabsMap2.put("toPeriod", "12"); + chartSlabsMap2.put("annualInterestRate", "6"); + chartSlabsMap2.put("locale", LOCALE); + chartSlabs.add(1, chartSlabsMap2); + + HashMap<String, String> chartSlabsMap3 = new HashMap<>(); + chartSlabsMap3.put("description", "Third"); + chartSlabsMap3.put("periodType", MONTHS); + chartSlabsMap3.put("fromPeriod", "13"); + chartSlabsMap3.put("toPeriod", "18"); + chartSlabsMap3.put("annualInterestRate", "7"); + chartSlabsMap3.put("locale", LOCALE); + chartSlabs.add(2, chartSlabsMap3); + + HashMap<String, String> chartSlabsMap4 = new HashMap<>(); + chartSlabsMap4.put("description", "Fourth"); + chartSlabsMap4.put("periodType", MONTHS); + chartSlabsMap4.put("fromPeriod", "19"); + chartSlabsMap4.put("toPeriod", "24"); + chartSlabsMap4.put("annualInterestRate", "8"); + chartSlabsMap4.put("locale", LOCALE); + chartSlabs.add(3, chartSlabsMap4); + + List<HashMap<String, Object>> charts = new ArrayList<HashMap<String, Object>>(); + HashMap<String, Object> chartsMap = new HashMap<>(); + chartsMap.put("fromDate", validFrom); + chartsMap.put("endDate", validTo); + chartsMap.put("dateFormat", "dd MMMM yyyy"); + chartsMap.put("locale", LOCALE); + chartsMap.put("isActiveChart", this.isActiveChart); + chartsMap.put("chartSlabs", chartSlabs); + charts.add(chartsMap); + + map.put("charts", charts); + map.put("productId", productId); + map.put("clientId", clientId); + map.put("interestCalculationDaysInYearType", this.interestCalculationDaysInYearType); + map.put("locale", LOCALE); + map.put("dateFormat", "dd MMMM yyyy"); + map.put("monthDayFormat", "dd MMM"); + map.put("interestCalculationType", this.interestCalculationType); + map.put("interestCompoundingPeriodType", this.interestCompoundingPeriodType); + map.put("interestPostingPeriodType", this.interestPostingPeriodType); + map.put("lockinPeriodFrequency", this.lockinPeriodFrequency); + map.put("lockinPeriodFrequencyType", this.lockingPeriodFrequencyType); + map.put("preClosurePenalApplicable", "true"); + map.put("minDepositTermTypeId", this.minDepositTermTypeId); + map.put("minDepositTerm", this.minDepositTerm); + map.put("maxDepositTermTypeId", this.maxDepositTermTypeId); + map.put("maxDepositTerm", this.maxDepositTerm); + map.put("preClosurePenalApplicable", this.preClosurePenalApplicable); + map.put("inMultiplesOfDepositTerm", this.inMultiplesOfDepositTerm); + map.put("inMultiplesOfDepositTermTypeId", this.inMultiplesOfDepositTermTypeId); + map.put("preClosurePenalInterest", this.preClosurePenalInterest); + map.put("preClosurePenalInterestOnTypeId", penalInterestType); + map.put("depositAmount", depositAmount); + map.put("depositPeriod", this.depositPeriod); + map.put("depositPeriodFrequencyId", this.depositPeriodFrequencyId); + map.put("submittedOnDate", this.submittedOnDate); + map.put("linkAccountId", savingsId); + map.put("transferInterestToSavings", transferInterest); + + String fixedDepositAccountJson = new Gson().toJson(map); + System.out.println(fixedDepositAccountJson); + return fixedDepositAccountJson; + } + + public static Integer applyFixedDepositApplication(final String fixedDepositAccountAsJson, final RequestSpecification requestSpec, + final ResponseSpecification responseSpec) { + System.out.println("--------------------- APPLYING FOR FIXED DEPOSIT ACCOUNT ------------------------"); + return Utils.performServerPost(requestSpec, responseSpec, APPLY_FIXED_DEPOSIT_ACCOUNT_URL, fixedDepositAccountAsJson, + CommonConstants.RESPONSE_RESOURCE_ID); + } + + public static HashMap getFixedDepositAccountById(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, + final Integer accountID) { + final String GET_FIXED_DEPOSIT_BY_ID_URL = FIXED_DEPOSIT_ACCOUNT_URL + "/" + accountID + "?" + Utils.TENANT_IDENTIFIER; + System.out.println("------------------------ RETRIEVING FIXED DEPOSIT ACCOUNT BY ID -------------------------"); + return Utils.performServerGet(requestSpec, responseSpec, GET_FIXED_DEPOSIT_BY_ID_URL, ""); + } + + public HashMap getFixedDepositSummary(final Integer accountID) { + final String URL = FIXED_DEPOSIT_ACCOUNT_URL + "/" + accountID + "?" + Utils.TENANT_IDENTIFIER; + final HashMap response = Utils.performServerGet(requestSpec, responseSpec, URL, "summary"); + return response; + } + + public static Float getInterestRate(ArrayList<ArrayList<HashMap>> interestSlabData, Integer depositPeriod) { + + Float annualInterestRate = 0.0f; + for (Integer slabIndex = 0; slabIndex < interestSlabData.get(0).size(); slabIndex++) { + Integer fromPeriod = (Integer) interestSlabData.get(0).get(slabIndex).get("fromPeriod"); + Integer toPeriod = (Integer) interestSlabData.get(0).get(slabIndex).get("toPeriod"); + if (depositPeriod >= fromPeriod && depositPeriod <= toPeriod) { + annualInterestRate = (Float) interestSlabData.get(0).get(slabIndex).get("annualInterestRate"); + break; + } + } + + return annualInterestRate; + } + + public static Float getPrincipalAfterCompoundingInterest(Calendar currentDate, Float principal, Integer depositPeriod, + double interestPerDay, Integer compoundingInterval, Integer postingInterval) { + + Float totalInterest = 0.0f; + Float interestEarned = 0.0f; + + for (int i = 1; i <= depositPeriod; i++) { + Integer daysInMonth = currentDate.getActualMaximum(Calendar.DATE); + for (int j = 0; j < daysInMonth; j++) { + + interestEarned = (float) (principal * interestPerDay); + totalInterest += interestEarned; + if (compoundingInterval == 0) { + principal += interestEarned; + } + } + if ((i % postingInterval) == 0 || i == depositPeriod) { + if (compoundingInterval != 0) { + principal += totalInterest; + } + totalInterest = 0.0f; + System.out.println(principal); + + } + currentDate.add(Calendar.MONTH, 1); + interestEarned = 0.0f; + } + return principal; + } + + public HashMap updateFixedDepositAccount(final String clientID, final String productID, final String accountID, final String validFrom, + final String validTo, final String penalInterestType, final String submittedOnDate) { + + final String fixedDepositApplicationJSON = new FixedDepositAccountHelper(this.requestSpec, this.responseSpec) // + .withSubmittedOnDate(submittedOnDate) // + .build(clientID, productID, validFrom, validTo, penalInterestType); + + return Utils.performServerPut(this.requestSpec, this.responseSpec, FIXED_DEPOSIT_ACCOUNT_URL + "/" + accountID + "?" + + Utils.TENANT_IDENTIFIER, fixedDepositApplicationJSON, CommonConstants.RESPONSE_CHANGES); + } + + public HashMap updateInterestCalculationConfigForFixedDeposit(final String clientID, final String productID, final String accountID, + final String submittedOnDate, final String validFrom, final String validTo, final String numberOfDaysPerYear, + final String penalInterestType, final String interestCalculationType, final String interestCompoundingPeriodType, + final String interestPostingPeriodType) { + + final String fixedDepositApplicationJSON = new FixedDepositAccountHelper(this.requestSpec, this.responseSpec) // + .withSubmittedOnDate(submittedOnDate) // + .withNumberOfDaysPerYear(numberOfDaysPerYear) // + .withInterestCalculationPeriodType(interestCalculationType) // + .withInterestCompoundingPeriodType(interestCompoundingPeriodType) // + .withInterestPostingPeriodType(interestPostingPeriodType) // + .build(clientID, productID, validFrom, validTo, penalInterestType); + + return Utils.performServerPut(this.requestSpec, this.responseSpec, FIXED_DEPOSIT_ACCOUNT_URL + "/" + accountID + "?" + + Utils.TENANT_IDENTIFIER, fixedDepositApplicationJSON, CommonConstants.RESPONSE_CHANGES); + } + + public HashMap approveFixedDeposit(final Integer fixedDepositAccountID, final String approvedOnDate) { + System.out.println("--------------------------------- APPROVING FIXED DEPOSIT APPLICATION ------------------------------------"); + return performFixedDepositApplicationActions(createFixedDepositOperationURL(APPROVE_FIXED_DEPOSIT_COMMAND, fixedDepositAccountID), + getApproveFixedDepositAccountAsJSON(approvedOnDate)); + } + + public HashMap undoApproval(final Integer fixedDepositAccountID) { + System.out.println("--------------------------------- UNDO APPROVING FIXED DEPOSIT APPLICATION -------------------------------"); + final String undoBodyJson = "{'note':'UNDO APPROVAL'}"; + return performFixedDepositApplicationActions( + createFixedDepositOperationURL(UNDO_APPROVAL_FIXED_DEPOSIT_COMMAND, fixedDepositAccountID), undoBodyJson); + } + + public HashMap rejectApplication(final Integer fixedDepositAccountID, final String rejectedOnDate) { + System.out.println("--------------------------------- REJECT FIXED DEPOSIT APPLICATION -------------------------------"); + return performFixedDepositApplicationActions(createFixedDepositOperationURL(REJECT_FIXED_DEPOSIT_COMMAND, fixedDepositAccountID), + getRejectedFixedDepositAsJSON(rejectedOnDate)); + } + + public HashMap withdrawApplication(final Integer fixedDepositAccountID, final String withdrawApplicationOnDate) { + System.out.println("--------------------------------- Withdraw FIXED DEPOSIT APPLICATION -------------------------------"); + return performFixedDepositApplicationActions( + createFixedDepositOperationURL(WITHDRAWN_BY_CLIENT_FIXED_DEPOSIT_COMMAND, fixedDepositAccountID), + getWithdrawnFixedDepositAccountAsJSON(withdrawApplicationOnDate)); + } + + public HashMap activateFixedDeposit(final Integer fixedDepositAccountID, final String activationDate) { + System.out.println("---------------------------------- ACTIVATING FIXED DEPOSIT APPLICATION ----------------------------------"); + return performFixedDepositApplicationActions(createFixedDepositOperationURL(ACTIVATE_FIXED_DEPOSIT_COMMAND, fixedDepositAccountID), + getActivatedFixedDepositAccountAsJSON(activationDate)); + } + + public Object deleteFixedDepositApplication(final Integer fixedDepositAccountID, final String jsonAttributeToGetBack) { + System.out.println("---------------------------------- DELETE FIXED DEPOSIT APPLICATION ----------------------------------"); + return Utils.performServerDelete(this.requestSpec, this.responseSpec, FIXED_DEPOSIT_ACCOUNT_URL + "/" + fixedDepositAccountID + "?" + + Utils.TENANT_IDENTIFIER, jsonAttributeToGetBack); + + } + + public Integer calculateInterestForFixedDeposit(final Integer fixedDepositAccountId) { + System.out.println("--------------------------------- CALCULATING INTEREST FOR FIXED DEPOSIT --------------------------------"); + return (Integer) performFixedDepositActions( + createFixedDepositCalculateInterestURL(CALCULATE_INTEREST_FIXED_DEPOSIT_COMMAND, fixedDepositAccountId), + getCalculatedInterestForFixedDepositApplicationAsJSON(), CommonConstants.RESPONSE_RESOURCE_ID); + } + + public Integer postInterestForFixedDeposit(final Integer fixedDepositAccountId) { + System.out.println("--------------------------------- POST INTEREST FOR FIXED DEPOSIT --------------------------------"); + return (Integer) performFixedDepositActions( + createFixedDepositCalculateInterestURL(POST_INTEREST_FIXED_DEPOSIT_COMMAND, fixedDepositAccountId), + getCalculatedInterestForFixedDepositApplicationAsJSON(), CommonConstants.RESPONSE_RESOURCE_ID); + } + + public HashMap calculatePrematureAmountForFixedDeposit(final Integer fixedDepositAccountId, final String closedOnDate) { + System.out.println("--------------------- CALCULATING PREMATURE AMOUNT FOR FIXED DEPOSIT ----------------------------"); + return (HashMap) performFixedDepositActions( + createFixedDepositCalculateInterestURL(CALCULATE_PREMATURE_AMOUNT_COMMAND, fixedDepositAccountId), + getCalculatedPrematureAmountForFixedDepositAccountAsJSON(closedOnDate), ""); + } + + public Object prematureCloseForFixedDeposit(final Integer fixedDepositAccountId, final String closedOnDate, final String closureType, + final Integer toSavingsId, final String jsonAttributeToGetBack) { + System.out.println("--------------------- PREMATURE CLOSE FOR FIXED DEPOSIT ----------------------------"); + return performFixedDepositActions(createFixedDepositCalculateInterestURL(PREMATURE_CLOSE_COMMAND, fixedDepositAccountId), + getPrematureCloseForFixedDepositAccountAsJSON(closedOnDate, closureType, toSavingsId), jsonAttributeToGetBack); + } + + private String getApproveFixedDepositAccountAsJSON(final String approvedOnDate) { + final HashMap<String, Object> map = new HashMap<>(); + map.put("locale", CommonConstants.locale); + map.put("dateFormat", CommonConstants.dateFormat); + map.put("approvedOnDate", approvedOnDate); + map.put("note", "Approval NOTE"); + String fixedDepositAccountApproveJson = new Gson().toJson(map); + System.out.println(fixedDepositAccountApproveJson); + return fixedDepositAccountApproveJson; + } + + private String getRejectedFixedDepositAsJSON(final String rejectedOnDate) { + final HashMap<String, Object> map = new HashMap<>(); + map.put("locale", CommonConstants.locale); + map.put("dateFormat", CommonConstants.dateFormat); + map.put("rejectedOnDate", rejectedOnDate); + map.put("note", "Rejected NOTE"); + String fixedDepositAccountJson = new Gson().toJson(map); + System.out.println(fixedDepositAccountJson); + return fixedDepositAccountJson; + } + + private String getWithdrawnFixedDepositAccountAsJSON(final String withdrawnApplicationOnDate) { + final HashMap<String, Object> map = new HashMap<>(); + map.put("locale", CommonConstants.locale); + map.put("dateFormat", CommonConstants.dateFormat); + map.put("withdrawnOnDate", withdrawnApplicationOnDate); + map.put("note", "Withdraw NOTE"); + String fixedDepositAccountJson = new Gson().toJson(map); + System.out.println(fixedDepositAccountJson); + return fixedDepositAccountJson; + } + + private String getActivatedFixedDepositAccountAsJSON(final String activationDate) { + final HashMap<String, Object> map = new HashMap<>(); + map.put("locale", CommonConstants.locale); + map.put("dateFormat", CommonConstants.dateFormat); + map.put("activatedOnDate", activationDate); + String fixedDepositAccountActivateJson = new Gson().toJson(map); + System.out.println(fixedDepositAccountActivateJson); + return fixedDepositAccountActivateJson; + } + + private String getCalculatedInterestForFixedDepositApplicationAsJSON() { + final HashMap<String, String> map = new HashMap<>(); + String fixedDepositAccountCalculatedInterestJson = new Gson().toJson(map); + System.out.println(fixedDepositAccountCalculatedInterestJson); + return fixedDepositAccountCalculatedInterestJson; + } + + private String getCalculatedPrematureAmountForFixedDepositAccountAsJSON(final String closedOnDate) { + final HashMap<String, Object> map = new HashMap<>(); + map.put("locale", CommonConstants.locale); + map.put("dateFormat", CommonConstants.dateFormat); + map.put("closedOnDate", closedOnDate); + String fixedDepositAccountPrematureClosureJson = new Gson().toJson(map); + System.out.println(fixedDepositAccountPrematureClosureJson); + return fixedDepositAccountPrematureClosureJson; + } + + private String getPrematureCloseForFixedDepositAccountAsJSON(final String closedOnDate, final String closureType, + final Integer toSavingsId) { + final HashMap<String, Object> map = new HashMap<>(); + map.put("locale", CommonConstants.locale); + map.put("dateFormat", CommonConstants.dateFormat); + map.put("closedOnDate", closedOnDate); + map.put("onAccountClosureId", closureType); + if (toSavingsId != null) { + map.put("toSavingsAccountId", toSavingsId); + map.put("transferDescription", "Transferring To Savings Account"); + } + String fixedDepositAccountPrematureCloseJson = new Gson().toJson(map); + System.out.println(fixedDepositAccountPrematureCloseJson); + return fixedDepositAccountPrematureCloseJson; + } + + private String createFixedDepositOperationURL(final String command, final Integer fixedDepositAccountID) { + return FIXED_DEPOSIT_ACCOUNT_URL + "/" + fixedDepositAccountID + "?command=" + command + "&" + Utils.TENANT_IDENTIFIER; + } + + private Object performFixedDepositActions(final String postURLForFixedDeposit, final String jsonToBeSent, + final String jsonAttributeToGetBack) { + return Utils.performServerPost(this.requestSpec, this.responseSpec, postURLForFixedDeposit, jsonToBeSent, jsonAttributeToGetBack); + } + + private HashMap performFixedDepositApplicationActions(final String postURLForFixedDepositAction, final String jsonToBeSent) { + HashMap status = null; + final HashMap response = Utils.performServerPost(this.requestSpec, this.responseSpec, postURLForFixedDepositAction, jsonToBeSent, + CommonConstants.RESPONSE_CHANGES); + if (response != null) { + status = (HashMap) response.get("status"); + } + return status; + } + + private String createFixedDepositCalculateInterestURL(final String command, final Integer fixedDepositAccountID) { + return FIXED_DEPOSIT_ACCOUNT_URL + "/" + fixedDepositAccountID + "?command=" + command + "&" + Utils.TENANT_IDENTIFIER; + } + + public static ArrayList retrieveAllFixedDepositAccounts(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) { + System.out.println("-------------------- RETRIEVING ALL FIXED DEPOSIT ACCOUNTS ---------------------"); + final ArrayList response = Utils.performServerGet(requestSpec, responseSpec, FIXED_DEPOSIT_ACCOUNT_URL + "?" + + Utils.TENANT_IDENTIFIER, ""); + return response; + } + + public FixedDepositAccountHelper withSubmittedOnDate(final String fixedDepositApplicationSubmittedDate) { + this.submittedOnDate = fixedDepositApplicationSubmittedDate; + return this; + } + + public FixedDepositAccountHelper withNumberOfDaysPerYear(final String numberOfDaysPerYearTypeId) { + this.interestCalculationDaysInYearType = numberOfDaysPerYearTypeId; + return this; + } + + public FixedDepositAccountHelper withInterestCalculationPeriodType(final String interestCalculationTypeId) { + this.interestCalculationType = interestCalculationTypeId; + return this; + } + + public FixedDepositAccountHelper withInterestCompoundingPeriodType(final String interestCompoundingPeriodTypeId) { + this.interestCompoundingPeriodType = interestCompoundingPeriodTypeId; + return this; + } + + public FixedDepositAccountHelper withInterestPostingPeriodType(final String interestPostingPeriodTypeId) { + this.interestPostingPeriodType = interestPostingPeriodTypeId; + return this; + } + + public FixedDepositAccountHelper withSavings(final String savingsId) { + this.savingsId = savingsId; + return this; + } + + public FixedDepositAccountHelper transferInterest(final boolean transferInterest) { + this.transferInterest = transferInterest; + return this; + } + + public FixedDepositAccountHelper withLockinPeriodFrequency(final String lockingPeriodFrequencyType, final String lockinPeriodFrequency) { + this.lockingPeriodFrequencyType = lockingPeriodFrequencyType; + this.lockinPeriodFrequency = lockinPeriodFrequency; + return this; + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/4b1ec9ef/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/fixeddeposit/FixedDepositAccountStatusChecker.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/fixeddeposit/FixedDepositAccountStatusChecker.java b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/fixeddeposit/FixedDepositAccountStatusChecker.java new file mode 100644 index 0000000..fca5cec --- /dev/null +++ b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/fixeddeposit/FixedDepositAccountStatusChecker.java @@ -0,0 +1,94 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.fineract.integrationtests.common.fixeddeposit; + +import static org.junit.Assert.assertTrue; + +import java.util.HashMap; + +import org.apache.fineract.integrationtests.common.Utils; +import org.junit.Assert; + +import com.jayway.restassured.specification.RequestSpecification; +import com.jayway.restassured.specification.ResponseSpecification; + +@SuppressWarnings("rawtypes") +public class FixedDepositAccountStatusChecker { + + private static final String FIXED_DEPOSIT_ACCOUNT_URL = "/fineract-provider/api/v1/fixeddepositaccounts"; + + public static void verifyFixedDepositIsApproved(final HashMap fixedDepositStatusHashMap) { + System.out.println("-------------------- VERIFYING FIXED DEPOSIT APPLICATION IS APPROVED --------------------"); + assertTrue("Error in Approving Fixed deposit application", getStatus(fixedDepositStatusHashMap, "approved")); + System.out.println(fixedDepositStatusHashMap); + } + + public static void verifyFixedDepositIsPending(final HashMap fixedDepositStatusHashMap) { + System.out.println("-------------------- VERIFYING FIXED DEPOSIT APPLICATION IS PENDING --------------------"); + assertTrue("FIXED DEPOSIT ACCOUNT IS NOT IN PENDING STATE", getStatus(fixedDepositStatusHashMap, "submittedAndPendingApproval")); + System.out.println(fixedDepositStatusHashMap); + } + + public static void verifyFixedDepositIsActive(final HashMap fixedDepositStatusHashMap) { + System.out.println("----------------- VERIFYING FIXED DEPOSIT APPLICATION IS ACTIVE -----------------"); + assertTrue("ERROR IN ACTIVATING THE FIXED DEPOSIT APPLICATION", getStatus(fixedDepositStatusHashMap, "active")); + System.out.println(fixedDepositStatusHashMap); + } + + public static void verifyFixedDepositIsRejected(final HashMap fixedDepositStatusHashMap) { + System.out.println("-------------- VERIFYING FIXED DEPOSIT APPLICATION IS REJECTED ----------------"); + assertTrue("ERROR IN REJECTING THE FIXED DEPOSIT APPLICATION", getStatus(fixedDepositStatusHashMap, "rejected")); + System.out.println(fixedDepositStatusHashMap); + } + + public static void verifyFixedDepositIsWithdrawn(final HashMap fixedDepositStatusHashMap) { + System.out.println("---------------- VERIFYING FIXED DEPOSIT APPLICATION IS WITHDRAWN ----------------"); + assertTrue("ERROR IN WITHDRAW THE FIXED DEPOSIT APPLICATION", getStatus(fixedDepositStatusHashMap, "withdrawnByApplicant")); + System.out.println(fixedDepositStatusHashMap); + } + + public static void verifyFixedDepositAccountIsClosed(final HashMap fixedDepositStatusHashMap) { + System.out.println("--------------------- VERIFYING FIXED DEPOSIT APPLICATION IS CLOSED ---------------------"); + assertTrue("ERROR IN CLOSING THE FIXED DEPOSIT APPLICATION", getStatus(fixedDepositStatusHashMap, "closed")); + System.out.println(fixedDepositStatusHashMap); + } + + public static void verifyFixedDepositAccountIsNotActive(final HashMap fixedDepositStatusHashMap) { + System.out.println("------------------ VERIFYING FIXED DEPOSIT APPLICATION IS INACTIVE --------------------"); + Assert.assertFalse(getStatus(fixedDepositStatusHashMap, "active")); + System.out.println(fixedDepositStatusHashMap); + } + + public static HashMap getStatusOfFixedDepositAccount(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, + final String fixedDepositAccountID) { + final String GET_STATUS_OF_FIXED_DEPOSIT_ACCOUNT_URL = FIXED_DEPOSIT_ACCOUNT_URL + "/" + fixedDepositAccountID + "?" + + Utils.TENANT_IDENTIFIER; + return Utils.performServerGet(requestSpec, responseSpec, GET_STATUS_OF_FIXED_DEPOSIT_ACCOUNT_URL, "status"); + } + + public static void verifyFixedDepositAccountIsPrematureClosed(HashMap fixedDepositStatusHashMap) { + System.out.println("--------------------- VERIFYING FIXED DEPOSIT APPLICATION IS CLOSED ---------------------"); + assertTrue("ERROR IN PREMATURELY CLOSING THE FIXED DEPOSIT ACCOUNT", getStatus(fixedDepositStatusHashMap, "prematureClosed")); + System.out.println(fixedDepositStatusHashMap); + } + + private static boolean getStatus(final HashMap fixedDepositStatusMap, final String fixedDepositStatusString) { + return (Boolean) fixedDepositStatusMap.get(fixedDepositStatusString); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/4b1ec9ef/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/fixeddeposit/FixedDepositProductHelper.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/fixeddeposit/FixedDepositProductHelper.java b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/fixeddeposit/FixedDepositProductHelper.java new file mode 100644 index 0000000..2703340 --- /dev/null +++ b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/fixeddeposit/FixedDepositProductHelper.java @@ -0,0 +1,254 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.fineract.integrationtests.common.fixeddeposit; + +import static org.junit.Assert.assertEquals; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.fineract.integrationtests.common.CommonConstants; +import org.apache.fineract.integrationtests.common.Utils; +import org.apache.fineract.integrationtests.common.accounting.Account; +import org.apache.fineract.integrationtests.common.accounting.Account.AccountType; +import org.apache.fineract.integrationtests.common.savings.SavingsProductHelper; + +import com.google.gson.Gson; +import com.jayway.restassured.specification.RequestSpecification; +import com.jayway.restassured.specification.ResponseSpecification; + +@SuppressWarnings({ "unused", "rawtypes" }) +public class FixedDepositProductHelper { + + private final RequestSpecification requestSpec; + private final ResponseSpecification responseSpec; + + public FixedDepositProductHelper(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) { + this.requestSpec = requestSpec; + this.responseSpec = responseSpec; + } + + private static final String FIXED_DEPOSIT_PRODUCT_URL = "/fineract-provider/api/v1/fixeddepositproducts"; + private static final String INTEREST_CHART_URL = "/fineract-provider/api/v1/interestratecharts"; + private static final String CREATE_FIXED_DEPOSIT_PRODUCT_URL = FIXED_DEPOSIT_PRODUCT_URL + "?" + Utils.TENANT_IDENTIFIER; + + private static final String LOCALE = "en_GB"; + private static final String DIGITS_AFTER_DECIMAL = "4"; + private static final String IN_MULTIPLES_OF = "100"; + private static final String USD = "USD"; + private static final String DAYS = "0"; + private static final String WEEKS = "1"; + private static final String MONTHS = "2"; + private static final String YEARS = "3"; + private static final String DAILY = "1"; + private static final String MONTHLY = "4"; + private static final String QUARTERLY = "5"; + private static final String BI_ANNUALLY = "6"; + private static final String ANNUALLY = "7"; + private static final String INTEREST_CALCULATION_USING_DAILY_BALANCE = "1"; + private static final String INTEREST_CALCULATION_USING_AVERAGE_DAILY_BALANCE = "2"; + private static final String DAYS_360 = "360"; + private static final String DAYS_365 = "365"; + private static final String NONE = "1"; + private static final String CASH_BASED = "2"; + private static final String ACCRUAL_PERIODIC = "3"; + private static final String ACCRUAL_UPFRONT = "4"; + private static final String WHOLE_TERM = "1"; + private static final String TILL_PREMATURE_WITHDRAWAL = "2"; + + private String name = Utils.randomNameGenerator("FIXED_DEPOSIT_PRODUCT_", 6); + private String shortName = Utils.randomNameGenerator("", 4); + private String description = Utils.randomNameGenerator("", 20); + private String interestCompoundingPeriodType = MONTHLY; + private String interestPostingPeriodType = MONTHLY; + private String interestCalculationType = INTEREST_CALCULATION_USING_DAILY_BALANCE; + private String accountingRule = NONE; + private String lockinPeriodFrequency = "1"; + private String lockingPeriodFrequencyType = MONTHS; + private String minDepositTerm = "6"; + private String minDepositTermTypeId = MONTHS; + private String maxDepositTerm = "10"; + private String maxDepositTermTypeId = YEARS; + private String inMultiplesOfDepositTerm = "2"; + private final String depositAmount = "100000"; + private String inMultiplesOfDepositTermTypeId = MONTHS; + private String preClosurePenalInterest = "2"; + private String preClosurePenalInterestOnTypeId = WHOLE_TERM; + private final boolean preClosurePenalApplicable = true; + private final String currencyCode = USD; + private final String interestCalculationDaysInYearType = DAYS_365; + private Account[] accountList = null; + + public String build(final String validFrom, final String validTo) { + final HashMap<String, Object> map = new HashMap<>(); + + List<HashMap<String, String>> chartSlabs = new ArrayList<HashMap<String, String>>(); + HashMap<String, String> chartSlabsMap1 = new HashMap<>(); + chartSlabsMap1.put("description", "First"); + chartSlabsMap1.put("periodType", MONTHS); + chartSlabsMap1.put("fromPeriod", "1"); + chartSlabsMap1.put("toPeriod", "6"); + chartSlabsMap1.put("annualInterestRate", "5"); + chartSlabsMap1.put("locale", LOCALE); + chartSlabs.add(0, chartSlabsMap1); + + HashMap<String, String> chartSlabsMap2 = new HashMap<>(); + chartSlabsMap2.put("description", "Second"); + chartSlabsMap2.put("periodType", MONTHS); + chartSlabsMap2.put("fromPeriod", "7"); + chartSlabsMap2.put("toPeriod", "12"); + chartSlabsMap2.put("annualInterestRate", "6"); + chartSlabsMap2.put("locale", LOCALE); + chartSlabs.add(1, chartSlabsMap2); + + HashMap<String, String> chartSlabsMap3 = new HashMap<>(); + chartSlabsMap3.put("description", "Third"); + chartSlabsMap3.put("periodType", MONTHS); + chartSlabsMap3.put("fromPeriod", "13"); + chartSlabsMap3.put("toPeriod", "18"); + chartSlabsMap3.put("annualInterestRate", "7"); + chartSlabsMap3.put("locale", LOCALE); + chartSlabs.add(2, chartSlabsMap3); + + HashMap<String, String> chartSlabsMap4 = new HashMap<>(); + chartSlabsMap4.put("description", "Fourth"); + chartSlabsMap4.put("periodType", MONTHS); + chartSlabsMap4.put("fromPeriod", "19"); + chartSlabsMap4.put("toPeriod", "24"); + chartSlabsMap4.put("annualInterestRate", "8"); + chartSlabsMap4.put("locale", LOCALE); + chartSlabs.add(3, chartSlabsMap4); + + List<HashMap<String, Object>> charts = new ArrayList<HashMap<String, Object>>(); + HashMap<String, Object> chartsMap = new HashMap<>(); + chartsMap.put("fromDate", validFrom); + chartsMap.put("endDate", validTo); + chartsMap.put("dateFormat", "dd MMMM yyyy"); + chartsMap.put("locale", LOCALE); + chartsMap.put("chartSlabs", chartSlabs); + charts.add(chartsMap); + + map.put("charts", charts); + map.put("name", this.name); + map.put("shortName", this.shortName); + map.put("description", this.description); + map.put("currencyCode", this.currencyCode); + map.put("interestCalculationDaysInYearType", this.interestCalculationDaysInYearType); + map.put("locale", LOCALE); + map.put("digitsAfterDecimal", DIGITS_AFTER_DECIMAL); + map.put("inMultiplesOf", IN_MULTIPLES_OF); + map.put("interestCalculationType", this.interestCalculationType); + map.put("interestCompoundingPeriodType", this.interestCompoundingPeriodType); + map.put("interestPostingPeriodType", this.interestPostingPeriodType); + map.put("accountingRule", this.accountingRule); + map.put("lockinPeriodFrequency", this.lockinPeriodFrequency); + map.put("lockinPeriodFrequencyType", this.lockingPeriodFrequencyType); + map.put("preClosurePenalApplicable", "true"); + map.put("minDepositTermTypeId", this.minDepositTermTypeId); + map.put("minDepositTerm", this.minDepositTerm); + map.put("maxDepositTermTypeId", this.maxDepositTermTypeId); + map.put("maxDepositTerm", this.maxDepositTerm); + map.put("depositAmount", this.depositAmount); + map.put("preClosurePenalApplicable", this.preClosurePenalApplicable); + map.put("inMultiplesOfDepositTerm", this.inMultiplesOfDepositTerm); + map.put("inMultiplesOfDepositTermTypeId", this.inMultiplesOfDepositTermTypeId); + map.put("preClosurePenalInterest", this.preClosurePenalInterest); + map.put("preClosurePenalInterestOnTypeId", this.preClosurePenalInterestOnTypeId); + + if (this.accountingRule.equals(CASH_BASED)) { + map.putAll(getAccountMappingForCashBased()); + } + + String FixedDepositProductCreateJson = new Gson().toJson(map); + System.out.println(FixedDepositProductCreateJson); + return FixedDepositProductCreateJson; + } + + public FixedDepositProductHelper withAccountingRuleAsNone() { + this.accountingRule = NONE; + return this; + } + + public FixedDepositProductHelper withAccountingRuleAsCashBased(final Account[] account_list) { + this.accountingRule = CASH_BASED; + this.accountList = account_list; + return this; + } + + private Map<String, String> getAccountMappingForCashBased() { + final Map<String, String> map = new HashMap<>(); + if (accountList != null) { + for (int i = 0; i < this.accountList.length; i++) { + if (this.accountList[i].getAccountType().equals(Account.AccountType.ASSET)) { + final String ID = this.accountList[i].getAccountID().toString(); + map.put("savingsReferenceAccountId", ID); + } + if (this.accountList[i].getAccountType().equals(Account.AccountType.LIABILITY)) { + final String ID = this.accountList[i].getAccountID().toString(); + map.put("savingsControlAccountId", ID); + map.put("transfersInSuspenseAccountId", ID); + } + if (this.accountList[i].getAccountType().equals(Account.AccountType.EXPENSE)) { + final String ID = this.accountList[i].getAccountID().toString(); + map.put("interestOnSavingsAccountId", ID); + } + if (this.accountList[i].getAccountType().equals(Account.AccountType.INCOME)) { + final String ID = this.accountList[i].getAccountID().toString(); + map.put("incomeFromFeeAccountId", ID); + map.put("incomeFromPenaltyAccountId", ID); + } + } + } + return map; + } + + public static Integer createFixedDepositProduct(final String fixedDepositProductCreateJson, final RequestSpecification requestSpec, + final ResponseSpecification responseSpec) { + System.out.println("--------------------- CREATING FIXED DEPOSIT PRODUCT ------------------------"); + return Utils.performServerPost(requestSpec, responseSpec, CREATE_FIXED_DEPOSIT_PRODUCT_URL, fixedDepositProductCreateJson, + CommonConstants.RESPONSE_RESOURCE_ID); + } + + public static ArrayList retrieveAllFixedDepositProducts(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) { + System.out.println("-------------------- RETRIEVING ALL FIXED DEPOSIT PRODUCTS ---------------------"); + final ArrayList response = Utils.performServerGet(requestSpec, responseSpec, FIXED_DEPOSIT_PRODUCT_URL + "?" + + Utils.TENANT_IDENTIFIER, ""); + return response; + } + + public static HashMap retrieveFixedDepositProductById(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, + final String productId) { + System.out.println("------------------------ RETRIEVING FIXED DEPOSIT PRODUCT BY ID ------------------------"); + final String GET_FD_PRODUCT_BY_ID_URL = FIXED_DEPOSIT_PRODUCT_URL + "/" + productId + "?" + Utils.TENANT_IDENTIFIER; + final HashMap response = Utils.performServerGet(requestSpec, responseSpec, GET_FD_PRODUCT_BY_ID_URL, ""); + return response; + } + + public static ArrayList getInterestRateChartSlabsByProductId(final RequestSpecification requestSpec, + final ResponseSpecification responseSpec, final Integer productId) { + System.out.println("-------------------- RETRIEVE INTEREST CHART BY PRODUCT ID ---------------------"); + final ArrayList response = Utils.performServerGet(requestSpec, responseSpec, INTEREST_CHART_URL + "?productId=" + productId, + "chartSlabs"); + return response; + } + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/4b1ec9ef/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/funds/FundsHelper.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/funds/FundsHelper.java b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/funds/FundsHelper.java new file mode 100644 index 0000000..eed6ae5 --- /dev/null +++ b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/funds/FundsHelper.java @@ -0,0 +1,111 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.fineract.integrationtests.common.funds; + +import com.google.gson.Gson; + +public class FundsHelper { + + public static class Builder { + + private String name; + private String externalId; + + private Builder(final String name) { + this.name = name; + } + + public Builder externalId(final String externalId) { + this.externalId = externalId; + return this; + } + + public FundsHelper build() { + return new FundsHelper(this.name, this.externalId); + } + + } + + private String name; + private String externalId; + private Long resourceId; + + FundsHelper() { + super(); + } + + private FundsHelper(final String name, + final String externalId) { + super(); + this.name = name; + this.externalId = externalId; + } + + public String getName() { + return this.name; + } + + public String getExternalId() { + return this.externalId; + } + + public Long getResourceId() { + return this.resourceId; + } + + public String toJSON() { + return new Gson().toJson(this); + } + + public static FundsHelper fromJSON(final String jsonData) { + return new Gson().fromJson(jsonData, FundsHelper.class); + } + + public static Builder create(final String name) { + return new Builder(name); + } + + @Override + public int hashCode() { + if (this.name != null) { + return this.name.hashCode(); + } + return super.hashCode(); + } + + @Override + public boolean equals(Object o) { + if (o == this) { + return true; + } + + if (!(o instanceof FundsHelper)) { + return false; + } + + FundsHelper fh = (FundsHelper)o; + + if (this.name.equals(fh.name)) { + return true; + } + + return false; + } + +} http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/4b1ec9ef/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/funds/FundsResourceHandler.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/funds/FundsResourceHandler.java b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/funds/FundsResourceHandler.java new file mode 100644 index 0000000..5d605fc --- /dev/null +++ b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/funds/FundsResourceHandler.java @@ -0,0 +1,72 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.fineract.integrationtests.common.funds; + +import com.google.common.reflect.TypeToken; +import com.google.gson.Gson; +import com.jayway.restassured.specification.RequestSpecification; +import com.jayway.restassured.specification.ResponseSpecification; + +import org.apache.fineract.integrationtests.common.Utils; + +import java.util.HashMap; +import java.util.List; + +public class FundsResourceHandler { + + private static final String FUNDS_URL = "/fineract-provider/api/v1/funds"; + private static final String CREATE_FUNDS_URL = FUNDS_URL + "?" + Utils.TENANT_IDENTIFIER; + + public static Integer createFund(final String fundJSON, + final RequestSpecification requestSpec, + final ResponseSpecification responseSpec) { + return Utils.performServerPost(requestSpec, responseSpec, CREATE_FUNDS_URL, fundJSON, "resourceId"); + } + + public static List<FundsHelper> retrieveAllFunds(final RequestSpecification requestSpec, + final ResponseSpecification responseSpec) { + final String URL = FUNDS_URL + "?" + Utils.TENANT_IDENTIFIER; + List<HashMap<String, Object>> list = Utils.performServerGet(requestSpec, responseSpec, URL, ""); + final String jsonData = new Gson().toJson(list); + return new Gson().fromJson(jsonData, new TypeToken<List<FundsHelper>>(){}.getType()); + } + + public static String retrieveFund(final Long fundID, + final RequestSpecification requestSpec, + final ResponseSpecification responseSpec) { + final String URL = FUNDS_URL + "/" + fundID + "?" + Utils.TENANT_IDENTIFIER; + final HashMap response = Utils.performServerGet(requestSpec, responseSpec, URL, ""); + return new Gson().toJson(response); + } + + public static FundsHelper updateFund(final Long fundID, + final String newName, + final String newExternalId, + final RequestSpecification requestSpec, + final ResponseSpecification responseSpec) { + FundsHelper fh = FundsHelper.create(newName).externalId(newExternalId).build(); + String updateJSON = new Gson().toJson(fh); + + final String URL = FUNDS_URL + "/" + fundID + "?" + Utils.TENANT_IDENTIFIER; + final HashMap<String, String> response = Utils.performServerPut(requestSpec, responseSpec, URL, updateJSON, "changes"); + final String jsonData = new Gson().toJson(response); + return new Gson().fromJson(jsonData, FundsHelper.class); + } + +}
