details:   https://code.openbravo.com/erp/devel/pi/rev/828a35bc2b9b
changeset: 32726:828a35bc2b9b
user:      Mark <markmm82 <at> gmail.com>
date:      Tue Sep 19 11:24:16 2017 -0400
summary:   Related to issue 36707: Add some automated tests

Created automated tests for Price List generation process.

diffstat:

 src-test/src/org/openbravo/test/AllAntTaskTests.java                           
 |    5 +
 src-test/src/org/openbravo/test/pricelist/PriceListTest.java                   
 |  533 ++++++++++
 
src-test/src/org/openbravo/test/pricelist/data/PriceListSchemaLineTestData.java 
|  157 ++
 src-test/src/org/openbravo/test/pricelist/data/PriceListTestConstants.java     
 |   88 +
 src-test/src/org/openbravo/test/pricelist/data/PriceListTestData.java          
 |  130 ++
 src-test/src/org/openbravo/test/pricelist/data/PriceListTestData1.java         
 |   76 +
 src-test/src/org/openbravo/test/pricelist/data/PriceListTestData10.java        
 |   76 +
 src-test/src/org/openbravo/test/pricelist/data/PriceListTestData11.java        
 |   76 +
 src-test/src/org/openbravo/test/pricelist/data/PriceListTestData12.java        
 |   76 +
 src-test/src/org/openbravo/test/pricelist/data/PriceListTestData13.java        
 |   74 +
 src-test/src/org/openbravo/test/pricelist/data/PriceListTestData14.java        
 |   75 +
 src-test/src/org/openbravo/test/pricelist/data/PriceListTestData15.java        
 |  106 +
 src-test/src/org/openbravo/test/pricelist/data/PriceListTestData16.java        
 |  106 +
 src-test/src/org/openbravo/test/pricelist/data/PriceListTestData2.java         
 |   74 +
 src-test/src/org/openbravo/test/pricelist/data/PriceListTestData3.java         
 |   89 +
 src-test/src/org/openbravo/test/pricelist/data/PriceListTestData4.java         
 |   73 +
 src-test/src/org/openbravo/test/pricelist/data/PriceListTestData5.java         
 |   91 +
 src-test/src/org/openbravo/test/pricelist/data/PriceListTestData6.java         
 |   68 +
 src-test/src/org/openbravo/test/pricelist/data/PriceListTestData7.java         
 |   79 +
 src-test/src/org/openbravo/test/pricelist/data/PriceListTestData8.java         
 |   75 +
 src-test/src/org/openbravo/test/pricelist/data/PriceListTestData9.java         
 |   80 +
 21 files changed, 2207 insertions(+), 0 deletions(-)

diffs (truncated from 2308 to 300 lines):

diff -r 56870c4b2bd0 -r 828a35bc2b9b 
src-test/src/org/openbravo/test/AllAntTaskTests.java
--- a/src-test/src/org/openbravo/test/AllAntTaskTests.java      Tue Sep 19 
23:11:32 2017 +0530
+++ b/src-test/src/org/openbravo/test/AllAntTaskTests.java      Tue Sep 19 
11:24:16 2017 -0400
@@ -81,6 +81,7 @@
 import org.openbravo.test.modularity.MergePropertiesTest;
 import org.openbravo.test.modularity.TableNameTest;
 import org.openbravo.test.preference.PreferenceTest;
+import org.openbravo.test.pricelist.PriceListTest;
 import org.openbravo.test.reporting.JasperReportsCompilation;
 import org.openbravo.test.role.inheritance.RoleInheritanceTestSuite;
 import org.openbravo.test.scheduling.ProcessSchedulingTest;
@@ -205,9 +206,13 @@
     // Accounting
     RecordID2Test.class, //
     PostDocumentTest.class, //
+
     // Taxes
     TaxesTest.class, //
 
+    // Price List
+    PriceListTest.class, //
+
     // costing
     TestCosting.class, //
 
