From 6f1acd13dcbf2c93c06451f55a9bcff5c9f99de3 Mon Sep 17 00:00:00 2001 From: Karan Singh Date: Tue, 24 Mar 2020 21:36:00 -0400 Subject: [PATCH 01/12] FINERACT-38: Adding 2 test cases to check RunningBalanceNotCalculatedException. --- ...culateIncomeAndExpanseBookingImplTest.java | 101 ++++++++++++++++++ .../CalculateIncomeAndExpenseBookingImpl.java | 13 +-- 2 files changed, 108 insertions(+), 6 deletions(-) create mode 100644 fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/CalculateIncomeAndExpanseBookingImplTest.java diff --git a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/CalculateIncomeAndExpanseBookingImplTest.java b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/CalculateIncomeAndExpanseBookingImplTest.java new file mode 100644 index 00000000000..4d2088a59b7 --- /dev/null +++ b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/CalculateIncomeAndExpanseBookingImplTest.java @@ -0,0 +1,101 @@ +/** + * 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; + + +import org.apache.fineract.accounting.closure.command.GLClosureCommand; +import org.apache.fineract.accounting.closure.data.IncomeAndExpenseJournalEntryData; +import org.apache.fineract.accounting.closure.domain.GLClosureRepository; +import org.apache.fineract.accounting.closure.exception.RunningBalanceNotCalculatedException; +import org.apache.fineract.accounting.closure.serialization.GLClosureCommandFromApiJsonDeserializer; +import org.apache.fineract.accounting.closure.service.CalculateIncomeAndExpenseBookingImpl; +import org.apache.fineract.accounting.closure.service.IncomeAndExpenseReadPlatformService; +import org.apache.fineract.accounting.glaccount.domain.GLAccountRepositoryWrapper; +import org.apache.fineract.infrastructure.core.api.JsonQuery; +import org.apache.fineract.organisation.office.domain.OfficeRepositoryWrapper; +import org.apache.fineract.organisation.office.service.OfficeReadPlatformService; +import org.joda.time.LocalDate; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.springframework.beans.factory.annotation.Autowired; + +import java.util.ArrayList; +import java.util.List; + +/** + * JUnit Test Cases for Account Transfer for. + */ +public class CalculateIncomeAndExpanseBookingImplTest { + + /* + Test class CalculateIncomeAndExpenseBookingImpl + */ + @Autowired + private CalculateIncomeAndExpenseBookingImpl calculateIncomeAndExpenseBooking; + private GLClosureCommandFromApiJsonDeserializer fromApiJsonDeserializer; + private OfficeRepositoryWrapper officeRepository; + private GLClosureRepository glClosureRepository; + private GLAccountRepositoryWrapper glAccountRepository; + private IncomeAndExpenseReadPlatformService incomeAndExpenseReadPlatformService; + private OfficeReadPlatformService officeReadPlatformService; + + @Before + public void setup() { + } + + @After + public void tearDown() { + + } + + /* + Case 1: All running balances has to be calculated before booking off income and expense account + No exception is to be thrown since it is running for the input. + However, later a null pointer exception is thrown, since the object incomeAndExpense is not initialized. + */ + @Test(expected = Exception.class) + public void testBookOffIncomeAndExpense() { + JsonQuery query = new JsonQuery("select command to extract income and expanse", null, null); + GLClosureCommand glClosureCommand = new GLClosureCommand((long)10,(long)10, new LocalDate(),"Closing comment", false, (long)10 , "CAD", false, false, "comment" ); + IncomeAndExpenseJournalEntryData incomeAndExpenseJournalEntryData= new IncomeAndExpenseJournalEntryData(null, null,null, null + , true, true, null,null,null,10,10,null,null); + List incomeAndExpenseJournalEntryDataList = new ArrayList<>(); + incomeAndExpenseJournalEntryDataList.add(incomeAndExpenseJournalEntryData); + calculateIncomeAndExpenseBooking.bookOffIncomeAndExpense(incomeAndExpenseJournalEntryDataList, glClosureCommand, false,null,null); + + } + + /* + Case 2: All running balances has to be calculated before booking off income and expense account + If not running balances, then throw exception + */ + @Test(expected = RunningBalanceNotCalculatedException.class) + public void testBookOffIncomeAndExpenseCheckException() { + JsonQuery query = new JsonQuery("select command to extract income and expanse", null, null); + GLClosureCommand glClosureCommand = new GLClosureCommand((long)10,(long)10, new LocalDate(),"Closing comment", false, (long)10 , "CAD", false, false, "comment" ); + IncomeAndExpenseJournalEntryData incomeAndExpenseJournalEntryData= new IncomeAndExpenseJournalEntryData(null, null,null, null + , true, true, null,null,null,10,10,null,null); + List incomeAndExpenseJournalEntryDataList = new ArrayList(); + incomeAndExpenseJournalEntryDataList.add(incomeAndExpenseJournalEntryData); + calculateIncomeAndExpenseBooking.bookOffIncomeAndExpense(incomeAndExpenseJournalEntryDataList,glClosureCommand, false,null,null); + + } + +} \ No newline at end of file diff --git a/fineract-provider/src/main/java/org/apache/fineract/accounting/closure/service/CalculateIncomeAndExpenseBookingImpl.java b/fineract-provider/src/main/java/org/apache/fineract/accounting/closure/service/CalculateIncomeAndExpenseBookingImpl.java index b454581daca..13216144dea 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/accounting/closure/service/CalculateIncomeAndExpenseBookingImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/accounting/closure/service/CalculateIncomeAndExpenseBookingImpl.java @@ -19,11 +19,6 @@ package org.apache.fineract.accounting.closure.service; -import java.math.BigDecimal; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Date; -import java.util.List; import org.apache.fineract.accounting.closure.command.GLClosureCommand; import org.apache.fineract.accounting.closure.data.IncomeAndExpenseBookingData; import org.apache.fineract.accounting.closure.data.IncomeAndExpenseJournalEntryData; @@ -47,6 +42,12 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Date; +import java.util.List; + @Service public class CalculateIncomeAndExpenseBookingImpl implements CalculateIncomeAndExpenseBooking { @@ -124,7 +125,7 @@ public Collection CalculateIncomeAndExpenseBookings return incomeAndExpenseBookingCollection; } - private IncomeAndExpenseBookingData bookOffIncomeAndExpense(final List incomeAndExpenseJournalEntryDataList, + public IncomeAndExpenseBookingData bookOffIncomeAndExpense(final List incomeAndExpenseJournalEntryDataList, final GLClosureCommand closureData,final boolean preview,final GLAccount glAccount,final Office office){ /* All running balances has to be calculated before booking off income and expense account */ boolean isRunningBalanceCalculated = true; From d4ac3aed5c36381a03227cb0b7adcc49b2ce9fe4 Mon Sep 17 00:00:00 2001 From: Karan Singh Date: Fri, 3 Apr 2020 03:55:04 -0400 Subject: [PATCH 02/12] FINERACT-38 : Renaming and Updating test: --- ...comeAndExpanseBookingIntegrationTest.java} | 77 +++++++++---------- 1 file changed, 36 insertions(+), 41 deletions(-) rename fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/{CalculateIncomeAndExpanseBookingImplTest.java => CalculateIncomeAndExpanseBookingIntegrationTest.java} (70%) diff --git a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/CalculateIncomeAndExpanseBookingImplTest.java b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/CalculateIncomeAndExpanseBookingIntegrationTest.java similarity index 70% rename from fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/CalculateIncomeAndExpanseBookingImplTest.java rename to fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/CalculateIncomeAndExpanseBookingIntegrationTest.java index 4d2088a59b7..b2e27848652 100644 --- a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/CalculateIncomeAndExpanseBookingImplTest.java +++ b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/CalculateIncomeAndExpanseBookingIntegrationTest.java @@ -23,79 +23,74 @@ import org.apache.fineract.accounting.closure.data.IncomeAndExpenseJournalEntryData; import org.apache.fineract.accounting.closure.domain.GLClosureRepository; import org.apache.fineract.accounting.closure.exception.RunningBalanceNotCalculatedException; -import org.apache.fineract.accounting.closure.serialization.GLClosureCommandFromApiJsonDeserializer; import org.apache.fineract.accounting.closure.service.CalculateIncomeAndExpenseBookingImpl; import org.apache.fineract.accounting.closure.service.IncomeAndExpenseReadPlatformService; import org.apache.fineract.accounting.glaccount.domain.GLAccountRepositoryWrapper; -import org.apache.fineract.infrastructure.core.api.JsonQuery; +import org.apache.fineract.integrationtests.common.Utils; import org.apache.fineract.organisation.office.domain.OfficeRepositoryWrapper; import org.apache.fineract.organisation.office.service.OfficeReadPlatformService; +import org.junit.*; +import org.mockito.InjectMocks; +import org.mockito.Mock; + import org.joda.time.LocalDate; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.springframework.beans.factory.annotation.Autowired; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; -/** - * JUnit Test Cases for Account Transfer for. - */ -public class CalculateIncomeAndExpanseBookingImplTest { - +public class CalculateIncomeAndExpanseBookingIntegrationTest { /* Test class CalculateIncomeAndExpenseBookingImpl */ - @Autowired + + @Mock private OfficeRepositoryWrapper officeRepository; + @Mock private GLClosureRepository glClosureRepository; + @Mock private GLAccountRepositoryWrapper glAccountRepository; + @Mock private IncomeAndExpenseReadPlatformService incomeAndExpenseReadPlatformService; + @Mock private OfficeReadPlatformService officeReadPlatformService; + + @InjectMocks private CalculateIncomeAndExpenseBookingImpl calculateIncomeAndExpenseBooking; - private GLClosureCommandFromApiJsonDeserializer fromApiJsonDeserializer; - private OfficeRepositoryWrapper officeRepository; - private GLClosureRepository glClosureRepository; - private GLAccountRepositoryWrapper glAccountRepository; - private IncomeAndExpenseReadPlatformService incomeAndExpenseReadPlatformService; - private OfficeReadPlatformService officeReadPlatformService; @Before public void setup() { + calculateIncomeAndExpenseBooking = new CalculateIncomeAndExpenseBookingImpl(null, officeRepository, glClosureRepository, glAccountRepository, incomeAndExpenseReadPlatformService,officeReadPlatformService); + } @After public void tearDown() { - - } - - /* - Case 1: All running balances has to be calculated before booking off income and expense account - No exception is to be thrown since it is running for the input. - However, later a null pointer exception is thrown, since the object incomeAndExpense is not initialized. - */ - @Test(expected = Exception.class) - public void testBookOffIncomeAndExpense() { - JsonQuery query = new JsonQuery("select command to extract income and expanse", null, null); - GLClosureCommand glClosureCommand = new GLClosureCommand((long)10,(long)10, new LocalDate(),"Closing comment", false, (long)10 , "CAD", false, false, "comment" ); - IncomeAndExpenseJournalEntryData incomeAndExpenseJournalEntryData= new IncomeAndExpenseJournalEntryData(null, null,null, null - , true, true, null,null,null,10,10,null,null); - List incomeAndExpenseJournalEntryDataList = new ArrayList<>(); - incomeAndExpenseJournalEntryDataList.add(incomeAndExpenseJournalEntryData); - calculateIncomeAndExpenseBooking.bookOffIncomeAndExpense(incomeAndExpenseJournalEntryDataList, glClosureCommand, false,null,null); - } - /* - Case 2: All running balances has to be calculated before booking off income and expense account + Case 1: All running balances has to be calculated before booking off income and expense account If not running balances, then throw exception */ @Test(expected = RunningBalanceNotCalculatedException.class) public void testBookOffIncomeAndExpenseCheckException() { - JsonQuery query = new JsonQuery("select command to extract income and expanse", null, null); GLClosureCommand glClosureCommand = new GLClosureCommand((long)10,(long)10, new LocalDate(),"Closing comment", false, (long)10 , "CAD", false, false, "comment" ); IncomeAndExpenseJournalEntryData incomeAndExpenseJournalEntryData= new IncomeAndExpenseJournalEntryData(null, null,null, null - , true, true, null,null,null,10,10,null,null); + , true, false, null,null,null,10,10,null,null); List incomeAndExpenseJournalEntryDataList = new ArrayList(); incomeAndExpenseJournalEntryDataList.add(incomeAndExpenseJournalEntryData); calculateIncomeAndExpenseBooking.bookOffIncomeAndExpense(incomeAndExpenseJournalEntryDataList,glClosureCommand, false,null,null); + } + /* + Case 2: All running balances has to be calculated before booking off income and expense account + No exception is to be thrown since it is running for the input. + However, later a null pointer exception is thrown, since the object incomeAndExpense is not initialized. + */ + @Test + public void testBookOffIncomeAndExpense() { + GLClosureCommand glClosureCommand = new GLClosureCommand(10L, 10L, new LocalDate(), "Closing comment", false, 10L , "CAD", false, false, "comment" ); + IncomeAndExpenseJournalEntryData incomeAndExpenseJournalEntryData= new IncomeAndExpenseJournalEntryData(null, null,null, null + , true, true, null,null,null,10,10,null,null); + List incomeAndExpenseJournalEntryDataList = new ArrayList<>(); + incomeAndExpenseJournalEntryDataList.add(incomeAndExpenseJournalEntryData); + Assert.assertNotNull(calculateIncomeAndExpenseBooking.bookOffIncomeAndExpense(incomeAndExpenseJournalEntryDataList, glClosureCommand, false,null,null)); } -} \ No newline at end of file + + +} From 3b009bf9d163b634d819e0ffbcbd312c8acc364e Mon Sep 17 00:00:00 2001 From: Karan Singh Date: Fri, 3 Apr 2020 16:36:47 -0400 Subject: [PATCH 03/12] Fineract-38: Adding 4 test cases signifying the calculation of debits and credits of Income and Expanse accounts. --- ...ncomeAndExpanseBookingIntegrationTest.java | 104 ++++++++++++++++-- .../JsonCommandWrapperTest.java | 15 +++ 2 files changed, 110 insertions(+), 9 deletions(-) create mode 100644 fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/JsonCommandWrapperTest.java diff --git a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/CalculateIncomeAndExpanseBookingIntegrationTest.java b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/CalculateIncomeAndExpanseBookingIntegrationTest.java index b2e27848652..b2975010430 100644 --- a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/CalculateIncomeAndExpanseBookingIntegrationTest.java +++ b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/CalculateIncomeAndExpanseBookingIntegrationTest.java @@ -18,35 +18,42 @@ */ package org.apache.fineract.integrationtests; - +import com.google.gson.JsonElement; +import com.google.gson.JsonParser; import org.apache.fineract.accounting.closure.command.GLClosureCommand; +import org.apache.fineract.accounting.closure.data.IncomeAndExpenseBookingData; import org.apache.fineract.accounting.closure.data.IncomeAndExpenseJournalEntryData; import org.apache.fineract.accounting.closure.domain.GLClosureRepository; import org.apache.fineract.accounting.closure.exception.RunningBalanceNotCalculatedException; import org.apache.fineract.accounting.closure.service.CalculateIncomeAndExpenseBookingImpl; import org.apache.fineract.accounting.closure.service.IncomeAndExpenseReadPlatformService; +import org.apache.fineract.accounting.glaccount.api.GLAccountJsonInputParams; +import org.apache.fineract.accounting.glaccount.domain.GLAccount; import org.apache.fineract.accounting.glaccount.domain.GLAccountRepositoryWrapper; +import org.apache.fineract.infrastructure.core.api.JsonCommand; import org.apache.fineract.integrationtests.common.Utils; import org.apache.fineract.organisation.office.domain.OfficeRepositoryWrapper; import org.apache.fineract.organisation.office.service.OfficeReadPlatformService; import org.junit.*; +import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.joda.time.LocalDate; +import org.mockito.junit.MockitoJUnitRunner; +import java.math.BigDecimal; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; +import static org.mockito.Mockito.when; + +@RunWith(MockitoJUnitRunner.class) public class CalculateIncomeAndExpanseBookingIntegrationTest { /* Test class CalculateIncomeAndExpenseBookingImpl */ - - @Mock private OfficeRepositoryWrapper officeRepository; - @Mock private GLClosureRepository glClosureRepository; - @Mock private GLAccountRepositoryWrapper glAccountRepository; + @Mock private JsonCommandWrapperTest jsonCommandWrapperTest; @Mock private IncomeAndExpenseReadPlatformService incomeAndExpenseReadPlatformService; @Mock private OfficeReadPlatformService officeReadPlatformService; @@ -55,12 +62,12 @@ public class CalculateIncomeAndExpanseBookingIntegrationTest { @Before public void setup() { - calculateIncomeAndExpenseBooking = new CalculateIncomeAndExpenseBookingImpl(null, officeRepository, glClosureRepository, glAccountRepository, incomeAndExpenseReadPlatformService,officeReadPlatformService); - - } + calculateIncomeAndExpenseBooking = new CalculateIncomeAndExpenseBookingImpl(null, null, null, null, incomeAndExpenseReadPlatformService,officeReadPlatformService); + } @After public void tearDown() { + } /* Case 1: All running balances has to be calculated before booking off income and expense account @@ -91,6 +98,85 @@ public void testBookOffIncomeAndExpense() { Assert.assertNotNull(calculateIncomeAndExpenseBooking.bookOffIncomeAndExpense(incomeAndExpenseJournalEntryDataList, glClosureCommand, false,null,null)); } + /* + Case 3: In the case of an income account type- if the OfficeRunningBalance is greater than 0, then add to debits + */ + @Test(expected = NoClassDefFoundError.class) + public void testIncomeAccountsRunningBalanceGreaterThanZero_Debit() { + GLClosureCommand glClosureCommand = new GLClosureCommand(10L, 10L, new LocalDate(), "Closing comment", false, 10L , "CAD", false, false, "comment" ); + IncomeAndExpenseJournalEntryData incomeAndExpenseJournalEntryData= new IncomeAndExpenseJournalEntryData(null, null,null, null, true, true, null,new BigDecimal(10),null,4,10,null,null); + IncomeAndExpenseJournalEntryData incomeAndExpenseJournalEntryData2= new IncomeAndExpenseJournalEntryData(null, null,null, null, true, true, null,new BigDecimal(20),null,4,10,null,null); + List incomeAndExpenseJournalEntryDataList = new ArrayList<>(); + incomeAndExpenseJournalEntryDataList.add(incomeAndExpenseJournalEntryData); + incomeAndExpenseJournalEntryDataList.add(incomeAndExpenseJournalEntryData2); + GLAccount glAccount = GLAccount.fromJson(null, jsonCommandWrapperTest.getCommand(),null); + IncomeAndExpenseBookingData incomeAndExpenseBookingData = calculateIncomeAndExpenseBooking.bookOffIncomeAndExpense(incomeAndExpenseJournalEntryDataList, glClosureCommand, false, null, null); + incomeAndExpenseBookingData.getJournalEntries().forEach(entry->{ + Assert.assertEquals(entry.getDebits().get(0).getAmount(), new BigDecimal(30)); + }); + Assert.assertNotNull(calculateIncomeAndExpenseBooking.bookOffIncomeAndExpense(incomeAndExpenseJournalEntryDataList, glClosureCommand, false,null,null)); + } + + + /* + Case 4: In the case of an income account type- if the OfficeRunningBalance is less than 0, then add to credits + */ + @Test(expected = NoClassDefFoundError.class) + public void testIncomeAccountsRunningBalanceLessThanZero_Credit() { + GLClosureCommand glClosureCommand = new GLClosureCommand(10L, 10L, new LocalDate(), "Closing comment", false, 10L , "CAD", false, false, "comment" ); + IncomeAndExpenseJournalEntryData incomeAndExpenseJournalEntryData= new IncomeAndExpenseJournalEntryData(null, null,null, null, true, true, null,new BigDecimal(-10),null,4,10,null,null); + IncomeAndExpenseJournalEntryData incomeAndExpenseJournalEntryData2= new IncomeAndExpenseJournalEntryData(null, null,null, null, true, true, null,new BigDecimal(-20),null,4,10,null,null); + List incomeAndExpenseJournalEntryDataList = new ArrayList<>(); + incomeAndExpenseJournalEntryDataList.add(incomeAndExpenseJournalEntryData); + incomeAndExpenseJournalEntryDataList.add(incomeAndExpenseJournalEntryData2); + GLAccount glAccount = GLAccount.fromJson(null, jsonCommandWrapperTest.getCommand(),null); + IncomeAndExpenseBookingData incomeAndExpenseBookingData = calculateIncomeAndExpenseBooking.bookOffIncomeAndExpense(incomeAndExpenseJournalEntryDataList, glClosureCommand, false, null, null); + incomeAndExpenseBookingData.getJournalEntries().forEach(entry->{ + Assert.assertEquals(entry.getCredits().get(0).getAmount(), new BigDecimal(30)); + }); + Assert.assertNotNull(calculateIncomeAndExpenseBooking.bookOffIncomeAndExpense(incomeAndExpenseJournalEntryDataList, glClosureCommand, false,null,null)); + } + + + /* + Case 5: In the case of an Expanse account type- if the OfficeRunningBalance is greater than 0, then add to credit + */ + @Test(expected = NoClassDefFoundError.class) + public void testIncomeAccountsRunningBalanceGreaterThanZero_Credit() { + GLClosureCommand glClosureCommand = new GLClosureCommand(10L, 10L, new LocalDate(), "Closing comment", false, 10L , "CAD", false, false, "comment" ); + IncomeAndExpenseJournalEntryData incomeAndExpenseJournalEntryData= new IncomeAndExpenseJournalEntryData(null, null,null, null, true, true, null,new BigDecimal(10),null,5,10,null,null); + IncomeAndExpenseJournalEntryData incomeAndExpenseJournalEntryData2= new IncomeAndExpenseJournalEntryData(null, null,null, null, true, true, null,new BigDecimal(20),null,5,10,null,null); + List incomeAndExpenseJournalEntryDataList = new ArrayList<>(); + incomeAndExpenseJournalEntryDataList.add(incomeAndExpenseJournalEntryData); + incomeAndExpenseJournalEntryDataList.add(incomeAndExpenseJournalEntryData2); + GLAccount glAccount = GLAccount.fromJson(null, jsonCommandWrapperTest.getCommand(),null); + IncomeAndExpenseBookingData incomeAndExpenseBookingData = calculateIncomeAndExpenseBooking.bookOffIncomeAndExpense(incomeAndExpenseJournalEntryDataList, glClosureCommand, false, null, null); + incomeAndExpenseBookingData.getJournalEntries().forEach(entry->{ + Assert.assertEquals(entry.getDebits().get(0).getAmount(), new BigDecimal(30)); + }); + Assert.assertNotNull(calculateIncomeAndExpenseBooking.bookOffIncomeAndExpense(incomeAndExpenseJournalEntryDataList, glClosureCommand, false,null,null)); + } + + + /* + Case 6: In the case of an Expanse account type- if the OfficeRunningBalance is less than 0, then add to debits + */ + @Test(expected = NoClassDefFoundError.class) + public void testIncomeAccountsRunningBalanceLessThanZero_Debit() { + GLClosureCommand glClosureCommand = new GLClosureCommand(10L, 10L, new LocalDate(), "Closing comment", false, 10L , "CAD", false, false, "comment" ); + IncomeAndExpenseJournalEntryData incomeAndExpenseJournalEntryData= new IncomeAndExpenseJournalEntryData(null, null,null, null, true, true, null,new BigDecimal(-10),null,5,10,null,null); + IncomeAndExpenseJournalEntryData incomeAndExpenseJournalEntryData2= new IncomeAndExpenseJournalEntryData(null, null,null, null, true, true, null,new BigDecimal(-20),null,5,10,null,null); + List incomeAndExpenseJournalEntryDataList = new ArrayList<>(); + incomeAndExpenseJournalEntryDataList.add(incomeAndExpenseJournalEntryData); + incomeAndExpenseJournalEntryDataList.add(incomeAndExpenseJournalEntryData2); + GLAccount glAccount = GLAccount.fromJson(null, jsonCommandWrapperTest.getCommand(),null); + IncomeAndExpenseBookingData incomeAndExpenseBookingData = calculateIncomeAndExpenseBooking.bookOffIncomeAndExpense(incomeAndExpenseJournalEntryDataList, glClosureCommand, false, null, null); + incomeAndExpenseBookingData.getJournalEntries().forEach(entry->{ + Assert.assertEquals(entry.getCredits().get(0).getAmount(), new BigDecimal(30)); + }); + Assert.assertNotNull(calculateIncomeAndExpenseBooking.bookOffIncomeAndExpense(incomeAndExpenseJournalEntryDataList, glClosureCommand, false,null,null)); + } + } diff --git a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/JsonCommandWrapperTest.java b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/JsonCommandWrapperTest.java new file mode 100644 index 00000000000..5571a2d46f0 --- /dev/null +++ b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/JsonCommandWrapperTest.java @@ -0,0 +1,15 @@ +package org.apache.fineract.integrationtests; + +import org.apache.fineract.infrastructure.core.api.JsonCommand; + +public class JsonCommandWrapperTest { + private JsonCommand command; + + public JsonCommand getCommand() { + return command; + } + + public void setCommand(JsonCommand command) { + this.command = command; + } +} From f76f1df1888dbe637a977c32a637013332fdbfc0 Mon Sep 17 00:00:00 2001 From: Karan Singh Date: Sun, 5 Apr 2020 12:53:49 -0400 Subject: [PATCH 04/12] FINERACT-38: Making xmlOutput & htmlOutput true for RAT to determine failing libraries --- fineract-provider/build.gradle | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/fineract-provider/build.gradle b/fineract-provider/build.gradle index 1d094cc6d0c..4809e81c242 100644 --- a/fineract-provider/build.gradle +++ b/fineract-provider/build.gradle @@ -156,10 +156,14 @@ openjpa { } rat { - xmlOutput = false - htmlOutput = false + xmlOutput = true + htmlOutput = true plainOutput = true verbose = false + +/* + failOnError = false +*/ // inputDir = './..' reportDir = new File(buildDir,'reports/rat') excludes = [ From 66e9db6572f9b5282b4513242edfbc01de14e09f Mon Sep 17 00:00:00 2001 From: Karan Singh Date: Tue, 7 Apr 2020 20:16:24 -0400 Subject: [PATCH 05/12] FINERACT-38: Optimizing imports --- ...IncomeAndExpanseBookingIntegrationTest.java | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/CalculateIncomeAndExpanseBookingIntegrationTest.java b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/CalculateIncomeAndExpanseBookingIntegrationTest.java index b2975010430..4842236cbd8 100644 --- a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/CalculateIncomeAndExpanseBookingIntegrationTest.java +++ b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/CalculateIncomeAndExpanseBookingIntegrationTest.java @@ -18,36 +18,28 @@ */ package org.apache.fineract.integrationtests; -import com.google.gson.JsonElement; -import com.google.gson.JsonParser; import org.apache.fineract.accounting.closure.command.GLClosureCommand; import org.apache.fineract.accounting.closure.data.IncomeAndExpenseBookingData; import org.apache.fineract.accounting.closure.data.IncomeAndExpenseJournalEntryData; -import org.apache.fineract.accounting.closure.domain.GLClosureRepository; import org.apache.fineract.accounting.closure.exception.RunningBalanceNotCalculatedException; import org.apache.fineract.accounting.closure.service.CalculateIncomeAndExpenseBookingImpl; import org.apache.fineract.accounting.closure.service.IncomeAndExpenseReadPlatformService; -import org.apache.fineract.accounting.glaccount.api.GLAccountJsonInputParams; import org.apache.fineract.accounting.glaccount.domain.GLAccount; -import org.apache.fineract.accounting.glaccount.domain.GLAccountRepositoryWrapper; -import org.apache.fineract.infrastructure.core.api.JsonCommand; -import org.apache.fineract.integrationtests.common.Utils; -import org.apache.fineract.organisation.office.domain.OfficeRepositoryWrapper; import org.apache.fineract.organisation.office.service.OfficeReadPlatformService; -import org.junit.*; +import org.joda.time.LocalDate; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; - -import org.joda.time.LocalDate; import org.mockito.junit.MockitoJUnitRunner; import java.math.BigDecimal; import java.util.ArrayList; import java.util.List; -import static org.mockito.Mockito.when; - @RunWith(MockitoJUnitRunner.class) public class CalculateIncomeAndExpanseBookingIntegrationTest { /* From f85b05c59a8e7aa847076ee0639e32b8796b7dfa Mon Sep 17 00:00:00 2001 From: Karan Singh Date: Tue, 7 Apr 2020 20:36:55 -0400 Subject: [PATCH 06/12] FINERACT-38: Adding Lynx in travis yaml to debug. --- .travis.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.travis.yml b/.travis.yml index 3a0f0a10837..622796a7d61 100644 --- a/.travis.yml +++ b/.travis.yml @@ -33,6 +33,7 @@ addons: packages: # https://httpie.org is used by the docker-compose test below - httpie + - lynx before_install: - echo "USE mysql;\nUPDATE user SET password=PASSWORD('mysql') WHERE user='root';\nFLUSH PRIVILEGES;\n" | mysql -u root @@ -51,6 +52,9 @@ cache: - $HOME/.gradle/wrapper/ - $HOME/.m2 +after_failure: + - if [ -f /home/travis/build/muellners/fineract/build/reports/rat/index.html ]; then lynx -dump /home/travis/build/muellners/fineract/build/reports/rat/index.html; fi + # NOTE: We used to run with --info, which is quite a bit more verbose, but is VERY useful to understand failures on Travis, # where you do not have access to any files like build/reports/tests/index.html, only the Console. # @see http://mrhaki.blogspot.ch/2013/05/gradle-goodness-show-more-information.html From c17512e6476448379ba2b48d785ec7e6e5a592d2 Mon Sep 17 00:00:00 2001 From: Saransh Sharma Date: Thu, 9 Apr 2020 15:09:17 +0530 Subject: [PATCH 07/12] File License Header Added and Some CheckStyleAdded --- ...IncomeAndExpanseBookingIntegrationTest.java | 12 ++++++------ .../JsonCommandWrapperTest.java | 18 ++++++++++++++++++ 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/CalculateIncomeAndExpanseBookingIntegrationTest.java b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/CalculateIncomeAndExpanseBookingIntegrationTest.java index 4842236cbd8..6f8587c1b64 100644 --- a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/CalculateIncomeAndExpanseBookingIntegrationTest.java +++ b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/CalculateIncomeAndExpanseBookingIntegrationTest.java @@ -16,8 +16,13 @@ * specific language governing permissions and limitations * under the License. */ + package org.apache.fineract.integrationtests; + +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.List; import org.apache.fineract.accounting.closure.command.GLClosureCommand; import org.apache.fineract.accounting.closure.data.IncomeAndExpenseBookingData; import org.apache.fineract.accounting.closure.data.IncomeAndExpenseJournalEntryData; @@ -26,19 +31,14 @@ import org.apache.fineract.accounting.closure.service.IncomeAndExpenseReadPlatformService; import org.apache.fineract.accounting.glaccount.domain.GLAccount; import org.apache.fineract.organisation.office.service.OfficeReadPlatformService; + import org.joda.time.LocalDate; import org.junit.After; import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; -import java.math.BigDecimal; -import java.util.ArrayList; -import java.util.List; @RunWith(MockitoJUnitRunner.class) public class CalculateIncomeAndExpanseBookingIntegrationTest { diff --git a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/JsonCommandWrapperTest.java b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/JsonCommandWrapperTest.java index 5571a2d46f0..96f434edddc 100644 --- a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/JsonCommandWrapperTest.java +++ b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/JsonCommandWrapperTest.java @@ -1,3 +1,21 @@ +/** + * 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; import org.apache.fineract.infrastructure.core.api.JsonCommand; From 932750419afdfd3222826120e5120ca4001f0363 Mon Sep 17 00:00:00 2001 From: Karan Singh Date: Thu, 9 Apr 2020 10:43:37 -0400 Subject: [PATCH 08/12] Revert "FINERACT-38: Adding Lynx in travis yaml to debug." This reverts commit f85b05c59a8e7aa847076ee0639e32b8796b7dfa. --- .travis.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 622796a7d61..3a0f0a10837 100644 --- a/.travis.yml +++ b/.travis.yml @@ -33,7 +33,6 @@ addons: packages: # https://httpie.org is used by the docker-compose test below - httpie - - lynx before_install: - echo "USE mysql;\nUPDATE user SET password=PASSWORD('mysql') WHERE user='root';\nFLUSH PRIVILEGES;\n" | mysql -u root @@ -52,9 +51,6 @@ cache: - $HOME/.gradle/wrapper/ - $HOME/.m2 -after_failure: - - if [ -f /home/travis/build/muellners/fineract/build/reports/rat/index.html ]; then lynx -dump /home/travis/build/muellners/fineract/build/reports/rat/index.html; fi - # NOTE: We used to run with --info, which is quite a bit more verbose, but is VERY useful to understand failures on Travis, # where you do not have access to any files like build/reports/tests/index.html, only the Console. # @see http://mrhaki.blogspot.ch/2013/05/gradle-goodness-show-more-information.html From 0598c7f2fc67452601ce3f9c190e14c092594eed Mon Sep 17 00:00:00 2001 From: Karan Singh Date: Thu, 9 Apr 2020 10:45:04 -0400 Subject: [PATCH 09/12] Revert "FINERACT-38: Making xmlOutput & htmlOutput true for RAT to determine failing libraries" This reverts commit f76f1df1888dbe637a977c32a637013332fdbfc0. --- fineract-provider/build.gradle | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/fineract-provider/build.gradle b/fineract-provider/build.gradle index 4809e81c242..1d094cc6d0c 100644 --- a/fineract-provider/build.gradle +++ b/fineract-provider/build.gradle @@ -156,14 +156,10 @@ openjpa { } rat { - xmlOutput = true - htmlOutput = true + xmlOutput = false + htmlOutput = false plainOutput = true verbose = false - -/* - failOnError = false -*/ // inputDir = './..' reportDir = new File(buildDir,'reports/rat') excludes = [ From 6603e6993abca5310027190361a686009ce79710 Mon Sep 17 00:00:00 2001 From: Karan Singh Date: Thu, 9 Apr 2020 10:57:53 -0400 Subject: [PATCH 10/12] FINERACT-38: Adding Mockito imports. --- .../CalculateIncomeAndExpanseBookingIntegrationTest.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/CalculateIncomeAndExpanseBookingIntegrationTest.java b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/CalculateIncomeAndExpanseBookingIntegrationTest.java index 6f8587c1b64..da30ab509b9 100644 --- a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/CalculateIncomeAndExpanseBookingIntegrationTest.java +++ b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/CalculateIncomeAndExpanseBookingIntegrationTest.java @@ -39,13 +39,17 @@ import org.junit.Test; import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; @RunWith(MockitoJUnitRunner.class) public class CalculateIncomeAndExpanseBookingIntegrationTest { /* Test class CalculateIncomeAndExpenseBookingImpl */ - @Mock private JsonCommandWrapperTest jsonCommandWrapperTest; + @Mock + private JsonCommandWrapperTest jsonCommandWrapperTest; @Mock private IncomeAndExpenseReadPlatformService incomeAndExpenseReadPlatformService; @Mock private OfficeReadPlatformService officeReadPlatformService; From b83e341b9162efb264ea1c74e3242431f1c09faf Mon Sep 17 00:00:00 2001 From: Karan Singh Date: Thu, 9 Apr 2020 11:11:41 -0400 Subject: [PATCH 11/12] FINERACT-38: Fix in Checkstyle --- .../CalculateIncomeAndExpanseBookingIntegrationTest.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/CalculateIncomeAndExpanseBookingIntegrationTest.java b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/CalculateIncomeAndExpanseBookingIntegrationTest.java index da30ab509b9..4d04c0a6b60 100644 --- a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/CalculateIncomeAndExpanseBookingIntegrationTest.java +++ b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/CalculateIncomeAndExpanseBookingIntegrationTest.java @@ -31,14 +31,12 @@ import org.apache.fineract.accounting.closure.service.IncomeAndExpenseReadPlatformService; import org.apache.fineract.accounting.glaccount.domain.GLAccount; import org.apache.fineract.organisation.office.service.OfficeReadPlatformService; - import org.joda.time.LocalDate; import org.junit.After; import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; - import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.runners.MockitoJUnitRunner; From a76c30631f247a4b0dae9bf61990ee2b4f29174d Mon Sep 17 00:00:00 2001 From: Karan Singh Date: Thu, 9 Apr 2020 11:56:04 -0400 Subject: [PATCH 12/12] FINERACT-38: Correcting checkstyle. --- ...lculateIncomeAndExpanseBookingIntegrationTest.java | 6 +----- .../service/CalculateIncomeAndExpenseBookingImpl.java | 11 +++++------ 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/CalculateIncomeAndExpanseBookingIntegrationTest.java b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/CalculateIncomeAndExpanseBookingIntegrationTest.java index 4d04c0a6b60..a1a1b615379 100644 --- a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/CalculateIncomeAndExpanseBookingIntegrationTest.java +++ b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/CalculateIncomeAndExpanseBookingIntegrationTest.java @@ -16,10 +16,7 @@ * specific language governing permissions and limitations * under the License. */ - package org.apache.fineract.integrationtests; - - import java.math.BigDecimal; import java.util.ArrayList; import java.util.List; @@ -46,8 +43,7 @@ public class CalculateIncomeAndExpanseBookingIntegrationTest { /* Test class CalculateIncomeAndExpenseBookingImpl */ - @Mock - private JsonCommandWrapperTest jsonCommandWrapperTest; + @Mock private JsonCommandWrapperTest jsonCommandWrapperTest; @Mock private IncomeAndExpenseReadPlatformService incomeAndExpenseReadPlatformService; @Mock private OfficeReadPlatformService officeReadPlatformService; diff --git a/fineract-provider/src/main/java/org/apache/fineract/accounting/closure/service/CalculateIncomeAndExpenseBookingImpl.java b/fineract-provider/src/main/java/org/apache/fineract/accounting/closure/service/CalculateIncomeAndExpenseBookingImpl.java index 13216144dea..d637cbd1061 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/accounting/closure/service/CalculateIncomeAndExpenseBookingImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/accounting/closure/service/CalculateIncomeAndExpenseBookingImpl.java @@ -19,6 +19,11 @@ package org.apache.fineract.accounting.closure.service; +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Date; +import java.util.List; import org.apache.fineract.accounting.closure.command.GLClosureCommand; import org.apache.fineract.accounting.closure.data.IncomeAndExpenseBookingData; import org.apache.fineract.accounting.closure.data.IncomeAndExpenseJournalEntryData; @@ -42,12 +47,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import java.math.BigDecimal; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Date; -import java.util.List; - @Service public class CalculateIncomeAndExpenseBookingImpl implements CalculateIncomeAndExpenseBooking {