merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / mod / _dbaccess / ConnectionLineAccessibility.java
blob0f1254b69fd6430283b252b29b883f0e40141926
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ConnectionLineAccessibility.java,v $
10 * $Revision: 1.10 $
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;
34 import lib.Status;
35 import lib.StatusException;
36 import lib.TestCase;
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;
63 import util.utils;
66 /**
67 * Object implements the following interfaces :
68 * <ul>
69 * <li><code>::com::sun::star::accessibility::XAccessible</code></li>
70 * <li><code>::com::sun::star::accessibility::XAccessibleContext
71 * </code></li>
72 * <li><code>::com::sun::star::accessibility::XAccessibleEventBroadcaster
73 * </code></li>
74 * </ul><p>
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 ConnectionLineAccessibility extends TestCase
84 XWindow xWindow = null;
85 Object oDBSource = null;
86 String aFile = "";
87 XConnection connection = null;
88 XIsolatedConnection isolConnection = null;
89 XComponent QueryComponent = null;
90 String user = "";
91 String password="";
93 /**
94 * Creates a new DataSource and stores it.
95 * Creates a connection and using it
96 * creates two tables in database.
97 * Creates a new query and adds it to DefinitionContainer.
98 * Opens the QueryComponent.with loadComponentFromURL
99 * and gets the object with the role UNKNOWN and the Impplementation
100 * name that contains ConnectionLine
101 * @param Param test parameters
102 * @param log writer to log information while testing
103 * @return
104 * @throws StatusException
105 * @see TestEnvironment
107 protected TestEnvironment createTestEnvironment(TestParameters Param,
108 PrintWriter log)
110 XInterface oObj = null;
112 Object oDBContext = null;
113 Object oDBSource = null;
114 Object newQuery = null;
115 Object toolkit = null;
116 XStorable store = null;
120 oDBContext = ((XMultiServiceFactory) Param.getMSF())
121 .createInstance("com.sun.star.sdb.DatabaseContext");
122 oDBSource = ((XMultiServiceFactory) Param.getMSF())
123 .createInstance("com.sun.star.sdb.DataSource");
124 newQuery = ((XMultiServiceFactory) Param.getMSF())
125 .createInstance("com.sun.star.sdb.QueryDefinition");
126 toolkit = ((XMultiServiceFactory) Param.getMSF())
127 .createInstance("com.sun.star.awt.Toolkit");
129 catch (com.sun.star.uno.Exception e)
131 e.printStackTrace(log);
132 throw new StatusException(Status.failed("Couldn't create instance"));
135 String mysqlURL = (String) Param.get("mysql.url");
137 if (mysqlURL == null)
139 throw new StatusException(Status.failed(
140 "Couldn't get 'mysql.url' from ini-file"));
143 user = (String) Param.get("jdbc.user");
144 password = (String) Param.get("jdbc.password");
146 if ((user == null) || (password == null))
148 throw new StatusException(Status.failed(
149 "Couldn't get 'jdbc.user' or 'jdbc.password' from ini-file"));
152 PropertyValue[] info = new PropertyValue[2];
153 info[0] = new PropertyValue();
154 info[0].Name = "user";
155 info[0].Value = user;
156 info[1] = new PropertyValue();
157 info[1].Name = "password";
158 info[1].Value = password;
160 XPropertySet propSetDBSource = (XPropertySet) UnoRuntime.queryInterface(
161 XPropertySet.class, oDBSource);
165 propSetDBSource.setPropertyValue("URL", mysqlURL);
166 propSetDBSource.setPropertyValue("Info", info);
168 catch (com.sun.star.lang.WrappedTargetException e)
170 e.printStackTrace(log);
171 throw new StatusException(Status.failed(
172 "Couldn't set property value"));
174 catch (com.sun.star.lang.IllegalArgumentException e)
176 e.printStackTrace(log);
177 throw new StatusException(Status.failed(
178 "Couldn't set property value"));
180 catch (com.sun.star.beans.PropertyVetoException e)
182 e.printStackTrace(log);
183 throw new StatusException(Status.failed(
184 "Couldn't set property value"));
186 catch (com.sun.star.beans.UnknownPropertyException e)
188 e.printStackTrace(log);
189 throw new StatusException(Status.failed(
190 "Couldn't set property value"));
195 log.println("writing database file ...");
196 XDocumentDataSource xDDS = (XDocumentDataSource)
197 UnoRuntime.queryInterface(XDocumentDataSource.class, oDBSource);
198 store = (XStorable) UnoRuntime.queryInterface(XStorable.class,
199 xDDS.getDatabaseDocument());
201 aFile = utils.getOfficeTemp((XMultiServiceFactory) Param.getMSF())+"ConnectionLine.odb";
202 log.println("... filename will be "+aFile);
203 store.storeAsURL(aFile,new PropertyValue[]
204 {});
205 log.println("... done");
207 catch (com.sun.star.uno.Exception e)
209 e.printStackTrace(log);
210 throw new StatusException(Status.failed("Couldn't register object"));
213 isolConnection = (XIsolatedConnection) UnoRuntime.queryInterface(
214 XIsolatedConnection.class,
215 oDBSource);
217 XConnection connection = null;
218 XStatement statement = null;
220 final String tbl_name1 = "tst_table1";
221 final String tbl_name2 = "tst_table2";
222 final String col_name1 = "id1";
223 final String col_name2 = "id2";
227 connection = isolConnection.getIsolatedConnection(user, password);
228 statement = connection.createStatement();
229 statement.executeUpdate("drop table if exists " + tbl_name1);
230 statement.executeUpdate("drop table if exists " + tbl_name2);
231 statement.executeUpdate("create table " + tbl_name1 + " (" +
232 col_name1 + " int)");
233 statement.executeUpdate("create table " + tbl_name2 + " (" +
234 col_name2 + " int)");
236 catch (com.sun.star.sdbc.SQLException e)
240 shortWait();
241 connection = isolConnection.getIsolatedConnection(user,
242 password);
243 statement = connection.createStatement();
244 statement.executeUpdate("drop table if exists " + tbl_name1);
245 statement.executeUpdate("drop table if exists " + tbl_name2);
246 statement.executeUpdate("create table " + tbl_name1 + " (" +
247 col_name1 + " int)");
248 statement.executeUpdate("create table " + tbl_name2 + " (" +
249 col_name2 + " int)");
251 catch (com.sun.star.sdbc.SQLException e2)
253 e2.printStackTrace(log);
254 throw new StatusException(Status.failed("SQLException"));
258 XQueryDefinitionsSupplier querySuppl = (XQueryDefinitionsSupplier) UnoRuntime.queryInterface(
259 XQueryDefinitionsSupplier.class,
260 oDBSource);
262 XNameAccess defContainer = querySuppl.getQueryDefinitions();
264 XPropertySet queryProp = (XPropertySet) UnoRuntime.queryInterface(
265 XPropertySet.class, newQuery);
269 final String query = "select * from " + tbl_name1 + ", " +
270 tbl_name2 + " where " + tbl_name1 + "." +
271 col_name1 + "=" + tbl_name2 + "." +
272 col_name2;
273 queryProp.setPropertyValue("Command", query);
275 catch (com.sun.star.lang.WrappedTargetException e)
277 e.printStackTrace(log);
278 throw new StatusException(Status.failed(
279 "Couldn't set property value"));
281 catch (com.sun.star.lang.IllegalArgumentException e)
283 e.printStackTrace(log);
284 throw new StatusException(Status.failed(
285 "Couldn't set property value"));
287 catch (com.sun.star.beans.PropertyVetoException e)
289 e.printStackTrace(log);
290 throw new StatusException(Status.failed(
291 "Couldn't set property value"));
293 catch (com.sun.star.beans.UnknownPropertyException e)
295 e.printStackTrace(log);
296 throw new StatusException(Status.failed(
297 "Couldn't set property value"));
300 XNameContainer queryContainer = (XNameContainer) UnoRuntime.queryInterface(
301 XNameContainer.class,
302 defContainer);
306 queryContainer.insertByName("Query1", newQuery);
307 store.store();
308 connection.close();
310 catch (com.sun.star.lang.WrappedTargetException e)
312 e.printStackTrace(log);
313 throw new StatusException(Status.failed("Couldn't insert query"));
315 catch (com.sun.star.container.ElementExistException e)
317 e.printStackTrace(log);
318 throw new StatusException(Status.failed("Couldn't insert query"));
320 catch (com.sun.star.lang.IllegalArgumentException e)
322 e.printStackTrace(log);
323 throw new StatusException(Status.failed("Couldn't insert query"));
325 catch (com.sun.star.io.IOException e)
327 e.printStackTrace(log);
328 throw new StatusException(Status.failed("Couldn't insert query"));
330 catch (com.sun.star.sdbc.SQLException e)
332 e.printStackTrace(log);
333 throw new StatusException(Status.failed("Couldn't insert query"));
336 PropertyValue[] loadProps = new PropertyValue[3];
337 loadProps[0] = new PropertyValue();
338 loadProps[0].Name = "QueryDesignView";
339 loadProps[0].Value = Boolean.TRUE;
341 loadProps[1] = new PropertyValue();
342 loadProps[1].Name = "CurrentQuery";
343 loadProps[1].Value = "Query1";
345 loadProps[2] = new PropertyValue();
346 loadProps[2].Name = "DataSource";
347 loadProps[2].Value = oDBSource;
349 QueryComponent = DesktopTools.loadDoc((XMultiServiceFactory) Param.getMSF(),".component:DB/QueryDesign",loadProps);
351 util.utils.shortWait(1000);
353 XExtendedToolkit tk = (XExtendedToolkit) UnoRuntime.queryInterface(
354 XExtendedToolkit.class, toolkit);
356 Object atw = tk.getActiveTopWindow();
358 xWindow = (XWindow) UnoRuntime.queryInterface(XWindow.class, atw);
360 XAccessible xRoot = AccessibilityTools.getAccessibleObject(xWindow);
362 AccessibilityTools.printAccessibleTree (log,xRoot, Param.getBool(util.PropertyName.DEBUG_IS_ACTIVE));
364 oObj = AccessibilityTools.getAccessibleObjectForRoleIgnoreShowing(xRoot, AccessibleRole.UNKNOWN, "", "ConnectionLine");
366 log.println("ImplementationName " + util.utils.getImplName(oObj));
368 log.println("creating TestEnvironment");
370 TestEnvironment tEnv = new TestEnvironment(oObj);
372 shortWait();
374 final XWindow queryWin = xWindow;
376 tEnv.addObjRelation("EventProducer",
377 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer()
379 public void fireEvent()
381 Rectangle rect = queryWin.getPosSize();
382 queryWin.setPosSize(rect.X, rect.Y, rect.Height-5, rect.Width-5, PosSize.POSSIZE);
386 return tEnv;
387 } // finish method getTestEnvironment
390 * Closes the DatasourceAdministration dialog and Query Dialog.
392 protected void cleanup(TestParameters Param, PrintWriter log)
397 log.println("closing QueryComponent ...");
398 DesktopTools.closeDoc(QueryComponent);
399 log.println("... done");
400 XMultiServiceFactory xMSF = (XMultiServiceFactory)Param.getMSF();
401 Object sfa = xMSF.createInstance("com.sun.star.comp.ucb.SimpleFileAccess");
402 XSimpleFileAccess xSFA = (XSimpleFileAccess) UnoRuntime.queryInterface(XSimpleFileAccess.class, sfa);
403 log.println("deleting database file");
404 xSFA.kill(aFile);
405 log.println("Could delete file "+aFile+": "+!xSFA.exists(aFile));
407 catch (Exception e)
409 e.printStackTrace();
414 * Sleeps for 1.5 sec. to allow StarOffice to react on <code>
415 * reset</code> call.
417 private void shortWait()
421 Thread.sleep(1500);
423 catch (InterruptedException e)
425 log.println("While waiting :" + e);