xref: /trunk/main/connectivity/qa/complex/connectivity/HsqlDriverTest.java (revision 3309286857f19787ae62bd793a98b5af4edd2ad3)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 package complex.connectivity;
24 
25 import complex.connectivity.hsqldb.TestCacheSize;
26 import com.sun.star.frame.XModel;
27 import com.sun.star.frame.XStorable;
28 
29 import com.sun.star.lang.*;
30 import com.sun.star.document.XDocumentSubStorageSupplier;
31 
32 
33 import org.hsqldb.lib.StopWatch;
34 import com.sun.star.uno.UnoRuntime;
35 import com.sun.star.beans.PropertyState;
36 import com.sun.star.lang.XMultiServiceFactory;
37 import com.sun.star.embed.XStorage;
38 import com.sun.star.sdbc.XDataSource;
39 import com.sun.star.sdbc.XDriver;
40 import connectivity.tools.HsqlDatabase;
41 
42 import org.junit.After;
43 import org.junit.AfterClass;
44 import org.junit.Before;
45 import org.junit.BeforeClass;
46 import org.junit.Test;
47 import static org.junit.Assert.*;
48 import org.openoffice.test.OfficeConnection;
49 
50 public class HsqlDriverTest {
51     private static final OfficeConnection connection = new OfficeConnection();
52 
53     @BeforeClass
beforeClass()54     public static void beforeClass() throws Exception {
55         connection.setUp();
56     }
57 
58     @AfterClass
afterClass()59     public static void afterClass() throws Exception {
60         connection.tearDown();
61     }
62 
63     @Test
test()64     public void test(){
65         XDataSource ds = null;
66         System.gc();
67         XMultiServiceFactory xMSF = UnoRuntime.queryInterface(XMultiServiceFactory.class, connection.getComponentContext().getServiceManager());
68         try {
69             HsqlDatabase database = new HsqlDatabase( xMSF );
70             ds = database.getDataSource().getXDataSource();
71         } catch(Exception ex) {
72             throw new RuntimeException("factory: unable to construct data source" );
73         }
74 
75         try{
76             XDocumentSubStorageSupplier doc = (XDocumentSubStorageSupplier)UnoRuntime.queryInterface(XDocumentSubStorageSupplier.class,ds);
77             XStorage stor = doc.getDocumentSubStorage("database",4);
78             try{
79             if ( stor.isStreamElement("db.log") )
80                 stor.removeElement("db.log");
81             } catch(Exception e){}
82             try{
83             if ( stor.isStreamElement("db.properties") )
84                 stor.removeElement("db.properties");
85             } catch(Exception e){}
86             try{
87             if ( stor.isStreamElement("db.script") )
88                 stor.removeElement("db.script");
89             } catch(Exception e){}
90             try{
91             if ( stor.isStreamElement("db.script.new") )
92                 stor.removeElement("db.script.new");
93             } catch(Exception e){}
94             XStorable mod = (XStorable)UnoRuntime.queryInterface(XStorable.class,ds);
95             mod.store();
96             XComponent xComp = (XComponent)UnoRuntime.queryInterface(XComponent.class,stor);
97             if ( xComp != null )
98                 xComp.dispose();
99         } catch(Exception e){}
100 
101         com.sun.star.beans.PropertyValue[] info = null;
102         XDriver drv = null;
103         try{
104             XDocumentSubStorageSupplier doc = (XDocumentSubStorageSupplier)UnoRuntime.queryInterface(XDocumentSubStorageSupplier.class,ds);
105             XModel mod = (XModel)UnoRuntime.queryInterface(XModel.class,ds);
106             XStorage stor = doc.getDocumentSubStorage("database",4);
107             info = new com.sun.star.beans.PropertyValue[]{
108                 new com.sun.star.beans.PropertyValue("Storage",0,stor,PropertyState.DIRECT_VALUE)
109                 ,new com.sun.star.beans.PropertyValue("URL",0,mod.getURL(),PropertyState.DIRECT_VALUE)
110             };
111             drv = (XDriver)UnoRuntime.queryInterface(XDriver.class, xMSF.createInstance("com.sun.star.sdbcx.comp.hsqldb.Driver"));
112 
113 
114             TestCacheSize test = new TestCacheSize(xMSF,info,drv);
115 
116             StopWatch     sw   = new StopWatch();
117 
118             try{
119                 test.setUp();
120                 test.testFillUp();
121                 test.checkResults();
122                 test.tearDown();
123                 System.out.println("Total Test Time: " + sw.elapsedTime());
124             } catch(Exception e){}
125 
126             try{
127                 XStorable mod2 = (XStorable)UnoRuntime.queryInterface(XStorable.class,ds);
128                 mod2.store();
129             } catch(Exception e){}
130         }catch(Exception e){}
131     }
test2()132     public void test2(){
133         System.gc();
134 
135         com.sun.star.beans.PropertyValue[] info = null;
136         XDriver drv = null;
137         XMultiServiceFactory xMSF = UnoRuntime.queryInterface(XMultiServiceFactory.class, connection.getComponentContext().getServiceManager());
138         try{
139             info = new com.sun.star.beans.PropertyValue[]{
140                 new com.sun.star.beans.PropertyValue("JavaDriverClass",0,"org.hsqldb.jdbcDriver",PropertyState.DIRECT_VALUE)
141                 ,new com.sun.star.beans.PropertyValue("ParameterNameSubstitution",0, false,PropertyState.DIRECT_VALUE)
142             };
143             drv = (XDriver)UnoRuntime.queryInterface(XDriver.class,xMSF.createInstance("com.sun.star.comp.sdbc.JDBCDriver"));
144             TestCacheSize test = new TestCacheSize(xMSF,info,drv);
145             test.setURL("jdbc:hsqldb:g:\\hsql\\db");
146 
147 
148             StopWatch     sw   = new StopWatch();
149 
150             try{
151                 test.setUp();
152                 test.testFillUp();
153                 test.checkResults();
154                 test.tearDown();
155                 System.out.println("Total Test Time: " + sw.elapsedTime());
156             } catch(Exception e){}
157         }catch(Exception e){}
158     }
159 }
160