From 1315c125303b84faaa8c9b8ed512668902aa6186 Mon Sep 17 00:00:00 2001 From: Isaias Battaglia Date: Thu, 30 Nov 2023 17:11:20 -0300 Subject: [PATCH 1/4] Issue #144: Handle null exception in product param and add test EPL-549 --- .../financial/FinancialUtilsTest.java | 35 +++++++++++++++++++ .../openbravo/financial/FinancialUtils.java | 18 ++++++---- 2 files changed, 46 insertions(+), 7 deletions(-) create mode 100644 src-test/src/org/openbravo/financial/FinancialUtilsTest.java diff --git a/src-test/src/org/openbravo/financial/FinancialUtilsTest.java b/src-test/src/org/openbravo/financial/FinancialUtilsTest.java new file mode 100644 index 00000000..e79c9e2c --- /dev/null +++ b/src-test/src/org/openbravo/financial/FinancialUtilsTest.java @@ -0,0 +1,35 @@ +package org.openbravo.financial; + +import java.util.Date; + +import org.openbravo.model.common.businesspartner.BusinessPartner; +import org.junit.Test; +import org.openbravo.base.exception.OBException; +import org.openbravo.dal.service.OBDal; +import org.openbravo.base.weld.test.WeldBaseTest; +import org.openbravo.model.pricing.pricelist.PriceList; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + + +public class FinancialUtilsTest extends WeldBaseTest { + protected static final String BP_HEALTHY_FOOD = "B3ABB0B4AFEA4541AC1E29891D496079"; + + + @Test + public void testGetProductPriceWithNullProduct() { + // Given + Date date = new Date(); + boolean useSalesPriceList = true; + BusinessPartner healthyFoodBP = OBDal.getInstance().get(BusinessPartner.class, BP_HEALTHY_FOOD); + PriceList priceList = healthyFoodBP.getPurchasePricelist(); + // When + try { + FinancialUtils.getProductPrice(null, date, useSalesPriceList, priceList); + fail("Expected an OBException to be thrown"); + } catch (OBException e) { + assertEquals("@ParameterMissing@", e.getMessage()); + } + } +} diff --git a/src/org/openbravo/financial/FinancialUtils.java b/src/org/openbravo/financial/FinancialUtils.java index 840a6ee3..2597afa3 100644 --- a/src/org/openbravo/financial/FinancialUtils.java +++ b/src/org/openbravo/financial/FinancialUtils.java @@ -71,7 +71,7 @@ public static BigDecimal getProductStdPrice(final Product product, final Date da * ProductPrice to be used. In case a conversion is needed it uses the * {@link #getConvertedAmount(BigDecimal, Currency, Currency, Date, Organization, String) * getConvertedAmount()} method. - * + * * @param product * Product to get its ProductPrice. * @param date @@ -131,7 +131,7 @@ public static ProductPrice getProductPrice(final Product product, final Date dat * Method to get a valid ProductPrice for the given Product. It only considers PriceList versions * valid on the given date. If a PriceList is given it searches on that one. If PriceList null is * passed it search on any Sales or Purchase PriceList based on the useSalesPriceList. - * + * * @param product * Product to get its ProductPrice. * @param date @@ -151,6 +151,10 @@ public static ProductPrice getProductPrice(final Product product, final Date dat public static ProductPrice getProductPrice(final Product product, final Date date, final boolean useSalesPriceList, final PriceList priceList, final boolean throwException, final boolean usePriceIncludeTax) throws OBException { + + if (product == null) { + throw new OBException("@ParameterMissing@"); + } //@formatter:off String hql = "as pp" + @@ -209,7 +213,7 @@ public static ProductPrice getProductPrice(final Product product, final Date dat * Method to get the conversion rate defined at system level. If there is not a conversion rate * defined on the given Organization it is searched recursively on its parent organization until * one is found. If no conversion rate is found null is returned. - * + * * @param date * Date conversion is being performed. * @param fromCurrency @@ -274,7 +278,7 @@ public static BigDecimal getConvertedAmount(final BigDecimal amount, final Curre /** * Converts an amount. - * + * * @param amount * BigDecimal amount to convert. * @param curFrom @@ -343,7 +347,7 @@ public static Currency getLegalEntityCurrency(final Organization organization) { /** * Calculates the net unit price using the C_GET_NET_PRICE_FROM_GROSS stored procedure. - * + * * @param strTaxId * Tax that applies to the price. * @param grossAmount @@ -355,7 +359,7 @@ public static Currency getLegalEntityCurrency(final Organization organization) { * @param quantity * number of units to divide the amount to get the price. * @return the net unit price - * + * * @deprecated Use {@link #calculateNetAmtFromGross} instead */ @Deprecated @@ -380,7 +384,7 @@ public static BigDecimal calculateNetFromGross(final String strTaxId, /** * Calculates the net unit price using the C_GET_NET_AMOUNT_FROM_GROSS stored procedure. - * + * * @param strTaxId * Tax that applies to the price. * @param grossAmount From 41b279751caedeee7fb2e4dcebd01f1ce2530083 Mon Sep 17 00:00:00 2001 From: Isaias Battaglia Date: Thu, 30 Nov 2023 17:38:29 -0300 Subject: [PATCH 2/4] Issue #144:Add FinancialUtilsTest test in StandaloneTestSuite EPL-549 --- src-test/src/org/openbravo/test/StandaloneTestSuite.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src-test/src/org/openbravo/test/StandaloneTestSuite.java b/src-test/src/org/openbravo/test/StandaloneTestSuite.java index f2c58703..3a105482 100644 --- a/src-test/src/org/openbravo/test/StandaloneTestSuite.java +++ b/src-test/src/org/openbravo/test/StandaloneTestSuite.java @@ -150,6 +150,7 @@ import org.openbravo.test.xml.EntityXMLIssues; import org.openbravo.test.xml.UniqueConstraintImportTest; import org.openbravo.userinterface.selectors.test.ExpressionsTest; +import org.openbravo.financial.FinancialUtilsTest; /** * This test class is called from the ant task run.all.tests by the CI server. It contains all the @@ -355,6 +356,7 @@ // others DocumentNumberGeneration.class, // GridExport.class, // + FinancialUtilsTest.class, // // Cancel and Replace Tests From 899f2190f1fdf9a6d3611de9c6bd1212f8a67c4f Mon Sep 17 00:00:00 2001 From: Isaias Battaglia Date: Fri, 1 Dec 2023 08:49:05 -0300 Subject: [PATCH 3/4] Issue #144: Improve exeption message EPL-549 --- src-test/src/org/openbravo/financial/FinancialUtilsTest.java | 2 +- src/org/openbravo/financial/FinancialUtils.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src-test/src/org/openbravo/financial/FinancialUtilsTest.java b/src-test/src/org/openbravo/financial/FinancialUtilsTest.java index e79c9e2c..91d096fa 100644 --- a/src-test/src/org/openbravo/financial/FinancialUtilsTest.java +++ b/src-test/src/org/openbravo/financial/FinancialUtilsTest.java @@ -29,7 +29,7 @@ public void testGetProductPriceWithNullProduct() { FinancialUtils.getProductPrice(null, date, useSalesPriceList, priceList); fail("Expected an OBException to be thrown"); } catch (OBException e) { - assertEquals("@ParameterMissing@", e.getMessage()); + assertEquals("@ParameterMissing@ @Product@", e.getMessage()); } } } diff --git a/src/org/openbravo/financial/FinancialUtils.java b/src/org/openbravo/financial/FinancialUtils.java index 2597afa3..3518389f 100644 --- a/src/org/openbravo/financial/FinancialUtils.java +++ b/src/org/openbravo/financial/FinancialUtils.java @@ -153,7 +153,7 @@ public static ProductPrice getProductPrice(final Product product, final Date dat final boolean usePriceIncludeTax) throws OBException { if (product == null) { - throw new OBException("@ParameterMissing@"); + throw new OBException("@ParameterMissing@ @Product@"); } //@formatter:off String hql = From aba414b31c3d78e2b5c13c80bf48e3f6f5300ea9 Mon Sep 17 00:00:00 2001 From: Isaias Battaglia Date: Fri, 1 Dec 2023 13:02:18 -0300 Subject: [PATCH 4/4] Issue #144:Remove redundant variable EPL-549 --- src-test/src/org/openbravo/financial/FinancialUtilsTest.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src-test/src/org/openbravo/financial/FinancialUtilsTest.java b/src-test/src/org/openbravo/financial/FinancialUtilsTest.java index 91d096fa..6219752b 100644 --- a/src-test/src/org/openbravo/financial/FinancialUtilsTest.java +++ b/src-test/src/org/openbravo/financial/FinancialUtilsTest.java @@ -21,12 +21,11 @@ public class FinancialUtilsTest extends WeldBaseTest { public void testGetProductPriceWithNullProduct() { // Given Date date = new Date(); - boolean useSalesPriceList = true; BusinessPartner healthyFoodBP = OBDal.getInstance().get(BusinessPartner.class, BP_HEALTHY_FOOD); PriceList priceList = healthyFoodBP.getPurchasePricelist(); // When try { - FinancialUtils.getProductPrice(null, date, useSalesPriceList, priceList); + FinancialUtils.getProductPrice(null, date, true, priceList); fail("Expected an OBException to be thrown"); } catch (OBException e) { assertEquals("@ParameterMissing@ @Product@", e.getMessage());