http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/4b1ec9ef/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/OfficeHelper.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/OfficeHelper.java b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/OfficeHelper.java new file mode 100755 index 0000000..d73c4c6 --- /dev/null +++ b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/OfficeHelper.java @@ -0,0 +1,79 @@ +/** + * 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; + +import java.util.HashMap; + +import com.google.common.reflect.TypeToken; +import com.google.gson.Gson; +import com.jayway.restassured.specification.RequestSpecification; +import com.jayway.restassured.specification.ResponseSpecification; + +public class OfficeHelper { + + private static final String OFFICE_URL = "/fineract-provider/api/v1/offices"; + private final RequestSpecification requestSpec; + private final ResponseSpecification responseSpec; + + public OfficeHelper(final RequestSpecification requestSpec, + final ResponseSpecification responseSpec) { + this.requestSpec = requestSpec; + this.responseSpec = responseSpec; + } + + public OfficeDomain retrieveOfficeByID(int id) { + final String json = new Gson().toJson(Utils.performServerGet( + requestSpec, responseSpec, OFFICE_URL + "/" + id + "?" + + Utils.TENANT_IDENTIFIER, "")); + return new Gson().fromJson(json, new TypeToken<OfficeDomain>() { + }.getType()); + } + + public Integer createOffice(final String openingDate) { + String json = getAsJSON(openingDate); + return Utils.performServerPost(this.requestSpec, this.responseSpec, + OFFICE_URL + "?" + Utils.TENANT_IDENTIFIER, json, + CommonConstants.RESPONSE_RESOURCE_ID); + } + + public Integer updateOffice(int id, String name, String openingDate) { + final HashMap map = new HashMap<>(); + map.put("name", name); + map.put("dateFormat", "dd MMMM yyyy"); + map.put("locale", "en"); + map.put("openingDate", openingDate); + + System.out.println("map : " + map); + + return Utils.performServerPut(requestSpec, responseSpec, OFFICE_URL + + "/" + id + "?" + Utils.TENANT_IDENTIFIER, + new Gson().toJson(map), "resourceId"); + } + + public static String getAsJSON(final String openingDate) { + final HashMap<String, String> map = new HashMap<>(); + map.put("parentId", "1"); + map.put("name", Utils.randomNameGenerator("Office_", 4)); + map.put("dateFormat", "dd MMMM yyyy"); + map.put("locale", "en"); + map.put("openingDate", openingDate); + System.out.println("map : " + map); + 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/PasswordPreferencesHelper.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/PasswordPreferencesHelper.java b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/PasswordPreferencesHelper.java new file mode 100644 index 0000000..52b8c5a --- /dev/null +++ b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/PasswordPreferencesHelper.java @@ -0,0 +1,70 @@ +/** + * 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; + +import java.util.HashMap; + +import com.google.gson.Gson; +import com.jayway.restassured.specification.RequestSpecification; +import com.jayway.restassured.specification.ResponseSpecification; + +public class PasswordPreferencesHelper { + + private static final String PASSWORD_PREFERENCES_URL = "/fineract-provider/api/v1/passwordpreferences"; + + public static Object updatePasswordPreferences(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, + String validationPolicyId) { + final String UPDATE_PASSWORD_PREFERENCES_URL = PASSWORD_PREFERENCES_URL + "?" + Utils.TENANT_IDENTIFIER; + System.out.println("---------------------------------UPDATE PASSWORD PREFERENCE---------------------------------------------"); + return Utils.performServerPut(requestSpec, responseSpec, UPDATE_PASSWORD_PREFERENCES_URL, updatePreferencesAsJson(validationPolicyId), ""); + } + + public static Object updateWithInvalidValidationPolicyId(final RequestSpecification requestSpec, + final ResponseSpecification responseSpec,String invalidValidationPolicyId, String jsonAttributeToGetback) { + final String UPDATE_PASSWORD_PREFERENCES_URL = PASSWORD_PREFERENCES_URL + "?" + Utils.TENANT_IDENTIFIER; + System.out + .println("---------------------------------UPDATE PASSWORD PREFERENCES WITH INVALID ID-----------------------------------------"); + return Utils.performServerPut(requestSpec, responseSpec, UPDATE_PASSWORD_PREFERENCES_URL, updatePreferencesWithInvalidId(invalidValidationPolicyId), + jsonAttributeToGetback); + } + + public static String updatePreferencesAsJson(String validationPolicyId) { + final HashMap<String, Object> map = new HashMap<>(); + map.put("validationPolicyId", validationPolicyId); + return new Gson().toJson(map); + } + + public static String updatePreferencesWithInvalidId(String invalidValidationPolicyId) { + final HashMap<String, Object> map = new HashMap<>(); + map.put("validationPolicyId", invalidValidationPolicyId); + return new Gson().toJson(map); + } + + + public static int getActivePasswordPreference(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) { + return Utils.performServerGet(requestSpec, responseSpec, PASSWORD_PREFERENCES_URL + "?" + Utils.TENANT_IDENTIFIER, "id"); + } + + public static HashMap<String, Object> getAllPreferences(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) { + + return Utils.performServerGet(requestSpec, responseSpec, PASSWORD_PREFERENCES_URL + "/template" + "?" + Utils.TENANT_IDENTIFIER, ""); + + } + +} http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/4b1ec9ef/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/PaymentTypeDomain.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/PaymentTypeDomain.java b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/PaymentTypeDomain.java new file mode 100644 index 0000000..7437ec8 --- /dev/null +++ b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/PaymentTypeDomain.java @@ -0,0 +1,79 @@ +/** + * 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; + +public class PaymentTypeDomain { + + private Integer id; + private String name; + private String description; + private Boolean isCashPayment; + private Integer position; + + private PaymentTypeDomain(final Integer id, final String name, final String description, final Boolean isCashPayment, + final Integer position) { + this.id = id; + this.name = name; + this.description = description; + this.isCashPayment = isCashPayment; + this.position = position; + + } + + public Integer getId() { + return this.id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getName() { + return this.name; + } + + public void setName(String name) { + this.name = name; + } + + public String getDescription() { + return this.description; + } + + public void setDescription(String description) { + this.description = description; + } + + public Boolean getIsCashPayment() { + return this.isCashPayment; + } + + public void setIsCashPayment(Boolean isCashPayment) { + this.isCashPayment = isCashPayment; + } + + public Integer getPosition() { + return this.position; + } + + public void setPosition(Integer position) { + this.position = position; + } + +} http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/4b1ec9ef/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/PaymentTypeHelper.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/PaymentTypeHelper.java b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/PaymentTypeHelper.java new file mode 100644 index 0000000..50dcad6 --- /dev/null +++ b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/PaymentTypeHelper.java @@ -0,0 +1,91 @@ +/** + * 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; + +import static org.junit.Assert.assertEquals; + +import java.util.HashMap; + +import com.google.common.reflect.TypeToken; +import com.google.gson.Gson; +import com.jayway.restassured.specification.RequestSpecification; +import com.jayway.restassured.specification.ResponseSpecification; + +@SuppressWarnings({ "rawtypes", "unchecked" }) +public class PaymentTypeHelper { + + private static final String CREATE_PAYMENTTYPE_URL = "/fineract-provider/api/v1/paymenttypes?" + Utils.TENANT_IDENTIFIER; + private static final String PAYMENTTYPE_URL = "/fineract-provider/api/v1/paymenttypes"; + + public static Integer createPaymentType(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, + final String name, final String description, final Boolean isCashPayment, final Integer position) { + System.out.println("---------------------------------CREATING A PAYMENT TYPE---------------------------------------------"); + return Utils.performServerPost(requestSpec, responseSpec, CREATE_PAYMENTTYPE_URL, + getJsonToCreatePaymentType(name, description, isCashPayment, position), "resourceId"); + } + + public static String getJsonToCreatePaymentType(final String name, final String description, final Boolean isCashPayment, + final Integer position) { + HashMap hm = new HashMap(); + hm.put("name", name); + if (description != null) hm.put("description", description); + hm.put("isCashPayment", isCashPayment); + if (position != null) hm.put("position", position); + + System.out.println("------------------------CREATING PAYMENT TYPE-------------------------" + hm); + return new Gson().toJson(hm); + } + + public static void verifyPaymentTypeCreatedOnServer(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, + final Integer generatedPaymentTypeID) { + System.out.println("------------------------------CHECK PAYMENT DETAILS------------------------------------\n"); + final String GET_PAYMENTTYPE_URL = PAYMENTTYPE_URL + "/" + generatedPaymentTypeID + "?" + Utils.TENANT_IDENTIFIER; + final Integer responsePaymentTypeID = Utils.performServerGet(requestSpec, responseSpec, GET_PAYMENTTYPE_URL, "id"); + assertEquals("ERROR IN CREATING THE PAYMENT TYPE", generatedPaymentTypeID, responsePaymentTypeID); + } + + public static PaymentTypeDomain retrieveById(RequestSpecification requestSpec, ResponseSpecification responseSpec, + final Integer paymentTypeId) { + final String GET_PAYMENTTYPE_URL = PAYMENTTYPE_URL + "/" + paymentTypeId + "?" + Utils.TENANT_IDENTIFIER; + System.out.println("---------------------------------GET PAYMENT TYPE---------------------------------------------"); + final String jsonData = new Gson().toJson(Utils.performServerGet(requestSpec, responseSpec, GET_PAYMENTTYPE_URL, "")); + return new Gson().fromJson(jsonData, new TypeToken<PaymentTypeDomain>() {}.getType()); + + } + + public static HashMap<String, String> updatePaymentType(final int id, HashMap request, final RequestSpecification requestSpec, + final ResponseSpecification responseSpec) { + final String UPDATE_PAYMENTTYPE_URL = PAYMENTTYPE_URL + "/" + id + "?" + Utils.TENANT_IDENTIFIER; + System.out.println("---------------------------------UPDATE PAYMENT TYPE " + id + "---------------------------------------------"); + HashMap<String, String> hash = Utils.performServerPut(requestSpec, responseSpec, UPDATE_PAYMENTTYPE_URL, + new Gson().toJson(request), "changes"); + return hash; + } + + public static Integer deletePaymentType(final int id, final RequestSpecification requestSpec, final ResponseSpecification responseSpec) { + final String DELETE_PAYMENTTYPE_URL = PAYMENTTYPE_URL + "/" + id + "?" + Utils.TENANT_IDENTIFIER; + System.out.println("---------------------------------DELETING PAYMENT TYPE " + id + "--------------------------------------------"); + return Utils.performServerDelete(requestSpec, responseSpec, DELETE_PAYMENTTYPE_URL, "resourceId"); + } + + public static String randomNameGenerator(final String prefix, final int lenOfRandomSuffix) { + return Utils.randomStringGenerator(prefix, lenOfRandomSuffix); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/4b1ec9ef/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/ProvisioningIntegrationTest.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/ProvisioningIntegrationTest.java b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/ProvisioningIntegrationTest.java new file mode 100644 index 0000000..107bece --- /dev/null +++ b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/ProvisioningIntegrationTest.java @@ -0,0 +1,241 @@ +/** + * 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; + +import java.text.DateFormat; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.fineract.integrationtests.common.accounting.Account; +import org.apache.fineract.integrationtests.common.accounting.AccountHelper; +import org.apache.fineract.integrationtests.common.loans.LoanApplicationTestBuilder; +import org.apache.fineract.integrationtests.common.loans.LoanProductTestBuilder; +import org.apache.fineract.integrationtests.common.loans.LoanStatusChecker; +import org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper; +import org.apache.fineract.integrationtests.common.provisioning.ProvisioningHelper; +import org.apache.fineract.integrationtests.common.provisioning.ProvisioningTransactionHelper; +import org.junit.Assert; +import org.junit.Assume; +import org.junit.Before; +import org.junit.Test; + +import com.google.gson.Gson; +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", "unchecked" }) +public class ProvisioningIntegrationTest { + + private static final String NONE = "1"; + private final static int LOANPRODUCTS_SIZE = 10; + + private RequestSpecification requestSpec; + private ResponseSpecification responseSpec; + private AccountHelper accountHelper; + private LoanTransactionHelper loanTransactionHelper; + + @Before + public void setup() { + Utils.initializeRESTAssured(); + this.requestSpec = new RequestSpecBuilder().setContentType(ContentType.JSON).build(); + this.requestSpec.header("Authorization", "Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey()); + this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build(); + this.loanTransactionHelper = new LoanTransactionHelper(this.requestSpec, this.responseSpec); + this.accountHelper = new AccountHelper(this.requestSpec, this.responseSpec); + Assume.assumeTrue(!isAlreadyProvisioningEntriesCreated()); + } + + @Test + public void testCreateProvisioningCriteria() { + ProvisioningTransactionHelper transactionHelper = new ProvisioningTransactionHelper(requestSpec, responseSpec); + ArrayList<Integer> loanProducts = new ArrayList<>(LOANPRODUCTS_SIZE); + List<Integer> loans = new ArrayList<>(); + final Integer clientID = ClientHelper.createClient(this.requestSpec, this.responseSpec); + ClientHelper.verifyClientCreatedOnServer(this.requestSpec, this.responseSpec, clientID); + for (int i = 0; i < LOANPRODUCTS_SIZE; i++) { + final Integer loanProductID = createLoanProduct(false, NONE); + loanProducts.add(loanProductID); + Assert.assertNotNull(loanProductID); + final Integer loanID = applyForLoanApplication(clientID, loanProductID, null, null, "1,00,000.00"); + HashMap loanStatusHashMap = LoanStatusChecker.getStatusOfLoan(this.requestSpec, this.responseSpec, loanID); + LoanStatusChecker.verifyLoanIsPending(loanStatusHashMap); + loanStatusHashMap = this.loanTransactionHelper.approveLoan("20 September 2011", loanID); + LoanStatusChecker.verifyLoanIsApproved(loanStatusHashMap); + LoanStatusChecker.verifyLoanIsWaitingForDisbursal(loanStatusHashMap); + System.out.println("-------------------------------DISBURSE LOAN-------------------------------------------"); + loanStatusHashMap = this.loanTransactionHelper.disburseLoan("20 September 2011", loanID); + LoanStatusChecker.verifyLoanIsActive(loanStatusHashMap); + loans.add(loanID); + Assert.assertNotNull(loanID); + } + + ArrayList categories = transactionHelper.retrieveAllProvisioningCategories(); + Assert.assertTrue(categories.size() > 0) ; + Account liability = accountHelper.createLiabilityAccount() ; + Account expense = accountHelper.createExpenseAccount() ; + Map requestCriteria = ProvisioningHelper.createProvisioingCriteriaJson(loanProducts, categories, liability, expense); + String provisioningCriteriaCreateJson = new Gson().toJson(requestCriteria); + Integer criteriaId = transactionHelper.createProvisioningCriteria(provisioningCriteriaCreateJson); + Assert.assertNotNull(criteriaId); + + Map newCriteria = transactionHelper.retrieveProvisioningCriteria(criteriaId) ; + validateProvisioningCriteria(requestCriteria, newCriteria) ; + + ArrayList definitions = (ArrayList)newCriteria.get("definitions") ; + for(int i = 0 ; i < definitions.size(); i++) { + Map criteriadefinition = (Map) definitions.get(i) ; + criteriadefinition.put("provisioningPercentage", new Float(20.0)) ; + } + newCriteria.put("locale", "en"); + String updateCriteriaString = new Gson().toJson(newCriteria) ; + Integer criteriaId1 = transactionHelper.updateProvisioningCriteria(criteriaId, updateCriteriaString) ; + Map updatedCriteria = transactionHelper.retrieveProvisioningCriteria(criteriaId1) ; + validateProvisioningCriteria(newCriteria, updatedCriteria) ; + + transactionHelper.deleteProvisioningCriteria(criteriaId1) ; + + categories = transactionHelper.retrieveAllProvisioningCategories(); + liability = accountHelper.createLiabilityAccount() ; + expense = accountHelper.createExpenseAccount() ; + requestCriteria = ProvisioningHelper.createProvisioingCriteriaJson(loanProducts, categories, liability, expense); + provisioningCriteriaCreateJson = new Gson().toJson(requestCriteria); + criteriaId = transactionHelper.createProvisioningCriteria(provisioningCriteriaCreateJson); + Assert.assertNotNull(criteriaId); + + String provisioningEntryJson = ProvisioningHelper.createProvisioningEntryJson(); + Integer provisioningEntryId = transactionHelper.createProvisioningEntries(provisioningEntryJson); + Assert.assertNotNull(provisioningEntryId); + + transactionHelper.updateProvisioningEntry("recreateprovisioningentry", provisioningEntryId, "") ; + transactionHelper.updateProvisioningEntry("createjournalentry", provisioningEntryId, "") ; + Map entry = transactionHelper.retrieveProvisioningEntry(provisioningEntryId) ; + Assert.assertTrue((Boolean)entry.get("journalEntry")) ; + Map provisioningEntry = transactionHelper.retrieveProvisioningEntries(provisioningEntryId) ; + Assert.assertTrue(((ArrayList)provisioningEntry.get("pageItems")).size() > 0) ; + } + + private void validateProvisioningCriteria(Map requestCriteria, Map newCriteria) { + + //criteria name validation + String requestCriteriaName = (String)requestCriteria.get("criteriaName") ; + String criteriaName = (String)newCriteria.get("criteriaName") ; + Assert.assertEquals(criteriaName, requestCriteriaName) ; + + //loan products validation + ArrayList requestProducts = (ArrayList)requestCriteria.get("loanProducts") ; + ArrayList products = (ArrayList)newCriteria.get("loanProducts") ; + Assert.assertEquals(products.size(), requestProducts.size()) ; + + ArrayList requestedDefinitions = (ArrayList)requestCriteria.get("definitions") ; + ArrayList newdefintions = (ArrayList) newCriteria.get("definitions") ; + Assert.assertEquals(newdefintions.size(), requestedDefinitions.size()) ; + for(int i = 0 ; i < newdefintions.size() ; i++) { + Map requestedMap = (Map)requestedDefinitions.get(i) ; + Map newMap = (Map)newdefintions.get(i) ; + checkProperty("categoryId", requestedMap, newMap) ; + checkProperty("categoryName", requestedMap, newMap) ; + checkProperty("minAge", requestedMap, newMap) ; + checkProperty("maxAge", requestedMap, newMap) ; + checkProperty("provisioningPercentage", requestedMap, newMap) ; + checkProperty("liabilityAccount", requestedMap, newMap) ; + checkProperty("expenseAccount", requestedMap, newMap) ; + } + } + + private void checkProperty(String propertyName, Map requestMap, Map newMap) { + Object requested = requestMap.get(propertyName) ; + Object modified = newMap.get(propertyName) ; + Assert.assertEquals(requested, modified) ; + } + + private Integer createLoanProduct(final boolean multiDisburseLoan, final String accountingRule, final Account... accounts) { + System.out.println("------------------------------CREATING NEW LOAN PRODUCT ---------------------------------------"); + LoanProductTestBuilder builder = new LoanProductTestBuilder() // + .withPrincipal("1,00,000.00") // + .withNumberOfRepayments("4") // + .withRepaymentAfterEvery("1") // + .withRepaymentTypeAsMonth() // + .withinterestRatePerPeriod("1") // + .withInterestRateFrequencyTypeAsMonths() // + .withAmortizationTypeAsEqualInstallments() // + .withInterestTypeAsDecliningBalance() // + .withTranches(multiDisburseLoan) // + .withAccounting(accountingRule, accounts); + if (multiDisburseLoan) { + builder = builder.withInterestCalculationPeriodTypeAsRepaymentPeriod(true); + } + final String loanProductJSON = builder.build(null); + + return this.loanTransactionHelper.getLoanProductId(loanProductJSON); + } + + private Integer applyForLoanApplication(final Integer clientID, final Integer loanProductID, List<HashMap> charges, + final String savingsId, String principal) { + System.out.println("--------------------------------APPLYING FOR LOAN APPLICATION--------------------------------"); + final String loanApplicationJSON = new LoanApplicationTestBuilder() // + .withPrincipal(principal) // + .withLoanTermFrequency("4") // + .withLoanTermFrequencyAsMonths() // + .withNumberOfRepayments("4") // + .withRepaymentEveryAfter("1") // + .withRepaymentFrequencyTypeAsMonths() // + .withInterestRatePerPeriod("2") // + .withAmortizationTypeAsEqualInstallments() // + .withInterestTypeAsDecliningBalance() // + .withInterestCalculationPeriodTypeSameAsRepaymentPeriod() // + .withExpectedDisbursementDate("20 September 2011") // + .withSubmittedOnDate("20 September 2011") // + .withCharges(charges).build(clientID.toString(), loanProductID.toString(), savingsId); + return this.loanTransactionHelper.getLoanId(loanApplicationJSON); + } + + private boolean isAlreadyProvisioningEntriesCreated() { + ProvisioningTransactionHelper transactionHelper = new ProvisioningTransactionHelper(requestSpec, responseSpec); + Map entries = transactionHelper.retrieveAllProvisioningEntries() ; + ArrayList<Map> pageItems = (ArrayList)entries.get("pageItems") ; + boolean provisioningetryAlreadyCreated = false ; + if(pageItems != null) { + for(Map item: pageItems) { + String date = (String)item.get("createdDate") ; + DateFormat formatter = new SimpleDateFormat("MMM dd, yyyy"); + try { + Date date1 = formatter.parse(date) ; + DateFormat simple = new SimpleDateFormat("dd MMMM yyyy"); + String formattedString = simple.format(Utils.getLocalDateOfTenant().toDate()); + Date currentDate = simple.parse(formattedString) ; + if(date1.getTime() == currentDate.getTime()) { + provisioningetryAlreadyCreated = true ; + break ; + } + } catch (ParseException e) { + e.printStackTrace(); + } + } + } + return provisioningetryAlreadyCreated ; + } +} http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/4b1ec9ef/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/SchedulerJobHelper.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/SchedulerJobHelper.java b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/SchedulerJobHelper.java new file mode 100644 index 0000000..882e14d --- /dev/null +++ b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/SchedulerJobHelper.java @@ -0,0 +1,148 @@ +/** + * 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; + +import java.util.ArrayList; +import java.util.HashMap; + +import org.junit.Assert; + +import com.google.gson.Gson; +import com.jayway.restassured.builder.ResponseSpecBuilder; +import com.jayway.restassured.specification.RequestSpecification; +import com.jayway.restassured.specification.ResponseSpecification; + +@SuppressWarnings({ "rawtypes", "unchecked" }) +public class SchedulerJobHelper { + + private final RequestSpecification requestSpec; + private final ResponseSpecification responseSpec; + + public SchedulerJobHelper(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) { + this.requestSpec = requestSpec; + this.responseSpec = responseSpec; + } + + public static ArrayList getAllSchedulerJobs(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) { + final String GET_ALL_SCHEDULER_JOBS_URL = "/fineract-provider/api/v1/jobs?" + Utils.TENANT_IDENTIFIER; + System.out.println("------------------------ RETRIEVING ALL SCHEDULER JOBS -------------------------"); + final ArrayList response = Utils.performServerGet(requestSpec, responseSpec, GET_ALL_SCHEDULER_JOBS_URL, ""); + return response; + } + + public static HashMap getSchedulerJobById(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, + final String jobId) { + final String GET_SCHEDULER_JOB_BY_ID_URL = "/fineract-provider/api/v1/jobs/" + jobId + "?" + Utils.TENANT_IDENTIFIER; + System.out.println("------------------------ RETRIEVING SCHEDULER JOB BY ID -------------------------"); + final HashMap response = Utils.performServerGet(requestSpec, responseSpec, GET_SCHEDULER_JOB_BY_ID_URL, ""); + return response; + } + + public static HashMap getSchedulerStatus(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) { + final String GET_SCHEDULER_STATUS_URL = "/fineract-provider/api/v1/scheduler?" + Utils.TENANT_IDENTIFIER; + System.out.println("------------------------ RETRIEVING SCHEDULER STATUS -------------------------"); + final HashMap response = Utils.performServerGet(requestSpec, responseSpec, GET_SCHEDULER_STATUS_URL, ""); + return response; + } + + public static void updateSchedulerStatus(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, + final String command) { + final String UPDATE_SCHEDULER_STATUS_URL = "/fineract-provider/api/v1/scheduler?command=" + command + "&" + Utils.TENANT_IDENTIFIER; + System.out.println("------------------------ UPDATING SCHEDULER STATUS -------------------------"); + Utils.performServerPost(requestSpec, responseSpec, UPDATE_SCHEDULER_STATUS_URL, runSchedulerJobAsJSON(), null); + } + + public static HashMap updateSchedulerJob(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, + final String jobId, final String active) { + final String UPDATE_SCHEDULER_JOB_URL = "/fineract-provider/api/v1/jobs/" + jobId + "?" + Utils.TENANT_IDENTIFIER; + System.out.println("------------------------ UPDATING SCHEDULER JOB -------------------------"); + final HashMap response = Utils.performServerPut(requestSpec, responseSpec, UPDATE_SCHEDULER_JOB_URL, + updateSchedulerJobAsJSON(active), "changes"); + return response; + } + + public static String updateSchedulerJobAsJSON(final String active) { + final HashMap<String, String> map = new HashMap<>(); + map.put("active", active); + System.out.println("map : " + map); + return new Gson().toJson(map); + } + + public static ArrayList getSchedulerJobHistory(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, + final String jobId) { + final String GET_SCHEDULER_STATUS_URL = "/fineract-provider/api/v1/jobs/" + jobId + "/runhistory?" + Utils.TENANT_IDENTIFIER; + System.out.println("------------------------ RETRIEVING SCHEDULER JOB HISTORY -------------------------"); + final HashMap response = Utils.performServerGet(requestSpec, responseSpec, GET_SCHEDULER_STATUS_URL, ""); + return (ArrayList) response.get("pageItems"); + } + + public static void runSchedulerJob(final RequestSpecification requestSpec, final String jobId) { + final ResponseSpecification responseSpec = new ResponseSpecBuilder().expectStatusCode(202).build(); + final String RUN_SCHEDULER_JOB_URL = "/fineract-provider/api/v1/jobs/" + jobId + "?command=executeJob&" + Utils.TENANT_IDENTIFIER; + System.out.println("------------------------ RUN SCHEDULER JOB -------------------------"); + Utils.performServerPost(requestSpec, responseSpec, RUN_SCHEDULER_JOB_URL, runSchedulerJobAsJSON(), null); + } + + public static String runSchedulerJobAsJSON() { + final HashMap<String, String> map = new HashMap<>(); + String runSchedulerJob = new Gson().toJson(map); + System.out.println(runSchedulerJob); + return runSchedulerJob; + } + + public void executeJob(String JobName) throws InterruptedException { + ArrayList<HashMap> allSchedulerJobsData = getAllSchedulerJobs(this.requestSpec, this.responseSpec); + Assert.assertNotNull(allSchedulerJobsData); + + for (Integer jobIndex = 0; jobIndex < allSchedulerJobsData.size(); jobIndex++) { + if (allSchedulerJobsData.get(jobIndex).get("displayName").equals(JobName)) { + Integer jobId = (Integer) allSchedulerJobsData.get(jobIndex).get("jobId"); + + // Executing Scheduler Job + runSchedulerJob(this.requestSpec, jobId.toString()); + + // Retrieving Scheduler Job by ID + HashMap schedulerJob = getSchedulerJobById(this.requestSpec, this.responseSpec, jobId.toString()); + Assert.assertNotNull(schedulerJob); + + // Waiting for Job to complete + while ((Boolean) schedulerJob.get("currentlyRunning") == true) { + Thread.sleep(15000); + schedulerJob = getSchedulerJobById(this.requestSpec, this.responseSpec, jobId.toString()); + Assert.assertNotNull(schedulerJob); + System.out.println("Job is Still Running"); + } + + ArrayList<HashMap> jobHistoryData = getSchedulerJobHistory(this.requestSpec, this.responseSpec, jobId.toString()); + + // print error associated with recent job failure (if any) + System.out.println("Job run error message (printed only if the job fails: " + + jobHistoryData.get(jobHistoryData.size() - 1).get("jobRunErrorMessage")); + System.out.println("Job failure error log (printed only if the job fails: " + + jobHistoryData.get(jobHistoryData.size() - 1).get("jobRunErrorLog")); + + // Verifying the Status of the Recently executed Scheduler Job + Assert.assertEquals("Verifying Last Scheduler Job Status", "success", + jobHistoryData.get(jobHistoryData.size() - 1).get("status")); + + break; + } + } + } +} \ 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/StandingInstructionsHelper.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/StandingInstructionsHelper.java b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/StandingInstructionsHelper.java new file mode 100644 index 0000000..bf44576 --- /dev/null +++ b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/StandingInstructionsHelper.java @@ -0,0 +1,128 @@ +/** + * 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; + +import java.util.HashMap; +import java.util.List; + +import org.apache.fineract.integrationtests.common.Utils; + +import ch.qos.logback.classic.pattern.Util; + +import com.google.gson.Gson; +import com.jayway.restassured.specification.RequestSpecification; +import com.jayway.restassured.specification.ResponseSpecification; + +@SuppressWarnings({ "unused", "rawtypes", "unchecked" }) +public class StandingInstructionsHelper { + + private static final String STANDING_INSTRUCTIONS_URL = "/fineract-provider/api/v1/standinginstructions"; + private static final String STANDING_INSTRUCTIONS_RUNHISTORY_URL = "/fineract-provider/api/v1/standinginstructionrunhistory"; + private static final String LOCALE = "en_GB"; + private static final String OFFICE_ID = "1"; + private static final String INSTRUCTION_TYPE_FIXED = "1"; + private static final String INSTRUCTION_TYPE_DUES = "2"; + private static final String PRIORITY_URGENT = "1"; + private static final String PRIORITY_HIGH = "2"; + private static final String PRIORITY_MEDIUM = "3"; + private static final String PRIORITY_LOW = "4"; + private static final String RECURRENCE_FREQUENCY_DAYS = "0"; + private static final String RECURRENCE_FREQUENCY_WEEKS = "1"; + private static final String RECURRENCE_FREQUENCY_MONTHS = "2"; + private static final String RECURRENCE_FREQUENCY_YEARS = "3"; + private static final String RECURRENCE_TYPE_PERIODIC = "1"; + private static final String RECURRENCE_TYPE_AS_PER_DUES = "2"; + private static final String STATUS_ACTIVE = "1"; + private static final String STATUS_DISABLED = "2"; + private static final String TRANSFER_TYPE_ACCOUNT_TRANSFER = "1"; + private static final String TRANSFER_TYPE_LOAN_REPAYMENT = "2"; + private static final String ACCOUNT_TRANSFER_DATE = "01 March 2013"; + + private String transferDate = ""; + private String officeId = OFFICE_ID; + + private RequestSpecification requestSpec; + private ResponseSpecification responseSpec; + + public StandingInstructionsHelper(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) { + this.requestSpec = requestSpec; + this.responseSpec = responseSpec; + } + + public String build(final String clientId, final String fromAccountId, final String toAccountId, final String fromAccountType, + final String toAccountType, final String validFrom, final String validTo, final String monthDay) { + + final HashMap<String, String> map = new HashMap<>(); + map.put("name", Utils.randomNameGenerator("STANDING_INSTRUCTION_", 5)); + map.put("dateFormat", "dd MMMM yyyy"); + map.put("monthDayFormat", "dd MMMM"); + map.put("locale", LOCALE); + map.put("fromClientId", clientId); + map.put("fromAccountId", fromAccountId); + map.put("fromAccountType", fromAccountType); + map.put("fromOfficeId", this.officeId); + map.put("toClientId", clientId); + map.put("toAccountId", toAccountId); + map.put("toAccountType", toAccountType); + map.put("toOfficeId", this.officeId); + map.put("amount", "500"); + map.put("transferType", TRANSFER_TYPE_ACCOUNT_TRANSFER); + map.put("priority", PRIORITY_URGENT); + map.put("status", STATUS_ACTIVE); + map.put("instructionType", INSTRUCTION_TYPE_FIXED); + map.put("validFrom", validFrom); + map.put("validTill", validTo); + map.put("recurrenceType", RECURRENCE_TYPE_PERIODIC); + map.put("recurrenceInterval", "1"); + map.put("recurrenceFrequency", RECURRENCE_FREQUENCY_WEEKS); + map.put("recurrenceOnMonthDay", monthDay); + String savingsApplicationJSON = new Gson().toJson(map); + System.out.println(savingsApplicationJSON); + return savingsApplicationJSON; + } + + public Integer createStandingInstruction(final String clientId, final String fromAccountId, final String toAccountId, + final String fromAccountType, final String toAccountType, final String validFrom, final String validTo, final String monthDay) { + System.out.println("-------------------------------- CREATE STANDING INSTRUCTIONS --------------------------------"); + final String standingInstructionAsJSON = new StandingInstructionsHelper(this.requestSpec, this.responseSpec) // + .build(clientId.toString(), fromAccountId.toString(), toAccountId.toString(), fromAccountType, toAccountType, validFrom, + validTo, monthDay); + return Utils.performServerPost(this.requestSpec, this.responseSpec, STANDING_INSTRUCTIONS_URL + "?" + Utils.TENANT_IDENTIFIER, + standingInstructionAsJSON, "resourceId"); + } + + public HashMap getStandingInstructionById(final String standingInstructionId) { + + System.out.println("----------------------------- RETRIEVING STANDING INSTRUCTION BY ID---------------------------"); + final String GET_STANDING_INSTRUCTION_BY_ID_URL = STANDING_INSTRUCTIONS_URL + "/" + standingInstructionId + "?" + + Utils.TENANT_IDENTIFIER; + final HashMap response = Utils.performServerGet(this.requestSpec, this.responseSpec, GET_STANDING_INSTRUCTION_BY_ID_URL, ""); + return response; + } + + public List<HashMap> getStandingInstructionHistory(Integer fromSavingsId, Integer fromAccountType, Integer fromClientId, Integer transferType) { + final String STANDING_INSTRUCTIONS_HISTORY_URL = STANDING_INSTRUCTIONS_RUNHISTORY_URL + "?" + Utils.TENANT_IDENTIFIER + + "&fromSavingsId=" + fromSavingsId + "&fromAccountType=" + fromAccountType + "&clientId=" + fromClientId + + "&transferType=" + transferType; + System.out.println("STANDING_INSTRUCTIONS_HISTORY_URL="+STANDING_INSTRUCTIONS_HISTORY_URL); + final List<HashMap> response = (List<HashMap>) Utils.performServerGet(this.requestSpec, this.responseSpec, + STANDING_INSTRUCTIONS_HISTORY_URL, "pageItems"); + 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/SurveyHelper.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/SurveyHelper.java b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/SurveyHelper.java new file mode 100644 index 0000000..2fb2b09 --- /dev/null +++ b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/SurveyHelper.java @@ -0,0 +1,74 @@ +/** + * 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; + +import com.google.gson.Gson; +import com.jayway.restassured.specification.RequestSpecification; +import com.jayway.restassured.specification.ResponseSpecification; + +import java.util.HashMap; + +import static org.junit.Assert.assertEquals; + +public class SurveyHelper { + + private static final String FULFIL_SURVEY_URL = "/fineract-provider/api/v1/survey/ppi_kenya_2009/clientId?" + Utils.TENANT_IDENTIFIER; + + public static Integer fulfilSurvey(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) { + return fulfilSurvey(requestSpec, responseSpec, "04 March 2011"); + } + + public static Integer fulfilSurvey(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, + final String activationDate) { + System.out.println("---------------------------------FULFIL PPI ---------------------------------------------"); + return Utils.performServerPost(requestSpec, responseSpec,FULFIL_SURVEY_URL, getTestPPIAsJSON(), "clientId"); + } + + public static String getTestPPIAsJSON() { + final HashMap<String, String> map = new HashMap<>(); + + map.put("date", "2014-05-19 00:00:00"); + map.put("ppi_household_members_cd_q1_householdmembers","107"); + map.put("ppi_highestschool_cd_q2_highestschool","112"); + map.put("ppi_businessoccupation_cd_q3_businessoccupation","116"); + map.put("dateFormat", "dd MMMM yyyy"); + map.put("locale", "en"); + map.put("ppi_habitablerooms_cd_q4_habitablerooms", "120"); + + map.put("ppi_floortype_cd_q5_floortype", "124"); + map.put("ppi_lightingsource_cd_q6_lightingsource", "126"); + map.put("ppi_irons_cd_q7_irons", "128"); + map.put("ppi_mosquitonets_cd_q8_mosquitonets", "132"); + map.put("ppi_towels_cd_q9_towels", "134"); + map.put("ppi_fryingpans_cd_q10_fryingpans", "138"); + + System.out.println("map : " + map); + return new Gson().toJson(map); + } + + public static void verifySurveyCreatedOnServer(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, + final Integer generatedClientID) { + System.out.println("------------------------------CHECK CLIENT DETAILS------------------------------------\n"); + final String SURVEY_URL = "/fineract-provider/api/v1/Survey/ppi_kenya_2009/clientid/entryId" + generatedClientID + "?" + Utils.TENANT_IDENTIFIER; + final Integer responseClientID = Utils.performServerGet(requestSpec, responseSpec, SURVEY_URL, "id"); + assertEquals("ERROR IN CREATING THE CLIENT", generatedClientID, responseClientID); + } + + +} \ 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/Utils.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/Utils.java b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/Utils.java new file mode 100644 index 0000000..3d173c3 --- /dev/null +++ b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/Utils.java @@ -0,0 +1,168 @@ +/** + * 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; + +import static com.jayway.restassured.RestAssured.given; +import static com.jayway.restassured.path.json.JsonPath.from; +import static org.hamcrest.Matchers.is; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.fail; + +import java.text.DateFormat; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Calendar; +import java.util.Locale; +import java.util.Random; +import java.util.TimeZone; + +import org.apache.commons.lang.StringUtils; +import org.apache.http.conn.HttpHostConnectException; +import org.joda.time.DateTimeZone; +import org.joda.time.LocalDate; + +import com.jayway.restassured.RestAssured; +import com.jayway.restassured.path.json.JsonPath; +import com.jayway.restassured.specification.RequestSpecification; +import com.jayway.restassured.specification.ResponseSpecification; + +/** + * Util for RestAssured tests. This class here in src/integrationTest is + * copy/pasted to src/test; please keep them in sync. + */ +@SuppressWarnings("unchecked") +public class Utils { + + public static final String TENANT_IDENTIFIER = "tenantIdentifier=default"; + + public static final String TENANT_TIME_ZONE = "Asia/Kolkata"; + + private static final String LOGIN_URL = "/fineract-provider/api/v1/authentication?username=mifos&password=password&" + TENANT_IDENTIFIER; + + public static void initializeRESTAssured() { + RestAssured.baseURI = "https://localhost"; + RestAssured.port = 8443; + RestAssured.keystore("src/main/resources/keystore.jks", "openmf"); + } + + public static String loginIntoServerAndGetBase64EncodedAuthenticationKey() { + try { + System.out.println("-----------------------------------LOGIN-----------------------------------------"); + final String json = RestAssured.post(LOGIN_URL).asString(); + assertThat("Failed to login into fineract platform", StringUtils.isBlank(json), is(false)); + return JsonPath.with(json).get("base64EncodedAuthenticationKey"); + } catch (final Exception e) { + if (e instanceof HttpHostConnectException) { + final HttpHostConnectException hh = (HttpHostConnectException) e; + fail("Failed to connect to fineract platform:" + hh.getMessage()); + } + + throw new RuntimeException(e); + } + } + + public static <T> T performServerGet(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, + final String getURL, final String jsonAttributeToGetBack) { + final String json = given().spec(requestSpec).expect().spec(responseSpec).log().ifError().when().get(getURL).andReturn().asString(); + if (jsonAttributeToGetBack == null) { return (T) json; } + return (T) from(json).get(jsonAttributeToGetBack); + } + + public static String performGetTextResponse(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, + final String getURL){ + return given().spec(requestSpec).expect().spec(responseSpec).log().ifError().when().get(getURL).andReturn().asString(); + } + + public static byte[] performGetBinaryResponse(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, + final String getURL){ + return given().spec(requestSpec).expect().spec(responseSpec).log().ifError().when().get(getURL).andReturn().asByteArray(); + } + + public static <T> T performServerPost(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, + final String postURL, final String jsonBodyToSend, final String jsonAttributeToGetBack) { + final String json = given().spec(requestSpec).body(jsonBodyToSend).expect().spec(responseSpec).log().ifError().when().post(postURL) + .andReturn().asString(); + if (jsonAttributeToGetBack == null) { return (T) json; } + return (T) from(json).get(jsonAttributeToGetBack); + } + + public static <T> T performServerPut(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, + final String putURL, final String jsonBodyToSend, final String jsonAttributeToGetBack) { + final String json = given().spec(requestSpec).body(jsonBodyToSend).expect().spec(responseSpec).log().ifError().when().put(putURL) + .andReturn().asString(); + return (T) from(json).get(jsonAttributeToGetBack); + } + + public static <T> T performServerDelete(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, + final String deleteURL, final String jsonAttributeToGetBack) { + final String json = given().spec(requestSpec).expect().spec(responseSpec).log().ifError().when().delete(deleteURL).andReturn() + .asString(); + return (T) from(json).get(jsonAttributeToGetBack); + } + + public static String convertDateToURLFormat(final String dateToBeConvert) { + final SimpleDateFormat oldFormat = new SimpleDateFormat("dd MMMMMM yyyy", Locale.US); + final SimpleDateFormat newFormat = new SimpleDateFormat("yyyy-MM-dd"); + String reformattedStr = ""; + try { + reformattedStr = newFormat.format(oldFormat.parse(dateToBeConvert)); + } catch (final ParseException e) { + e.printStackTrace(); + } + return reformattedStr; + } + + public static String randomStringGenerator(final String prefix, final int len, final String sourceSetString) { + final int lengthOfSource = sourceSetString.length(); + final Random rnd = new Random(); + final StringBuilder sb = new StringBuilder(len); + for (int i = 0; i < len; i++) { + sb.append((sourceSetString).charAt(rnd.nextInt(lengthOfSource))); + } + return (prefix + (sb.toString())); + } + + public static String randomStringGenerator(final String prefix, final int len) { + return randomStringGenerator(prefix, len, "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"); + } + + public static String randomNameGenerator(final String prefix, final int lenOfRandomSuffix) { + return randomStringGenerator(prefix, lenOfRandomSuffix); + } + + public static String convertDateToURLFormat(final Calendar dateToBeConvert) { + DateFormat dateFormat = new SimpleDateFormat("dd MMMMMM yyyy"); + dateFormat.setTimeZone(Utils.getTimeZoneOfTenant()); + return dateFormat.format(dateToBeConvert.getTime()); + } + + public static LocalDate getLocalDateOfTenant() { + LocalDate today = new LocalDate(); + final DateTimeZone zone = DateTimeZone.forID(TENANT_TIME_ZONE); + if (zone != null) { + today = new LocalDate(zone); + } + return today; + } + + public static TimeZone getTimeZoneOfTenant() { + return TimeZone.getTimeZone(TENANT_TIME_ZONE); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/4b1ec9ef/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/WorkingDaysHelper.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/WorkingDaysHelper.java b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/WorkingDaysHelper.java new file mode 100755 index 0000000..8d5f808 --- /dev/null +++ b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/WorkingDaysHelper.java @@ -0,0 +1,83 @@ +/** + * 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; + +import java.util.HashMap; +import java.util.Random; + +import com.google.gson.Gson; +import com.jayway.restassured.specification.RequestSpecification; +import com.jayway.restassured.specification.ResponseSpecification; + +public class WorkingDaysHelper { + + private static final String WORKINGDAYS_URL = "/fineract-provider/api/v1/workingdays"; + + public static Object updateWorkingDays(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) { + final String UPDATE_WORKINGDAYS_URL = WORKINGDAYS_URL + "?" + Utils.TENANT_IDENTIFIER; + System.out.println("---------------------------------UPDATE WORKINGDAY---------------------------------------------"); + return Utils.performServerPut(requestSpec, responseSpec, UPDATE_WORKINGDAYS_URL, updateWorkingDaysAsJson(), ""); + } + + public static Object updateWorkingDaysWithWrongRecurrence(final RequestSpecification requestSpec, + final ResponseSpecification responseSpec, String jsonAttributeToGetback) { + final String UPDATE_WORKINGDAYS_URL = WORKINGDAYS_URL + "?" + Utils.TENANT_IDENTIFIER; + System.out + .println("---------------------------------UPDATE WORKINGDAY WITH WRONG RECURRENCE-----------------------------------------"); + return Utils.performServerPut(requestSpec, responseSpec, UPDATE_WORKINGDAYS_URL, updateWorkingDayWithWrongRecur(), + jsonAttributeToGetback); + } + + public static String updateWorkingDaysAsJson() { + final HashMap<String, Object> map = new HashMap<>(); + map.put("recurrence", "FREQ=WEEKLY;INTERVAL=1;BYDAY=MO,TU,WE,TH,FR,SA,SU"); + map.put("locale", "en"); + map.put("repaymentRescheduleType", randomInt(1, 4)); + map.put("extendTermForDailyRepayments", false); + System.out.println("map : " + map); + return new Gson().toJson(map); + } + + public static String updateWorkingDayWithWrongRecur() { + final HashMap<String, Object> map = new HashMap<>(); + map.put("recurrence", "FREQ=WEEKLY;INTERVAL=1;BYDAY=MP,TI,TE,TH"); + map.put("locale", "en"); + map.put("repaymentRescheduleType", randomInt(1, 4)); + map.put("extendTermForDailyRepayments", false); + System.out.println("map : " + map); + return new Gson().toJson(map); + } + + public static int randomInt(int low, int high) { + int i = new Random().nextInt(high) + low; + return i; + } + + public static int workingDaysId(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) { + HashMap<String, Object> workingDays = getAllWorkingDays(requestSpec, responseSpec); + return (int) workingDays.get("id"); + } + + public static HashMap<String, Object> getAllWorkingDays(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) { + + return Utils.performServerGet(requestSpec, responseSpec, WORKINGDAYS_URL + "?" + Utils.TENANT_IDENTIFIER, ""); + + } + +} http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/4b1ec9ef/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/accounting/Account.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/accounting/Account.java b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/accounting/Account.java new file mode 100644 index 0000000..2cb9de0 --- /dev/null +++ b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/accounting/Account.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; + +public class Account { + + public enum AccountType { + ASSET("1"), INCOME("4"), EXPENSE("5"), LIABILITY("2"), EQUITY("3"); + + private final String accountValue; + + AccountType(final String accountValue) { + this.accountValue = accountValue; + } + + @Override + public String toString() { + return this.accountValue; + } + } + + private final AccountType accountType; + private final Integer accountID; + + public Account(final Integer accountID, final AccountType accountType) { + this.accountID = accountID; + this.accountType = accountType; + } + + public AccountType getAccountType() { + return this.accountType; + } + + public Integer getAccountID() { + return this.accountID; + } +} http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/4b1ec9ef/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/accounting/AccountHelper.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/accounting/AccountHelper.java b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/accounting/AccountHelper.java new file mode 100644 index 0000000..3362857 --- /dev/null +++ b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/accounting/AccountHelper.java @@ -0,0 +1,83 @@ +/** + * 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.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 AccountHelper { + + private final String CREATE_GL_ACCOUNT_URL = "/fineract-provider/api/v1/glaccounts?" + Utils.TENANT_IDENTIFIER; + private final String GL_ACCOUNT_ID_RESPONSE = "resourceId"; + + private final RequestSpecification requestSpec; + private final ResponseSpecification responseSpec; + + public AccountHelper(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) { + this.requestSpec = requestSpec; + this.responseSpec = responseSpec; + } + + public Account createAssetAccount() { + final String assetAccountJSON = new GLAccountBuilder().withAccountTypeAsAsset().build(); + final Integer accountID = Utils.performServerPost(this.requestSpec, this.responseSpec, this.CREATE_GL_ACCOUNT_URL, + assetAccountJSON, this.GL_ACCOUNT_ID_RESPONSE); + return new Account(accountID, Account.AccountType.ASSET); + } + + public Account createIncomeAccount() { + final String assetAccountJSON = new GLAccountBuilder().withAccountTypeAsIncome().build(); + final Integer accountID = Utils.performServerPost(this.requestSpec, this.responseSpec, this.CREATE_GL_ACCOUNT_URL, + assetAccountJSON, this.GL_ACCOUNT_ID_RESPONSE); + return new Account(accountID, Account.AccountType.INCOME); + } + + public Account createExpenseAccount() { + final String assetAccountJSON = new GLAccountBuilder().withAccountTypeAsExpense().build(); + final Integer accountID = Utils.performServerPost(this.requestSpec, this.responseSpec, this.CREATE_GL_ACCOUNT_URL, + assetAccountJSON, this.GL_ACCOUNT_ID_RESPONSE); + return new Account(accountID, Account.AccountType.EXPENSE); + } + + public Account createLiabilityAccount() { + final String liabilityAccountJSON = new GLAccountBuilder().withAccountTypeAsLiability().build(); + final Integer accountID = Utils.performServerPost(this.requestSpec, this.responseSpec, this.CREATE_GL_ACCOUNT_URL, + liabilityAccountJSON, this.GL_ACCOUNT_ID_RESPONSE); + return new Account(accountID, Account.AccountType.LIABILITY); + } + + public ArrayList getAccountingWithRunningBalances() { + final String GET_RUNNING_BALANCE_URL = "/fineract-provider/api/v1/glaccounts?fetchRunningBalance=true"; + final ArrayList<HashMap> accountRunningBalance = Utils.performServerGet(this.requestSpec, this.responseSpec, GET_RUNNING_BALANCE_URL, ""); + return accountRunningBalance; + } + + public HashMap getAccountingWithRunningBalanceById(final String accountId) { + final String GET_RUNNING_BALANCE_URL = "/fineract-provider/api/v1/glaccounts/" + accountId + "?fetchRunningBalance=true"; + final HashMap accountRunningBalance = Utils.performServerGet(this.requestSpec, this.responseSpec, GET_RUNNING_BALANCE_URL, ""); + return accountRunningBalance; + } + +} http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/4b1ec9ef/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/accounting/FinancialActivityAccountHelper.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/accounting/FinancialActivityAccountHelper.java b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/accounting/FinancialActivityAccountHelper.java new file mode 100755 index 0000000..ae20cda --- /dev/null +++ b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/accounting/FinancialActivityAccountHelper.java @@ -0,0 +1,69 @@ +/** + * 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 java.util.List; + +import org.apache.fineract.integrationtests.common.Utils; + +import com.jayway.restassured.specification.RequestSpecification; +import com.jayway.restassured.specification.ResponseSpecification; + +@SuppressWarnings("rawtypes") +public class FinancialActivityAccountHelper { + + private static final String FINANCIAL_ACTIVITY_ACCOUNT_MAPPING_URL = "/fineract-provider/api/v1/financialactivityaccounts"; + private final RequestSpecification requestSpec; + + public FinancialActivityAccountHelper(final RequestSpecification requestSpec) { + this.requestSpec = requestSpec; + } + + public Object createFinancialActivityAccount(Integer financialActivityId, Integer glAccountId, + final ResponseSpecification responseSpecification, String jsonBack) { + String json = FinancialActivityAccountsMappingBuilder.build(financialActivityId, glAccountId); + return Utils.performServerPost(this.requestSpec, responseSpecification, FINANCIAL_ACTIVITY_ACCOUNT_MAPPING_URL + "?" + + Utils.TENANT_IDENTIFIER, json, jsonBack); + } + + public Object updateFinancialActivityAccount(Integer financialActivityAccountId, Integer financialActivityId, Integer glAccountId, + final ResponseSpecification responseSpecification, String jsonBack) { + String json = FinancialActivityAccountsMappingBuilder.build(financialActivityId, glAccountId); + return Utils.performServerPut(this.requestSpec, responseSpecification, FINANCIAL_ACTIVITY_ACCOUNT_MAPPING_URL + "/" + + financialActivityAccountId + "?" + Utils.TENANT_IDENTIFIER, json, jsonBack); + } + + public HashMap getFinancialActivityAccount(final Integer financialActivityAccountId, final ResponseSpecification responseSpecification) { + final String url = FINANCIAL_ACTIVITY_ACCOUNT_MAPPING_URL + "/" + financialActivityAccountId + "?" + Utils.TENANT_IDENTIFIER; + return Utils.performServerGet(requestSpec, responseSpecification, url, ""); + } + + public List<HashMap> getAllFinancialActivityAccounts(final ResponseSpecification responseSpecification) { + final String url = FINANCIAL_ACTIVITY_ACCOUNT_MAPPING_URL + "?" + Utils.TENANT_IDENTIFIER; + return Utils.performServerGet(this.requestSpec, responseSpecification, url, ""); + } + + public Integer deleteFinancialActivityAccount(final Integer financialActivityAccountId, + final ResponseSpecification responseSpecification, String jsonBack) { + final String url = FINANCIAL_ACTIVITY_ACCOUNT_MAPPING_URL + "/" + financialActivityAccountId + "?" + Utils.TENANT_IDENTIFIER; + return Utils.performServerDelete(this.requestSpec, responseSpecification, url, jsonBack); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/4b1ec9ef/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/accounting/FinancialActivityAccountsMappingBuilder.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/accounting/FinancialActivityAccountsMappingBuilder.java b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/accounting/FinancialActivityAccountsMappingBuilder.java new file mode 100755 index 0000000..2436330 --- /dev/null +++ b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/accounting/FinancialActivityAccountsMappingBuilder.java @@ -0,0 +1,33 @@ +/** + * 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 com.google.gson.Gson; + +public class FinancialActivityAccountsMappingBuilder { + + public static String build(Integer financialActivityId, Integer glAccountId) { + final HashMap<String, Object> map = new HashMap<>(); + map.put("financialActivityId", financialActivityId); + map.put("glAccountId", glAccountId); + 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/accounting/GLAccountBuilder.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/accounting/GLAccountBuilder.java b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/accounting/GLAccountBuilder.java new file mode 100644 index 0000000..502e0d1 --- /dev/null +++ b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/accounting/GLAccountBuilder.java @@ -0,0 +1,110 @@ +/** + * 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.Calendar; +import java.util.HashMap; + +import org.apache.fineract.integrationtests.common.Utils; + +import com.google.gson.Gson; + +public class GLAccountBuilder { + + public static final String ASSET_ACCOUNT = "1"; + public static final String LIABILITY_ACCOUNT = "2"; + public static final String EQUITY_ACCOUNT = "3"; + public static final String INCOME_ACCOUNT = "4"; + public static final String EXPENSE_ACCOUNT = "5"; + + private static final String ACCOUNT_USAGE_DETAIL = "1"; + private static final String ACCOUNT_USAGE_HEADER = "2"; + private static final String MANUAL_ENTRIES_ALLOW = "true"; + private static final String MANUAL_ENTRIES_NOT_ALLOW = "false"; + + private static String name = Utils.randomStringGenerator("ACCOUNT_NAME_", 5); + + private static String GLCode = ""; + private static String accountType = ""; + private static String accountUsage = ACCOUNT_USAGE_DETAIL; + private static String manualEntriesAllowed = MANUAL_ENTRIES_ALLOW; + private static String description = "DEFAULT_DESCRIPTION"; + + public String build() { + final HashMap<String, String> map = new HashMap<>(); + map.put("name", GLAccountBuilder.name); + map.put("glCode", GLAccountBuilder.GLCode); + map.put("manualEntriesAllowed", GLAccountBuilder.manualEntriesAllowed); + map.put("type", GLAccountBuilder.accountType); + map.put("usage", GLAccountBuilder.accountUsage); + map.put("description", GLAccountBuilder.description); + return new Gson().toJson(map); + } + + public GLAccountBuilder withAccountTypeAsAsset() { + GLAccountBuilder.accountType = ASSET_ACCOUNT; + GLAccountBuilder.GLCode = Utils.randomStringGenerator("ASSET_", 2); + GLAccountBuilder.GLCode += Calendar.getInstance().getTimeInMillis() + ""; // Added + // unique + // timestamp + // for + // avoiding + // random + // collisions + return this; + } + + public GLAccountBuilder withAccountTypeAsLiability() { + GLAccountBuilder.accountType = LIABILITY_ACCOUNT; + GLAccountBuilder.GLCode = Utils.randomStringGenerator("LIABILITY_", 2); + GLAccountBuilder.GLCode += Calendar.getInstance().getTimeInMillis() + ""; + return this; + } + + public GLAccountBuilder withAccountTypeAsAsEquity() { + GLAccountBuilder.accountType = EQUITY_ACCOUNT; + GLAccountBuilder.GLCode = Utils.randomStringGenerator("EQUITY_", 2); + GLAccountBuilder.GLCode += Calendar.getInstance().getTimeInMillis() + ""; + return this; + } + + public GLAccountBuilder withAccountTypeAsIncome() { + GLAccountBuilder.accountType = INCOME_ACCOUNT; + GLAccountBuilder.GLCode = Utils.randomStringGenerator("INCOME_", 2); + GLAccountBuilder.GLCode += Calendar.getInstance().getTimeInMillis() + ""; + return this; + } + + public GLAccountBuilder withAccountTypeAsExpense() { + GLAccountBuilder.accountType = EXPENSE_ACCOUNT; + GLAccountBuilder.GLCode = Utils.randomStringGenerator("EXPENSE_", 2); + GLAccountBuilder.GLCode += Calendar.getInstance().getTimeInMillis() + ""; + return this; + } + + public GLAccountBuilder withAccountUsageAsHeader() { + GLAccountBuilder.accountUsage = ACCOUNT_USAGE_HEADER; + return this; + } + + public GLAccountBuilder withMaualEntriesNotAllowed() { + GLAccountBuilder.manualEntriesAllowed = MANUAL_ENTRIES_NOT_ALLOW; + return this; + } +} http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/4b1ec9ef/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/accounting/JournalEntry.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/accounting/JournalEntry.java b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/accounting/JournalEntry.java new file mode 100644 index 0000000..bbfd8fd --- /dev/null +++ b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/accounting/JournalEntry.java @@ -0,0 +1,56 @@ +/** + * 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; + +public class JournalEntry { + + public enum TransactionType { + CREDIT("CREDIT"), DEBIT("DEBIT"); + + private TransactionType(final String type) { + this.type = type; + } + + private final String type; + + @Override + public String toString() { + return this.type; + } + } + + private final Float transactionAmount; + private final TransactionType transactionType; + private final Integer officeId; + + public JournalEntry(final float transactionAmount, final TransactionType type) { + this.transactionAmount = transactionAmount; + this.transactionType = type; + this.officeId = null; + } + + public Float getTransactionAmount() { + return this.transactionAmount; + } + + public String getTransactionType() { + return this.transactionType.toString(); + } + +}
