IDEMPIERE-5063 - Move AccessSqlParserTest class from model to org.ide… (#1028)

* IDEMPIERE-5063 - Move AccessSqlParserTest class from model to org.idempiere.test

* IDEMPIERE-5063 - Set right header in the Test class
This commit is contained in:
Diego Ruiz 2021-12-06 11:49:11 +01:00 committed by GitHub
parent a14ac5fbe2
commit 1f1797ce5b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 49 additions and 112 deletions

View File

@ -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)<TO_DATE('2003-10-16','YYYY-MM-DD') AND asi.M_AttributeSetInstance_ID IN (SELECT M_AttributeSetInstance_ID FROM M_AttributeInstance WHERE (M_Attribute_ID=103 AND Value LIKE '33') AND (M_Attribute_ID=102 AND M_AttributeValue_ID=106))) AND p.M_AttributeSetInstance_ID IN (SELECT M_AttributeSetInstance_ID FROM M_AttributeInstance WHERE (M_Attribute_ID=101 AND M_AttributeValue_ID=105) AND (M_Attribute_ID=100 AND M_AttributeValue_ID=102)) AND p.AD_Client_ID IN(0,11) AND p.AD_Org_ID IN(0,11,12) ORDER BY QtyAvailable DESC, Margin DESC";
@ -196,27 +177,17 @@ public class AccessSqlParserTest extends TestCase
/**
* Run the Product Attribute Query
*/
@Test
public void testProductAttributeQuery()
{
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 p.M_AttributeSetInstance_ID IN (SELECT M_AttributeSetInstance_ID FROM M_AttributeInstance WHERE (M_Attribute_ID=100 AND M_AttributeValue_ID=101)) ORDER BY QtyAvailable DESC, Margin DESC";
AccessSqlParser fixture = new AccessSqlParser(sql);
assertEquals("AccessSqlParser[M_AttributeInstance|M_Product=p,M_ProductPrice=pr,M_AttributeSet=pa|1]", fixture.toString());
}
/** **/
/*public void testHinttech()
{
String sql = "SELECT XX_HTC1_EMPLOYEE_V.C_BPartner_ID,NULL,XX_HTC1_EMPLOYEE_V.C_BPARTNER_NAME,XX_HTC1_EMPLOYEE_V.IsActive FROM XX_HTC1_EMPLOYEE_V WHERE XX_HTC1_EMPLOYEE_V.AD_User_ID IN (SELECT ur.AD_User_ID FROM AD_User_Roles ur INNER JOIN AD_Role r ON (ur.AD_Role_ID=r.AD_Role_ID) WHERE r.Name like '%Field Manager%')";
AccessSqlParser fixture = new AccessSqlParser(sql);
}*/
/**
* <li>teo_sarca - [ 1652623 ] AccessSqlParser.getTableInfo(String) - tablename parsing bug
* <li>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
* <pre>
* 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")
* </pre>
*
* @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
*/