From 1f1797ce5b424773e3449479582ce7b07a7772a4 Mon Sep 17 00:00:00 2001 From: Diego Ruiz <12065321+d-ruiz@users.noreply.github.com> Date: Mon, 6 Dec 2021 11:49:11 +0100 Subject: [PATCH] =?UTF-8?q?IDEMPIERE-5063=20-=20Move=20AccessSqlParserTest?= =?UTF-8?q?=20class=20from=20model=20to=20org.ide=E2=80=A6=20(#1028)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * IDEMPIERE-5063 - Move AccessSqlParserTest class from model to org.idempiere.test * IDEMPIERE-5063 - Set right header in the Test class --- .../test/base/AcessSQLParserTest.java | 161 ++++++------------ 1 file changed, 49 insertions(+), 112 deletions(-) rename org.adempiere.base/src/org/compiere/model/AccessSqlParserTest.java => org.idempiere.test/src/org/idempiere/test/base/AcessSQLParserTest.java (67%) diff --git a/org.adempiere.base/src/org/compiere/model/AccessSqlParserTest.java b/org.idempiere.test/src/org/idempiere/test/base/AcessSQLParserTest.java similarity index 67% rename from org.adempiere.base/src/org/compiere/model/AccessSqlParserTest.java rename to org.idempiere.test/src/org/idempiere/test/base/AcessSQLParserTest.java index d40896d020..f628c12c4f 100644 --- a/org.adempiere.base/src/org/compiere/model/AccessSqlParserTest.java +++ b/org.idempiere.test/src/org/idempiere/test/base/AcessSQLParserTest.java @@ -1,69 +1,39 @@ -/****************************************************************************** - * Product: Adempiere ERP & CRM Smart Business Solution * - * Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. * - * This program is free software; you can redistribute it and/or modify it * - * under the terms version 2 of the GNU General Public License as published * - * by the Free Software Foundation. This program is distributed in the hope * - * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * - * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * - * See the GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along * - * with this program; if not, write to the Free Software Foundation, Inc., * - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * - * For the text or an alternative of this public license, you may reach us * - * ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA * - * or via info@compiere.org or http://www.compiere.org/license.html * - *****************************************************************************/ -package org.compiere.model; +/*********************************************************************** + * This file is part of iDempiere ERP Open Source * + * http://www.idempiere.org * + * * + * Copyright (C) Contributors * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License * + * as published by the Free Software Foundation; either version 2 * + * of the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * + * MA 02110-1301, USA. * + * * + **********************************************************************/ +package org.idempiere.test.base; -import junit.framework.TestCase; -import junit.textui.TestRunner; +import static org.junit.jupiter.api.Assertions.assertEquals; -/** - * AccessSqlParserTest tests the class - * AccessSqlParser - * - * @author Jorg Janke - * @version $Id: AccessSqlParserTest.java,v 1.2 2006/07/30 00:58:04 jjanke Exp $ - */ -public class AccessSqlParserTest extends TestCase -{ - /** - * Construct new test instance - * - * @param name the test name - */ - public AccessSqlParserTest(String name) - { - super(name); - } - - /** - * Launch the test. - * - * @param args String[] - */ - public static void main(String[] args) - { - TestRunner.run(AccessSqlParserTest.class); - } - - /** - * Perform pre-test initialization - * - * @throws Exception - * - * @see TestCase#setUp() - */ - protected void setUp() throws Exception - { - super.setUp(); -// Adempiere.startup(true); - } +import org.compiere.model.AccessSqlParser; +import org.idempiere.test.AbstractTestCase; +import org.junit.jupiter.api.Test; +public final class AcessSQLParserTest extends AbstractTestCase { + /** * Run the oneTable test */ + @Test public void testOneTable() { String sql = "SELECT AD_Table_ID, TableName FROM AD_Table WHERE IsActive='Y'"; @@ -74,6 +44,7 @@ public class AccessSqlParserTest extends TestCase /** * Run the oneTableSyn test */ + @Test public void testOneTableSyn() { String sql = "SELECT t.AD_Table_ID, t.TableName FROM AD_Table t WHERE t.IsActive='Y'"; @@ -84,6 +55,7 @@ public class AccessSqlParserTest extends TestCase /** * Run the oneTableSyn test */ + @Test public void testOneTableSynAS() { String sql = "SELECT t.AD_Table_ID, t.TableName FROM AD_Table AS t WHERE t.IsActive='Y'"; @@ -94,6 +66,7 @@ public class AccessSqlParserTest extends TestCase /** * Run the twoTable test */ + @Test public void testTwoTable() { String sql = "SELECT t.AD_Table_ID, t.TableName, c.AD_Column_ID, c.ColumnName FROM AD_Table t, AD_Column c WHERE t.AD_Table_ID=c.AD_Table_ID AND t.IsActive='Y'"; @@ -104,6 +77,7 @@ public class AccessSqlParserTest extends TestCase /** * Run the twoTableSyn test */ + @Test public void testTwoTableSyn() { String sql = "SELECT t.AD_Table_ID, t.TableName, c.AD_Column_ID, c.ColumnName FROM AD_Table as t, AD_Column AS c WHERE t.AD_Table_ID=c.AD_Table_ID AND t.IsActive='Y'"; @@ -114,6 +88,7 @@ public class AccessSqlParserTest extends TestCase /** * Run the joinInner test */ + @Test public void testJoinInner() { String sql = "SELECT t.AD_Table_ID, t.TableName, c.AD_Column_ID, c.ColumnName " @@ -125,6 +100,7 @@ public class AccessSqlParserTest extends TestCase /** * Run the joinOuter test */ + @Test public void testJoinOuter() { String sql = "SELECT t.AD_Table_ID, t.TableName, c.AD_Column_ID, c.ColumnName " @@ -136,6 +112,7 @@ public class AccessSqlParserTest extends TestCase /** * Run the exists test */ + @Test public void testExists() { String sql = "SELECT AD_Table.AD_Table_ID, AD_Table.TableName " @@ -148,6 +125,7 @@ public class AccessSqlParserTest extends TestCase /** * Run the exists test with syn */ + @Test public void testExistsSyn() { String sql = "SELECT t.AD_Table_ID, t.TableName " @@ -160,6 +138,7 @@ public class AccessSqlParserTest extends TestCase /** * Run the embeddedSelect test */ + @Test public void testEmbeddedSelect() { String sql = "SELECT t.AD_Table_ID, t.TableName," @@ -172,6 +151,7 @@ public class AccessSqlParserTest extends TestCase /** * Run the embeddedFrom test */ + @Test public void testEmbeddedFrom() { String sql = "SELECT t.AD_Table_ID, t.TableName, cc.CCount " @@ -186,6 +166,7 @@ public class AccessSqlParserTest extends TestCase /** * Run the Product & Instance Attribute Query */ + @Test public void testProductInstanceAttributeQuery() { String sql = "SELECT p.M_Product_ID, p.Discontinued, p.Value, p.Name, BOM_Qty_Available(p.M_Product_ID,?) AS QtyAvailable, bomQtyList(p.M_Product_ID, pr.M_PriceList_Version_ID) AS PriceList, bomQtyStd(p.M_Product_ID, pr.M_PriceList_Version_ID) AS PriceStd, BOM_Qty_OnHand(p.M_Product_ID,?) AS QtyOnHand, BOM_Qty_Reserved(p.M_Product_ID,?) AS QtyReserved, BOM_Qty_Ordered(p.M_Product_ID,?) AS QtyOrdered, bomQtyStd(p.M_Product_ID, pr.M_PriceList_Version_ID)-bomQtyLimit(p.M_Product_ID, pr.M_PriceList_Version_ID) AS Margin, bomQtyLimit(p.M_Product_ID, pr.M_PriceList_Version_ID) AS PriceLimit, pa.IsInstanceAttribute FROM M_Product p INNER JOIN M_ProductPrice pr ON (p.M_Product_ID=pr.M_Product_ID) LEFT OUTER JOIN M_AttributeSet pa ON (p.M_AttributeSet_ID=pa.M_AttributeSet_ID) WHERE p.IsSummary='N' AND p.IsActive='Y' AND pr.IsActive='Y' AND pr.M_PriceList_Version_ID=? AND EXISTS (SELECT * FROM M_StorageOnHand s INNER JOIN M_AttributeSetInstance asi ON (s.M_AttributeSetInstance_ID=asi.M_AttributeSetInstance_ID) WHERE s.M_Product_ID=p.M_Product_ID AND asi.SerNo LIKE '33' AND asi.Lot LIKE '33' AND asi.M_Lot_ID=101 AND TRUNC(asi.GuaranteeDate)teo_sarca - [ 1652623 ] AccessSqlParser.getTableInfo(String) - tablename parsing bug - *
  • teo_sarca - [ 1964496 ] AccessSqlParser is not parsing well JOIN CLAUSE - */ + + @Test public void testTableNameParsing() { - // - // BF [ 1652623 ] AccessSqlParser.getTableInfo(String) - tablename parsing bug String sql = "SELECT SUM(il.QtyInvoiced)\n" + "FROM RV_C_Invoice\n" @@ -225,62 +196,28 @@ public class AccessSqlParserTest extends TestCase + "C_Invoice.IsSOTrx='Y' AND C_Invoice.Processed='Y' AND C_Invoice.IsPaid='Y'"; AccessSqlParser fixture = new AccessSqlParser(sql); assertEquals("AccessSqlParser[RV_C_Invoice=C_Invoice,RV_C_InvoiceLine=il|0]", fixture.toString()); - // - // BF [ 1964496 ] AccessSqlParser is not parsing well JOIN CLAUSE + sql = "SELECT C_Invoice.* FROM C_Invoice\n" +"INNER JOIN C_BPartner bp ON (bp.C_BPartner_ID=C_Invoice.C_BPartner_ID) WHERE 1=0"; - ; fixture = new AccessSqlParser(sql); assertEquals("AccessSqlParser[C_Invoice,C_BPartner=bp|0]", fixture.toString()); } /** - * BF [ 2840157 ] AccessSqlParser is not parsing well ON keyword - *
    -	 * Following query is generating OutOfMemoryException:
    -	 * SELECT 1
    -	 * FROM M_Product p
    -	 * INNER JOIN M_Product_Category pc on
    -	 * (pc.M_Product_Category_ID=p.M_Product_Category_ID)
    -	 * LEFT OUTER JOIN M_Product_PO mpo ON (mpo.M_Product_ID=p.M_Product_ID)
    -	 *
    -	 * (please note the lower case "on")
    -	 * 
    - * - * @see https://sourceforge.net/tracker/?func=detail&aid=2840157&group_id=176962&atid=879332 + * Run test against ON SQL keyword. Both in upper and lowercase */ - public void test_BF2840157() + @Test + public void testONKeyword() { final String sql = "SELECT 1 FROM M_Product p" +"\n"+"INNER JOIN M_Product_Category pc on (pc.M_Product_Category_ID=p.M_Product_Category_ID)" +"\n"+"LEFT OUTER JOIN M_Product_PO mpo ON (mpo.M_Product_ID=p.M_Product_ID)" +"\n"+" WHERE p.IsActive='Y' AND p.IsPurchased='Y'" - +"\n"+"AND COALESCE(mpo.DeliveryTime_Promised,0) <= 0" - ; + +"\n"+"AND COALESCE(mpo.DeliveryTime_Promised,0) <= 0"; final String expected = "AccessSqlParser[M_Product=p,M_Product_Category=pc,M_Product_PO=mpo|0]"; AccessSqlParser fixture = new AccessSqlParser(sql); assertEquals(expected, fixture.toString()); } - } - -/*$CPS$ This comment was generated by CodePro. Do not edit it. - * patternId = com.instantiations.assist.eclipse.pattern.testCasePattern - * strategyId = com.instantiations.assist.eclipse.pattern.testCasePattern.junitTestCase - * additionalTestNames = oneTable, oneTableSyn, twoTable, twoTableSyn, joinInner, joinOuter, embeddedSelect, embeddedFrom - * assertTrue = false - * callTestMethod = true - * createMain = true - * createSetUp = true - * createTearDown = false - * createTestFixture = false - * createTestStubs = false - * methods = getSql(),parse() - * package = org.compiere.model - * package.sourceFolder = dbPort/src - * superclassType = junit.framework.TestCase - * testCase = AccessSqlParserTest - * testClassType = org.compiere.model.AccessSqlParser - */