You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@fineract.apache.org by ar...@apache.org on 2022/06/29 13:57:20 UTC
[fineract] branch develop updated: Implement integration tests for Accounting rules
This is an automated email from the ASF dual-hosted git repository.
arnold pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/fineract.git
The following commit(s) were added to refs/heads/develop by this push:
new 9c8239a9b Implement integration tests for Accounting rules
9c8239a9b is described below
commit 9c8239a9b10fa65417359265cc8dd444c9e0e907
Author: Jose Alberto Hernandez <al...@MacBook-Pro.local>
AuthorDate: Sun Jun 19 10:23:22 2022 -0500
Implement integration tests for Accounting rules
---
.../accounting/AccountingRuleIntegrationTest.java | 79 ++++++++++++++++++++++
.../common/accounting/AccountRuleHelper.java | 59 ++++++++++++++++
.../common/accounting/AccountingRuleBuilder.java | 58 ++++++++++++++++
3 files changed, 196 insertions(+)
diff --git a/integration-tests/src/test/java/org/apache/fineract/integrationtests/accounting/AccountingRuleIntegrationTest.java b/integration-tests/src/test/java/org/apache/fineract/integrationtests/accounting/AccountingRuleIntegrationTest.java
new file mode 100644
index 000000000..9d6698dc0
--- /dev/null
+++ b/integration-tests/src/test/java/org/apache/fineract/integrationtests/accounting/AccountingRuleIntegrationTest.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.accounting;
+
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import io.restassured.builder.RequestSpecBuilder;
+import io.restassured.builder.ResponseSpecBuilder;
+import io.restassured.http.ContentType;
+import io.restassured.specification.RequestSpecification;
+import io.restassured.specification.ResponseSpecification;
+import java.util.ArrayList;
+import org.apache.fineract.client.models.GetAccountRulesResponse;
+import org.apache.fineract.client.models.GetOfficesResponse;
+import org.apache.fineract.client.models.PostAccountingRulesResponse;
+import org.apache.fineract.integrationtests.common.OfficeHelper;
+import org.apache.fineract.integrationtests.common.Utils;
+import org.apache.fineract.integrationtests.common.accounting.Account;
+import org.apache.fineract.integrationtests.common.accounting.AccountHelper;
+import org.apache.fineract.integrationtests.common.accounting.AccountRuleHelper;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+public class AccountingRuleIntegrationTest {
+
+ private ResponseSpecification responseSpec;
+ private RequestSpecification requestSpec;
+
+ private AccountHelper accountHelper;
+ private AccountRuleHelper accountRuleHelper;
+
+ @BeforeEach
+ public void setup() {
+ Utils.initializeRESTAssured();
+
+ requestSpec = new RequestSpecBuilder().setContentType(ContentType.JSON).build();
+ requestSpec.header("Authorization", "Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey());
+ responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build();
+
+ accountRuleHelper = new AccountRuleHelper(requestSpec, responseSpec);
+ accountHelper = new AccountHelper(requestSpec, responseSpec);
+ }
+
+ @Test
+ public void testAccountingRuleCreation() {
+ // given
+ final Account accountToCredit = accountHelper.createIncomeAccount();
+ final Account accountToDebit = accountHelper.createExpenseAccount();
+ final GetOfficesResponse headOffice = OfficeHelper.getHeadOffice(requestSpec, responseSpec);
+
+ // when
+ final PostAccountingRulesResponse accountingRule = accountRuleHelper.createAccountRule(headOffice.getId(), accountToCredit,
+ accountToDebit);
+ final ArrayList<GetAccountRulesResponse> accountingRules = accountRuleHelper.getAccountingRules();
+
+ // then
+ assertNotNull(accountingRule);
+ assertNotNull(accountingRule.getResourceId());
+ assertNotNull(accountingRules);
+ assertTrue(accountingRules.size() > 0);
+ }
+}
diff --git a/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/accounting/AccountRuleHelper.java b/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/accounting/AccountRuleHelper.java
new file mode 100644
index 000000000..c13db44a2
--- /dev/null
+++ b/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/accounting/AccountRuleHelper.java
@@ -0,0 +1,59 @@
+/**
+ * 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 com.google.gson.Gson;
+import com.linecorp.armeria.internal.shaded.guava.reflect.TypeToken;
+import io.restassured.specification.RequestSpecification;
+import io.restassured.specification.ResponseSpecification;
+import java.lang.reflect.Type;
+import java.util.ArrayList;
+import org.apache.fineract.client.models.GetAccountRulesResponse;
+import org.apache.fineract.client.models.PostAccountingRulesResponse;
+import org.apache.fineract.client.util.JSON;
+import org.apache.fineract.integrationtests.common.Utils;
+
+public class AccountRuleHelper {
+
+ private static final Gson GSON = new JSON().getGson();
+
+ private static final String ACCOUNTINGRULES_URL = "/fineract-provider/api/v1/accountingrules?" + Utils.TENANT_IDENTIFIER;
+
+ private final RequestSpecification requestSpec;
+ private final ResponseSpecification responseSpec;
+
+ public AccountRuleHelper(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) {
+ this.requestSpec = requestSpec;
+ this.responseSpec = responseSpec;
+ }
+
+ public ArrayList<GetAccountRulesResponse> getAccountingRules() {
+ final String response = Utils.performServerGet(this.requestSpec, this.responseSpec, ACCOUNTINGRULES_URL);
+ Type accountRuleListType = new TypeToken<ArrayList<GetAccountRulesResponse>>() {}.getType();
+ return GSON.fromJson(response, accountRuleListType);
+ }
+
+ public PostAccountingRulesResponse createAccountRule(final Long officeId, final Account accountToCredit, final Account accountToDebit) {
+ final String assetAccountJSON = new AccountingRuleBuilder()
+ .withGLAccounts(accountToCredit.getAccountID(), accountToDebit.getAccountID()).withOffice(officeId).build();
+ final String response = Utils.performServerPost(requestSpec, responseSpec, ACCOUNTINGRULES_URL, assetAccountJSON);
+ return GSON.fromJson(response, PostAccountingRulesResponse.class);
+ }
+
+}
diff --git a/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/accounting/AccountingRuleBuilder.java b/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/accounting/AccountingRuleBuilder.java
new file mode 100644
index 000000000..5eb467b50
--- /dev/null
+++ b/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/accounting/AccountingRuleBuilder.java
@@ -0,0 +1,58 @@
+/**
+ * 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 com.google.gson.Gson;
+import java.util.HashMap;
+import org.apache.fineract.integrationtests.common.Utils;
+
+public class AccountingRuleBuilder {
+
+ private Long officeId;
+ private Integer accountToCreditId;
+ private Integer accountToDebitId;
+ private String name;
+ private String description;
+
+ public AccountingRuleBuilder() {
+ name = Utils.randomStringGenerator("ACCOUNTRULE_NAME_", 5);
+ description = name;
+ }
+
+ public String build() {
+ final HashMap<String, Object> map = new HashMap<>();
+ map.put("name", name);
+ map.put("officeId", officeId);
+ map.put("accountToCredit", accountToCreditId);
+ map.put("accountToDebit", accountToDebitId);
+ map.put("description", description);
+ return new Gson().toJson(map);
+ }
+
+ public AccountingRuleBuilder withGLAccounts(final Integer accountToCreditId, final Integer accountToDebitId) {
+ this.accountToCreditId = accountToCreditId;
+ this.accountToDebitId = accountToDebitId;
+ return this;
+ }
+
+ public AccountingRuleBuilder withOffice(final Long officeId) {
+ this.officeId = officeId;
+ return this;
+ }
+}