2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 package mod
._dbaccess
;
20 import java
.io
.PrintWriter
;
23 import lib
.StatusException
;
25 import lib
.TestEnvironment
;
26 import lib
.TestParameters
;
27 import util
.AccessibilityTools
;
29 import com
.sun
.star
.accessibility
.AccessibleRole
;
30 import com
.sun
.star
.accessibility
.XAccessible
;
31 import com
.sun
.star
.awt
.PosSize
;
32 import com
.sun
.star
.awt
.Rectangle
;
33 import com
.sun
.star
.awt
.XWindow
;
34 import com
.sun
.star
.beans
.PropertyValue
;
35 import com
.sun
.star
.beans
.XPropertySet
;
36 import com
.sun
.star
.container
.XNameAccess
;
37 import com
.sun
.star
.container
.XNameContainer
;
38 import com
.sun
.star
.frame
.XModel
;
39 import com
.sun
.star
.frame
.XStorable
;
40 import com
.sun
.star
.lang
.XComponent
;
41 import com
.sun
.star
.lang
.XMultiServiceFactory
;
42 import com
.sun
.star
.sdb
.XDocumentDataSource
;
43 import com
.sun
.star
.sdb
.XQueryDefinitionsSupplier
;
44 import com
.sun
.star
.sdbc
.XConnection
;
45 import com
.sun
.star
.sdbc
.XIsolatedConnection
;
46 import com
.sun
.star
.sdbc
.XStatement
;
47 import com
.sun
.star
.ucb
.XSimpleFileAccess
;
48 import com
.sun
.star
.uno
.UnoRuntime
;
49 import com
.sun
.star
.uno
.XInterface
;
50 import util
.DesktopTools
;
55 * Object implements the following interfaces :
57 * <li><code>::com::sun::star::accessibility::XAccessible</code></li>
58 * <li><code>::com::sun::star::accessibility::XAccessibleContext
60 * <li><code>::com::sun::star::accessibility::XAccessibleEventBroadcaster
63 * @see com.sun.star.accessibility.XAccessible
64 * @see com.sun.star.accessibility.XAccessibleContext
65 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
66 * @see ifc.accessibility._XAccessible
67 * @see ifc.accessibility._XAccessibleContext
68 * @see ifc.accessibility._XAccessibleEventBroadcaster
70 public class JoinViewAccessibility
extends TestCase
{
71 XWindow xWindow
= null;
72 Object oDBSource
= null;
74 XConnection connection
= null;
75 XIsolatedConnection isolConnection
= null;
76 XComponent QueryComponent
= null;
81 * Creates a new DataSource and stores it.
82 * Creates a connection and using it
83 * creates two tables in database.
84 * Creates a new query and adds it to DefinitionContainer.
85 * Opens the QueryComponent.with loadComponentFromURL
86 * and gets the object with the role UNKNOWN and the Impplementation
87 * name that contains ConnectionLine
88 * @param Param test parameters
89 * @param log writer to log information while testing
91 * @throws StatusException
92 * @see TestEnvironment
94 protected TestEnvironment
createTestEnvironment (TestParameters Param
,
97 XInterface oObj
= null;
99 Object oDBSource
= null;
100 Object newQuery
= null;
101 XStorable store
= null;
105 ((XMultiServiceFactory
) Param
.getMSF ())
106 .createInstance ("com.sun.star.sdb.DatabaseContext");
107 oDBSource
= ((XMultiServiceFactory
) Param
.getMSF ())
108 .createInstance ("com.sun.star.sdb.DataSource");
109 newQuery
= ((XMultiServiceFactory
) Param
.getMSF ())
110 .createInstance ("com.sun.star.sdb.QueryDefinition");
111 ((XMultiServiceFactory
) Param
.getMSF ())
112 .createInstance ("com.sun.star.awt.Toolkit");
113 } catch (com
.sun
.star
.uno
.Exception e
)
115 e
.printStackTrace (log
);
116 throw new StatusException (Status
.failed ("Couldn't create instance"));
119 String mysqlURL
= (String
) Param
.get ("mysql.url");
121 if (mysqlURL
== null)
123 throw new StatusException (Status
.failed (
124 "Couldn't get 'mysql.url' from ini-file"));
127 user
= (String
) Param
.get ("jdbc.user");
128 password
= (String
) Param
.get ("jdbc.password");
130 if ((user
== null) || (password
== null))
132 throw new StatusException (Status
.failed (
133 "Couldn't get 'jdbc.user' or 'jdbc.password' from ini-file"));
136 PropertyValue
[] info
= new PropertyValue
[2];
137 info
[0] = new PropertyValue ();
138 info
[0].Name
= "user";
139 info
[0].Value
= user
;
140 info
[1] = new PropertyValue ();
141 info
[1].Name
= "password";
142 info
[1].Value
= password
;
144 XPropertySet propSetDBSource
= UnoRuntime
.queryInterface (
145 XPropertySet
.class, oDBSource
);
149 propSetDBSource
.setPropertyValue ("URL", mysqlURL
);
150 propSetDBSource
.setPropertyValue ("Info", info
);
151 } catch (com
.sun
.star
.lang
.WrappedTargetException e
)
153 e
.printStackTrace (log
);
154 throw new StatusException (Status
.failed (
155 "Couldn't set property value"));
156 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
)
158 e
.printStackTrace (log
);
159 throw new StatusException (Status
.failed (
160 "Couldn't set property value"));
161 } catch (com
.sun
.star
.beans
.PropertyVetoException e
)
163 e
.printStackTrace (log
);
164 throw new StatusException (Status
.failed (
165 "Couldn't set property value"));
166 } catch (com
.sun
.star
.beans
.UnknownPropertyException e
)
168 e
.printStackTrace (log
);
169 throw new StatusException (Status
.failed (
170 "Couldn't set property value"));
175 log
.println ("writing database file ...");
176 XDocumentDataSource xDDS
= UnoRuntime
.queryInterface(XDocumentDataSource
.class, oDBSource
);
177 store
= UnoRuntime
.queryInterface(XStorable
.class,
178 xDDS
.getDatabaseDocument());
179 aFile
= utils
.getOfficeTemp ((XMultiServiceFactory
) Param
.getMSF ())+"JoinView.odb";
180 log
.println ("... filename will be "+aFile
);
181 store
.storeAsURL (aFile
,new PropertyValue
[]
183 log
.println ("... done");
184 } catch (com
.sun
.star
.uno
.Exception e
)
186 e
.printStackTrace (log
);
187 throw new StatusException (Status
.failed ("Couldn't register object"));
190 isolConnection
= UnoRuntime
.queryInterface (
191 XIsolatedConnection
.class,
194 XConnection connection
= null;
195 XStatement statement
= null;
197 final String tbl_name1
= "tst_table1";
198 final String tbl_name2
= "tst_table2";
199 final String col_name1
= "id1";
200 final String col_name2
= "id2";
204 connection
= isolConnection
.getIsolatedConnection (user
, password
);
205 statement
= connection
.createStatement ();
206 statement
.executeUpdate ("drop table if exists " + tbl_name1
);
207 statement
.executeUpdate ("drop table if exists " + tbl_name2
);
208 statement
.executeUpdate ("create table " + tbl_name1
+ " (" +
209 col_name1
+ " int)");
210 statement
.executeUpdate ("create table " + tbl_name2
+ " (" +
211 col_name2
+ " int)");
212 } catch (com
.sun
.star
.sdbc
.SQLException e
)
217 connection
= isolConnection
.getIsolatedConnection (user
,
219 statement
= connection
.createStatement ();
220 statement
.executeUpdate ("drop table if exists " + tbl_name1
);
221 statement
.executeUpdate ("drop table if exists " + tbl_name2
);
222 statement
.executeUpdate ("create table " + tbl_name1
+ " (" +
223 col_name1
+ " int)");
224 statement
.executeUpdate ("create table " + tbl_name2
+ " (" +
225 col_name2
+ " int)");
226 } catch (com
.sun
.star
.sdbc
.SQLException e2
)
228 e2
.printStackTrace (log
);
229 throw new StatusException (Status
.failed ("SQLException"));
233 XQueryDefinitionsSupplier querySuppl
= UnoRuntime
.queryInterface (
234 XQueryDefinitionsSupplier
.class,
237 XNameAccess defContainer
= querySuppl
.getQueryDefinitions ();
239 XPropertySet queryProp
= UnoRuntime
.queryInterface (
240 XPropertySet
.class, newQuery
);
244 final String query
= "select * from " + tbl_name1
+ ", " +
245 tbl_name2
+ " where " + tbl_name1
+ "." +
246 col_name1
+ "=" + tbl_name2
+ "." +
248 queryProp
.setPropertyValue ("Command", query
);
249 } catch (com
.sun
.star
.lang
.WrappedTargetException e
)
251 e
.printStackTrace (log
);
252 throw new StatusException (Status
.failed (
253 "Couldn't set property value"));
254 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
)
256 e
.printStackTrace (log
);
257 throw new StatusException (Status
.failed (
258 "Couldn't set property value"));
259 } catch (com
.sun
.star
.beans
.PropertyVetoException e
)
261 e
.printStackTrace (log
);
262 throw new StatusException (Status
.failed (
263 "Couldn't set property value"));
264 } catch (com
.sun
.star
.beans
.UnknownPropertyException e
)
266 e
.printStackTrace (log
);
267 throw new StatusException (Status
.failed (
268 "Couldn't set property value"));
271 XNameContainer queryContainer
= UnoRuntime
.queryInterface (
272 XNameContainer
.class,
277 queryContainer
.insertByName ("Query1", newQuery
);
280 } catch (com
.sun
.star
.lang
.WrappedTargetException e
)
282 e
.printStackTrace (log
);
283 throw new StatusException (Status
.failed ("Couldn't insert query"));
284 } catch (com
.sun
.star
.container
.ElementExistException e
)
286 e
.printStackTrace (log
);
287 throw new StatusException (Status
.failed ("Couldn't insert query"));
288 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
)
290 e
.printStackTrace (log
);
291 throw new StatusException (Status
.failed ("Couldn't insert query"));
292 } catch (com
.sun
.star
.io
.IOException e
)
294 e
.printStackTrace (log
);
295 throw new StatusException (Status
.failed ("Couldn't insert query"));
296 } catch (com
.sun
.star
.sdbc
.SQLException e
)
298 e
.printStackTrace (log
);
299 throw new StatusException (Status
.failed ("Couldn't insert query"));
302 PropertyValue
[] loadProps
= new PropertyValue
[3];
303 loadProps
[0] = new PropertyValue ();
304 loadProps
[0].Name
= "QueryDesignView";
305 loadProps
[0].Value
= Boolean
.TRUE
;
307 loadProps
[1] = new PropertyValue ();
308 loadProps
[1].Name
= "CurrentQuery";
309 loadProps
[1].Value
= "Query1";
311 loadProps
[2] = new PropertyValue ();
312 loadProps
[2].Name
= "DataSource";
313 loadProps
[2].Value
= oDBSource
;
315 QueryComponent
= DesktopTools
.loadDoc ((XMultiServiceFactory
) Param
.getMSF (),".component:DB/QueryDesign",loadProps
);
317 xWindow
= UnoRuntime
.queryInterface(XModel
.class, QueryComponent
).
318 getCurrentController().getFrame().getContainerWindow();
320 XAccessible xRoot
= AccessibilityTools
.getAccessibleObject (xWindow
);
322 AccessibilityTools
.printAccessibleTree (log
,xRoot
, Param
.getBool(util
.PropertyName
.DEBUG_IS_ACTIVE
));
324 oObj
= AccessibilityTools
.getAccessibleObjectForRole(xRoot
, AccessibleRole
.VIEW_PORT
);
326 log
.println("ImplementationName " + util
.utils
.getImplName(oObj
));
328 log
.println("creating TestEnvironment");
330 TestEnvironment tEnv
= new TestEnvironment(oObj
);
334 final XWindow queryWin
= xWindow
;
336 tEnv
.addObjRelation("EventProducer",
337 new ifc
.accessibility
._XAccessibleEventBroadcaster
.EventProducer() {
338 public void fireEvent() {
339 Rectangle rect
= queryWin
.getPosSize();
340 queryWin
.setPosSize(rect
.X
, rect
.Y
, rect
.Height
-5, rect
.Width
-5, PosSize
.POSSIZE
);
345 } // finish method getTestEnvironment
348 * Closes the DatasourceAdministration dialog and Query Dialog.
350 protected void cleanup(TestParameters Param
, PrintWriter log
) {
354 log
.println ("closing QueryComponent ...");
355 DesktopTools
.closeDoc (QueryComponent
);
356 log
.println ("... done");
357 XMultiServiceFactory xMSF
= (XMultiServiceFactory
)Param
.getMSF ();
358 Object sfa
= xMSF
.createInstance ("com.sun.star.comp.ucb.SimpleFileAccess");
359 XSimpleFileAccess xSFA
= UnoRuntime
.queryInterface (XSimpleFileAccess
.class, sfa
);
360 log
.println ("deleting database file");
362 log
.println ("Could delete file "+aFile
+": "+!xSFA
.exists (aFile
));
363 } catch (Exception e
)
365 e
.printStackTrace ();
370 * Sleeps for 1.5 sec. to allow StarOffice to react on <code>
373 private void shortWait() {
376 } catch (InterruptedException e
) {
377 log
.println("While waiting :" + e
);