Tag: cws_dev300_odbmacros3
User: fs      
Date: 2008-07-24 05:37:59+0000
Modified:
   dba/dbaccess/qa/complex/dbaccess/DatabaseDocument.java

Log:
 #i76128# some flesh in testLoadable (not yet finished)

File Changes:

Directory: /dba/dbaccess/qa/complex/dbaccess/
=============================================

File [changed]: DatabaseDocument.java
Url: 
http://dba.openoffice.org/source/browse/dba/dbaccess/qa/complex/dbaccess/DatabaseDocument.java?r1=1.1.2.1&r2=1.1.2.2
Delta lines:  +113 -25
----------------------
--- DatabaseDocument.java       2008-07-23 13:15:02+0000        1.1.2.1
+++ DatabaseDocument.java       2008-07-24 05:37:56+0000        1.1.2.2
@@ -7,7 +7,7 @@
  * OpenOffice.org - a multi-platform office productivity suite
  *
  * $RCSfile: DatabaseDocument.java,v $
- * $Revision: 1.1.2.1 $
+ * $Revision: 1.1.2.2 $
  *
  * This file is part of OpenOffice.org.
  *
@@ -30,12 +30,24 @@
 package complex.dbaccess;
 
 import com.sun.star.lang.XMultiServiceFactory;
+import com.sun.star.uno.Exception;
 import com.sun.star.uno.UnoRuntime;
 import com.sun.star.frame.XStorable;
 import com.sun.star.frame.FrameSearchFlag;
 import com.sun.star.beans.PropertyValue;
+import com.sun.star.beans.XPropertySet;
+import com.sun.star.document.XEventsSupplier;
+import com.sun.star.document.XScriptInvocationContext;
 import com.sun.star.lang.XComponent;
 import com.sun.star.frame.XComponentLoader;
+import com.sun.star.frame.XModel;
+import com.sun.star.frame.XModel2;
+import com.sun.star.frame.XTitle;
+import com.sun.star.lang.NotInitializedException;
+import com.sun.star.script.provider.XScriptProviderSupplier;
+import com.sun.star.sdb.XFormDocumentsSupplier;
+import com.sun.star.sdb.XOfficeDatabaseDocument;
+import com.sun.star.sdb.XReportDocumentsSupplier;
 import com.sun.star.util.XCloseable;
 import connectivity.tools.*;
 
@@ -45,7 +57,8 @@
     public String[] getTestMethodNames() {
         return new String[]
         {
-            "testStorable"
+            "testLoadable"
+            //"testStorable"
         };
     }
 
@@ -57,16 +70,16 @@
     // 
--------------------------------------------------------------------------------------------------------
     protected void createTestCase()
     {
-        try
-        {
+//        try
+//        {
             super.createTestCase();
-        }
-        catch( Exception e )
-        {
-            System.err.println( "could not create the test case, error 
message:\n" + e.getMessage() );
-            e.printStackTrace( System.err );
-            assure( "failed to created the test case", false );
-        }
+//        }
+//        catch( Exception e )
+//        {
+//            System.err.println( "could not create the test case, error 
message:\n" + e.getMessage() );
+//            e.printStackTrace( System.err );
+//            assure( "failed to created the test case", false );
+//        }
     }
 
     // 
--------------------------------------------------------------------------------------------------------
@@ -76,25 +89,100 @@
     }
 
     // 