diff -r 56870c4b2bd0 -r 828a35bc2b9b 
src-test/src/org/openbravo/test/pricelist/PriceListTest.java
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/src-test/src/org/openbravo/test/pricelist/PriceListTest.java      Tue Sep 
19 11:24:16 2017 -0400
@@ -0,0 +1,533 @@
+/*
+ *************************************************************************
+ * The contents of this file are subject to the Openbravo  Public  License
+ * Version  1.1  (the  "License"),  being   the  Mozilla   Public  License
+ * Version 1.1  with a permitted attribution clause; you may not  use this
+ * file except in compliance with the License. You  may  obtain  a copy of
+ * the License at http://www.openbravo.com/legal/license.html 
+ * Software distributed under the License  is  distributed  on  an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific  language  governing  rights  and  limitations
+ * under the License. 
+ * The Original Code is Openbravo ERP. 
+ * The Initial Developer of the Original Code is Openbravo SLU 
+ * All portions are Copyright (C) 2017 Openbravo SLU 
+ * All Rights Reserved. 
+ * Contributor(s):  ______________________________________.
+ ************************************************************************
+ */
+
+package org.openbravo.test.pricelist;
+
+import static org.hamcrest.Matchers.comparesEqualTo;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
+
+import java.math.BigDecimal;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Date;
+import java.util.HashMap;
+
+import org.apache.commons.lang.StringUtils;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+import org.openbravo.base.provider.OBProvider;
+import org.openbravo.dal.core.OBContext;
+import org.openbravo.dal.service.OBDal;
+import org.openbravo.model.ad.system.Client;
+import org.openbravo.model.ad.ui.Process;
+import org.openbravo.model.common.businesspartner.BusinessPartner;
+import org.openbravo.model.common.currency.Currency;
+import org.openbravo.model.common.enterprise.Organization;
+import org.openbravo.model.common.plm.Product;
+import org.openbravo.model.common.plm.ProductCategory;
+import org.openbravo.model.pricing.pricelist.PriceList;
+import org.openbravo.model.pricing.pricelist.PriceListSchema;
+import org.openbravo.model.pricing.pricelist.PriceListSchemeLine;
+import org.openbravo.model.pricing.pricelist.PriceListVersion;
+import org.openbravo.model.pricing.pricelist.ProductPrice;
+import org.openbravo.service.db.CallProcess;
+import org.openbravo.test.base.OBBaseTest;
+import org.openbravo.test.pricelist.data.PriceListSchemaLineTestData;
+import org.openbravo.test.pricelist.data.PriceListTestConstants;
+import org.openbravo.test.pricelist.data.PriceListTestData;
+import org.openbravo.test.pricelist.data.PriceListTestData1;
+import org.openbravo.test.pricelist.data.PriceListTestData10;
+import org.openbravo.test.pricelist.data.PriceListTestData11;
+import org.openbravo.test.pricelist.data.PriceListTestData12;
+import org.openbravo.test.pricelist.data.PriceListTestData13;
+import org.openbravo.test.pricelist.data.PriceListTestData14;
+import org.openbravo.test.pricelist.data.PriceListTestData15;
+import org.openbravo.test.pricelist.data.PriceListTestData16;
+import org.openbravo.test.pricelist.data.PriceListTestData2;
+import org.openbravo.test.pricelist.data.PriceListTestData3;
+import org.openbravo.test.pricelist.data.PriceListTestData4;
+import org.openbravo.test.pricelist.data.PriceListTestData5;
+import org.openbravo.test.pricelist.data.PriceListTestData6;
+import org.openbravo.test.pricelist.data.PriceListTestData7;
+import org.openbravo.test.pricelist.data.PriceListTestData8;
+import org.openbravo.test.pricelist.data.PriceListTestData9;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Tests cases to check Price Lists Generation
+ * 
+ * @author Mark
+ *
+ */
+@RunWith(Parameterized.class)
+public class PriceListTest extends OBBaseTest {
+  final static private Logger log = 
LoggerFactory.getLogger(PriceListTest.class);
+
+  // User Openbravo
+  private final String USER_ID = "100";
+  // Client QA Testing
+  private final String CLIENT_ID = "4028E6C72959682B01295A070852010D";
+  // Organization Spain
+  private final String ORGANIZATION_ID = "357947E87C284935AD1D783CF6F099A1";
+  // Role QA Testing Admin
+  private final String ROLE_ID = "4028E6C72959682B01295A071429011E";
+  // M_PRICELIST_CREATE Procedure ID and NAME
+  private final String M_PRICELIST_CREATE_PROCEDURE_ID = "103";
+
+  // Test information
+  private String testNumber;
+  private String testDescription;
+
+  // Price List Scheme Lines
+  private PriceListSchemaLineTestData[] testPriceListRules;
+  private HashMap<String, String[]> expectedProductPricesData;
+
+  // Price List Header
+  private String currencyId;
+  private boolean isSalesPrice;
+  private boolean isBasedOnCost;
+  private boolean isPriceIncludesTax;
+
+  // Price List Version
+  private String basePriceListVersionId;
+
+  public PriceListTest(String testNumber, String testDescription, 
PriceListTestData data) {
+    this.testNumber = testNumber;
+    this.testDescription = testDescription;
+    this.testPriceListRules = data.getTestPriceListRulesData();
+    this.currencyId = data.getCurrencyId();
+    this.isSalesPrice = data.isSalesPrice();
+    this.isBasedOnCost = data.isBasedOnCost();
+    this.isPriceIncludesTax = data.isPriceIncludesTax();
+    this.basePriceListVersionId = data.getBasePriceListVersionId();
+    this.expectedProductPricesData = data.getExpectedProductPrices();
+  }
+
+  /** Parameterized possible combinations for price list computation */
+  @Parameters(name = "idx:{0} name:{1}")
+  public static Collection<Object[]> params() {
+    return Arrays
+        .asList(new Object[][] {
+            {
+                "01",
+                "PriceListSchema with one rule associated to the same Product 
Category. Unit Price and List Price discounts applied.",
+                new PriceListTestData1() //
+            },
+            {
+                "02",
+                "PriceListSchema with one rule associated to specific Product. 
Unit Price and List Price discounts applied.",
+                new PriceListTestData2() //
+            },
+            {
+                "03",
+                "PriceListSchema with more than one rule associated. First to 
an entire Product category and second one to specific Product. Unit Price and 
List Price discounts applied in both rules.",
+                new PriceListTestData3() //
+            },
+            {
+                "04",
+                "Price List Schema with Fixed Prices for an entire Product 
Category and selected base Price List.",
+                new PriceListTestData4() //
+            },
+            {
+                "05",
+                "Price List Schema with Cost Prices and an entire Product 
Category and without select base Price List.",
+                new PriceListTestData5() //
+            },
+            {
+                "06",
+                "Price List Schema with Cost Prices and an selected Product 
and without select base Price List.",
+                new PriceListTestData6() //
+            },
+            {
+                "07",
+                "Price List Schema with Fixed Price or Cost Based, an entire 
Product Category and base Price List.",
+                new PriceListTestData7() //
+            },
+            {
+                "08",
+                "Price List Schema with Fixed Price or Cost Based, and 
selected Product and base Price List.",
+                new PriceListTestData8() //
+            },
+            {
+                "09",
+                "Price List Schema with Fixed Price or Cost plus Margin Based, 
an entire Product Category and base Price List.",
+                new PriceListTestData9() //
+            },
+            {
+                "10",
+                "Price List Schema with Fixed Price or Cost plus Margin Based, 
and selected Product and base Price List.",
+                new PriceListTestData10() //
+            },
+            {
+                "11",
+                "Price List Schema with different unit price and list price 
discounts of ZERO percent, surcharge amounts and all products of a Product 
Category and base Price List.",
+                new PriceListTestData11() //
+            },
+            {
+                "12",
+                "Price List Schema with different unit price and list price 
discounts, surcharge amounts and all products of a Product Category and base 
Price List.",
+                new PriceListTestData12() //
+            },
+            {
+                "13",
+                "Price List Schema with different Limit (PO) price and Limit 
(PO) price discounts of ZERO percent, surcharge amounts and all products of a 
Product Category. Price List Based On Cost.",
+                new PriceListTestData13() //
+            },
+            {
+                "14",
+                "Price List Schema with different Limit (PO) price and Limit 
(PO) price discounts, surcharge amounts and all products of a Product Category 
and base Price List. Price list doesn't based on cost.",
+                new PriceListTestData14() //
+            },
+            {
+                "15",
+                "Price List Schema with more than one discount line, each 
associated to different Product Categories and rules. Price List Based on 
Cost.",
+                new PriceListTestData15() //
+            },
+            {
+                "16",
+                "Price List Schema with four different rules applied. Unit 
Price and List Price discounts applied.",
+                new PriceListTestData16() //
+            } });
+  }
+
+  @Test
+  public void testPriceListProductPrices() {
+
+    log.info("Test Started {}: {} ", this.testNumber, this.testDescription);
+
+    // Set QA context
+    OBContext.setOBContext(USER_ID, ROLE_ID, CLIENT_ID, ORGANIZATION_ID);
+
+    try {
+      PriceListSchema priceListSchema = createPriceListSchema();
+      addPriceListSchemeLines(priceListSchema);
+
+      PriceList priceList = createPriceList();
+      PriceListVersion priceListVersion = addPriceListVersion(priceList, 
priceListSchema);
+
+      generateProductPriceList(priceListVersion);
+      validateGeneratedPrices(priceListVersion);
+
+      deletePriceList(priceList);
+      deletePriceListSchema(priceListSchema);
+
+      log.info("Test Completed successfully");
+    }
+
+    catch (Exception e) {
+      log.error("Error when executing testPriceListProductPrices", e);
+      assertFalse(true);
+    }
+
+  }
+
+  /**
+   * Create a new Price List Schema (Header only)
+   * 
+   * @return The new Price List Schema created.
+   */
+  private PriceListSchema createPriceListSchema() {
+    PriceListSchema pls = OBProvider.getInstance().get(PriceListSchema.class);
+    pls.setClient(OBDal.getInstance().get(Client.class, CLIENT_ID));
+    pls.setOrganization(OBDal.getInstance().get(Organization.class, 
ORGANIZATION_ID));
+    pls.setName(PriceListTestConstants.PRICE_LIST_SCHEMA_NAME);
+    OBDal.getInstance().save(pls);
+    return pls;
+  }
+
+  /**
+   * Add lines to a Price List Schema. It creates as many lines as defined in 
the Price List Schema
+   * test data, and add them to the price list schema.
+   * 
+   * @param priceListSchema
+   *          The Price List Schema where the lines will be added
+   */
+  private void addPriceListSchemeLines(PriceListSchema priceListSchema) {
+    for (int i = 0; i < testPriceListRules.length; i++) {
+      PriceListSchemeLine line = createPriceListSchemeLine(priceListSchema, 
testPriceListRules[i],
+          i);
+      priceListSchema.getPricingPriceListSchemeLineList().add(line);
+      OBDal.getInstance().save(priceListSchema);

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Openbravo-commits mailing list
Openbravo-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to