Tag: cws_src680_dba24d User: fs Date: 2007-11-21 12:12:50+0000 Modified: dba/dbaccess/qa/complex/dbaccess/SingleSelectQueryComposer.java
Log: #i82233# new test case: testDisjunctiveNormalForm File Changes: Directory: /dba/dbaccess/qa/complex/dbaccess/ ============================================= File [changed]: SingleSelectQueryComposer.java Url: http://dba.openoffice.org/source/browse/dba/dbaccess/qa/complex/dbaccess/SingleSelectQueryComposer.java?r1=1.5.212.1&r2=1.5.212.2 Delta lines: +87 -4 -------------------- --- SingleSelectQueryComposer.java 2007-11-21 07:47:26+0000 1.5.212.1 +++ SingleSelectQueryComposer.java 2007-11-21 12:12:47+0000 1.5.212.2 @@ -4,9 +4,9 @@ * * $RCSfile: SingleSelectQueryComposer.java,v $ * - * $Revision: 1.5.212.1 $ + * $Revision: 1.5.212.2 $ * - * last change: $Author: fs $ $Date: 2007/11/21 07:47:26 $ + * last change: $Author: fs $ $Date: 2007/11/21 12:12:47 $ * * The Contents of this file are made available subject to * the terms of GNU Lesser General Public License Version 2.1. @@ -64,7 +64,8 @@ return new String[] { "testAttributes", "testSubQueries", - "testParameters" + "testParameters", + "testDisjunctiveNormalForm" }; } @@ -124,7 +125,6 @@ private void checkAttributeAccess( String _attributeName, String _attributeValue ) { log.println( "setting " + _attributeName + " to " + _attributeValue ); - boolean success = false; String realValue = null; try { @@ -254,4 +254,87 @@ assure( "caught an exception: " + e, false ); } } + + private void impl_testDisjunctiveNormalForm( String _query, PropertyValue[][] _expectedDNF ) + { + try { m_composer.setQuery( _query ); } + catch ( Exception e ) + { + // this is an error: the query is expected to be parseable + assure( "caught an exception: " + e, false ); + } + + PropertyValue[][] disjunctiveNormalForm = m_composer.getStructuredFilter(); + + assureEquals( "DNF: wrong number of rows", _expectedDNF.length, disjunctiveNormalForm.length ); + for ( int i=0; i<_expectedDNF.length; ++i ) + { + assureEquals( "DNF: wrong number of columns in row " + i, _expectedDNF[i].length, disjunctiveNormalForm[i].length ); + for ( int j=0; j<_expectedDNF[i].length; ++j ) + { + assureEquals( "DNF: wrong content in column " + j + ", row " + i, + _expectedDNF[i][j].Name, disjunctiveNormalForm[i][j].Name ); + } + } + } + + /** tests the disjunctive normal form functionality, aka the structured filter, + * of the composer + */ + public void testDisjunctiveNormalForm() + { + // a simple case: WHERE clause simply is a combination of predicates knitted with AND + String query = + "SELECT \"customers\".\"Name\", " + + "\"customers\".\"Address\", " + + "\"customers\".\"City\", " + + "\"customers\".\"Postal\", " + + "\"products\".\"Name\" " + + "FROM \"orders\", \"customers\", \"orders_details\", \"products\" " + + "WHERE ( \"orders\".\"CustomerID\" = \"customers\".\"ID\" " + + "AND \"orders_details\".\"OrderID\" = \"orders\".\"ID\" " + + "AND \"orders_details\".\"ProductID\" = \"products\".\"ID\" " + + ") "; + + impl_testDisjunctiveNormalForm( query, new PropertyValue[][] { + new PropertyValue[] { + new PropertyValue( "CustomerID", SQLFilterOperator.EQUAL, "\"customers\".\"ID\"", PropertyState.DIRECT_VALUE ), + new PropertyValue( "OrderID", SQLFilterOperator.EQUAL, "\"orders\".\"ID\"", PropertyState.DIRECT_VALUE ), + new PropertyValue( "ProductID", SQLFilterOperator.EQUAL, "\"products\".\"ID\"", PropertyState.DIRECT_VALUE ) + } } + ); + + // somewhat more challenging: One of the conjunction terms is a disjunction itself + query = + "SELECT \"customers\".\"Name\", " + + "\"customers\".\"Address\", " + + "\"customers\".\"City\", " + + "\"customers\".\"Postal\", " + + "\"products\".\"Name\" " + + "FROM \"orders\", \"customers\", \"orders_details\", \"products\" " + + "WHERE ( \"orders\".\"CustomerID\" = \"customers\".\"ID\" " + + "AND \"orders_details\".\"OrderID\" = \"orders\".\"ID\" " + + "AND \"orders_details\".\"ProductID\" = \"products\".\"ID\" " + + ") " + + "AND " + + "( \"products\".\"Name\" = 'Apples' " + + "OR \"products\".\"ID\" = 2 " + + ")"; + + impl_testDisjunctiveNormalForm( query, new PropertyValue[][] { + new PropertyValue[] { + new PropertyValue( "CustomerID", SQLFilterOperator.EQUAL, "\"customers\".\"ID\"", PropertyState.DIRECT_VALUE ), + new PropertyValue( "OrderID", SQLFilterOperator.EQUAL, "\"orders\".\"ID\"", PropertyState.DIRECT_VALUE ), + new PropertyValue( "ProductID", SQLFilterOperator.EQUAL, "\"products\".\"ID\"", PropertyState.DIRECT_VALUE ), + new PropertyValue( "Name", SQLFilterOperator.EQUAL, "Apples", PropertyState.DIRECT_VALUE ) + }, + new PropertyValue[] { + new PropertyValue( "CustomerID", SQLFilterOperator.EQUAL, "\"customers\".\"ID\"", PropertyState.DIRECT_VALUE ), + new PropertyValue( "OrderID", SQLFilterOperator.EQUAL, "\"orders\".\"ID\"", PropertyState.DIRECT_VALUE ), + new PropertyValue( "ProductID", SQLFilterOperator.EQUAL, "\"products\".\"ID\"", PropertyState.DIRECT_VALUE ), + new PropertyValue( "ID", SQLFilterOperator.EQUAL, new Integer(2), PropertyState.DIRECT_VALUE ) + } } + ); + + } } --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
