1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: JoinViewAccessibility.java,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 package mod
._dbaccess
;
32 import java
.io
.PrintWriter
;
35 import lib
.StatusException
;
37 import lib
.TestEnvironment
;
38 import lib
.TestParameters
;
39 import util
.AccessibilityTools
;
41 import com
.sun
.star
.accessibility
.AccessibleRole
;
42 import com
.sun
.star
.accessibility
.XAccessible
;
43 import com
.sun
.star
.awt
.PosSize
;
44 import com
.sun
.star
.awt
.Rectangle
;
45 import com
.sun
.star
.awt
.XExtendedToolkit
;
46 import com
.sun
.star
.awt
.XWindow
;
47 import com
.sun
.star
.beans
.PropertyValue
;
48 import com
.sun
.star
.beans
.XPropertySet
;
49 import com
.sun
.star
.container
.XNameAccess
;
50 import com
.sun
.star
.container
.XNameContainer
;
51 import com
.sun
.star
.frame
.XStorable
;
52 import com
.sun
.star
.lang
.XComponent
;
53 import com
.sun
.star
.lang
.XMultiServiceFactory
;
54 import com
.sun
.star
.sdb
.XDocumentDataSource
;
55 import com
.sun
.star
.sdb
.XQueryDefinitionsSupplier
;
56 import com
.sun
.star
.sdbc
.XConnection
;
57 import com
.sun
.star
.sdbc
.XIsolatedConnection
;
58 import com
.sun
.star
.sdbc
.XStatement
;
59 import com
.sun
.star
.ucb
.XSimpleFileAccess
;
60 import com
.sun
.star
.uno
.UnoRuntime
;
61 import com
.sun
.star
.uno
.XInterface
;
62 import util
.DesktopTools
;
67 * Object implements the following interfaces :
69 * <li><code>::com::sun::star::accessibility::XAccessible</code></li>
70 * <li><code>::com::sun::star::accessibility::XAccessibleContext
72 * <li><code>::com::sun::star::accessibility::XAccessibleEventBroadcaster
75 * @see com.sun.star.accessibility.XAccessible
76 * @see com.sun.star.accessibility.XAccessibleContext
77 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
78 * @see ifc.accessibility._XAccessible
79 * @see ifc.accessibility._XAccessibleContext
80 * @see ifc.accessibility._XAccessibleEventBroadcaster
82 public class JoinViewAccessibility
extends TestCase
{
83 XWindow xWindow
= null;
84 Object oDBSource
= null;
86 XConnection connection
= null;
87 XIsolatedConnection isolConnection
= null;
88 XComponent QueryComponent
= null;
93 * Creates a new DataSource and stores it.
94 * Creates a connection and using it
95 * creates two tables in database.
96 * Creates a new query and adds it to DefinitionContainer.
97 * Opens the QueryComponent.with loadComponentFromURL
98 * and gets the object with the role UNKNOWN and the Impplementation
99 * name that contains ConnectionLine
100 * @param Param test parameters
101 * @param log writer to log information while testing
103 * @throws StatusException
104 * @see TestEnvironment
106 protected TestEnvironment
createTestEnvironment (TestParameters Param
,
109 XInterface oObj
= null;
111 Object oDBContext
= null;
112 Object oDBSource
= null;
113 Object newQuery
= null;
114 Object toolkit
= null;
115 XStorable store
= null;
119 oDBContext
= ((XMultiServiceFactory
) Param
.getMSF ())
120 .createInstance ("com.sun.star.sdb.DatabaseContext");
121 oDBSource
= ((XMultiServiceFactory
) Param
.getMSF ())
122 .createInstance ("com.sun.star.sdb.DataSource");
123 newQuery
= ((XMultiServiceFactory
) Param
.getMSF ())
124 .createInstance ("com.sun.star.sdb.QueryDefinition");
125 toolkit
= ((XMultiServiceFactory
) Param
.getMSF ())
126 .createInstance ("com.sun.star.awt.Toolkit");
127 } catch (com
.sun
.star
.uno
.Exception e
)
129 e
.printStackTrace (log
);
130 throw new StatusException (Status
.failed ("Couldn't create instance"));
133 String mysqlURL
= (String
) Param
.get ("mysql.url");
135 if (mysqlURL
== null)
137 throw new StatusException (Status
.failed (
138 "Couldn't get 'mysql.url' from ini-file"));
141 user
= (String
) Param
.get ("jdbc.user");
142 password
= (String
) Param
.get ("jdbc.password");
144 if ((user
== null) || (password
== null))
146 throw new StatusException (Status
.failed (
147 "Couldn't get 'jdbc.user' or 'jdbc.password' from ini-file"));
150 PropertyValue
[] info
= new PropertyValue
[2];
151 info
[0] = new PropertyValue ();
152 info
[0].Name
= "user";
153 info
[0].Value
= user
;
154 info
[1] = new PropertyValue ();
155 info
[1].Name
= "password";
156 info
[1].Value
= password
;
158 XPropertySet propSetDBSource
= (XPropertySet
) UnoRuntime
.queryInterface (
159 XPropertySet
.class, oDBSource
);
163 propSetDBSource
.setPropertyValue ("URL", mysqlURL
);
164 propSetDBSource
.setPropertyValue ("Info", info
);
165 } catch (com
.sun
.star
.lang
.WrappedTargetException e
)
167 e
.printStackTrace (log
);
168 throw new StatusException (Status
.failed (
169 "Couldn't set property value"));
170 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
)
172 e
.printStackTrace (log
);
173 throw new StatusException (Status
.failed (
174 "Couldn't set property value"));
175 } catch (com
.sun
.star
.beans
.PropertyVetoException e
)
177 e
.printStackTrace (log
);
178 throw new StatusException (Status
.failed (
179 "Couldn't set property value"));
180 } catch (com
.sun
.star
.beans
.UnknownPropertyException e
)
182 e
.printStackTrace (log
);
183 throw new StatusException (Status
.failed (
184 "Couldn't set property value"));
189 log
.println ("writing database file ...");
190 XDocumentDataSource xDDS
= (XDocumentDataSource
)
191 UnoRuntime
.queryInterface(XDocumentDataSource
.class, oDBSource
);
192 store
= (XStorable
) UnoRuntime
.queryInterface(XStorable
.class,
193 xDDS
.getDatabaseDocument());
194 aFile
= utils
.getOfficeTemp ((XMultiServiceFactory
) Param
.getMSF ())+"JoinView.odb";
195 log
.println ("... filename will be "+aFile
);
196 store
.storeAsURL (aFile
,new PropertyValue
[]
198 log
.println ("... done");
199 } catch (com
.sun
.star
.uno
.Exception e
)
201 e
.printStackTrace (log
);
202 throw new StatusException (Status
.failed ("Couldn't register object"));
205 isolConnection
= (XIsolatedConnection
) UnoRuntime
.queryInterface (
206 XIsolatedConnection
.class,
209 XConnection connection
= null;
210 XStatement statement
= null;
212 final String tbl_name1
= "tst_table1";
213 final String tbl_name2
= "tst_table2";
214 final String col_name1
= "id1";
215 final String col_name2
= "id2";
219 connection
= isolConnection
.getIsolatedConnection (user
, password
);
220 statement
= connection
.createStatement ();
221 statement
.executeUpdate ("drop table if exists " + tbl_name1
);
222 statement
.executeUpdate ("drop table if exists " + tbl_name2
);
223 statement
.executeUpdate ("create table " + tbl_name1
+ " (" +
224 col_name1
+ " int)");
225 statement
.executeUpdate ("create table " + tbl_name2
+ " (" +
226 col_name2
+ " int)");
227 } catch (com
.sun
.star
.sdbc
.SQLException e
)
232 connection
= isolConnection
.getIsolatedConnection (user
,
234 statement
= connection
.createStatement ();
235 statement
.executeUpdate ("drop table if exists " + tbl_name1
);
236 statement
.executeUpdate ("drop table if exists " + tbl_name2
);
237 statement
.executeUpdate ("create table " + tbl_name1
+ " (" +
238 col_name1
+ " int)");
239 statement
.executeUpdate ("create table " + tbl_name2
+ " (" +
240 col_name2
+ " int)");
241 } catch (com
.sun
.star
.sdbc
.SQLException e2
)
243 e2
.printStackTrace (log
);
244 throw new StatusException (Status
.failed ("SQLException"));
248 XQueryDefinitionsSupplier querySuppl
= (XQueryDefinitionsSupplier
) UnoRuntime
.queryInterface (
249 XQueryDefinitionsSupplier
.class,
252 XNameAccess defContainer
= querySuppl
.getQueryDefinitions ();
254 XPropertySet queryProp
= (XPropertySet
) UnoRuntime
.queryInterface (
255 XPropertySet
.class, newQuery
);
259 final String query
= "select * from " + tbl_name1
+ ", " +
260 tbl_name2
+ " where " + tbl_name1
+ "." +
261 col_name1
+ "=" + tbl_name2
+ "." +
263 queryProp
.setPropertyValue ("Command", query
);
264 } catch (com
.sun
.star
.lang
.WrappedTargetException e
)
266 e
.printStackTrace (log
);
267 throw new StatusException (Status
.failed (
268 "Couldn't set property value"));
269 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
)
271 e
.printStackTrace (log
);
272 throw new StatusException (Status
.failed (
273 "Couldn't set property value"));
274 } catch (com
.sun
.star
.beans
.PropertyVetoException e
)
276 e
.printStackTrace (log
);
277 throw new StatusException (Status
.failed (
278 "Couldn't set property value"));
279 } catch (com
.sun
.star
.beans
.UnknownPropertyException e
)
281 e
.printStackTrace (log
);
282 throw new StatusException (Status
.failed (
283 "Couldn't set property value"));
286 XNameContainer queryContainer
= (XNameContainer
) UnoRuntime
.queryInterface (
287 XNameContainer
.class,
292 queryContainer
.insertByName ("Query1", newQuery
);
295 } catch (com
.sun
.star
.lang
.WrappedTargetException e
)
297 e
.printStackTrace (log
);
298 throw new StatusException (Status
.failed ("Couldn't insert query"));
299 } catch (com
.sun
.star
.container
.ElementExistException e
)
301 e
.printStackTrace (log
);
302 throw new StatusException (Status
.failed ("Couldn't insert query"));
303 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
)
305 e
.printStackTrace (log
);
306 throw new StatusException (Status
.failed ("Couldn't insert query"));
307 } catch (com
.sun
.star
.io
.IOException e
)
309 e
.printStackTrace (log
);
310 throw new StatusException (Status
.failed ("Couldn't insert query"));
311 } catch (com
.sun
.star
.sdbc
.SQLException e
)
313 e
.printStackTrace (log
);
314 throw new StatusException (Status
.failed ("Couldn't insert query"));
317 PropertyValue
[] loadProps
= new PropertyValue
[3];
318 loadProps
[0] = new PropertyValue ();
319 loadProps
[0].Name
= "QueryDesignView";
320 loadProps
[0].Value
= Boolean
.TRUE
;
322 loadProps
[1] = new PropertyValue ();
323 loadProps
[1].Name
= "CurrentQuery";
324 loadProps
[1].Value
= "Query1";
326 loadProps
[2] = new PropertyValue ();
327 loadProps
[2].Name
= "DataSource";
328 loadProps
[2].Value
= oDBSource
;
330 QueryComponent
= DesktopTools
.loadDoc ((XMultiServiceFactory
) Param
.getMSF (),".component:DB/QueryDesign",loadProps
);
332 XExtendedToolkit tk
= (XExtendedToolkit
) UnoRuntime
.queryInterface (
333 XExtendedToolkit
.class, toolkit
);
335 Object atw
= tk
.getActiveTopWindow ();
337 xWindow
= (XWindow
) UnoRuntime
.queryInterface (XWindow
.class, atw
);
339 XAccessible xRoot
= AccessibilityTools
.getAccessibleObject (xWindow
);
341 AccessibilityTools
.printAccessibleTree (log
,xRoot
, Param
.getBool(util
.PropertyName
.DEBUG_IS_ACTIVE
));
343 oObj
= AccessibilityTools
.getAccessibleObjectForRole(xRoot
, AccessibleRole
.VIEW_PORT
);
345 log
.println("ImplementationName " + util
.utils
.getImplName(oObj
));
347 log
.println("creating TestEnvironment");
349 TestEnvironment tEnv
= new TestEnvironment(oObj
);
353 final XWindow queryWin
= xWindow
;
355 tEnv
.addObjRelation("EventProducer",
356 new ifc
.accessibility
._XAccessibleEventBroadcaster
.EventProducer() {
357 public void fireEvent() {
358 Rectangle rect
= queryWin
.getPosSize();
359 queryWin
.setPosSize(rect
.X
, rect
.Y
, rect
.Height
-5, rect
.Width
-5, PosSize
.POSSIZE
);
364 } // finish method getTestEnvironment
367 * Closes the DatasourceAdministration dialog and Query Dialog.
369 protected void cleanup(TestParameters Param
, PrintWriter log
) {
373 log
.println ("closing QueryComponent ...");
374 DesktopTools
.closeDoc (QueryComponent
);
375 log
.println ("... done");
376 XMultiServiceFactory xMSF
= (XMultiServiceFactory
)Param
.getMSF ();
377 Object sfa
= xMSF
.createInstance ("com.sun.star.comp.ucb.SimpleFileAccess");
378 XSimpleFileAccess xSFA
= (XSimpleFileAccess
) UnoRuntime
.queryInterface (XSimpleFileAccess
.class, sfa
);
379 log
.println ("deleting database file");
381 log
.println ("Could delete file "+aFile
+": "+!xSFA
.exists (aFile
));
382 } catch (Exception e
)
384 e
.printStackTrace ();
389 * Sleeps for 1.5 sec. to allow StarOffice to react on <code>
392 private void shortWait() {
395 } catch (InterruptedException e
) {
396 log
.println("While waiting :" + e
);