galovics commented on code in PR #2369:
URL: https://github.com/apache/fineract/pull/2369#discussion_r906373825


##########
integration-tests/src/test/java/org/apache/fineract/integrationtests/accounting/AccountingRuleIntegrationTest.java:
##########
@@ -0,0 +1,80 @@
+/**
+ * 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.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+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.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;
+
+    private Account accountToCredit;
+    private Account accountToDebit;
+    private GetOfficesResponse headOffice;
+
+    @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
+        accountToCredit = accountHelper.createIncomeAccount();

Review Comment:
   Let's keep this as local variables. It's important to not store state on an 
object/class level to prevent potential concurrency issues in the future (if we 
decide to run the tests in parallel mode)



##########
integration-tests/src/test/java/org/apache/fineract/integrationtests/common/accounting/AccountRuleHelper.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 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.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 static final String ACCOUNTRULE_ID_RESPONSE = "resourceId";
+
+    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 Integer createAccountRule(final Long officeId, final Account 
accountToCredit, final Account accountToDebit) {
+        final String assetAccountJSON = new AccountingRuleBuilder()

Review Comment:
   Why don't we use the generated models here as well?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to