--------------------------------------------------------------------------------------------------------
-    public void testStorable()
-    {
-        createTestCase();
-
-        try
+    public void testStorable() throws Exception
         {
                        Object object = 
getFactory().createInstance("com.sun.star.frame.Desktop");
                        XComponentLoader xComponentLoader = 
(XComponentLoader)UnoRuntime.queryInterface(XComponentLoader.class, object);
-                       XComponent xComponent = 
xComponentLoader.loadComponentFromURL( 
m_database.getDatabase().getDocumentURL(), "_blank",FrameSearchFlag.ALL, new 
PropertyValue[0]);
+        XComponent xComponent = xComponentLoader.loadComponentFromURL( 
m_database.getDatabase().getDocumentURL(), "_blank", FrameSearchFlag.ALL, new 
PropertyValue[0] );
                        m_database.close();
+
                        XStorable storable = 
(XStorable)UnoRuntime.queryInterface(XStorable.class,xComponent);
                        storable.store();
+
             XCloseable close = 
(XCloseable)UnoRuntime.queryInterface(XCloseable.class,xComponent);
             close.close(true);
         }
-        catch ( AssureException e ) { throw e; }
-        catch ( Exception e )
+
+    // 
--------------------------------------------------------------------------------------------------------
+    private class UnoMethodDescriptor
+    {
+        public Class    unoInterfaceClass = null;
+        public String   methodName = null;
+
+        public UnoMethodDescriptor( Class _class, String _method )
+        {
+            unoInterfaceClass = _class;
+            methodName = _method;
+        }
+    }
+
+    // 
--------------------------------------------------------------------------------------------------------
+    public void testLoadable() throws Exception
+    {
+        XModel databaseDoc = (XModel)UnoRuntime.queryInterface( XModel.class,
+            getORB().createInstance( "com.sun.star.sdb.OfficeDatabaseDocument" 
) );
+        XStorable storeDoc = (XStorable)UnoRuntime.queryInterface( 
XStorable.class,
+            databaseDoc );
+
+        // things you cannot do with an uninitialized document:
+        UnoMethodDescriptor[] unsupportedMethods = new UnoMethodDescriptor[] {
+            new UnoMethodDescriptor( XStorable.class, "store" ),
+            new UnoMethodDescriptor( XFormDocumentsSupplier.class, 
"getFormDocuments" ),
+            new UnoMethodDescriptor( XReportDocumentsSupplier.class, 
"getReportDocuments" ),
+            new UnoMethodDescriptor( XScriptInvocationContext.class, 
"getScriptContainer" ),
+            new UnoMethodDescriptor( XScriptProviderSupplier.class, 
"getScriptProvider" ),
+            new UnoMethodDescriptor( XEventsSupplier.class, "getEvents" ),
+            new UnoMethodDescriptor( XTitle.class, "getTitle" ),
+            new UnoMethodDescriptor( XModel2.class, "getControllers" )
+            // (there's much more than this, but we cannot list all methods 
here, can we ...)
+        };
+
+        for ( int i=0; i<unsupportedMethods.length; ++i)
+        {
+            verifyExpectedException( databaseDoc, 
unsupportedMethods[i].unoInterfaceClass,
+                unsupportedMethods[i].methodName, new Object[]{}, 
NotInitializedException.class );
+        }
+
+        // however, you can ask the document for its URL and location
+        String location = storeDoc.getLocation();
+        String url = databaseDoc.getURL();
+        // 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, "" );
+
+        // and, you should be able to set properties at the data source
+        XOfficeDatabaseDocument dataSourceAccess = 
(XOfficeDatabaseDocument)UnoRuntime.queryInterface(
+            XOfficeDatabaseDocument.class, databaseDoc );
+        XPropertySet dsProperties = (XPropertySet)UnoRuntime.queryInterface(
+            XPropertySet.class, dataSourceAccess.getDataSource() );
+        dsProperties.setPropertyValue( "URL", "sdbc:embedded:hsqldb" );
+
+        // there's three methods how you can initialize a database document
+        // 1. XLoadable::initNew
+        // 2. XLoadable::load
+        // 3. XStorable::storeAsURL
+        //      (this is for compatibility reasons, to not break existing code)
+
+        // Let's check 3. first
+        String documentURL = null;
+        try
+        {
+            documentURL = java.io.File.createTempFile(
+                getTestObjectName(), ".oxs" 
).getAbsoluteFile().toURL().toString();
+            storeDoc.storeAsURL( documentURL, new PropertyValue[] {} );
+        }
+        catch( java.lang.Exception e )
+        {
+            assure( "could not store the document", false );
+        }
+        // now that the document is stored, ...
+        // ... its URL should be correct
+        assureEquals( "wrong URL after storing the document", documentURL, 
databaseDoc.getURL() );
+        // ... it should be initialized, i.e. we should be able to call all 
the methods from above
+        for ( int i=0; i<unsupportedMethods.length; ++i)
         {
-            assure( "caught an unexpected exception: " + e.getMessage(), false 
);
+            verifyExpectedException( databaseDoc, 
unsupportedMethods[i].unoInterfaceClass,
+                unsupportedMethods[i].methodName, new Object[]{}, null );
         }
     }
 }




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to