/*********************************************************************** * 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 static org.junit.jupiter.api.Assertions.assertEquals; 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'"; AccessSqlParser fixture = new AccessSqlParser(sql); assertEquals("AccessSqlParser[AD_Table|0]", fixture.toString()); } /** * 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'"; AccessSqlParser fixture = new AccessSqlParser(sql); assertEquals("AccessSqlParser[AD_Table=t|0]", fixture.toString()); } /** * 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'"; AccessSqlParser fixture = new AccessSqlParser(sql); assertEquals("AccessSqlParser[AD_Table=t|0]", fixture.toString()); } /** * 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'"; AccessSqlParser fixture = new AccessSqlParser(sql); assertEquals("AccessSqlParser[AD_Table=t,AD_Column=c|0]", fixture.toString()); } /** * 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'"; AccessSqlParser fixture = new AccessSqlParser(sql); assertEquals("AccessSqlParser[AD_Table=t,AD_Column=c|0]", fixture.toString()); } /** * Run the joinInner test */ @Test public void testJoinInner() { String sql = "SELECT t.AD_Table_ID, t.TableName, c.AD_Column_ID, c.ColumnName " + "FROM AD_Table t INNER JOIN AD_Column c ON (t.AD_Table_ID=c.AD_Table_ID) WHERE t.IsActive='Y'"; AccessSqlParser fixture = new AccessSqlParser(sql); assertEquals("AccessSqlParser[AD_Table=t,AD_Column=c|0]", fixture.toString()); } /** * Run the joinOuter test */ @Test public void testJoinOuter() { String sql = "SELECT t.AD_Table_ID, t.TableName, c.AD_Column_ID, c.ColumnName " + "FROM AD_Table t LEFT OUTER JOIN AD_Column c ON (t.AD_Table_ID=c.AD_Table_ID) WHERE t.IsActive='Y'"; AccessSqlParser fixture = new AccessSqlParser(sql); assertEquals("AccessSqlParser[AD_Table=t,AD_Column=c|0]", fixture.toString()); } /** * Run the exists test */ @Test public void testExists() { String sql = "SELECT AD_Table.AD_Table_ID, AD_Table.TableName " + "FROM AD_Table " + "WHERE EXISTS (SELECT * FROM AD_Column c WHERE AD_Table.AD_Table_ID=c.AD_Table_ID)"; AccessSqlParser fixture = new AccessSqlParser(sql); assertEquals("AccessSqlParser[AD_Column=c|AD_Table|1]", fixture.toString()); } /** * Run the exists test with syn */ @Test public void testExistsSyn() { String sql = "SELECT t.AD_Table_ID, t.TableName " + "FROM AD_Table t " + "WHERE EXISTS (SELECT * FROM AD_Column c WHERE t.AD_Table_ID=c.AD_Table_ID)"; AccessSqlParser fixture = new AccessSqlParser(sql); assertEquals("AccessSqlParser[AD_Column=c|AD_Table=t|1]", fixture.toString()); } /** * Run the embeddedSelect test */ @Test public void testEmbeddedSelect() { String sql = "SELECT t.AD_Table_ID, t.TableName," + "(SELECT COUNT(c.ColumnName) FROM AD_Column c WHERE t.AD_Table_ID=c.AD_Table_ID) " + "FROM AD_Table t WHERE t.IsActive='Y'"; AccessSqlParser fixture = new AccessSqlParser(sql); assertEquals("AccessSqlParser[AD_Column=c|AD_Table=t|1]", fixture.toString()); } /** * Run the embeddedFrom test */ @Test public void testEmbeddedFrom() { String sql = "SELECT t.AD_Table_ID, t.TableName, cc.CCount " + "FROM AD_Table t," + "(SELECT COUNT(ColumnName) AS CCount FROM AD_Column) cc " + "WHERE t.IsActive='Y'"; AccessSqlParser fixture = new AccessSqlParser(sql); assertEquals("AccessSqlParser[AD_Column|AD_Table=t,(##)=cc|1]", fixture.toString()); } /** * 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)