diff options
author | Vladimir Glazunov <vg@openoffice.org> | 2010-10-14 14:25:42 +0200 |
---|---|---|
committer | Vladimir Glazunov <vg@openoffice.org> | 2010-10-14 14:25:42 +0200 |
commit | c2c8869c40e7831f0d040dc4b7d54c31954413d8 (patch) | |
tree | d521c9b1365ccfa0dce62888dc7000d0942c464b /dbaccess/qa | |
parent | 7d4814bb93a75943282167707e69588969145d1f (diff) | |
parent | 11fb383f4d40fafad034662f01108ed04485489b (diff) |
CWS-TOOLING: integrate CWS sb123
Notes
Notes:
split repo tag: base_ooo/DEV300_m90
Diffstat (limited to 'dbaccess/qa')
-rw-r--r-- | dbaccess/qa/complex/dbaccess/ApplicationController.java | 49 | ||||
-rw-r--r-- | dbaccess/qa/complex/dbaccess/Beamer.java | 126 | ||||
-rw-r--r-- | dbaccess/qa/complex/dbaccess/CRMBasedTestCase.java | 24 | ||||
-rwxr-xr-x | dbaccess/qa/complex/dbaccess/CopyTableWizard.java | 58 | ||||
-rw-r--r-- | dbaccess/qa/complex/dbaccess/DataSource.java | 72 | ||||
-rwxr-xr-x | dbaccess/qa/complex/dbaccess/DatabaseApplication.java | 11 | ||||
-rw-r--r-- | dbaccess/qa/complex/dbaccess/DatabaseDocument.java | 261 | ||||
-rw-r--r-- | dbaccess/qa/complex/dbaccess/Parser.java | 59 | ||||
-rw-r--r-- | dbaccess/qa/complex/dbaccess/PropertyBag.java | 130 | ||||
-rw-r--r-- | dbaccess/qa/complex/dbaccess/Query.java | 52 | ||||
-rw-r--r-- | dbaccess/qa/complex/dbaccess/QueryInQuery.java | 72 | ||||
-rw-r--r-- | dbaccess/qa/complex/dbaccess/RowSet.java | 220 | ||||
-rwxr-xr-x | dbaccess/qa/complex/dbaccess/SingleSelectQueryComposer.java | 136 | ||||
-rw-r--r-- | dbaccess/qa/complex/dbaccess/TestCase.java | 65 | ||||
-rw-r--r-- | dbaccess/qa/complex/dbaccess/UISettings.java | 58 | ||||
-rwxr-xr-x | dbaccess/qa/complex/dbaccess/makefile.mk | 143 |
16 files changed, 858 insertions, 678 deletions
diff --git a/dbaccess/qa/complex/dbaccess/ApplicationController.java b/dbaccess/qa/complex/dbaccess/ApplicationController.java index 4c964e82dc06..bffc1ce97c4c 100644 --- a/dbaccess/qa/complex/dbaccess/ApplicationController.java +++ b/dbaccess/qa/complex/dbaccess/ApplicationController.java @@ -48,6 +48,17 @@ import helper.URLHelper; import java.io.File; import java.io.IOException; + +// ---------- 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.*; +// ------------------------------------------ + /** complex test case for Base's application UI */ public class ApplicationController extends TestCase @@ -64,13 +75,13 @@ public class ApplicationController extends TestCase // -------------------------------------------------------------------------------------------------------- - public String[] getTestMethodNames() - { - return new String[] - { - "checkSaveAs" - }; - } +// public String[] getTestMethodNames() +// { +// return new String[] +// { +// "checkSaveAs" +// }; +// } // -------------------------------------------------------------------------------------------------------- public String getTestObjectName() @@ -98,16 +109,16 @@ public class ApplicationController extends TestCase // create/load the new database document m_database = (_documentURL == null) - ? new HsqlDatabase(getORB()) - : new HsqlDatabase(getORB(), _documentURL); + ? new HsqlDatabase(getMSF()) + : new HsqlDatabase(getMSF(), _documentURL); m_databaseDocument = m_database.getDatabaseDocument(); // load it into a frame - final Object object = getORB().createInstance("com.sun.star.frame.Desktop"); + final Object object = getMSF().createInstance("com.sun.star.frame.Desktop"); final XComponentLoader xComponentLoader = UnoRuntime.queryInterface(XComponentLoader.class, object); final XComponent loadedComponent = xComponentLoader.loadComponentFromURL(m_database.getDocumentURL(), "_blank", FrameSearchFlag.ALL, new PropertyValue[0]); - assure("too many document instances!", + assertTrue("too many document instances!", UnoRuntime.areSame(loadedComponent, m_databaseDocument)); // get the controller, which provides access to various UI operations @@ -118,21 +129,21 @@ public class ApplicationController extends TestCase } // -------------------------------------------------------------------------------------------------------- - public void before() throws java.lang.Exception + @Before public void before() throws java.lang.Exception { super.before(); impl_switchToDocument(null); } // -------------------------------------------------------------------------------------------------------- - public void after() throws java.lang.Exception + @After public void after() throws java.lang.Exception { impl_closeDocument(); super.after(); } // -------------------------------------------------------------------------------------------------------- - public void checkSaveAs() throws Exception, IOException, java.lang.Exception + @Test public void checkSaveAs() throws Exception, IOException, java.lang.Exception { // issue 93737 describes the problem that when you save-as a database document, and do changes to it, // then those changes are saved in the old document, actually @@ -146,7 +157,7 @@ public class ApplicationController extends TestCase // connect m_documentUI.connect(); - assure("could not connect to " + m_database.getDocumentURL(), m_documentUI.isConnected()); + assertTrue("could not connect to " + m_database.getDocumentURL(), m_documentUI.isConnected()); // create a table in the database m_database.createTable(new HsqlTableDescriptor("abc", new HsqlColumnDescriptor[] @@ -159,18 +170,18 @@ public class ApplicationController extends TestCase // load the old document, and verify there is *no* table therein impl_switchToDocument(oldDocumentURL); m_documentUI.connect(); - assure("could not connect to " + m_database.getDocumentURL(), m_documentUI.isConnected()); + assertTrue("could not connect to " + m_database.getDocumentURL(), m_documentUI.isConnected()); XTablesSupplier suppTables = UnoRuntime.queryInterface( XTablesSupplier.class, m_documentUI.getActiveConnection() ); XNameAccess tables = suppTables.getTables(); - assure("the table was created in the wrong database", !tables.hasByName("abc")); + assertTrue("the table was created in the wrong database", !tables.hasByName("abc")); // load the new document, and verify there *is* a table therein impl_switchToDocument(newDocumentURL); m_documentUI.connect(); - assure("could not connect to " + m_database.getDocumentURL(), m_documentUI.isConnected()); + assertTrue("could not connect to " + m_database.getDocumentURL(), m_documentUI.isConnected()); suppTables = UnoRuntime.queryInterface( XTablesSupplier.class, m_documentUI.getActiveConnection() ); tables = suppTables.getTables(); - assure("the newly created table has not been written", tables.hasByName("abc")); + assertTrue("the newly created table has not been written", tables.hasByName("abc")); } } diff --git a/dbaccess/qa/complex/dbaccess/Beamer.java b/dbaccess/qa/complex/dbaccess/Beamer.java index 909bf39d1707..2b77e21b9d60 100644 --- a/dbaccess/qa/complex/dbaccess/Beamer.java +++ b/dbaccess/qa/complex/dbaccess/Beamer.java @@ -28,10 +28,8 @@ package complex.dbaccess; import com.sun.star.beans.PropertyState; import com.sun.star.beans.PropertyValue; -import com.sun.star.beans.XPropertySet; import com.sun.star.container.XEnumeration; import com.sun.star.container.XEnumerationAccess; -import com.sun.star.container.XNameAccess; import com.sun.star.frame.FrameSearchFlag; import com.sun.star.frame.XComponentLoader; import com.sun.star.frame.XController; @@ -39,34 +37,30 @@ import com.sun.star.frame.XDispatch; import com.sun.star.frame.XDispatchProvider; import com.sun.star.frame.XFrame; import com.sun.star.frame.XModel; -import com.sun.star.frame.XStorable; import com.sun.star.lang.XComponent; -import com.sun.star.lang.XMultiServiceFactory; import com.sun.star.sdb.CommandType; -import com.sun.star.sdb.XDocumentDataSource; -import com.sun.star.sdb.XOfficeDatabaseDocument; -import com.sun.star.sdb.application.XDatabaseDocumentUI; -import com.sun.star.sdbcx.XTablesSupplier; import com.sun.star.uno.Exception; import com.sun.star.uno.UnoRuntime; -import com.sun.star.uno.XComponentContext; -import com.sun.star.uno.XNamingService; import com.sun.star.util.URL; -import com.sun.star.util.XCloseable; import com.sun.star.util.XURLTransformer; import com.sun.star.view.XSelectionSupplier; -import connectivity.tools.DataSource; -import connectivity.tools.HsqlColumnDescriptor; -import connectivity.tools.HsqlDatabase; -import connectivity.tools.HsqlTableDescriptor; -import helper.URLHelper; -import java.io.File; import java.io.IOException; -import util.UITools; + + +// ---------- 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.*; +// ------------------------------------------ + /** complex test case for Base's application UI */ -public class Beamer extends complexlib.ComplexTestCase +public class Beamer extends TestCase { private XModel docModel; @@ -76,43 +70,43 @@ public class Beamer extends complexlib.ComplexTestCase super(); } - // -------------------------------------------------------------------------------------------------------- - protected final XComponentContext getComponentContext() - { - XComponentContext context = null; - try - { - final XPropertySet orbProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, getORB()); - context = (XComponentContext) UnoRuntime.queryInterface(XComponentContext.class, - orbProps.getPropertyValue("DefaultContext")); - } - catch (Exception ex) - { - failed("could not retrieve the ComponentContext"); - } - return context; - } +// // -------------------------------------------------------------------------------------------------------- +// protected final XComponentContext getComponentContext() +// { +// XComponentContext context = null; +// try +// { +// final XPropertySet orbProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, getORB()); +// context = (XComponentContext) UnoRuntime.queryInterface(XComponentContext.class, +// orbProps.getPropertyValue("DefaultContext")); +// } +// catch (Exception ex) +// { +// failed("could not retrieve the ComponentContext"); +// } +// return context; +// } // -------------------------------------------------------------------------------------------------------- - public String[] getTestMethodNames() - { - return new String[] - { - "testBeamer" - }; - } +// public String[] getTestMethodNames() +// { +// return new String[] +// { +// "testBeamer" +// }; +// } - // -------------------------------------------------------------------------------------------------------- - public String getTestObjectName() - { - return getClass().getName(); - } +// // -------------------------------------------------------------------------------------------------------- +// public String getTestObjectName() +// { +// return getClass().getName(); +// } // -------------------------------------------------------------------------------------------------------- - protected final XMultiServiceFactory getORB() - { - return (XMultiServiceFactory) param.getMSF(); - } +// protected final XMultiServiceFactory getORB() +// { +// return (XMultiServiceFactory) param.getMSF(); +// } // -------------------------------------------------------------------------------------------------------- private void impl_closeDocument() @@ -120,40 +114,40 @@ public class Beamer extends complexlib.ComplexTestCase } // -------------------------------------------------------------------------------------------------------- - public void before() throws Exception, java.lang.Exception + @Before public void before() throws Exception, java.lang.Exception { // load it into a frame - final Object object = getORB().createInstance("com.sun.star.frame.Desktop"); - final XComponentLoader xComponentLoader = (XComponentLoader) UnoRuntime.queryInterface(XComponentLoader.class, object); + final Object object = getMSF().createInstance("com.sun.star.frame.Desktop"); + final XComponentLoader xComponentLoader = UnoRuntime.queryInterface(XComponentLoader.class, object); final XComponent loadedComponent = xComponentLoader.loadComponentFromURL("private:factory/swriter", "_blank", 0, new PropertyValue[0]); // get the controller, which provides access to various UI operations - docModel = (XModel) UnoRuntime.queryInterface(XModel.class, loadedComponent); + docModel = UnoRuntime.queryInterface(XModel.class, loadedComponent); } // -------------------------------------------------------------------------------------------------------- - public void after() + @After public void after() { } // -------------------------------------------------------------------------------------------------------- - public void testBeamer() throws Exception, IOException, java.lang.Exception + @Test public void testBeamer() throws Exception, IOException, java.lang.Exception { final XController controller = docModel.getCurrentController(); final XFrame frame = controller.getFrame(); - final XDispatchProvider dispatchP = (XDispatchProvider) UnoRuntime.queryInterface(XDispatchProvider.class, frame); + final XDispatchProvider dispatchP = UnoRuntime.queryInterface(XDispatchProvider.class, frame); URL command = new URL(); // command.Complete = ".component:DB/DataSourceBrowser"; command.Complete = ".uno:ViewDataSourceBrowser"; - Object instance = getORB().createInstance("com.sun.star.util.URLTransformer"); - XURLTransformer atrans = (XURLTransformer) UnoRuntime.queryInterface(XURLTransformer.class, instance); + Object instance = getMSF().createInstance("com.sun.star.util.URLTransformer"); + XURLTransformer atrans = UnoRuntime.queryInterface(XURLTransformer.class, instance); com.sun.star.util.URL[] aURLA = new com.sun.star.util.URL[1]; aURLA[0] = command; atrans.parseStrict(aURLA); command = aURLA[0]; final XDispatch dispatch = dispatchP.queryDispatch(command, "_self", FrameSearchFlag.AUTO); - assure(dispatch != null); + assertNotNull(dispatch); dispatch.dispatch(command, new PropertyValue[0]); final PropertyValue[] props = new PropertyValue[] @@ -164,8 +158,8 @@ public class Beamer extends complexlib.ComplexTestCase }; final XFrame beamer = frame.findFrame("_beamer", 0); - assure(beamer != null); - final XEnumerationAccess evtBc = (XEnumerationAccess) UnoRuntime.queryInterface(XEnumerationAccess.class, getORB().createInstance("com.sun.star.frame.GlobalEventBroadcaster")); + assertNotNull(beamer); + final XEnumerationAccess evtBc = UnoRuntime.queryInterface(XEnumerationAccess.class, getMSF().createInstance("com.sun.star.frame.GlobalEventBroadcaster")); XEnumeration enumeration = evtBc.createEnumeration(); int count = -1; while (enumeration.hasMoreElements()) @@ -173,9 +167,9 @@ public class Beamer extends complexlib.ComplexTestCase enumeration.nextElement(); ++count; } - final XSelectionSupplier selSup = (XSelectionSupplier)UnoRuntime.queryInterface(XSelectionSupplier.class, beamer.getController()); + final XSelectionSupplier selSup = UnoRuntime.queryInterface(XSelectionSupplier.class, beamer.getController()); selSup.select(props); - final com.sun.star.util.XCloseable close = (com.sun.star.util.XCloseable)UnoRuntime.queryInterface(com.sun.star.util.XCloseable.class, frame); + final com.sun.star.util.XCloseable close = UnoRuntime.queryInterface(com.sun.star.util.XCloseable.class, frame); close.close(false); enumeration = evtBc.createEnumeration(); @@ -186,6 +180,6 @@ public class Beamer extends complexlib.ComplexTestCase ++count2; } - assure("count1 = " + count + " count2 = " + count2, count == count2); + assertTrue("count1 = " + count + " count2 = " + count2, count == count2); } } diff --git a/dbaccess/qa/complex/dbaccess/CRMBasedTestCase.java b/dbaccess/qa/complex/dbaccess/CRMBasedTestCase.java index 3bba8fa45001..ff89c755a90f 100644 --- a/dbaccess/qa/complex/dbaccess/CRMBasedTestCase.java +++ b/dbaccess/qa/complex/dbaccess/CRMBasedTestCase.java @@ -26,13 +26,21 @@ ************************************************************************/ package complex.dbaccess; -import com.sun.star.lang.XMultiServiceFactory; import com.sun.star.sdb.XSingleSelectQueryComposer; -import com.sun.star.uno.UnoRuntime; import connectivity.tools.CRMDatabase; import java.util.logging.Level; import java.util.logging.Logger; +// ---------- 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 abstract class CRMBasedTestCase extends TestCase { protected CRMDatabase m_database; @@ -42,30 +50,30 @@ public abstract class CRMBasedTestCase extends TestCase { try { - m_database = new CRMDatabase( getORB(), false ); + m_database = new CRMDatabase( getMSF(), false ); } catch ( Exception e ) { e.printStackTrace( System.err ); - assure( "caught an exception (" + e.getMessage() + ") while creating the test case", false ); + fail( "caught an exception (" + e.getMessage() + ") while creating the test case"); } } // -------------------------------------------------------------------------------------------------------- - @Override - public void before() + @Before public void before() { createTestCase(); } // -------------------------------------------------------------------------------------------------------- - @Override - public void after() + @After public void after() { try { if ( m_database != null ) + { m_database.saveAndClose(); + } } catch ( Exception ex ) { diff --git a/dbaccess/qa/complex/dbaccess/CopyTableWizard.java b/dbaccess/qa/complex/dbaccess/CopyTableWizard.java index 7c3db7f6020d..89fc56253ed0 100755 --- a/dbaccess/qa/complex/dbaccess/CopyTableWizard.java +++ b/dbaccess/qa/complex/dbaccess/CopyTableWizard.java @@ -46,6 +46,16 @@ import connectivity.tools.DbaseDatabase; import java.io.IOException; import util.UITools; +// ---------- 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.*; +// ------------------------------------------ + /** complex test case for Base's application UI */ public class CopyTableWizard extends CRMBasedTestCase @@ -60,42 +70,40 @@ public class CopyTableWizard extends CRMBasedTestCase } // -------------------------------------------------------------------------------------------------------- - public String[] getTestMethodNames() - { - return new String[] - { - "copyTable", "copyTableDbase" - }; - } +// public String[] getTestMethodNames() +// { +// return new String[] +// { +// "copyTable", "copyTableDbase" +// }; +// } // -------------------------------------------------------------------------------------------------------- - @Override - public String getTestObjectName() - { - return getClass().getName(); - } +// @Override +// public String getTestObjectName() +// { +// return getClass().getName(); +// } // -------------------------------------------------------------------------------------------------------- // -------------------------------------------------------------------------------------------------------- - @Override - public void after() + @After public void after() { dest.store(); super.after(); } - @Override - public void before() + @Before public void before() { try { createTestCase(); source = new DatabaseApplication(this.m_database.getDatabase()); - dest = new DatabaseApplication(new DbaseDatabase(getORB())); + dest = new DatabaseApplication(new DbaseDatabase(getMSF())); } catch (java.lang.Exception ex) { - assure(false); + fail(""); } } // -------------------------------------------------------------------------------------------------------- @@ -123,7 +131,7 @@ public class CopyTableWizard extends CRMBasedTestCase Object toolKit = null; try { - toolKit = getORB().createInstance("com.sun.star.awt.Toolkit"); + toolKit = getMSF().createInstance("com.sun.star.awt.Toolkit"); } catch (com.sun.star.uno.Exception e) { @@ -135,21 +143,21 @@ public class CopyTableWizard extends CRMBasedTestCase return (XWindow) UnoRuntime.queryInterface(XWindow.class, atw); } - public void copyTable() throws Exception, IOException, java.lang.Exception + @Test public void copyTable() throws Exception, IOException, java.lang.Exception { copyTable(source,source); } - public void copyTableDbase() throws Exception, IOException, java.lang.Exception + @Test public void copyTableDbase() throws Exception, IOException, java.lang.Exception { copyTable(source,dest); } - public void copyTable(final DatabaseApplication sourceDb,final DatabaseApplication destDb) throws Exception, IOException, java.lang.Exception + private void copyTable(final DatabaseApplication sourceDb,final DatabaseApplication destDb) throws Exception, IOException, java.lang.Exception { final XConnection destConnection = destDb.getDocumentUI().getActiveConnection(); final XConnection sourceConnection = sourceDb.getDocumentUI().getActiveConnection(); - final XTablesSupplier suppTables = (XTablesSupplier) UnoRuntime.queryInterface(XTablesSupplier.class, sourceConnection); + final XTablesSupplier suppTables = UnoRuntime.queryInterface(XTablesSupplier.class, sourceConnection); final XNameAccess tables = suppTables.getTables(); final String[] names = tables.getElementNames(); @@ -161,7 +169,7 @@ public class CopyTableWizard extends CRMBasedTestCase public void assure(final String message) { - assure(message, false); + fail(message); } private void copyTable(final String tableName, final XConnection sourceConnection, final XConnection destConnection) throws Exception, IOException, java.lang.Exception @@ -194,7 +202,7 @@ public class CopyTableWizard extends CRMBasedTestCase try { final XWindow dialog = getActiveWindow(); - final UITools uiTools = new UITools(getORB(), dialog); + final UITools uiTools = new UITools(getMSF(), dialog); final XAccessible root = uiTools.getRoot(); final XAccessibleContext accContext = root.getAccessibleContext(); final int count = accContext.getAccessibleChildCount(); diff --git a/dbaccess/qa/complex/dbaccess/DataSource.java b/dbaccess/qa/complex/dbaccess/DataSource.java index f74d5af8d8f0..ce1e6db28e99 100644 --- a/dbaccess/qa/complex/dbaccess/DataSource.java +++ b/dbaccess/qa/complex/dbaccess/DataSource.java @@ -30,32 +30,43 @@ import com.sun.star.lang.XMultiServiceFactory; import com.sun.star.uno.Exception; import com.sun.star.uno.UnoRuntime; import com.sun.star.uno.XNamingService; -import complexlib.ComplexTestCase; +// import complexlib.ComplexTestCase; import connectivity.tools.CRMDatabase; import connectivity.tools.HsqlDatabase; -import java.util.logging.Level; -import java.util.logging.Logger; +//import java.util.logging.Level; +//import java.util.logging.Logger; -public class DataSource extends ComplexTestCase +// ---------- 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 DataSource extends TestCase { HsqlDatabase m_database; connectivity.tools.DataSource m_dataSource; // -------------------------------------------------------------------------------------------------------- - public String[] getTestMethodNames() - { - return new String[] - { - "testRegistrationName" - }; - } - - // -------------------------------------------------------------------------------------------------------- - public String getTestObjectName() - { - return "DataSource"; - } +// public String[] getTestMethodNames() +// { +// return new String[] +// { +// "testRegistrationName" +// }; +// } +// +// // -------------------------------------------------------------------------------------------------------- +// public String getTestObjectName() +// { +// return "DataSource"; +// } // -------------------------------------------------------------------------------------------------------- private void createTestCase() @@ -64,47 +75,48 @@ public class DataSource extends ComplexTestCase { if (m_database == null) { - final CRMDatabase database = new CRMDatabase( getFactory(), false ); + final CRMDatabase database = new CRMDatabase( getMSF(), false ); m_database = database.getDatabase(); m_dataSource = m_database.getDataSource(); } } catch (Exception e) { - failed("could not create the test case, error message:\n" + e.getMessage()); + fail("could not create the test case, error message:\n" + e.getMessage()); } catch (java.lang.Exception e) { - failed("could not create the test case, error message:\n" + e.getMessage()); + fail("could not create the test case, error message:\n" + e.getMessage()); } } // -------------------------------------------------------------------------------------------------------- - private XMultiServiceFactory getFactory() - { - return (XMultiServiceFactory) param.getMSF(); - } +// private XMultiServiceFactory getFactory() +// { +// return (XMultiServiceFactory) param.getMSF(); +// } // -------------------------------------------------------------------------------------------------------- - public void testRegistrationName() + @Test public void testRegistrationName() { try { createTestCase(); // 1. check the existing "Bibliography" data source whether it has the proper name String dataSourceName = "Bibliography"; - final connectivity.tools.DataSource bibliography = new connectivity.tools.DataSource(getFactory(), dataSourceName); - assureEquals("pre-registered database has a wrong name!", dataSourceName, bibliography.getName()); + final connectivity.tools.DataSource bibliography = new connectivity.tools.DataSource(getMSF(), dataSourceName); + assertEquals("pre-registered database has a wrong name!", dataSourceName, bibliography.getName()); // 2. register a newly created data source, and verify it has the proper name dataSourceName = "someDataSource"; final XNamingService dataSourceRegistrations = (XNamingService) UnoRuntime.queryInterface( - XNamingService.class, getFactory().createInstance("com.sun.star.sdb.DatabaseContext")); + XNamingService.class, getMSF().createInstance("com.sun.star.sdb.DatabaseContext")); dataSourceRegistrations.registerObject("someDataSource", m_dataSource.getXDataSource()); - assureEquals("registration name of a newly registered data source is wrong", dataSourceName, m_dataSource.getName()); + assertEquals("registration name of a newly registered data source is wrong", dataSourceName, m_dataSource.getName()); } catch (Exception ex) { - Logger.getLogger(DataSource.class.getName()).log(Level.SEVERE, null, ex); + // Logger.getLogger(DataSource.class.getName()).log(Level.SEVERE, null, ex); + fail(); } } } diff --git a/dbaccess/qa/complex/dbaccess/DatabaseApplication.java b/dbaccess/qa/complex/dbaccess/DatabaseApplication.java index d6bfa804eafa..0941bd318d47 100755 --- a/dbaccess/qa/complex/dbaccess/DatabaseApplication.java +++ b/dbaccess/qa/complex/dbaccess/DatabaseApplication.java @@ -56,14 +56,12 @@ public class DatabaseApplication // load it into a frame final Object object = db.getORB().createInstance("com.sun.star.frame.Desktop"); - final XComponentLoader xComponentLoader = (XComponentLoader) UnoRuntime.queryInterface(XComponentLoader.class, object); + final XComponentLoader xComponentLoader = UnoRuntime.queryInterface(XComponentLoader.class, object); final XComponent loadedComponent = xComponentLoader.loadComponentFromURL(db.getDocumentURL(), "_blank", FrameSearchFlag.ALL, new PropertyValue[0]); // get the controller, which provides access to various UI operations - final XModel docModel = (XModel) UnoRuntime.queryInterface(XModel.class, - loadedComponent); - documentUI = (XDatabaseDocumentUI) UnoRuntime.queryInterface(XDatabaseDocumentUI.class, - docModel.getCurrentController()); + final XModel docModel = UnoRuntime.queryInterface(XModel.class, loadedComponent); + documentUI = UnoRuntime.queryInterface(XDatabaseDocumentUI.class, docModel.getCurrentController()); documentUI.connect(); } @@ -87,8 +85,7 @@ public class DatabaseApplication // store the doc in a new location try { - final XStorable storeDoc = (XStorable) UnoRuntime.queryInterface(XStorable.class, - databaseDocument); + final XStorable storeDoc = UnoRuntime.queryInterface(XStorable.class, databaseDocument); if (storeDoc != null) { storeDoc.store(); diff --git a/dbaccess/qa/complex/dbaccess/DatabaseDocument.java b/dbaccess/qa/complex/dbaccess/DatabaseDocument.java index 02fb820f3fd4..757ae2de22d5 100644 --- a/dbaccess/qa/complex/dbaccess/DatabaseDocument.java +++ b/dbaccess/qa/complex/dbaccess/DatabaseDocument.java @@ -33,7 +33,7 @@ import com.sun.star.lang.XEventListener; import com.sun.star.lang.XMultiServiceFactory; import com.sun.star.script.XStorageBasedLibraryContainer; import com.sun.star.task.XInteractionRequest; -import com.sun.star.uno.Exception; + import com.sun.star.uno.Type; import com.sun.star.uno.UnoRuntime; import com.sun.star.frame.XStorable; @@ -45,7 +45,6 @@ import com.sun.star.document.XDocumentEventBroadcaster; import com.sun.star.document.XDocumentEventListener; import com.sun.star.document.XEmbeddedScripts; import com.sun.star.document.XEventsSupplier; -import com.sun.star.frame.DoubleInitializationException; import com.sun.star.lang.XComponent; import com.sun.star.frame.XComponentLoader; import com.sun.star.frame.XDispatch; @@ -56,13 +55,12 @@ import com.sun.star.frame.XModel; import com.sun.star.frame.XModel2; import com.sun.star.frame.XTitle; import com.sun.star.lang.EventObject; -import com.sun.star.lang.NotInitializedException; import com.sun.star.lang.XServiceInfo; import com.sun.star.lang.XSingleComponentFactory; import com.sun.star.lang.XTypeProvider; import com.sun.star.script.provider.XScriptProviderSupplier; import com.sun.star.sdb.XDocumentDataSource; -import com.sun.star.sdbc.XDataSource; + import com.sun.star.sdb.XFormDocumentsSupplier; import com.sun.star.sdb.XOfficeDatabaseDocument; import com.sun.star.sdb.XReportDocumentsSupplier; @@ -83,6 +81,16 @@ import java.util.ArrayList; import java.util.logging.Level; import java.util.logging.Logger; +// ---------- 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 DatabaseDocument extends TestCase implements com.sun.star.document.XDocumentEventListener { @@ -145,12 +153,12 @@ public class DatabaseDocument extends TestCase implements com.sun.star.document. private final ArrayList m_eventListeners = new ArrayList(); - public Object createInstanceWithContext(XComponentContext _context) throws Exception + public Object createInstanceWithContext(XComponentContext _context) throws com.sun.star.uno.Exception { return new CallbackComponent(); } - public Object createInstanceWithArgumentsAndContext(Object[] arg0, XComponentContext _context) throws Exception + public Object createInstanceWithArgumentsAndContext(Object[] arg0, XComponentContext _context) throws com.sun.star.uno.Exception { return createInstanceWithContext(_context); } @@ -209,8 +217,7 @@ public class DatabaseDocument extends TestCase implements com.sun.star.document. { try { - m_defaultHandler = (XInteractionHandler) UnoRuntime.queryInterface(XInteractionHandler.class, - _factory.createInstance("com.sun.star.task.InteractionHandler")); + m_defaultHandler = UnoRuntime.queryInterface(XInteractionHandler.class, _factory.createInstance("com.sun.star.task.InteractionHandler")); } catch (Exception ex) { @@ -227,14 +234,13 @@ public class DatabaseDocument extends TestCase implements com.sun.star.document. return; } - assureEquals("interaction handleer called in wrong state", STATE_LOADING_DOC, m_loadDocState); + assertEquals("interaction handleer called in wrong state", STATE_LOADING_DOC, m_loadDocState); // auto-approve final XInteractionContinuation continuations[] = _request.getContinuations(); for (int i = 0; i < continuations.length; ++i) { - final XInteractionApprove approve = (XInteractionApprove) UnoRuntime.queryInterface(XInteractionApprove.class, - continuations[i]); + final XInteractionApprove approve = UnoRuntime.queryInterface(XInteractionApprove.class, continuations[i]); if (approve != null) { approve.select(); @@ -247,25 +253,25 @@ public class DatabaseDocument extends TestCase implements com.sun.star.document. // ======================================================================================================== // -------------------------------------------------------------------------------------------------------- - public String[] getTestMethodNames() - { - return new String[] - { - "testLoadable", - "testDocumentRevenants", - "testDocumentEvents", - "testGlobalEvents" - }; - } +// public String[] getTestMethodNames() +// { +// return new String[] +// { +// "testLoadable", +// "testDocumentRevenants", +// "testDocumentEvents", +// "testGlobalEvents" +// }; +// } +// +// // -------------------------------------------------------------------------------------------------------- +// public String getTestObjectName() +// { +// return "DatabaseDocument"; +// } // -------------------------------------------------------------------------------------------------------- - public String getTestObjectName() - { - return "DatabaseDocument"; - } - - // -------------------------------------------------------------------------------------------------------- - public void before() throws java.lang.Exception + @Before public void before() throws java.lang.Exception { super.before(); @@ -274,26 +280,24 @@ public class DatabaseDocument extends TestCase implements com.sun.star.document. // at our service factory, insert a new factory for our CallbackComponent // this will allow the Basic code in our test documents to call back into this test case // here, by just instantiating this service - final XSet globalFactory = (XSet) UnoRuntime.queryInterface( - XSet.class, getORB()); + final XSet globalFactory = UnoRuntime.queryInterface(XSet.class, getMSF()); m_callbackFactory = new CallbackComponentFactory(); globalFactory.insert(m_callbackFactory); // register ourself as listener at the global event broadcaster - final XDocumentEventBroadcaster broadcaster = (XDocumentEventBroadcaster) UnoRuntime.queryInterface( - XDocumentEventBroadcaster.class, getORB().createInstance("com.sun.star.frame.GlobalEventBroadcaster")); + final XDocumentEventBroadcaster broadcaster = UnoRuntime.queryInterface(XDocumentEventBroadcaster.class, getMSF().createInstance("com.sun.star.frame.GlobalEventBroadcaster")); broadcaster.addDocumentEventListener(this); } catch (Exception e) { - log.println("could not create the test case, error message:\n" + e.getMessage()); + System.out.println("could not create the test case, error message:\n" + e.getMessage()); e.printStackTrace(System.err); - failed("failed to create the test case"); + fail("failed to create the test case"); } } // -------------------------------------------------------------------------------------------------------- - public void after() throws java.lang.Exception + @After public void after() throws java.lang.Exception { try { @@ -302,15 +306,14 @@ public class DatabaseDocument extends TestCase implements com.sun.star.document. m_callbackFactory.dispose(); // revoke ourself as listener at the global event broadcaster - final XDocumentEventBroadcaster broadcaster = (XDocumentEventBroadcaster) UnoRuntime.queryInterface( - XDocumentEventBroadcaster.class, getORB().createInstance("com.sun.star.frame.GlobalEventBroadcaster")); + final XDocumentEventBroadcaster broadcaster = UnoRuntime.queryInterface(XDocumentEventBroadcaster.class, getMSF().createInstance("com.sun.star.frame.GlobalEventBroadcaster")); broadcaster.removeDocumentEventListener(this); } catch (Exception e) { - log.println("could not create the test case, error message:\n" + e.getMessage()); + System.out.println("could not create the test case, error message:\n" + e.getMessage()); e.printStackTrace(System.err); - failed("failed to close the test case"); + fail("failed to close the test case"); } super.after(); @@ -348,16 +351,15 @@ public class DatabaseDocument extends TestCase implements com.sun.star.document. for (int i = 0; i < unsupportedMethods.length; ++i) { - assureException( _document, unsupportedMethods[i].unoInterfaceClass, - unsupportedMethods[i].methodName, new Object[]{}, _isInitialized ? null : NotInitializedException.class ); +// assureException( _document, unsupportedMethods[i].unoInterfaceClass, +// unsupportedMethods[i].methodName, new Object[]{}, _isInitialized ? null : NotInitializedException.class ); } } // -------------------------------------------------------------------------------------------------------- private XModel impl_createDocument() throws Exception { - final XModel databaseDoc = (XModel) UnoRuntime.queryInterface(XModel.class, - getORB().createInstance("com.sun.star.sdb.OfficeDatabaseDocument")); + final XModel databaseDoc = UnoRuntime.queryInterface(XModel.class, getMSF().createInstance("com.sun.star.sdb.OfficeDatabaseDocument")); // should not be initialized here - we did neither initNew nor load nor storeAsURL it impl_checkDocumentInitState(databaseDoc, false); @@ -368,17 +370,15 @@ public class DatabaseDocument extends TestCase implements com.sun.star.document. // -------------------------------------------------------------------------------------------------------- private void impl_closeDocument(XModel _databaseDoc) throws CloseVetoException, IOException, Exception { - final XCloseable closeDoc = (XCloseable) UnoRuntime.queryInterface(XCloseable.class, - _databaseDoc); + final XCloseable closeDoc = UnoRuntime.queryInterface(XCloseable.class, _databaseDoc); closeDoc.close(true); } // -------------------------------------------------------------------------------------------------------- private XModel impl_createEmptyEmbeddedHSQLDocument() throws Exception, IOException { - final XModel databaseDoc = (XModel) UnoRuntime.queryInterface(XModel.class, - getORB().createInstance("com.sun.star.sdb.OfficeDatabaseDocument")); - final XStorable storeDoc = (XStorable) UnoRuntime.queryInterface(XStorable.class, databaseDoc); + final XModel databaseDoc = UnoRuntime.queryInterface(XModel.class, getMSF().createInstance("com.sun.star.sdb.OfficeDatabaseDocument")); + final XStorable storeDoc = UnoRuntime.queryInterface(XStorable.class, databaseDoc); // verify the document rejects API calls which require it to be initialized impl_checkDocumentInitState(databaseDoc, false); @@ -388,15 +388,13 @@ public class DatabaseDocument extends TestCase implements com.sun.star.document. final String url = databaseDoc.getURL(); final PropertyValue[] args = databaseDoc.getArgs(); // they should be all empty at this time - assureEquals("location is expected to be empty here", "", location); - assureEquals("URL is expected to be empty here", "", url); - assureEquals("Args are expected to be empty here", 0, args.length); + assertEquals("location is expected to be empty here", "", location); + assertEquals("URL is expected to be empty here", "", url); + assertEquals("Args are expected to be empty here", 0, args.length); // and, you should be able to set properties at the data source - final XOfficeDatabaseDocument dataSourceAccess = (XOfficeDatabaseDocument) UnoRuntime.queryInterface( - XOfficeDatabaseDocument.class, databaseDoc); - final XPropertySet dsProperties = (XPropertySet) UnoRuntime.queryInterface( - XPropertySet.class, dataSourceAccess.getDataSource()); + final XOfficeDatabaseDocument dataSourceAccess = UnoRuntime.queryInterface(XOfficeDatabaseDocument.class, databaseDoc); + final XPropertySet dsProperties = UnoRuntime.queryInterface(XPropertySet.class, dataSourceAccess.getDataSource()); dsProperties.setPropertyValue("URL", "sdbc:embedded:hsqldb"); final String documentURL = createTempFileURL(); @@ -404,7 +402,7 @@ public class DatabaseDocument extends TestCase implements com.sun.star.document. // now that the document is stored, ... // ... its URL should be correct - assureEquals("wrong URL after storing the document", documentURL, databaseDoc.getURL()); + assertEquals("wrong URL after storing the document", documentURL, databaseDoc.getURL()); // ... it should be initialized impl_checkDocumentInitState(databaseDoc, true); @@ -412,7 +410,7 @@ public class DatabaseDocument extends TestCase implements com.sun.star.document. } // -------------------------------------------------------------------------------------------------------- - public void testLoadable() throws Exception, IOException + @Test public void testLoadable() throws Exception, IOException { XModel databaseDoc = impl_createEmptyEmbeddedHSQLDocument(); String documentURL = databaseDoc.getURL(); @@ -426,40 +424,39 @@ public class DatabaseDocument extends TestCase implements com.sun.star.document. // .................................................................... // 2. XLoadable::load - databaseDoc = (XModel) UnoRuntime.queryInterface(XModel.class, - getORB().createInstance("com.sun.star.sdb.OfficeDatabaseDocument")); + databaseDoc = UnoRuntime.queryInterface(XModel.class, getMSF().createInstance("com.sun.star.sdb.OfficeDatabaseDocument")); documentURL = copyToTempFile(documentURL); // load the doc, and verify it's initialized then, and has the proper URL - XLoadable loadDoc = (XLoadable) UnoRuntime.queryInterface(XLoadable.class, databaseDoc); + XLoadable loadDoc = UnoRuntime.queryInterface(XLoadable.class, databaseDoc); loadDoc.load(new PropertyValue[] { new PropertyValue("URL", 0, documentURL, PropertyState.DIRECT_VALUE) }); databaseDoc.attachResource(documentURL, new PropertyValue[0]); - assureEquals("wrong URL after loading the document", documentURL, databaseDoc.getURL()); + assertEquals("wrong URL after loading the document", documentURL, databaseDoc.getURL()); impl_checkDocumentInitState(databaseDoc, true); // and while we are here ... initilizing the same document again should not be possible - assureException( databaseDoc, XLoadable.class, "initNew", new Object[0], - DoubleInitializationException.class ); - assureException( databaseDoc, XLoadable.class, "load", new Object[] { new PropertyValue[0] }, - DoubleInitializationException.class ); +// assureException( databaseDoc, XLoadable.class, "initNew", new Object[0], +// DoubleInitializationException.class ); +// assureException( databaseDoc, XLoadable.class, "load", new Object[] { new PropertyValue[0] }, +// DoubleInitializationException.class ); // .................................................................... // 3. XLoadable::initNew impl_closeDocument(databaseDoc); databaseDoc = impl_createDocument(); - loadDoc = (XLoadable) UnoRuntime.queryInterface(XLoadable.class, databaseDoc); + loadDoc = UnoRuntime.queryInterface(XLoadable.class, databaseDoc); loadDoc.initNew(); - assureEquals("wrong URL after initializing the document", "", databaseDoc.getURL()); + assertEquals("wrong URL after initializing the document", "", databaseDoc.getURL()); impl_checkDocumentInitState(databaseDoc, true); // same as above - initializing the document a second time must fail - assureException( databaseDoc, XLoadable.class, "initNew", new Object[0], - DoubleInitializationException.class ); - assureException( databaseDoc, XLoadable.class, "load", new Object[] { new PropertyValue[0] }, - DoubleInitializationException.class ); +// assureException( databaseDoc, XLoadable.class, "initNew", new Object[0], +// DoubleInitializationException.class ); +// assureException( databaseDoc, XLoadable.class, "load", new Object[] { new PropertyValue[0] }, +// DoubleInitializationException.class ); } // -------------------------------------------------------------------------------------------------------- @@ -478,7 +475,9 @@ public class DatabaseDocument extends TestCase implements com.sun.star.document. for ( int i=0; i<_args.length; ++i ) { if ( _args[i].Name.equals( "TestCase_Marker" ) && _args[i].Value.equals( "Yes" ) ) + { return true; + } } return false; } @@ -499,28 +498,25 @@ public class DatabaseDocument extends TestCase implements com.sun.star.document. { new PropertyValue("PickListEntry", 0, false, PropertyState.DIRECT_VALUE), new PropertyValue("MacroExecutionMode", 0, com.sun.star.document.MacroExecMode.USE_CONFIG, PropertyState.DIRECT_VALUE), - new PropertyValue("InteractionHandler", 0, new MacroExecutionApprove(getORB()), PropertyState.DIRECT_VALUE) + new PropertyValue("InteractionHandler", 0, new MacroExecutionApprove(getMSF()), PropertyState.DIRECT_VALUE) }; } // -------------------------------------------------------------------------------------------------------- private int impl_setMacroSecurityLevel(int _level) throws Exception { - final XMultiServiceFactory configProvider = (XMultiServiceFactory) UnoRuntime.queryInterface(XMultiServiceFactory.class, - getORB().createInstance("com.sun.star.configuration.ConfigurationProvider")); + final XMultiServiceFactory configProvider = UnoRuntime.queryInterface(XMultiServiceFactory.class, getMSF().createInstance("com.sun.star.configuration.ConfigurationProvider")); final PropertyValue[] args = new PropertyValue[] { new PropertyValue("nodepath", 0, "/org.openoffice.Office.Common/Security/Scripting", PropertyState.DIRECT_VALUE) }; - final XPropertySet securitySettings = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, - configProvider.createInstanceWithArguments("com.sun.star.configuration.ConfigurationUpdateAccess", args)); + final XPropertySet securitySettings = UnoRuntime.queryInterface(XPropertySet.class, configProvider.createInstanceWithArguments("com.sun.star.configuration.ConfigurationUpdateAccess", args)); final int oldValue = ((Integer) securitySettings.getPropertyValue("MacroSecurityLevel")).intValue(); securitySettings.setPropertyValue("MacroSecurityLevel", Integer.valueOf(_level)); - final XChangesBatch committer = (XChangesBatch) UnoRuntime.queryInterface(XChangesBatch.class, - securitySettings); + final XChangesBatch committer = UnoRuntime.queryInterface(XChangesBatch.class, securitySettings); committer.commitChanges(); return oldValue; @@ -529,10 +525,8 @@ public class DatabaseDocument extends TestCase implements com.sun.star.document. // -------------------------------------------------------------------------------------------------------- private XModel impl_loadDocument( final String _documentURL, final PropertyValue[] _loadArgs ) throws Exception { - final XComponentLoader loader = (XComponentLoader) UnoRuntime.queryInterface( XComponentLoader.class, - getORB().createInstance("com.sun.star.frame.Desktop") ); - return (XModel) UnoRuntime.queryInterface( XModel.class, - loader.loadComponentFromURL( _documentURL, _BLANK, 0, _loadArgs ) ); + final XComponentLoader loader = UnoRuntime.queryInterface(XComponentLoader.class, getMSF().createInstance("com.sun.star.frame.Desktop")); + return UnoRuntime.queryInterface(XModel.class, loader.loadComponentFromURL(_documentURL, _BLANK, 0, _loadArgs)); } // -------------------------------------------------------------------------------------------------------- @@ -540,8 +534,7 @@ public class DatabaseDocument extends TestCase implements com.sun.star.document. { // store the document final String documentURL = FileHelper.getOOoCompatibleFileURL( _document.getURL() ); - final XStorable storeDoc = (XStorable) UnoRuntime.queryInterface( XStorable.class, - _document ); + final XStorable storeDoc = UnoRuntime.queryInterface(XStorable.class, _document); storeDoc.store(); } @@ -553,8 +546,7 @@ public class DatabaseDocument extends TestCase implements com.sun.star.document. XModel databaseDoc = impl_createEmptyEmbeddedHSQLDocument(); // create Basic library/module therein - final XEmbeddedScripts embeddedScripts = (XEmbeddedScripts) UnoRuntime.queryInterface(XEmbeddedScripts.class, - databaseDoc); + final XEmbeddedScripts embeddedScripts = UnoRuntime.queryInterface(XEmbeddedScripts.class, databaseDoc); final XStorageBasedLibraryContainer basicLibs = embeddedScripts.getBasicLibraries(); final XNameContainer newLib = basicLibs.createLibrary( _libName ); newLib.insertByName( _moduleName, _code ); @@ -579,7 +571,7 @@ public class DatabaseDocument extends TestCase implements com.sun.star.document. * This method here tests some of those aspects of a document which should survive the death of one * instance and re-creation as a revenant. */ - public void testDocumentRevenants() throws Exception, IOException + @Test public void testDocumentRevenants() throws Exception, IOException { // create an empty document XModel databaseDoc = impl_createDocWithMacro( "Lib", "Module", @@ -592,42 +584,38 @@ public class DatabaseDocument extends TestCase implements com.sun.star.document. // at this stage, the marker should not yet be present in the doc's args, else some of the below // tests become meaningless - assure( "A newly created doc should not have the test case marker", !impl_hasMarker( databaseDoc.getArgs() ) ); + assertTrue( "A newly created doc should not have the test case marker", !impl_hasMarker( databaseDoc.getArgs() ) ); // obtain the DataSource associated with the document. Keeping this alive // ensures that the "impl data" of the document is kept alive, too, so when closing // and re-opening it, this "impl data" must be re-used. - XDocumentDataSource dataSource = (XDocumentDataSource)UnoRuntime.queryInterface( XDocumentDataSource.class, - ((XOfficeDatabaseDocument)UnoRuntime.queryInterface( - XOfficeDatabaseDocument.class, databaseDoc )).getDataSource() ); + XDocumentDataSource dataSource = UnoRuntime.queryInterface(XDocumentDataSource.class, (UnoRuntime.queryInterface(XOfficeDatabaseDocument.class, databaseDoc)).getDataSource()); // close and reload the doc impl_closeDocument(databaseDoc); databaseDoc = impl_loadDocument( documentURL, impl_getMarkerLoadArgs() ); // since we just put the marker into the load-call, it should be present at the doc - assure( "The test case marker got lost.", impl_hasMarker( databaseDoc.getArgs() ) ); + assertTrue( "The test case marker got lost.", impl_hasMarker( databaseDoc.getArgs() ) ); // The basic library should have survived - final XEmbeddedScripts embeddedScripts = (XEmbeddedScripts) UnoRuntime.queryInterface(XEmbeddedScripts.class, - databaseDoc); + final XEmbeddedScripts embeddedScripts = UnoRuntime.queryInterface(XEmbeddedScripts.class, databaseDoc); final XStorageBasedLibraryContainer basicLibs = embeddedScripts.getBasicLibraries(); - assure( "Baisc lib did not survive reloading a closed document", basicLibs.hasByName( "Lib" ) ); - final XNameContainer lib = (XNameContainer)UnoRuntime.queryInterface( - XNameContainer.class, basicLibs.getByName( "Lib" ) ); - assure( "Basic module did not survive reloading a closed document", lib.hasByName( "Module" ) ); + assertTrue( "Baisc lib did not survive reloading a closed document", basicLibs.hasByName( "Lib" ) ); + final XNameContainer lib = UnoRuntime.queryInterface(XNameContainer.class, basicLibs.getByName("Lib")); + assertTrue( "Basic module did not survive reloading a closed document", lib.hasByName( "Module" ) ); // now closing the doc, and obtaining it from the data source, should preserve the marker we put into the load // args impl_closeDocument( databaseDoc ); - databaseDoc = (XModel)UnoRuntime.queryInterface( XModel.class, dataSource.getDatabaseDocument() ); - assure( "The test case marker did not survive re-retrieval of the doc from the data source.", + databaseDoc = UnoRuntime.queryInterface(XModel.class, dataSource.getDatabaseDocument()); + assertTrue( "The test case marker did not survive re-retrieval of the doc from the data source.", impl_hasMarker( databaseDoc.getArgs() ) ); // on the other hand, closing and regurlarly re-loading the doc *without* the marker should indeed // lose it impl_closeDocument( databaseDoc ); databaseDoc = impl_loadDocument( documentURL, impl_getDefaultLoadArgs() ); - assure( "Reloading the document kept the old args, instead of the newly supplied ones.", + assertTrue( "Reloading the document kept the old args, instead of the newly supplied ones.", !impl_hasMarker( databaseDoc.getArgs() ) ); // clean up @@ -635,7 +623,7 @@ public class DatabaseDocument extends TestCase implements com.sun.star.document. } // -------------------------------------------------------------------------------------------------------- - public void testDocumentEvents() throws Exception, IOException + @Test public void testDocumentEvents() throws Exception, IOException { // create an empty document final String libName = "EventHandlers"; @@ -660,8 +648,7 @@ public class DatabaseDocument extends TestCase implements com.sun.star.document. // bind the macro to the OnLoad event final String macroURI = "vnd.sun.star.script:" + libName + "." + moduleName + ".OnLoad?language=Basic&location=document"; - final XEventsSupplier eventsSupplier = (XEventsSupplier) UnoRuntime.queryInterface(XEventsSupplier.class, - databaseDoc); + final XEventsSupplier eventsSupplier = UnoRuntime.queryInterface(XEventsSupplier.class, databaseDoc); eventsSupplier.getEvents().replaceByName("OnLoad", new PropertyValue[] { new PropertyValue("EventType", 0, "Script", PropertyState.DIRECT_VALUE), @@ -694,7 +681,7 @@ public class DatabaseDocument extends TestCase implements com.sun.star.document. "OnLoad" }, context); - assureEquals("our provided interaction handler was not called", STATE_ON_LOAD_RECEIVED, m_loadDocState); + assertEquals("our provided interaction handler was not called", STATE_ON_LOAD_RECEIVED, m_loadDocState); // restore macro security level impl_setMacroSecurityLevel(oldSecurityLevel); @@ -704,11 +691,10 @@ public class DatabaseDocument extends TestCase implements com.sun.star.document. } // -------------------------------------------------------------------------------------------------------- - public void testGlobalEvents() throws Exception, IOException + @Test public void testGlobalEvents() throws Exception, IOException { XModel databaseDoc = impl_createEmptyEmbeddedHSQLDocument(); - final XStorable storeDoc = (XStorable) UnoRuntime.queryInterface(XStorable.class, - databaseDoc); + final XStorable storeDoc = UnoRuntime.queryInterface(XStorable.class, databaseDoc); String context, newURL; @@ -717,7 +703,7 @@ public class DatabaseDocument extends TestCase implements com.sun.star.document. context = "store"; impl_startObservingEvents(context); storeDoc.store(); - assureEquals("store is not expected to change the document URL", databaseDoc.getURL(), oldURL); + assertEquals("store is not expected to change the document URL", databaseDoc.getURL(), oldURL); impl_stopObservingEvents(m_globalEvents, new String[] { "OnSave", "OnSaveDone" @@ -727,7 +713,7 @@ public class DatabaseDocument extends TestCase implements com.sun.star.document. context = "storeToURL"; impl_startObservingEvents(context); storeDoc.storeToURL(createTempFileURL(), new PropertyValue[0]); - assureEquals("storetoURL is not expected to change the document URL", databaseDoc.getURL(), oldURL); + assertEquals("storetoURL is not expected to change the document URL", databaseDoc.getURL(), oldURL); impl_stopObservingEvents(m_globalEvents, new String[] { "OnSaveTo", "OnSaveToDone" @@ -738,19 +724,18 @@ public class DatabaseDocument extends TestCase implements com.sun.star.document. context = "storeAsURL"; impl_startObservingEvents(context); storeDoc.storeAsURL(newURL, new PropertyValue[0]); - assureEquals("storeAsURL is expected to change the document URL", databaseDoc.getURL(), newURL); + assertEquals("storeAsURL is expected to change the document URL", databaseDoc.getURL(), newURL); impl_stopObservingEvents(m_globalEvents, new String[] { "OnSaveAs", "OnSaveAsDone" }, context); // XModifiable.setModified - final XModifiable modifyDoc = (XModifiable) UnoRuntime.queryInterface(XModifiable.class, - databaseDoc); + final XModifiable modifyDoc = UnoRuntime.queryInterface(XModifiable.class, databaseDoc); context = "setModified"; impl_startObservingEvents(context); modifyDoc.setModified(true); - assureEquals("setModified didn't work", modifyDoc.isModified(), true); + assertEquals("setModified didn't work", modifyDoc.isModified(), true); impl_stopObservingEvents(m_globalEvents, new String[] { "OnModifyChanged" @@ -760,7 +745,7 @@ public class DatabaseDocument extends TestCase implements com.sun.star.document. context = "store (2)"; impl_startObservingEvents(context); storeDoc.store(); - assureEquals("'store' should implicitly reset the modified flag", modifyDoc.isModified(), false); + assertEquals("'store' should implicitly reset the modified flag", modifyDoc.isModified(), false); impl_stopObservingEvents(m_globalEvents, new String[] { "OnSave", "OnSaveDone", "OnModifyChanged" @@ -768,12 +753,10 @@ public class DatabaseDocument extends TestCase implements com.sun.star.document. // XComponentLoader.loadComponentFromURL newURL = copyToTempFile(databaseDoc.getURL()); - final XComponentLoader loader = (XComponentLoader) UnoRuntime.queryInterface(XComponentLoader.class, - getORB().createInstance("com.sun.star.frame.Desktop")); + final XComponentLoader loader = UnoRuntime.queryInterface(XComponentLoader.class, getMSF().createInstance("com.sun.star.frame.Desktop")); context = "loadComponentFromURL"; impl_startObservingEvents(context); - databaseDoc = (XModel) UnoRuntime.queryInterface(XModel.class, - loader.loadComponentFromURL(newURL, _BLANK, 0, impl_getDefaultLoadArgs())); + databaseDoc = UnoRuntime.queryInterface(XModel.class, loader.loadComponentFromURL(newURL, _BLANK, 0, impl_getDefaultLoadArgs())); impl_stopObservingEvents(m_globalEvents, new String[] { @@ -781,8 +764,7 @@ public class DatabaseDocument extends TestCase implements com.sun.star.document. }, context); // closing a document by API - final XCloseable closeDoc = (XCloseable) UnoRuntime.queryInterface(XCloseable.class, - databaseDoc); + final XCloseable closeDoc = UnoRuntime.queryInterface(XCloseable.class, databaseDoc); context = "close (API)"; impl_startObservingEvents(context); closeDoc.close(true); @@ -795,13 +777,11 @@ public class DatabaseDocument extends TestCase implements com.sun.star.document. // closing a document via UI context = "close (UI)"; impl_startObservingEvents("prepare for '" + context + "'"); - databaseDoc = (XModel) UnoRuntime.queryInterface(XModel.class, - loader.loadComponentFromURL(newURL, _BLANK, 0, impl_getDefaultLoadArgs())); + databaseDoc = UnoRuntime.queryInterface(XModel.class, loader.loadComponentFromURL(newURL, _BLANK, 0, impl_getDefaultLoadArgs())); impl_waitForEvent(m_globalEvents, "OnLoad", 5000); // wait for all events to arrive - OnLoad should be the last one - final XDispatchProvider dispatchProvider = (XDispatchProvider) UnoRuntime.queryInterface(XDispatchProvider.class, - databaseDoc.getCurrentController().getFrame()); + final XDispatchProvider dispatchProvider = UnoRuntime.queryInterface(XDispatchProvider.class, databaseDoc.getCurrentController().getFrame()); final URL url = impl_getURL(".uno:CloseDoc"); final XDispatch dispatcher = dispatchProvider.queryDispatch(url, "", 0); impl_startObservingEvents(context); @@ -814,8 +794,7 @@ public class DatabaseDocument extends TestCase implements com.sun.star.document. // creating a new document databaseDoc = impl_createDocument(); - final XLoadable loadDoc = (XLoadable) UnoRuntime.queryInterface(XLoadable.class, - databaseDoc); + final XLoadable loadDoc = UnoRuntime.queryInterface(XLoadable.class, databaseDoc); context = "initNew"; impl_startObservingEvents(context); loadDoc.initNew(); @@ -832,13 +811,11 @@ public class DatabaseDocument extends TestCase implements com.sun.star.document. context = "activation"; // for this, load a database document ... impl_startObservingEvents("prepare for '" + context + "'"); - databaseDoc = (XModel) UnoRuntime.queryInterface(XModel.class, - loader.loadComponentFromURL(newURL, _BLANK, 0, impl_getDefaultLoadArgs())); + databaseDoc = UnoRuntime.queryInterface(XModel.class, loader.loadComponentFromURL(newURL, _BLANK, 0, impl_getDefaultLoadArgs())); final int previousOnLoadEventPos = impl_waitForEvent(m_globalEvents, "OnLoad", 5000); // ... and another document ... final String otherURL = copyToTempFile(databaseDoc.getURL()); - final XModel otherDoc = (XModel) UnoRuntime.queryInterface(XModel.class, - loader.loadComponentFromURL(otherURL, _BLANK, 0, impl_getDefaultLoadArgs())); + final XModel otherDoc = UnoRuntime.queryInterface(XModel.class, loader.loadComponentFromURL(otherURL, _BLANK, 0, impl_getDefaultLoadArgs())); impl_raise(otherDoc); impl_waitForEvent(m_globalEvents, "OnLoad", 5000, previousOnLoadEventPos + 1); @@ -864,8 +841,7 @@ public class DatabaseDocument extends TestCase implements com.sun.star.document. new URL() }; url[0].Complete = _completeURL; - final XURLTransformer urlTransformer = (XURLTransformer) UnoRuntime.queryInterface(XURLTransformer.class, - getORB().createInstance("com.sun.star.util.URLTransformer")); + final XURLTransformer urlTransformer = UnoRuntime.queryInterface(XURLTransformer.class, getMSF().createInstance("com.sun.star.util.URLTransformer")); urlTransformer.parseStrict(url); return url[0]; } @@ -874,15 +850,14 @@ public class DatabaseDocument extends TestCase implements com.sun.star.document. private void impl_raise(XModel _document) { final XFrame frame = _document.getCurrentController().getFrame(); - final XTopWindow topWindow = (XTopWindow) UnoRuntime.queryInterface(XTopWindow.class, - frame.getContainerWindow()); + final XTopWindow topWindow = UnoRuntime.queryInterface(XTopWindow.class, frame.getContainerWindow()); topWindow.toFront(); } // -------------------------------------------------------------------------------------------------------- private void impl_startObservingEvents(String _context) { - log.println(" " + _context + " {"); + System.out.println(" " + _context + " {"); synchronized (m_documentEvents) { m_documentEvents.clear(); @@ -923,19 +898,19 @@ public class DatabaseDocument extends TestCase implements com.sun.star.document. actualEventCount = _actualEvents.size(); } - assureEquals("wrong event count for '" + _context + "'", + assertEquals("wrong event count for '" + _context + "'", _expectedEvents.length, _actualEvents.size()); for (int i = 0; i < _expectedEvents.length; ++i) { - assureEquals("wrong event at positon " + (i + 1) + " for '" + _context + "'", + assertEquals("wrong event at positon " + (i + 1) + " for '" + _context + "'", _expectedEvents[i], _actualEvents.get(i)); } } } finally { - log.println(" }"); + System.out.println(" }"); } } @@ -975,7 +950,7 @@ public class DatabaseDocument extends TestCase implements com.sun.star.document. } } - failed("expected event '" + _expectedEvent + "' did not arrive after " + _maxMilliseconds + " milliseconds"); + fail("expected event '" + _expectedEvent + "' did not arrive after " + _maxMilliseconds + " milliseconds"); return -1; } @@ -994,7 +969,7 @@ public class DatabaseDocument extends TestCase implements com.sun.star.document. if ((_Event.EventName.equals("OnLoad")) && (m_loadDocState != STATE_NOT_STARTED)) { - assureEquals("OnLoad event must come *after* invocation of the interaction handler / user!", + assertEquals("OnLoad event must come *after* invocation of the interaction handler / user!", m_loadDocState, STATE_MACRO_EXEC_APPROVED); m_loadDocState = STATE_ON_LOAD_RECEIVED; } @@ -1005,7 +980,7 @@ public class DatabaseDocument extends TestCase implements com.sun.star.document. m_documentEvents.notifyAll(); } - log.println(" document event: " + _Event.EventName); + System.out.println(" document event: " + _Event.EventName); } // -------------------------------------------------------------------------------------------------------- @@ -1023,7 +998,7 @@ public class DatabaseDocument extends TestCase implements com.sun.star.document. m_globalEvents.notifyAll(); } - log.println(" global event: " + _Event.EventName); + System.out.println(" global event: " + _Event.EventName); } // -------------------------------------------------------------------------------------------------------- diff --git a/dbaccess/qa/complex/dbaccess/Parser.java b/dbaccess/qa/complex/dbaccess/Parser.java index 2b1b9342edcb..3b6b0b92e3ed 100644 --- a/dbaccess/qa/complex/dbaccess/Parser.java +++ b/dbaccess/qa/complex/dbaccess/Parser.java @@ -35,23 +35,34 @@ import com.sun.star.sdbc.SQLException; import com.sun.star.uno.Exception; import com.sun.star.uno.UnoRuntime; + +// ---------- 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 Parser extends CRMBasedTestCase { // -------------------------------------------------------------------------------------------------------- - public String[] getTestMethodNames() - { - return new String[] { - "checkJoinSyntax", - "checkParameterTypes", - "checkWhere", - }; - } +// public String[] getTestMethodNames() +// { +// return new String[] { +// "checkJoinSyntax", +// "checkParameterTypes", +// "checkWhere", +// }; +// } // -------------------------------------------------------------------------------------------------------- - public String getTestObjectName() - { - return "Parser"; - } +// public String getTestObjectName() +// { +// return "Parser"; +// } // -------------------------------------------------------------------------------------------------------- protected void createTestCase() @@ -64,11 +75,11 @@ public class Parser extends CRMBasedTestCase catch ( Exception e ) { e.printStackTrace( System.err ); - assure( "caught an exception (" + e.getMessage() + ") while creating the test case", false ); + fail( "caught an exception (" + e.getMessage() + ") while creating the test case"); } } - public void checkWhere() throws Exception + @Test public void checkWhere() throws Exception { final XSingleSelectQueryComposer composer = createQueryComposer(); final String SELECT = "SELECT \"products\".\"Name\" FROM \"products\" WHERE "; @@ -107,7 +118,7 @@ public class Parser extends CRMBasedTestCase // -------------------------------------------------------------------------------------------------------- /** verifies that aliases for inner queries work as expected */ - public void checkJoinSyntax() throws Exception + @Test public void checkJoinSyntax() throws Exception { final XSingleSelectQueryComposer composer = createQueryComposer(); @@ -144,7 +155,7 @@ public class Parser extends CRMBasedTestCase { caughtExpected = true; } - assure( "pre-condition not met: parser should except on unparseable statements, else the complete" + + assertTrue( "pre-condition not met: parser should except on unparseable statements, else the complete" + "test is bogus!", caughtExpected ); } @@ -154,30 +165,28 @@ public class Parser extends CRMBasedTestCase final XSingleSelectQueryComposer composer = createQueryComposer(); composer.setQuery( _statement ); - assureEquals( "checkParameterTypes: internal error", _expectedParameterNames.length, _expectedParameterTypes.length ); + assertEquals( "checkParameterTypes: internal error", _expectedParameterNames.length, _expectedParameterTypes.length ); - final XParametersSupplier paramSupp = (XParametersSupplier)UnoRuntime.queryInterface( - XParametersSupplier.class, composer ); + final XParametersSupplier paramSupp = UnoRuntime.queryInterface(XParametersSupplier.class, composer); final XIndexAccess parameters = paramSupp.getParameters(); - assureEquals( "(ctx: " + _context + ") unexpected parameter count", _expectedParameterNames.length, parameters.getCount() ); + assertEquals( "(ctx: " + _context + ") unexpected parameter count", _expectedParameterNames.length, parameters.getCount() ); for ( int i=0; i<parameters.getCount(); ++i ) { - final XPropertySet parameter = (XPropertySet)UnoRuntime.queryInterface( XPropertySet.class, - parameters.getByIndex(i) ); + final XPropertySet parameter = UnoRuntime.queryInterface(XPropertySet.class, parameters.getByIndex(i)); final String name = (String)parameter.getPropertyValue( "Name" ); - assureEquals( "(ctx: " + _context + ") unexpected parameter name for parameter number " + ( i + 1 ), _expectedParameterNames[i], name ); + assertEquals( "(ctx: " + _context + ") unexpected parameter name for parameter number " + ( i + 1 ), _expectedParameterNames[i], name ); final int type = ((Integer)parameter.getPropertyValue( "Type" )).intValue(); - assureEquals( "(ctx: " + _context + ") unexpected data type for parameter number " + ( i + 1 ), _expectedParameterTypes[i], type ); + assertEquals( "(ctx: " + _context + ") unexpected data type for parameter number " + ( i + 1 ), _expectedParameterTypes[i], type ); } } // -------------------------------------------------------------------------------------------------------- /** verifies that the parser properly recognizes the types of parameters */ - public void checkParameterTypes() throws Exception + @Test public void checkParameterTypes() throws Exception { impl_checkParameters( "SELECT * FROM \"all orders\" " + diff --git a/dbaccess/qa/complex/dbaccess/PropertyBag.java b/dbaccess/qa/complex/dbaccess/PropertyBag.java index c686be886bba..4920f8fa0006 100644 --- a/dbaccess/qa/complex/dbaccess/PropertyBag.java +++ b/dbaccess/qa/complex/dbaccess/PropertyBag.java @@ -27,14 +27,24 @@ package complex.dbaccess; -import complexlib.ComplexTestCase; +// import complexlib.ComplexTestCase; import com.sun.star.uno.UnoRuntime; import com.sun.star.uno.XInterface; import com.sun.star.lang.XMultiServiceFactory; import com.sun.star.beans.*; -public class PropertyBag extends ComplexTestCase +// ---------- 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 PropertyBag extends TestCase { private static final String VALUE = "Value"; private XPropertyContainer m_bag; @@ -42,30 +52,30 @@ public class PropertyBag extends ComplexTestCase private XPropertyAccess m_access; private XMultiServiceFactory m_orb = null; - public String[] getTestMethodNames() - { - return new String[] - { - "checkBasics", - "checkSequenceAccess", - "checkDynamicSet" - }; - } +// public String[] getTestMethodNames() +// { +// return new String[] +// { +// "checkBasics", +// "checkSequenceAccess", +// "checkDynamicSet" +// }; +// } public String getTestObjectName() { return "PropertyBag"; } - public void before() + @Before public void before() { - m_orb = (XMultiServiceFactory)param.getMSF(); + m_orb = getMSF(); } - public void checkBasics() + @Test public void checkBasics() { createEmptyBag(); - log.println("testing the basics"); + System.out.println("testing the basics"); // check whether empty property names are rejected boolean caughtExpected = false; @@ -76,7 +86,9 @@ public class PropertyBag extends ComplexTestCase catch(com.sun.star.lang.IllegalArgumentException e) { caughtExpected = true; } catch(com.sun.star.uno.Exception e) { } if ( !caughtExpected ) - failed( "empty property names are not rejected by XPropertyContainer::addProperty" ); + { + fail("empty property names are not rejected by XPropertyContainer::addProperty"); + } // check whether duplicate insertions are rejected caughtExpected = false; @@ -88,7 +100,9 @@ public class PropertyBag extends ComplexTestCase catch(com.sun.star.beans.PropertyExistException e) { caughtExpected = true; } catch(com.sun.star.uno.Exception e) { } if ( !caughtExpected ) - failed( "insertion of duplicate property names is not rejected" ); + { + fail("insertion of duplicate property names is not rejected"); + } // try removing the property we just added - this should fail, as it does not have // the REMOVEABLE attribute @@ -100,7 +114,9 @@ public class PropertyBag extends ComplexTestCase catch(com.sun.star.beans.NotRemoveableException e) { caughtExpected = true; } catch(com.sun.star.uno.Exception e) { } if ( !caughtExpected ) - failed( "removing non-removeable properties is expected to fail - but it didn't" ); + { + fail("removing non-removeable properties is expected to fail - but it didn't"); + } // try removing a non-existent property caughtExpected = false; @@ -111,7 +127,9 @@ public class PropertyBag extends ComplexTestCase catch(com.sun.star.beans.UnknownPropertyException e) { caughtExpected = true; } catch(com.sun.star.uno.Exception e) { } if ( !caughtExpected ) - failed( "removing non-existent properties is expected to fail - but it didn't" ); + { + fail("removing non-existent properties is expected to fail - but it didn't"); + } // try writing and reading a value for the one property we have so far try @@ -120,11 +138,13 @@ public class PropertyBag extends ComplexTestCase m_set.setPropertyValue( VALUE , testValue); final String currentValue = (String)m_set.getPropertyValue( VALUE); if ( !currentValue.equals( testValue ) ) - failed( "set property is not remembered" ); + { + fail("set property is not remembered"); + } } catch(com.sun.star.uno.Exception e) { - failed( "setting or getting a property value failed" ); + fail( "setting or getting a property value failed" ); } // try setting an illegal value for the property @@ -136,12 +156,14 @@ public class PropertyBag extends ComplexTestCase catch(com.sun.star.lang.IllegalArgumentException e) { caughtExpected = true; } catch(com.sun.star.uno.Exception e) { } if ( !caughtExpected ) - failed( "the bag does not respect the property type we declared for the property" ); + { + fail("the bag does not respect the property type we declared for the property"); + } } - public void checkSequenceAccess() throws com.sun.star.uno.Exception + @Test public void checkSequenceAccess() throws com.sun.star.uno.Exception { - log.println( "checking PropertySetAccess via sequences" ); + System.out.println( "checking PropertySetAccess via sequences" ); createStandardBag( false ); // --------------------------------- @@ -160,10 +182,10 @@ public class PropertyBag extends ComplexTestCase final Object value = m_set.getPropertyValue( expectedValues[i].Name ); if ( !value.equals( expectedValues[i].Value ) ) { - log.println( "property name : " + expectedValues[i].Name ); - log.println( "expected value: " + expectedValues[i].Value.toString() ); - log.println( "current value : " + value.toString() ); - failed( "retrieving a previously set property (" + expectedValues[i].Value.getClass().toString() + ") failed" ); + System.out.println( "property name : " + expectedValues[i].Name ); + System.out.println( "expected value: " + expectedValues[i].Value.toString() ); + System.out.println( "current value : " + value.toString() ); + fail( "retrieving a previously set property (" + expectedValues[i].Value.getClass().toString() + ") failed" ); } } @@ -180,23 +202,25 @@ public class PropertyBag extends ComplexTestCase { if ( !expectedValues[j].Value.equals( value ) ) { - log.println( "property name : " + expectedValues[j].Name ); - log.println( "expected value: " + expectedValues[j].Value.toString() ); - log.println( "current value : " + value.toString() ); - failed( "getPropertyValues failed for property '" + name + "' failed" ); + System.out.println( "property name : " + expectedValues[j].Name ); + System.out.println( "expected value: " + expectedValues[j].Value.toString() ); + System.out.println( "current value : " + value.toString() ); + fail( "getPropertyValues failed for property '" + name + "' failed" ); } break; } } if ( !m_set.getPropertyValue( name ).equals( value ) ) - failed( "XPropertyAccess::getPropertyValues() and XPropertyset::getPropertyValue results are inconsistent" ); + { + fail("XPropertyAccess::getPropertyValues() and XPropertyset::getPropertyValue results are inconsistent"); + } } } - public void checkDynamicSet() throws com.sun.star.uno.Exception + @Test public void checkDynamicSet() throws com.sun.star.uno.Exception { - log.println( "checking proper dynamic of the set" ); + System.out.println( "checking proper dynamic of the set" ); createStandardBag( false ); final PropertyValue props[] = @@ -215,7 +239,9 @@ public class PropertyBag extends ComplexTestCase catch( com.sun.star.beans.UnknownPropertyException e ) { caughtExpected = true; } catch( com.sun.star.uno.Exception e ) { } if ( !caughtExpected ) - failed( "the set shouldn't accept unknown property values, if not explicitly told to do so" ); + { + fail("the set shouldn't accept unknown property values, if not explicitly told to do so"); + } // re-create the bag, this time allow it to implicitly add properties createStandardBag( true ); @@ -223,14 +249,18 @@ public class PropertyBag extends ComplexTestCase try { m_access.setPropertyValues( props ); success = true; } catch( com.sun.star.uno.Exception e ) { } if ( !success ) - failed( "property bag failed to implicitly add unknown properties" ); + { + fail("property bag failed to implicitly add unknown properties"); + } // see whether this property was really added, and not just ignored final PropertyValue newlyAdded = props[ props.length - 1 ]; try { if ( !m_set.getPropertyValue( newlyAdded.Name ).equals( newlyAdded.Value ) ) - failed( "the new property was not really added, or not added with the proper value" ); + { + fail("the new property was not really added, or not added with the proper value"); + } } catch( com.sun.star.uno.Exception e ) { } } @@ -241,13 +271,13 @@ public class PropertyBag extends ComplexTestCase { m_bag = null; final String serviceName = "com.sun.star.beans.PropertyBag"; - m_bag = (XPropertyContainer)UnoRuntime.queryInterface( XPropertyContainer.class, - m_orb.createInstance( serviceName ) - ); + m_bag = UnoRuntime.queryInterface(XPropertyContainer.class, m_orb.createInstance(serviceName)); if ( m_bag == null ) - failed( "could not create a " + serviceName + " instance" ); - m_set = (XPropertySet)UnoRuntime.queryInterface( XPropertySet.class, m_bag ); - m_access = (XPropertyAccess)UnoRuntime.queryInterface( XPropertyAccess.class, m_bag ); + { + fail("could not create a " + serviceName + " instance"); + } + m_set = UnoRuntime.queryInterface(XPropertySet.class, m_bag); + m_access = UnoRuntime.queryInterface(XPropertyAccess.class, m_bag); } catch( com.sun.star.uno.Exception e ) { @@ -263,13 +293,13 @@ public class PropertyBag extends ComplexTestCase final Object initArgs[] = { new NamedValue( "AutomaticAddition", Boolean.valueOf( allowLazyAdding ) ) }; final String serviceName = "com.sun.star.beans.PropertyBag"; - m_bag = (XPropertyContainer)UnoRuntime.queryInterface( XPropertyContainer.class, - m_orb.createInstanceWithArguments( serviceName, initArgs ) - ); + m_bag = UnoRuntime.queryInterface(XPropertyContainer.class, m_orb.createInstanceWithArguments(serviceName, initArgs)); if ( m_bag == null ) - failed( "could not create a " + serviceName + " instance" ); - m_set = (XPropertySet)UnoRuntime.queryInterface( XPropertySet.class, m_bag ); - m_access = (XPropertyAccess)UnoRuntime.queryInterface( XPropertyAccess.class, m_bag ); + { + fail("could not create a " + serviceName + " instance"); + } + m_set = UnoRuntime.queryInterface(XPropertySet.class, m_bag); + m_access = UnoRuntime.queryInterface(XPropertyAccess.class, m_bag); final Object properties[][] = { diff --git a/dbaccess/qa/complex/dbaccess/Query.java b/dbaccess/qa/complex/dbaccess/Query.java index 81a651fd5696..222a6668f705 100644 --- a/dbaccess/qa/complex/dbaccess/Query.java +++ b/dbaccess/qa/complex/dbaccess/Query.java @@ -36,22 +36,32 @@ import com.sun.star.sdbcx.XColumnsSupplier; import com.sun.star.uno.UnoRuntime; import connectivity.tools.CRMDatabase; -public class Query extends complexlib.ComplexTestCase { +// ---------- 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 Query extends TestCase { connectivity.tools.HsqlDatabase m_database; // -------------------------------------------------------------------------------------------------------- - public String[] getTestMethodNames() { - return new String[] - { - "testQueryColumns" - }; - } +// public String[] getTestMethodNames() { +// return new String[] +// { +// "testQueryColumns" +// }; +// } // -------------------------------------------------------------------------------------------------------- - public String getTestObjectName() { - return "Query"; - } +// public String getTestObjectName() { +// return "Query"; +// } // -------------------------------------------------------------------------------------------------------- private void createTestCase() @@ -60,26 +70,26 @@ public class Query extends complexlib.ComplexTestCase { { if ( m_database == null ) { - final CRMDatabase database = new CRMDatabase( getFactory(), false ); + final CRMDatabase database = new CRMDatabase( getMSF(), false ); m_database = database.getDatabase(); } } catch( Exception e ) { - log.println( "could not create the test case, error message:\n" + e.getMessage() ); + System.out.println( "could not create the test case, error message:\n" + e.getMessage() ); e.printStackTrace( System.err ); - assure( "failed to created the test case", false ); + fail( "failed to created the test case"); } } // -------------------------------------------------------------------------------------------------------- - private XMultiServiceFactory getFactory() - { - return (XMultiServiceFactory)param.getMSF(); - } +// private XMultiServiceFactory getFactory() +// { +// return (XMultiServiceFactory)param.getMSF(); +// } // -------------------------------------------------------------------------------------------------------- - public void testQueryColumns() + @Test public void testQueryColumns() { createTestCase(); @@ -107,20 +117,20 @@ public class Query extends complexlib.ComplexTestCase { XIndexAccess.class, suppCols.getColumns()); // check whether the columns supplied by the query match what we expected - assure( "invalid column count (found " + columns.getCount() + ", expected: " + expectedColumnNames[i].length + ") for query \"" + queryNames[i] + "\"", + assertTrue( "invalid column count (found " + columns.getCount() + ", expected: " + expectedColumnNames[i].length + ") for query \"" + queryNames[i] + "\"", columns.getCount() == expectedColumnNames[i].length ); for ( int col = 0; col < columns.getCount(); ++col ) { final XNamed columnName = UnoRuntime.queryInterface( XNamed.class, columns.getByIndex(col) ); - assure( "column no. " + col + " of query \"" + queryNames[i] + "\" not matching", + assertTrue( "column no. " + col + " of query \"" + queryNames[i] + "\" not matching", columnName.getName().equals( expectedColumnNames[i][col] ) ); } } } catch ( Exception e ) { - assure( "caught an unexpected exception: " + e.getMessage(), false ); + fail( "caught an unexpected exception: " + e.getMessage() ); } } } diff --git a/dbaccess/qa/complex/dbaccess/QueryInQuery.java b/dbaccess/qa/complex/dbaccess/QueryInQuery.java index 002d0395b791..0cb0789b782c 100644 --- a/dbaccess/qa/complex/dbaccess/QueryInQuery.java +++ b/dbaccess/qa/complex/dbaccess/QueryInQuery.java @@ -37,26 +37,36 @@ import connectivity.tools.RowSet; import com.sun.star.sdbc.XStatement; import com.sun.star.sdbc.XResultSet; +// ---------- 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 QueryInQuery extends CRMBasedTestCase { private static final String QUERY_PRODUCTS = "query products"; - // -------------------------------------------------------------------------------------------------------- - public String[] getTestMethodNames() - { - return new String[] { - "executeSimpleSelect", - "executeAliasedSelect", - "checkNameCollisions", - "checkCyclicReferences", - "checkStatementQiQSupport" - }; - } - - // -------------------------------------------------------------------------------------------------------- - public String getTestObjectName() - { - return "QueryInQuery"; - } +// // -------------------------------------------------------------------------------------------------------- +// public String[] getTestMethodNames() +// { +// return new String[] { +// "executeSimpleSelect", +// "executeAliasedSelect", +// "checkNameCollisions", +// "checkCyclicReferences", +// "checkStatementQiQSupport" +// }; +// } +// +// // -------------------------------------------------------------------------------------------------------- +// public String getTestObjectName() +// { +// return "QueryInQuery"; +// } // -------------------------------------------------------------------------------------------------------- protected void createTestCase() @@ -69,7 +79,7 @@ public class QueryInQuery extends CRMBasedTestCase catch ( Exception e ) { e.printStackTrace( System.err ); - assure( "caught an exception (" + e.getMessage() + ") while creating the test case", false ); + fail( "caught an exception (" + e.getMessage() + ") while creating the test case" ); } } @@ -84,17 +94,17 @@ public class QueryInQuery extends CRMBasedTestCase outerRowSet.last(); innerRowSet.last(); - assure( "wrong record counts", outerRowSet.getRow() == innerRowSet.getRow() ); + assertTrue( "wrong record counts", outerRowSet.getRow() == innerRowSet.getRow() ); outerRowSet.beforeFirst(); innerRowSet.beforeFirst(); - assure( "wrong column counts", outerRowSet.getColumnCount() == innerRowSet.getColumnCount() ); + assertTrue( "wrong column counts", outerRowSet.getColumnCount() == innerRowSet.getColumnCount() ); while ( outerRowSet.next() && innerRowSet.next() ) { for ( int i=1; i <= outerRowSet.getColumnCount(); ++i ) { - assure( "content of column " + i + " of row " + outerRowSet.getRow() + " not identical", + assertTrue( "content of column " + i + " of row " + outerRowSet.getRow() + " not identical", innerRowSet.getString(i).equals( outerRowSet.getString(i) ) ); } } @@ -103,7 +113,7 @@ public class QueryInQuery extends CRMBasedTestCase // -------------------------------------------------------------------------------------------------------- /** executes a SQL statement simply selecting all columns from a query */ - public void executeSimpleSelect() throws SQLException + @Test public void executeSimpleSelect() throws SQLException { verifyEqualRowSetContent( CommandType.COMMAND, "SELECT * FROM \"query products\"", @@ -113,7 +123,7 @@ public class QueryInQuery extends CRMBasedTestCase // -------------------------------------------------------------------------------------------------------- /** verifies that aliases for inner queries work as expected */ - public void executeAliasedSelect() throws SQLException + @Test public void executeAliasedSelect() throws SQLException { verifyEqualRowSetContent( CommandType.COMMAND, "SELECT \"PROD\".\"ID\" FROM \"query products\" AS \"PROD\"", @@ -126,7 +136,7 @@ public class QueryInQuery extends CRMBasedTestCase // -------------------------------------------------------------------------------------------------------- /** verifies that aliases for inner queries work as expected */ - public void checkNameCollisions() + @Test public void checkNameCollisions() { // create a query with a name which is used by a table boolean caughtExpected = false; @@ -137,7 +147,7 @@ public class QueryInQuery extends CRMBasedTestCase catch ( WrappedTargetException e ) { caughtExpected = true; } catch ( IllegalArgumentException e ) {} catch ( ElementExistException e ) { caughtExpected = true; } - assure( "creating queries with the name of an existing table should not be possible", + assertTrue( "creating queries with the name of an existing table should not be possible", caughtExpected ); // create a table with a name which is used by a query @@ -153,12 +163,12 @@ public class QueryInQuery extends CRMBasedTestCase } catch ( SQLException e ) { caughtExpected = true; } catch ( ElementExistException ex ) { } - assure( "creating tables with the name of an existing query should not be possible", + assertTrue( "creating tables with the name of an existing query should not be possible", caughtExpected ); } // -------------------------------------------------------------------------------------------------------- - public void checkCyclicReferences() throws ElementExistException, WrappedTargetException, IllegalArgumentException + @Test public void checkCyclicReferences() throws ElementExistException, WrappedTargetException, IllegalArgumentException { // some queries which create a cycle in the sub query tree m_database.getDatabase().getDataSource().createQuery( "orders level 1", "SELECT * FROM \"orders level 0\"" ); @@ -172,21 +182,21 @@ public class QueryInQuery extends CRMBasedTestCase try { rowSet.execute(); } catch ( SQLException e ) { caughtExpected = ( e.ErrorCode == -com.sun.star.sdb.ErrorCondition.PARSER_CYCLIC_SUB_QUERIES ); } - assure( "executing a query with cyclic nested sub queries should fail!", caughtExpected ); + assertTrue( "executing a query with cyclic nested sub queries should fail!", caughtExpected ); } // -------------------------------------------------------------------------------------------------------- - public void checkStatementQiQSupport() + @Test public void checkStatementQiQSupport() { try { final XStatement statement = m_database.getConnection().createStatement(); final XResultSet resultSet = statement.executeQuery( "SELECT * FROM \"query products\"" ); - assure( "Result Set is null", resultSet != null ); + assertTrue( "Result Set is null", resultSet != null ); } catch( SQLException e ) { - assure( "SDB level statements do not allow for queries in queries", false ); + fail( "SDB level statements do not allow for queries in queries" ); } } } diff --git a/dbaccess/qa/complex/dbaccess/RowSet.java b/dbaccess/qa/complex/dbaccess/RowSet.java index 5a13f6724d1f..7a11a96d9b00 100644 --- a/dbaccess/qa/complex/dbaccess/RowSet.java +++ b/dbaccess/qa/complex/dbaccess/RowSet.java @@ -49,7 +49,7 @@ import com.sun.star.sdbcx.XColumnsSupplier; import com.sun.star.sdbcx.XDeleteRows; import com.sun.star.sdbcx.XRowLocate; import com.sun.star.uno.UnoRuntime; -import complexlib.ComplexTestCase; + import connectivity.tools.CRMDatabase; import connectivity.tools.DataSource; import connectivity.tools.HsqlDatabase; @@ -57,7 +57,17 @@ import connectivity.tools.sdb.Connection; import java.lang.reflect.Method; import java.util.Random; -public class RowSet extends ComplexTestCase +// ---------- 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 RowSet extends TestCase { static final int MAX_TABLE_ROWS = 100; @@ -98,41 +108,41 @@ public class RowSet extends ComplexTestCase { int pos = m_resultSet.getRow(); // final int val = m_row.getInt(1); -// log.println("Clone Move(" + m_id +") before i: " + (i+1) + " Pos: " + pos + " Val: " + val); +// System.out.println("Clone Move(" + m_id +") before i: " + (i+1) + " Pos: " + pos + " Val: " + val); testPosition(m_resultSet, m_row, i + 1, "clone move(" + m_id + ")"); // val = m_row.getInt(1); -// log.println("Clone Move(" + m_id +") after i: " + (i+1) + " Pos: " + pos + " Val: " + val); +// System.out.println("Clone Move(" + m_id +") after i: " + (i+1) + " Pos: " + pos + " Val: " + val); int pos2 = m_resultSet.getRow(); - assure("ResultSetMovementStress wrong position: " + i + " Pos1: " + pos + " Pos2: " + pos2, pos == pos2); + assertTrue("ResultSetMovementStress wrong position: " + i + " Pos1: " + pos + " Pos2: " + pos2, pos == pos2); } } catch (Exception e) { - assure("ResultSetMovementStress(" + m_id + ") failed: " + e, false); + fail("ResultSetMovementStress(" + m_id + ") failed: " + e); } } } // -------------------------------------------------------------------------------------------------------- - public String[] getTestMethodNames() - { - return new String[] - { - "testRowSet", - "testRowSetEvents", - "testDeleteBehavior", - "testCloneMovesPlusDeletions", - "testCloneMovesPlusInsertions", - "testParameters" - }; - } - - // -------------------------------------------------------------------------------------------------------- - public String getTestObjectName() - { - return "RowSet"; - } - +// public String[] getTestMethodNames() +// { +// return new String[] +// { +// "testRowSet", +// "testRowSetEvents", +// "testDeleteBehavior", +// "testCloneMovesPlusDeletions", +// "testCloneMovesPlusInsertions", +// "testParameters" +// }; +// } +// +// // -------------------------------------------------------------------------------------------------------- +// public String getTestObjectName() +// { +// return "RowSet"; +// } +// // -------------------------------------------------------------------------------------------------------- private void createTestCase(boolean _defaultRowSet) { @@ -140,13 +150,13 @@ public class RowSet extends ComplexTestCase { try { - final CRMDatabase database = new CRMDatabase( getFactory(), false ); + final CRMDatabase database = new CRMDatabase( getMSF(), false ); m_database = database.getDatabase(); m_dataSource = m_database.getDataSource(); } catch (Exception e) { - assure("could not create the embedded HSQL database: " + e.getMessage(), false); + fail("could not create the embedded HSQL database: " + e.getMessage()); } } @@ -156,7 +166,7 @@ public class RowSet extends ComplexTestCase } catch (SQLException e) { - assure("could not connect to the database/table structure, error message:\n" + e.getMessage(), false); + fail("could not connect to the database/table structure, error message:\n" + e.getMessage()); } if (_defaultRowSet) @@ -166,10 +176,10 @@ public class RowSet extends ComplexTestCase } // -------------------------------------------------------------------------------------------------------- - private XMultiServiceFactory getFactory() - { - return (XMultiServiceFactory) param.getMSF(); - } +// private XMultiServiceFactory getFactory() +// { +// return (XMultiServiceFactory) param.getMSF(); +// } // -------------------------------------------------------------------------------------------------------- /** creates a com.sun.star.sdb.RowSet to use during the test @@ -200,7 +210,7 @@ public class RowSet extends ComplexTestCase { try { - m_rowSet = UnoRuntime.queryInterface( XRowSet.class, getFactory().createInstance( "com.sun.star.sdb.RowSet" ) ); + m_rowSet = UnoRuntime.queryInterface( XRowSet.class, getMSF().createInstance( "com.sun.star.sdb.RowSet" ) ); final XPropertySet rowSetProperties = UnoRuntime.queryInterface( XPropertySet.class, m_rowSet ); rowSetProperties.setPropertyValue("Command", command); rowSetProperties.setPropertyValue("CommandType", Integer.valueOf(commandType)); @@ -224,15 +234,15 @@ public class RowSet extends ComplexTestCase } catch (Exception e) { - assure("caught an exception while creating the RowSet. Type:\n" + e.getClass().toString() + "\nMessage:\n" + e.getMessage(), false); + fail("caught an exception while creating the RowSet. Type:\n" + e.getClass().toString() + "\nMessage:\n" + e.getMessage()); } } // -------------------------------------------------------------------------------------------------------- - public void testRowSet() throws java.lang.Exception + @Test public void testRowSet() throws java.lang.Exception { - log.println("testing testRowSet"); + System.out.println("testing testRowSet"); createTestCase(true); // sequential postioning @@ -282,8 +292,8 @@ public class RowSet extends ComplexTestCase { final int val = m_row.getInt(1); final int pos = m_resultSet.getRow(); - assure(location + ": value/position do not match: " + pos + " (pos) != " + val + " (val)", val == pos); - assure(location + ": value/position are not as expected: " + val + " (val) != " + expectedValue + " (expected)", val == expectedValue); + assertTrue(location + ": value/position do not match: " + pos + " (pos) != " + val + " (val)", val == pos); + assertTrue(location + ": value/position are not as expected: " + val + " (val) != " + expectedValue + " (expected)", val == expectedValue); } // -------------------------------------------------------------------------------------------------------- @@ -301,7 +311,7 @@ public class RowSet extends ComplexTestCase } catch (Exception e) { - assure("testSequentialPositining failed: " + e, false); + fail("testSequentialPositining failed: " + e); } } @@ -313,13 +323,13 @@ public class RowSet extends ComplexTestCase for (int i = 1; i <= MAX_FETCH_ROWS; ++i) { final int calcPos = (MAX_TABLE_ROWS % i) + 1; - assure("testAbsolutePositioning failed", _resultSet.absolute(calcPos)); + assertTrue("testAbsolutePositioning failed", _resultSet.absolute(calcPos)); testPosition(_resultSet, _row, calcPos, "testAbsolutePositioning"); } } catch (Exception e) { - assure("testAbsolutePositioning failed: " + e, false); + fail("testAbsolutePositioning failed: " + e); } } @@ -343,7 +353,7 @@ public class RowSet extends ComplexTestCase } catch (Exception e) { - assure("test3 failed: " + e, false); + fail("test3 failed: " + e); } } @@ -370,14 +380,14 @@ public class RowSet extends ComplexTestCase } catch (Exception e) { - assure("test4 failed: " + e, false); + fail("test4 failed: " + e); } } // -------------------------------------------------------------------------------------------------------- void testConcurrentAccess(XResultSet _resultSet) { - log.println("testing Thread"); + System.out.println("testing Thread"); try { // final XRow _row = (XRow)UnoRuntime.queryInterface(XRow.class,_resultSet); @@ -389,7 +399,7 @@ public class RowSet extends ComplexTestCase for (int i = 0; i < numberOfThreads; ++i) { threads[i] = new Thread(new ResultSetMovementStress(createClone(), i)); - log.println("starting thread " + (i + 1) + " of " + (numberOfThreads)); + System.out.println("starting thread " + (i + 1) + " of " + (numberOfThreads)); threads[i].start(); } @@ -400,14 +410,14 @@ public class RowSet extends ComplexTestCase } catch (Exception e) { - assure("testConcurrentAccess failed: " + e, false); + fail("testConcurrentAccess failed: " + e); } } // -------------------------------------------------------------------------------------------------------- - public void testRowSetEvents() throws java.lang.Exception + @Test public void testRowSetEvents() throws java.lang.Exception { - log.println("testing RowSet Events"); + System.out.println("testing RowSet Events"); createTestCase(true); // first we create our RowSet object @@ -552,26 +562,26 @@ public class RowSet extends ComplexTestCase _evt.clearCalling(); _method.invoke(res, args); - log.println("testing events for " + _method.getName()); + System.out.println("testing events for " + _method.getName()); final int calling[] = _evt.getCalling(); int pos = 1; - assure("Callings are not in the correct order for APPROVE_CURSOR_MOVE ", + assertTrue("Callings are not in the correct order for APPROVE_CURSOR_MOVE ", (!_must[RowSetEventListener.APPROVE_CURSOR_MOVE] || calling[RowSetEventListener.APPROVE_CURSOR_MOVE] == -1) || calling[RowSetEventListener.APPROVE_CURSOR_MOVE] == pos++); - assure("Callings are not in the correct order for APPROVE_ROW_CHANGE", + assertTrue("Callings are not in the correct order for APPROVE_ROW_CHANGE", (!_must[RowSetEventListener.APPROVE_ROW_CHANGE] || calling[RowSetEventListener.APPROVE_ROW_CHANGE] == -1) || calling[RowSetEventListener.APPROVE_ROW_CHANGE] == pos++); - assure("Callings are not in the correct order for COLUMN_VALUE", + assertTrue("Callings are not in the correct order for COLUMN_VALUE", (!_must[RowSetEventListener.COLUMN_VALUE] || calling[RowSetEventListener.COLUMN_VALUE] == -1) || calling[RowSetEventListener.COLUMN_VALUE] == pos++); - assure("Callings are not in the correct order for CURSOR_MOVED", + assertTrue("Callings are not in the correct order for CURSOR_MOVED", (!_must[RowSetEventListener.CURSOR_MOVED] || calling[RowSetEventListener.CURSOR_MOVED] == -1) || calling[RowSetEventListener.CURSOR_MOVED] == pos++); - assure("Callings are not in the correct order for ROW_CHANGED", + assertTrue("Callings are not in the correct order for ROW_CHANGED", (!_must[RowSetEventListener.ROW_CHANGED] || calling[RowSetEventListener.ROW_CHANGED] == -1) || calling[RowSetEventListener.ROW_CHANGED] == pos++); - assure("Callings are not in the correct order for IS_MODIFIED", + assertTrue("Callings are not in the correct order for IS_MODIFIED", (!_must[RowSetEventListener.IS_MODIFIED] || calling[RowSetEventListener.IS_MODIFIED] == -1) || calling[RowSetEventListener.IS_MODIFIED] == pos++); - assure("Callings are not in the correct order for IS_NEW", + assertTrue("Callings are not in the correct order for IS_NEW", (!_must[RowSetEventListener.IS_NEW] || calling[RowSetEventListener.IS_NEW] == -1) || calling[RowSetEventListener.IS_NEW] == pos++); - assure("Callings are not in the correct order for ROW_COUNT", + assertTrue("Callings are not in the correct order for ROW_COUNT", (!_must[RowSetEventListener.ROW_COUNT] || calling[RowSetEventListener.ROW_COUNT] == -1) || calling[RowSetEventListener.ROW_COUNT] == pos++); - assure("Callings are not in the correct order for IS_ROW_COUNT_FINAL", + assertTrue("Callings are not in the correct order for IS_ROW_COUNT_FINAL", (!_must[RowSetEventListener.IS_ROW_COUNT_FINAL] || calling[RowSetEventListener.IS_ROW_COUNT_FINAL] == -1) || calling[RowSetEventListener.IS_ROW_COUNT_FINAL] == pos); _evt.clearCalling(); @@ -592,7 +602,7 @@ public class RowSet extends ComplexTestCase private int positionRandom() throws SQLException, UnknownPropertyException, WrappedTargetException { final int position = (new Random()).nextInt(currentRowCount() - 2) + 2; - assure("sub task failed: could not position to row no. " + (Integer.valueOf(position)).toString(), + assertTrue("sub task failed: could not position to row no. " + (Integer.valueOf(position)).toString(), m_resultSet.absolute(position)); return m_resultSet.getRow(); } @@ -614,15 +624,15 @@ public class RowSet extends ComplexTestCase final int positionAfter = m_resultSet.getRow(); final int rowCountAfter = currentRowCount(); - assure("position changed during |deleteRow| (it should not)", positionAfter == positionBefore); - assure("row count changed with a |deleteRow| (it should not)", rowCountBefore == rowCountAfter); - assure("RowSet does not report the current row as deleted after |deleteRow|", m_resultSet.rowDeleted()); + assertTrue("position changed during |deleteRow| (it should not)", positionAfter == positionBefore); + assertTrue("row count changed with a |deleteRow| (it should not)", rowCountBefore == rowCountAfter); + assertTrue("RowSet does not report the current row as deleted after |deleteRow|", m_resultSet.rowDeleted()); return positionBefore; } // -------------------------------------------------------------------------------------------------------- - public void testDeleteBehavior() throws Exception + @Test public void testDeleteBehavior() throws Exception { createTestCase(true); @@ -644,40 +654,40 @@ public class RowSet extends ComplexTestCase { caughtException = true; } - assure("asking for the bookmark of a deleted row should throw an exception", caughtException); + assertTrue("asking for the bookmark of a deleted row should throw an exception", caughtException); // ..................................................................................................... // isXXX methods should return |false| on a deleted row - assure("one of the isFoo failed after |deleteRow|", !m_resultSet.isBeforeFirst() && !m_resultSet.isAfterLast() && !m_resultSet.isFirst() && !m_resultSet.isLast()); + assertTrue("one of the isFoo failed after |deleteRow|", !m_resultSet.isBeforeFirst() && !m_resultSet.isAfterLast() && !m_resultSet.isFirst() && !m_resultSet.isLast()); // note that we can assume that isFirst / isLast also return |false|, since deleteRandom did // not position on the first or last record, but inbetween // ..................................................................................................... // check if moving away from this row in either direction yields the expected results - assure("|previous| after |deleteRow| failed", m_resultSet.previous()); + assertTrue("|previous| after |deleteRow| failed", m_resultSet.previous()); final int positionPrevious = m_resultSet.getRow(); - assure("position after |previous| after |deleteRow| is not as expected", positionPrevious == deletedRow - 1); + assertTrue("position after |previous| after |deleteRow| is not as expected", positionPrevious == deletedRow - 1); deletedRow = deleteRandom(); - assure("|next| after |deleteRow| failed", m_resultSet.next()); + assertTrue("|next| after |deleteRow| failed", m_resultSet.next()); final int positionAfter = m_resultSet.getRow(); - assure("position after |next| after |deleteRow| is not as expected", positionAfter == deletedRow); + assertTrue("position after |next| after |deleteRow| is not as expected", positionAfter == deletedRow); // since the deleted record "vanishs" as soon as the cursor is moved away from it, the absolute position does // not change with a |next| call here // ..................................................................................................... // check if the deleted rows really vanished after moving away from them - assure("row count did not change as expected after two deletions", initialRowCount - 2 == currentRowCount()); + assertTrue("row count did not change as expected after two deletions", initialRowCount - 2 == currentRowCount()); // ..................................................................................................... // check if the deleted row vanishes after moving to the insertion row final int rowCountBefore = currentRowCount(); final int deletedPos = deleteRandom(); m_resultSetUpdate.moveToInsertRow(); - assure("moving to the insertion row immediately after |deleteRow| does not adjust the row count", rowCountBefore == currentRowCount() + 1); + assertTrue("moving to the insertion row immediately after |deleteRow| does not adjust the row count", rowCountBefore == currentRowCount() + 1); m_resultSetUpdate.moveToCurrentRow(); - assure("|moveToCurrentRow| after |deleteRow| + |moveToInsertRow| results in unexpected position", + assertTrue("|moveToCurrentRow| after |deleteRow| + |moveToInsertRow| results in unexpected position", (m_resultSet.getRow() == deletedPos) && !m_resultSet.rowDeleted()); // the same, but this time with deleting the first row (which is not covered by deleteRandom) @@ -685,7 +695,7 @@ public class RowSet extends ComplexTestCase m_resultSetUpdate.deleteRow(); m_resultSetUpdate.moveToInsertRow(); m_resultSetUpdate.moveToCurrentRow(); - assure("|last| + |deleteRow| + |moveToInsertRow| + |moveToCurrentRow| results in wrong state", m_resultSet.isAfterLast()); + assertTrue("|last| + |deleteRow| + |moveToInsertRow| + |moveToCurrentRow| results in wrong state", m_resultSet.isAfterLast()); // ..................................................................................................... // check if deleting a deleted row fails as expected @@ -699,7 +709,7 @@ public class RowSet extends ComplexTestCase { caughtException = true; } - assure("deleting a deleted row succeeded - it shouldn't", caughtException); + assertTrue("deleting a deleted row succeeded - it shouldn't", caughtException); // ..................................................................................................... // check if deleteRows fails if it contains the bookmark of a previously-deleted row @@ -713,7 +723,7 @@ public class RowSet extends ComplexTestCase { firstBookmark, deleteBookmark }); - assure("XDeleteRows::deleteRows with the bookmark of an already-deleted row failed", + assertTrue("XDeleteRows::deleteRows with the bookmark of an already-deleted row failed", (deleteSuccess.length == 2) && (deleteSuccess[0] != 0) && (deleteSuccess[1] == 0)); // ..................................................................................................... @@ -728,12 +738,12 @@ public class RowSet extends ComplexTestCase { caughtException = true; } - assure("refreshing a deleted row succeeded - it shouldn't", caughtException); + assertTrue("refreshing a deleted row succeeded - it shouldn't", caughtException); // ..................................................................................................... // rowUpdated/rowDeleted deleteRandom(); - assure("rowDeleted and/or rowUpdated are wrong on a deleted row", !m_resultSet.rowUpdated() && !m_resultSet.rowInserted()); + assertTrue("rowDeleted and/or rowUpdated are wrong on a deleted row", !m_resultSet.rowUpdated() && !m_resultSet.rowInserted()); // ..................................................................................................... // updating values in a deleted row should fail @@ -748,7 +758,7 @@ public class RowSet extends ComplexTestCase { caughtException = true; } - assure("updating values in a deleted row should not succeed", caughtException); + assertTrue("updating values in a deleted row should not succeed", caughtException); } // -------------------------------------------------------------------------------------------------------- @@ -756,7 +766,7 @@ public class RowSet extends ComplexTestCase * on a clone of the RowSet */ @SuppressWarnings("empty-statement") - public void testCloneMovesPlusDeletions() throws SQLException, UnknownPropertyException, WrappedTargetException + @Test public void testCloneMovesPlusDeletions() throws SQLException, UnknownPropertyException, WrappedTargetException { createTestCase(true); // ensure that all records are known @@ -773,20 +783,20 @@ public class RowSet extends ComplexTestCase final int clonePosition = clone.getRow(); m_resultSetUpdate.deleteRow(); - assure("clone doesn't know that its current row has been deleted via the RowSet", clone.rowDeleted()); - assure("clone's position changed somehow during deletion", clonePosition == clone.getRow()); + assertTrue("clone doesn't know that its current row has been deleted via the RowSet", clone.rowDeleted()); + assertTrue("clone's position changed somehow during deletion", clonePosition == clone.getRow()); // ..................................................................................................... // move the row set away from the deleted record. This should still not touch the state of the clone m_resultSet.previous(); - assure("clone doesn't know (anymore) that its current row has been deleted via the RowSet", clone.rowDeleted()); - assure("clone's position changed somehow during deletion and RowSet-movement", clonePosition == clone.getRow()); + assertTrue("clone doesn't know (anymore) that its current row has been deleted via the RowSet", clone.rowDeleted()); + assertTrue("clone's position changed somehow during deletion and RowSet-movement", clonePosition == clone.getRow()); // ..................................................................................................... // move the clone away from the deleted record clone.next(); - assure("clone still assumes that its row is deleted - but we already moved it", !clone.rowDeleted()); + assertTrue("clone still assumes that its row is deleted - but we already moved it", !clone.rowDeleted()); // ..................................................................................................... // check whether deleting the extremes (first / last) work @@ -794,37 +804,37 @@ public class RowSet extends ComplexTestCase cloneRowLocate.moveToBookmark(m_rowLocate.getBookmark()); m_resultSetUpdate.deleteRow(); clone.previous(); - assure("deleting the first record left the clone in a strange state (after |previous|)", clone.isBeforeFirst()); + assertTrue("deleting the first record left the clone in a strange state (after |previous|)", clone.isBeforeFirst()); clone.next(); - assure("deleting the first record left the clone in a strange state (after |previous| + |next|)", clone.isFirst()); + assertTrue("deleting the first record left the clone in a strange state (after |previous| + |next|)", clone.isFirst()); m_resultSet.last(); cloneRowLocate.moveToBookmark(m_rowLocate.getBookmark()); m_resultSetUpdate.deleteRow(); clone.next(); - assure("deleting the last record left the clone in a strange state (after |next|)", clone.isAfterLast()); + assertTrue("deleting the last record left the clone in a strange state (after |next|)", clone.isAfterLast()); clone.previous(); - assure("deleting the first record left the clone in a strange state (after |next| + |previous|)", clone.isLast()); + assertTrue("deleting the first record left the clone in a strange state (after |next| + |previous|)", clone.isLast()); // ..................................................................................................... // check whether movements of the clone interfere with movements of the RowSet, if the latter is on a deleted row final int positionBefore = positionRandom(); m_resultSetUpdate.deleteRow(); - assure("|deleteRow|, but no |rowDeleted| (this should have been found much earlier!)", m_resultSet.rowDeleted()); + assertTrue("|deleteRow|, but no |rowDeleted| (this should have been found much earlier!)", m_resultSet.rowDeleted()); clone.beforeFirst(); while (clone.next()); - assure("row set forgot that the current row is deleted", m_resultSet.rowDeleted()); + assertTrue("row set forgot that the current row is deleted", m_resultSet.rowDeleted()); - assure("moving to the next record after |deleteRow| and clone moves failed", m_resultSet.next()); - assure("wrong position after |deleteRow| and clone movement", !m_resultSet.isAfterLast() && !m_resultSet.isBeforeFirst()); - assure("wrong absolute position after |deleteRow| and clone movement", m_resultSet.getRow() == positionBefore); + assertTrue("moving to the next record after |deleteRow| and clone moves failed", m_resultSet.next()); + assertTrue("wrong position after |deleteRow| and clone movement", !m_resultSet.isAfterLast() && !m_resultSet.isBeforeFirst()); + assertTrue("wrong absolute position after |deleteRow| and clone movement", m_resultSet.getRow() == positionBefore); } // -------------------------------------------------------------------------------------------------------- /** checks whether insertions on the main RowSet properly interfere (or don't interfere) with the movement * on a clone of the RowSet */ - public void testCloneMovesPlusInsertions() throws SQLException, UnknownPropertyException, WrappedTargetException, PropertyVetoException, com.sun.star.lang.IllegalArgumentException + @Test public void testCloneMovesPlusInsertions() throws SQLException, UnknownPropertyException, WrappedTargetException, PropertyVetoException, com.sun.star.lang.IllegalArgumentException { createTestCase(true); // ensure that all records are known @@ -844,7 +854,7 @@ public class RowSet extends ComplexTestCase final int rowValue1 = m_row.getInt(1); final int rowPos = m_resultSet.getRow(); final int rowValue2 = m_row.getInt(1); - assure("repeated query for the same column value delivers different values (" + rowValue1 + " and " + rowValue2 + ") on row: " + rowPos, + assertTrue("repeated query for the same column value delivers different values (" + rowValue1 + " and " + rowValue2 + ") on row: " + rowPos, rowValue1 == rowValue2); testPosition(clone, cloneRow, 1, "mixed clone/rowset move: clone check"); @@ -876,7 +886,7 @@ public class RowSet extends ComplexTestCase } catch (Exception e) { - assure("testing the parameters of a table failed" + e.getMessage(), false); + fail("testing the parameters of a table failed" + e.getMessage()); } } // -------------------------------------------------------------------------------------------------------- @@ -893,7 +903,7 @@ public class RowSet extends ComplexTestCase } catch (Exception e) { - assure("testing the parameters of a table failed" + e.getMessage(), false); + fail("testing the parameters of a table failed" + e.getMessage()); } } @@ -904,7 +914,7 @@ public class RowSet extends ComplexTestCase final int expected = _paramNames.length; final int found = params != null ? params.getCount() : 0; - assure("wrong number of parameters (expected: " + expected + ", found: " + found + ") in " + _context, + assertTrue("wrong number of parameters (expected: " + expected + ", found: " + found + ") in " + _context, found == expected); if (found == 0) @@ -918,7 +928,7 @@ public class RowSet extends ComplexTestCase final String expectedName = _paramNames[i]; final String foundName = (String) parameter.getPropertyValue("Name"); - assure("wrong parameter name (expected: " + expectedName + ", found: " + foundName + ") in" + _context, + assertTrue("wrong parameter name (expected: " + expectedName + ", found: " + foundName + ") in" + _context, expectedName.equals(foundName)); } } @@ -939,7 +949,7 @@ public class RowSet extends ComplexTestCase } catch (Exception e) { - assure("testing the parameters of a parametrized query failed" + e.getMessage(), false); + fail("testing the parameters of a parametrized query failed" + e.getMessage()); } } @@ -958,7 +968,7 @@ public class RowSet extends ComplexTestCase XPropertySet firstParam = UnoRuntime.queryInterface( XPropertySet.class, params.getByIndex( 0 ) ); Object firstParamValue = firstParam.getPropertyValue("Value"); - assure("XParameters and the parameters container do not properly interact", + assertTrue("XParameters and the parameters container do not properly interact", "Apples".equals(firstParamValue)); // let's see whether this also survices an execute of the row set @@ -972,12 +982,12 @@ public class RowSet extends ComplexTestCase firstParam = UnoRuntime.queryInterface( XPropertySet.class, params.getByIndex( 0 ) ); } firstParamValue = firstParam.getPropertyValue("Value"); - assure("XParameters and the parameters container do not properly interact, after the row set has been executed", + assertTrue("XParameters and the parameters container do not properly interact, after the row set has been executed", "Oranges".equals(firstParamValue)); } catch (Exception e) { - assure("could not test the relationship between XParameters and XParametersSupplier" + e.getMessage(), false); + fail("could not test the relationship between XParameters and XParametersSupplier" + e.getMessage()); } } @@ -1002,14 +1012,14 @@ public class RowSet extends ComplexTestCase } catch (Exception e) { - assure("testing the parameters within a WHERE clause failed" + e.getMessage(), false); + fail("testing the parameters within a WHERE clause failed" + e.getMessage()); } } // -------------------------------------------------------------------------------------------------------- /** checks the XParametersSupplier functionality of a RowSet */ - public void testParameters() + @Test public void testParameters() { createTestCase(false); // use an own RowSet instance, not the one which is also used for the other cases 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 = diff --git a/dbaccess/qa/complex/dbaccess/TestCase.java b/dbaccess/qa/complex/dbaccess/TestCase.java index b8dae3f6f350..ba899a114205 100644 --- a/dbaccess/qa/complex/dbaccess/TestCase.java +++ b/dbaccess/qa/complex/dbaccess/TestCase.java @@ -31,7 +31,7 @@ import com.sun.star.beans.XPropertySet; import com.sun.star.frame.XComponentLoader; import com.sun.star.frame.XModel; import com.sun.star.lang.XMultiServiceFactory; -import com.sun.star.uno.Exception; +// import com.sun.star.uno.Exception; import com.sun.star.uno.UnoRuntime; import com.sun.star.uno.XComponentContext; import helper.FileTools; @@ -40,13 +40,24 @@ import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; -public abstract class TestCase extends complexlib.ComplexTestCase +// ---------- 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 abstract class TestCase { // -------------------------------------------------------------------------------------------------------- - protected final XMultiServiceFactory getORB() - { - return (XMultiServiceFactory)param.getMSF(); - } +// protected final XMultiServiceFactory getORB() +// { +// return (XMultiServiceFactory)param.getMSF(); +// } // -------------------------------------------------------------------------------------------------------- protected final XComponentContext getComponentContext() @@ -54,13 +65,13 @@ public abstract class TestCase extends complexlib.ComplexTestCase XComponentContext context = null; try { - final XPropertySet orbProps = UnoRuntime.queryInterface( XPropertySet.class, getORB() ); + final XPropertySet orbProps = UnoRuntime.queryInterface( XPropertySet.class, getMSF() ); context = UnoRuntime.queryInterface( XComponentContext.class, orbProps.getPropertyValue( "DefaultContext" ) ); } catch ( Exception ex ) { - failed( "could not retrieve the ComponentContext" ); + fail( "could not retrieve the ComponentContext" ); } return context; } @@ -83,9 +94,11 @@ public abstract class TestCase extends complexlib.ComplexTestCase */ protected final String createTempFileURL() throws IOException { - final File documentFile = java.io.File.createTempFile( getTestObjectName(), ".odb" ).getAbsoluteFile(); + final File documentFile = java.io.File.createTempFile( "dbaccess_test", ".odb" ).getAbsoluteFile(); if ( documentFile.exists() ) + { documentFile.delete(); + } return FileHelper.getOOoCompatibleFileURL( documentFile.toURI().toURL().toString() ); } @@ -111,16 +124,40 @@ public abstract class TestCase extends complexlib.ComplexTestCase protected final XModel loadDocument( final String _docURL ) throws Exception { final XComponentLoader loader = UnoRuntime.queryInterface( XComponentLoader.class, - getORB().createInstance( "com.sun.star.frame.Desktop" ) ); + getMSF().createInstance( "com.sun.star.frame.Desktop" ) ); return UnoRuntime.queryInterface( XModel.class, loader.loadComponentFromURL( _docURL, "_blank", 0, new PropertyValue[] {} ) ); } // -------------------------------------------------------------------------------------------------------- - protected void assureException( Object _object, Class _unoInterfaceClass, String _methodName, Object[] _methodArgs, - Class _expectedExceptionClass ) +// protected void assureException( Object _object, Class _unoInterfaceClass, String _methodName, Object[] _methodArgs, +// Class _expectedExceptionClass ) +// { +// assureException( UnoRuntime.queryInterface( _unoInterfaceClass, _object ), _methodName, +// _methodArgs, _expectedExceptionClass ); +// } + + + + protected XMultiServiceFactory getMSF() + { + final XMultiServiceFactory xMSF1 = UnoRuntime.queryInterface(XMultiServiceFactory.class, connection.getComponentContext().getServiceManager()); + return xMSF1; + } + + // setup and close connections + @BeforeClass public static void setUpConnection() throws Exception { + System.out.println("setUpConnection()"); + connection.setUp(); + } + + @AfterClass public static void tearDownConnection() + throws InterruptedException, com.sun.star.uno.Exception { - assureException( UnoRuntime.queryInterface( _unoInterfaceClass, _object ), _methodName, - _methodArgs, _expectedExceptionClass ); + System.out.println("tearDownConnection()"); + connection.tearDown(); } + + private static final OfficeConnection connection = new OfficeConnection(); + } diff --git a/dbaccess/qa/complex/dbaccess/UISettings.java b/dbaccess/qa/complex/dbaccess/UISettings.java index fc772b158f5f..8733f000f644 100644 --- a/dbaccess/qa/complex/dbaccess/UISettings.java +++ b/dbaccess/qa/complex/dbaccess/UISettings.java @@ -32,37 +32,45 @@ import com.sun.star.beans.XPropertySet; import com.sun.star.container.XNameAccess; import com.sun.star.form.runtime.XFormController; import com.sun.star.frame.XController; -import com.sun.star.frame.XModel; import com.sun.star.sdb.application.DatabaseObject; -import com.sun.star.sdb.application.XDatabaseDocumentUI; import com.sun.star.uno.UnoRuntime; import com.sun.star.util.XCloseable; import connectivity.tools.CRMDatabase; +// ---------- 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 UISettings extends TestCase { // -------------------------------------------------------------------------------------------------------- - public String[] getTestMethodNames() - { - return new String[] { - "checkTableFormattingPersistence", - "checkTransparentQueryColumnSettings" - }; - } - - // -------------------------------------------------------------------------------------------------------- - public String getTestObjectName() - { - return "UISettings"; - } +// public String[] getTestMethodNames() +// { +// return new String[] { +// "checkTableFormattingPersistence", +// "checkTransparentQueryColumnSettings" +// }; +// } +// +// // -------------------------------------------------------------------------------------------------------- +// public String getTestObjectName() +// { +// return "UISettings"; +// } // -------------------------------------------------------------------------------------------------------- /** verifies that aliases for inner queries work as expected */ - public void checkTableFormattingPersistence() throws java.lang.Exception + @Test public void checkTableFormattingPersistence() throws java.lang.Exception { // create, load, and connect a DB doc - CRMDatabase database = new CRMDatabase( getORB(), true ); + CRMDatabase database = new CRMDatabase( getMSF(), true ); // display a table XFormController tableViewController = UnoRuntime.queryInterface( XFormController.class, @@ -89,7 +97,7 @@ public class UISettings extends TestCase // stay alive, and subsequent requests to load the doc will just reuse it, without really loading it. docURL = copyToTempFile( docURL ); loadDocument( docURL ); - database = new CRMDatabase( getORB(), docURL ); + database = new CRMDatabase( getMSF(), docURL ); // display the table, again tableViewController = UnoRuntime.queryInterface( XFormController.class, @@ -98,9 +106,9 @@ public class UISettings extends TestCase tableViewController.getCurrentControl().getModel() ); // verify the properties - assureEquals( "wrong font name", "Andale Sans UI", (String)tableControlModel.getPropertyValue( "FontName" ) ); - assureEquals( "wrong font height", (float)20, ((Float)tableControlModel.getPropertyValue( "FontHeight" )).floatValue() ); - assureEquals( "wrong font slant", FontSlant.ITALIC, (FontSlant)tableControlModel.getPropertyValue( "FontSlant" ) ); + assertEquals( "wrong font name", "Andale Sans UI", (String)tableControlModel.getPropertyValue( "FontName" ) ); + assertEquals( "wrong font height", (float)20, ((Float)tableControlModel.getPropertyValue( "FontHeight" )).floatValue() ); + assertEquals( "wrong font slant", FontSlant.ITALIC, (FontSlant)tableControlModel.getPropertyValue( "FontSlant" ) ); // close the doc database.saveAndClose(); @@ -111,10 +119,10 @@ public class UISettings extends TestCase * settings * @throws java.lang.Exception */ - public void checkTransparentQueryColumnSettings() throws java.lang.Exception + @Test public void checkTransparentQueryColumnSettings() throws java.lang.Exception { // create, load, and connect a DB doc - CRMDatabase database = new CRMDatabase( getORB(), true ); + CRMDatabase database = new CRMDatabase( getMSF(), true ); // display a table XController tableView = database.loadSubComponent( DatabaseObject.TABLE, "customers" ); @@ -125,7 +133,7 @@ public class UISettings extends TestCase // change the formatting of a table column XPropertySet idColumn = UnoRuntime.queryInterface( XPropertySet.class, tableControlModel.getByName( "ID" ) ); - assure( "precondition not met: column already centered", + assertTrue( "precondition not met: column already centered", ((Short)idColumn.getPropertyValue( "Align" )).shortValue() != TextAlign.CENTER ); idColumn.setPropertyValue( "Align", TextAlign.CENTER ); @@ -143,7 +151,7 @@ public class UISettings extends TestCase queryViewController.getCurrentControl().getModel() ); idColumn = UnoRuntime.queryInterface( XPropertySet.class, tableControlModel.getByName( "ID" ) ); - assure( "table column alignment was not propagated to the query column", + assertTrue( "table column alignment was not propagated to the query column", ((Short)idColumn.getPropertyValue( "Align" )).shortValue() == TextAlign.CENTER ); // save close the database document diff --git a/dbaccess/qa/complex/dbaccess/makefile.mk b/dbaccess/qa/complex/dbaccess/makefile.mk index 56a24c0292fc..4a3e0426fe1d 100755 --- a/dbaccess/qa/complex/dbaccess/makefile.mk +++ b/dbaccess/qa/complex/dbaccess/makefile.mk @@ -25,54 +25,109 @@ # #************************************************************************* -PRJ = ..$/..$/.. -TARGET = DbaComplexTests -PRJNAME = $(TARGET) -PACKAGE = complex$/dbaccess - -# --- Settings ----------------------------------------------------- -.INCLUDE: settings.mk - -.IF "$(SOLAR_JAVA)" == "" -all: - @echo "Java not available. Build skipped" - -.INCLUDE : target.mk +.IF "$(OOO_SUBSEQUENT_TESTS)" == "" +nothing .PHONY: .ELSE -#----- compile .java files ----------------------------------------- - -JARFILES = ridl.jar unoil.jar jurt.jar juh.jar java_uno.jar OOoRunner.jar ConnectivityTools.jar -JAVAFILES := $(shell @$(FIND) ./*.java) -JAVACLASSFILES = $(foreach,i,$(JAVAFILES) $(CLASSDIR)$/$(PACKAGE)$/$(i:b).class) - -#----- make a jar from compiled files ------------------------------ - -MAXLINELENGTH = 100000 - -JARCLASSDIRS = $(PACKAGE) -JARTARGET = $(TARGET).jar -JARCOMPRESS = TRUE - -RUNNER_ARGS = -cp "$(CLASSPATH)$(PATH_SEPERATOR)$(SOLARBINDIR)$/OOoRunner.jar" org.openoffice.Runner -TestBase java_complex +PRJ = ../../.. +PRJNAME = dbaccess +TARGET = qa_complex_dbaccess + +.IF "$(OOO_JUNIT_JAR)" != "" +PACKAGE = complex/dbaccess + +# here store only Files which contain a @Test +JAVATESTFILES = \ + ApplicationController.java \ + Beamer.java \ + CRMBasedTestCase.java \ + CopyTableWizard.java \ + DataSource.java \ + DatabaseDocument.java \ + Parser.java \ + PropertyBag.java \ + Query.java \ + QueryInQuery.java \ + RowSet.java \ + SingleSelectQueryComposer.java \ + UISettings.java \ + TestCase.java + +# put here all other files +JAVAFILES = $(JAVATESTFILES) \ + CopyTableInterActionHandler.java \ + DatabaseApplication.java \ + FileHelper.java \ + RowSetEventListener.java + + +JARFILES = OOoRunner.jar ridl.jar test.jar unoil.jar ConnectivityTools.jar +EXTRAJARFILES = $(OOO_JUNIT_JAR) + +# Sample how to debug +# JAVAIFLAGS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,address=9003,suspend=y + +.END -RUNNER_CALL = $(AUGMENT_LIBRARY_PATH) java - -# --- Targets ------------------------------------------------------ - -.IF "$(depend)" == "" -ALL : ALLTAR -.ELSE -ALL: ALLDEP -.ENDIF - -.INCLUDE : target.mk +.INCLUDE: settings.mk +.INCLUDE: target.mk +.INCLUDE: installationtest.mk +ALLTAR : javatest -run: $(CLASSDIR)$/$(JARTARGET) - +$(RUNNER_CALL) $(RUNNER_ARGS) -sce dbaccess.sce +.END -run_%: $(CLASSDIR)$/$(JARTARGET) - +$(RUNNER_CALL) $(RUNNER_ARGS) -o complex.dbaccess.$(@:s/run_//) -.ENDIF # "$(SOLAR_JAVA)" == "" +# +# +# PRJ = ..$/..$/.. +# TARGET = DbaComplexTests +# PRJNAME = $(TARGET) +# PACKAGE = complex$/dbaccess +# +# # --- Settings ----------------------------------------------------- +# .INCLUDE: settings.mk +# +# .IF "$(SOLAR_JAVA)" == "" +# all: +# @echo "Java not available. Build skipped" +# +# .INCLUDE : target.mk +# .ELSE +# +# #----- compile .java files ----------------------------------------- +# +# JARFILES = ridl.jar unoil.jar jurt.jar juh.jar java_uno.jar OOoRunner.jar ConnectivityTools.jar +# JAVAFILES := $(shell @$(FIND) ./*.java) +# JAVACLASSFILES = $(foreach,i,$(JAVAFILES) $(CLASSDIR)$/$(PACKAGE)$/$(i:b).class) +# +# #----- make a jar from compiled files ------------------------------ +# +# MAXLINELENGTH = 100000 +# +# JARCLASSDIRS = $(PACKAGE) +# JARTARGET = $(TARGET).jar +# JARCOMPRESS = TRUE +# +# RUNNER_ARGS = -cp "$(CLASSPATH)$(PATH_SEPERATOR)$(SOLARBINDIR)$/OOoRunner.jar" org.openoffice.Runner -TestBase java_complex +# +# RUNNER_CALL = $(AUGMENT_LIBRARY_PATH) java +# +# # --- Targets ------------------------------------------------------ +# +# .IF "$(depend)" == "" +# ALL : ALLTAR +# .ELSE +# ALL: ALLDEP +# .ENDIF +# +# .INCLUDE : target.mk +# +# +# run: $(CLASSDIR)$/$(JARTARGET) +# +$(RUNNER_CALL) $(RUNNER_ARGS) -sce dbaccess.sce +# +# run_%: $(CLASSDIR)$/$(JARTARGET) +# +$(RUNNER_CALL) $(RUNNER_ARGS) -o complex.dbaccess.$(@:s/run_//) +# +# .ENDIF # "$(SOLAR_JAVA)" == "" |