diff options
Diffstat (limited to 'dbaccess/qa/complex/dbaccess/SingleSelectQueryComposer.java')
-rwxr-xr-x | dbaccess/qa/complex/dbaccess/SingleSelectQueryComposer.java | 136 |
1 files changed, 71 insertions, 65 deletions
diff --git a/dbaccess/qa/complex/dbaccess/SingleSelectQueryComposer.java b/dbaccess/qa/complex/dbaccess/SingleSelectQueryComposer.java index bb3636100849..ec77f084063e 100755 --- a/dbaccess/qa/complex/dbaccess/SingleSelectQueryComposer.java +++ b/dbaccess/qa/complex/dbaccess/SingleSelectQueryComposer.java @@ -36,6 +36,16 @@ import com.sun.star.sdbc.DataType; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; +// ---------- junit imports ----------------- +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.openoffice.test.OfficeConnection; +import static org.junit.Assert.*; +// ------------------------------------------ + public class SingleSelectQueryComposer extends CRMBasedTestCase { @@ -48,24 +58,24 @@ public class SingleSelectQueryComposer extends CRMBasedTestCase private final static String INNERPRODUCTSQUERY = "products (inner)"; // -------------------------------------------------------------------------------------------------------- - public String[] getTestMethodNames() - { - return new String[] - { - "testSetCommand", - "testAttributes", - "testSubQueries", - "testParameters", - "testDisjunctiveNormalForm", - "testConditionByColumn" - }; - } - - // -------------------------------------------------------------------------------------------------------- - public String getTestObjectName() - { - return "SingleSelectQueryComposer"; - } +// public String[] getTestMethodNames() +// { +// return new String[] +// { +// "testSetCommand", +// "testAttributes", +// "testSubQueries", +// "testParameters", +// "testDisjunctiveNormalForm", +// "testConditionByColumn" +// }; +// } + +// // -------------------------------------------------------------------------------------------------------- +// public String getTestObjectName() +// { +// return "SingleSelectQueryComposer"; +// } // -------------------------------------------------------------------------------------------------------- private void createQueries() throws Exception @@ -87,14 +97,14 @@ public class SingleSelectQueryComposer extends CRMBasedTestCase } catch (Exception e) { - assure("caught an exception (" + e.getMessage() + ") while creating the test case", false); + fail("caught an exception (" + e.getMessage() + ") while creating the test case"); } } // -------------------------------------------------------------------------------------------------------- private void checkAttributeAccess(String _attributeName, String _attributeValue) { - log.println("setting " + _attributeName + " to " + _attributeValue); + System.out.println("setting " + _attributeName + " to " + _attributeValue); String realValue = null; try { @@ -124,53 +134,53 @@ public class SingleSelectQueryComposer extends CRMBasedTestCase catch (InvocationTargetException e) { } - assure("set/get" + _attributeName + " not working as expected (set: " + _attributeValue + ", get: " + (realValue != null ? realValue : "null") + ")", + assertTrue("set/get" + _attributeName + " not working as expected (set: " + _attributeValue + ", get: " + (realValue != null ? realValue : "null") + ")", realValue.equals(_attributeValue)); - log.println(" (results in " + (String) m_composer.getQuery() + ")"); + System.out.println(" (results in " + m_composer.getQuery() + ")"); } /** tests setCommand of the composer */ - public void testSetCommand() + @Test public void testSetCommand() { - log.println("testing SingleSelectQueryComposer's setCommand"); + System.out.println("testing SingleSelectQueryComposer's setCommand"); try { final String table = "SELECT * FROM \"customers\""; m_composer.setCommand("customers",CommandType.TABLE); - assure("setCommand/getQuery TABLE inconsistent", m_composer.getQuery().equals(table)); + assertTrue("setCommand/getQuery TABLE inconsistent", m_composer.getQuery().equals(table)); m_database.getDatabase().getDataSource().createQuery("set command test", "SELECT * FROM \"orders for customer\" \"a\", \"customers\" \"b\" WHERE \"a\".\"Product Name\" = \"b\".\"Name\""); m_composer.setCommand("set command test",CommandType.QUERY); - assure("setCommand/getQuery QUERY inconsistent", m_composer.getQuery().equals(m_database.getDatabase().getDataSource().getQueryDefinition("set command test").getCommand())); + assertTrue("setCommand/getQuery QUERY inconsistent", m_composer.getQuery().equals(m_database.getDatabase().getDataSource().getQueryDefinition("set command test").getCommand())); final String sql = "SELECT * FROM \"orders for customer\" WHERE \"Product Name\" = 'test'"; m_composer.setCommand(sql,CommandType.COMMAND); - assure("setCommand/getQuery COMMAND inconsistent", m_composer.getQuery().equals(sql)); + assertTrue("setCommand/getQuery COMMAND inconsistent", m_composer.getQuery().equals(sql)); } catch (Exception e) { - assure("Exception caught: " + e, false); + fail("Exception caught: " + e); } } /** tests accessing attributes of the composer (order, filter, group by, having) */ - public void testAttributes() + @Test public void testAttributes() { - log.println("testing SingleSelectQueryComposer's attributes (order, filter, group by, having)"); + System.out.println("testing SingleSelectQueryComposer's attributes (order, filter, group by, having)"); try { - log.println("check setElementaryQuery"); + System.out.println("check setElementaryQuery"); final String simpleQuery2 = "SELECT * FROM \"customers\" WHERE \"Name\" = 'oranges'"; m_composer.setElementaryQuery(simpleQuery2); - assure("setElementaryQuery/getQuery inconsistent", m_composer.getQuery().equals(simpleQuery2)); + assertTrue("setElementaryQuery/getQuery inconsistent", m_composer.getQuery().equals(simpleQuery2)); - log.println("check setQuery"); + System.out.println("check setQuery"); final String simpleQuery = "SELECT * FROM \"customers\""; m_composer.setQuery(simpleQuery); - assure("set/getQuery inconsistent", m_composer.getQuery().equals(simpleQuery)); + assertTrue("set/getQuery inconsistent", m_composer.getQuery().equals(simpleQuery)); checkAttributeAccess("Filter", "\"Name\" = 'oranges'"); checkAttributeAccess("Group", "\"City\""); @@ -178,16 +188,16 @@ public class SingleSelectQueryComposer extends CRMBasedTestCase checkAttributeAccess("HavingClause", "\"ID\" <> 4"); final XIndexAccess orderColumns = m_composer.getOrderColumns(); - assure("Order columns doesn't exist: \"Address\"", + assertTrue("Order columns doesn't exist: \"Address\"", orderColumns != null && orderColumns.getCount() == 1 && orderColumns.getByIndex(0) != null); final XIndexAccess groupColumns = m_composer.getGroupColumns(); - assure("Group columns doesn't exist: \"City\"", + assertTrue("Group columns doesn't exist: \"City\"", groupColumns != null && groupColumns.getCount() == 1 && groupColumns.getByIndex(0) != null); // XColumnsSupplier - final XColumnsSupplier xSelectColumns = (XColumnsSupplier) UnoRuntime.queryInterface(XColumnsSupplier.class, m_composer); - assure("no select columns, or wrong number of select columns", + final XColumnsSupplier xSelectColumns = UnoRuntime.queryInterface(XColumnsSupplier.class, m_composer); + assertTrue("no select columns, or wrong number of select columns", xSelectColumns != null && xSelectColumns.getColumns() != null && xSelectColumns.getColumns().getElementNames().length == 6); // structured filter @@ -196,41 +206,40 @@ public class SingleSelectQueryComposer extends CRMBasedTestCase final PropertyValue[][] aStructuredFilter = m_composer.getStructuredFilter(); m_composer.setFilter(""); m_composer.setStructuredFilter(aStructuredFilter); - assure("Structured Filter not identical", m_composer.getFilter().equals(COMPLEXFILTER)); + assertTrue("Structured Filter not identical", m_composer.getFilter().equals(COMPLEXFILTER)); // structured having clause m_composer.setHavingClause(COMPLEXFILTER); final PropertyValue[][] aStructuredHaving = m_composer.getStructuredHavingClause(); m_composer.setHavingClause(""); m_composer.setStructuredHavingClause(aStructuredHaving); - assure("Structured Having Clause not identical", m_composer.getHavingClause().equals(COMPLEXFILTER)); + assertTrue("Structured Having Clause not identical", m_composer.getHavingClause().equals(COMPLEXFILTER)); } catch (Exception e) { - assure("Exception caught: " + e, false); + fail("Exception caught: " + e); } } /** test various sub query related features ("queries in queries") */ - public void testSubQueries() throws Exception + @Test public void testSubQueries() throws Exception { m_composer.setQuery("SELECT * from \"" + INNERPRODUCTSQUERY + "\""); - final XTablesSupplier suppTables = (XTablesSupplier) UnoRuntime.queryInterface( - XTablesSupplier.class, m_composer); + final XTablesSupplier suppTables = UnoRuntime.queryInterface(XTablesSupplier.class, m_composer); final XNameAccess tables = suppTables.getTables(); - assure("a simple SELECT * FROM <query> could not be parsed", + assertTrue("a simple SELECT * FROM <query> could not be parsed", tables != null && tables.hasByName(INNERPRODUCTSQUERY)); final String sInnerCommand = m_database.getDatabase().getDataSource().getQueryDefinition(INNERPRODUCTSQUERY).getCommand(); final String sExecutableQuery = m_composer.getQueryWithSubstitution(); - assure("simple query containing a sub query improperly parsed to SDBC level statement: \n1. " + sExecutableQuery + "\n2. " + "SELECT * FROM ( " + sInnerCommand + " ) AS \"" + INNERPRODUCTSQUERY + "\"", + assertTrue("simple query containing a sub query improperly parsed to SDBC level statement: \n1. " + sExecutableQuery + "\n2. " + "SELECT * FROM ( " + sInnerCommand + " ) AS \"" + INNERPRODUCTSQUERY + "\"", sExecutableQuery.equals("SELECT * FROM ( " + sInnerCommand + " ) AS \"" + INNERPRODUCTSQUERY + "\"")); } /** tests the XParametersSupplier functionality */ - public void testParameters() + @Test public void testParameters() { try { @@ -241,8 +250,7 @@ public class SingleSelectQueryComposer extends CRMBasedTestCase m_database.getDatabase().getDataSource().createQuery("orders for customer and product", "SELECT * FROM \"orders for customer\" WHERE \"Product Name\" LIKE ?"); m_composer.setQuery(m_database.getDatabase().getDataSource().getQueryDefinition("orders for customer and product").getCommand()); - final XParametersSupplier suppParams = (XParametersSupplier) UnoRuntime.queryInterface( - XParametersSupplier.class, m_composer); + final XParametersSupplier suppParams = UnoRuntime.queryInterface(XParametersSupplier.class, m_composer); final XIndexAccess parameters = suppParams.getParameters(); final String expectedParamNames[] = @@ -252,26 +260,25 @@ public class SingleSelectQueryComposer extends CRMBasedTestCase }; final int paramCount = parameters.getCount(); - assure("composer did find wrong number of parameters in the nested queries.", + assertTrue("composer did find wrong number of parameters in the nested queries.", paramCount == expectedParamNames.length); for (int i = 0; i < paramCount; ++i) { - final XPropertySet parameter = (XPropertySet) UnoRuntime.queryInterface( - XPropertySet.class, parameters.getByIndex(i)); + final XPropertySet parameter = UnoRuntime.queryInterface(XPropertySet.class, parameters.getByIndex(i)); final String paramName = (String) parameter.getPropertyValue("Name"); - assure("wrong parameter name at position " + (i + 1) + " (expected: " + expectedParamNames[i] + ", found: " + paramName + ")", + assertTrue("wrong parameter name at position " + (i + 1) + " (expected: " + expectedParamNames[i] + ", found: " + paramName + ")", paramName.equals(expectedParamNames[i])); } } catch (Exception e) { - assure("caught an exception: " + e, false); + fail("caught an exception: " + e); } } - public void testConditionByColumn() + @Test public void testConditionByColumn() { try { @@ -282,23 +289,22 @@ public class SingleSelectQueryComposer extends CRMBasedTestCase new NamedValue("AutomaticAddition", Boolean.valueOf(true)) }; final String serviceName = "com.sun.star.beans.PropertyBag"; - final XPropertyContainer filter = (XPropertyContainer) UnoRuntime.queryInterface(XPropertyContainer.class, - getORB().createInstanceWithArguments(serviceName, initArgs)); + final XPropertyContainer filter = UnoRuntime.queryInterface(XPropertyContainer.class, getMSF().createInstanceWithArguments(serviceName, initArgs)); filter.addProperty("Name", PropertyAttribute.MAYBEVOID, "Comment"); filter.addProperty("RealName", PropertyAttribute.MAYBEVOID, "Comment"); filter.addProperty("TableName", PropertyAttribute.MAYBEVOID, "customers"); filter.addProperty("Value", PropertyAttribute.MAYBEVOID, "Good one."); filter.addProperty("Type", PropertyAttribute.MAYBEVOID, Integer.valueOf(DataType.LONGVARCHAR)); - final XPropertySet column = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class,filter); + final XPropertySet column = UnoRuntime.queryInterface(XPropertySet.class, filter); m_composer.appendFilterByColumn(column, true,SQLFilterOperator.LIKE); - assure("At least one row should exist",m_database.getConnection().createStatement().executeQuery(m_composer.getQuery()).next()); + assertTrue("At least one row should exist",m_database.getConnection().createStatement().executeQuery(m_composer.getQuery()).next()); } catch (Exception e) { // this is an error: the query is expected to be parseable - assure("caught an exception: " + e, false); + fail("caught an exception: " + e); } } @@ -311,18 +317,18 @@ public class SingleSelectQueryComposer extends CRMBasedTestCase catch (Exception e) { // this is an error: the query is expected to be parseable - assure("caught an exception: " + e, false); + fail("caught an exception: " + e); } final PropertyValue[][] disjunctiveNormalForm = m_composer.getStructuredFilter(); - assureEquals("DNF: wrong number of rows", _expectedDNF.length, disjunctiveNormalForm.length); + assertEquals("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); + assertEquals("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, + assertEquals("DNF: wrong content in column " + j + ", row " + i, _expectedDNF[i][j].Name, disjunctiveNormalForm[i][j].Name); } } @@ -331,7 +337,7 @@ public class SingleSelectQueryComposer extends CRMBasedTestCase /** tests the disjunctive normal form functionality, aka the structured filter, * of the composer */ - public void testDisjunctiveNormalForm() + @Test public void testDisjunctiveNormalForm() { // a simple case: WHERE clause simply is a combination of predicates knitted with AND String query = |