bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _dbaccess / ConnectionLineAccessibility.java
blob42586601874894e72a5926e18b60c4ed5bfe7b2c
1 /*
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;
22 import lib.Status;
23 import lib.StatusException;
24 import lib.TestCase;
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;
51 import util.utils;
54 /**
55 * Object implements the following interfaces :
56 * <ul>
57 * <li><code>::com::sun::star::accessibility::XAccessible</code></li>
58 * <li><code>::com::sun::star::accessibility::XAccessibleContext
59 * </code></li>
60 * <li><code>::com::sun::star::accessibility::XAccessibleEventBroadcaster
61 * </code></li>
62 * </ul><p>
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 ConnectionLineAccessibility extends TestCase
72 XWindow xWindow = null;
73 Object oDBSource = null;
74 String aFile = "";
75 XConnection connection = null;
76 XIsolatedConnection isolConnection = null;
77 XComponent QueryComponent = null;
78 String user = "";
79 String password="";
81 /**
82 * Creates a new DataSource and stores it.
83 * Creates a connection and using it
84 * creates two tables in database.
85 * Creates a new query and adds it to DefinitionContainer.
86 * Opens the QueryComponent.with loadComponentFromURL
87 * and gets the object with the role UNKNOWN and the Impplementation
88 * name that contains ConnectionLine
89 * @param Param test parameters
90 * @param log writer to log information while testing
91 * @return
92 * @throws StatusException
93 * @see TestEnvironment
95 protected TestEnvironment createTestEnvironment(TestParameters Param,
96 PrintWriter log)
98 XInterface oObj = null;
100 Object oDBSource = null;
101 Object newQuery = null;
102 XStorable store = null;
106 ((XMultiServiceFactory) Param.getMSF())
107 .createInstance("com.sun.star.sdb.DatabaseContext");
108 oDBSource = ((XMultiServiceFactory) Param.getMSF())
109 .createInstance("com.sun.star.sdb.DataSource");
110 newQuery = ((XMultiServiceFactory) Param.getMSF())
111 .createInstance("com.sun.star.sdb.QueryDefinition");
112 ((XMultiServiceFactory) Param.getMSF())
113 .createInstance("com.sun.star.awt.Toolkit");
115 catch (com.sun.star.uno.Exception e)
117 e.printStackTrace(log);
118 throw new StatusException(Status.failed("Couldn't create instance"));
121 String mysqlURL = (String) Param.get("mysql.url");
123 if (mysqlURL == null)
125 throw new StatusException(Status.failed(
126 "Couldn't get 'mysql.url' from ini-file"));
129 user = (String) Param.get("jdbc.user");
130 password = (String) Param.get("jdbc.password");
132 if ((user == null) || (password == null))
134 throw new StatusException(Status.failed(
135 "Couldn't get 'jdbc.user' or 'jdbc.password' from ini-file"));
138 PropertyValue[] info = new PropertyValue[2];
139 info[0] = new PropertyValue();
140 info[0].Name = "user";
141 info[0].Value = user;
142 info[1] = new PropertyValue();
143 info[1].Name = "password";
144 info[1].Value = password;
146 XPropertySet propSetDBSource = UnoRuntime.queryInterface(
147 XPropertySet.class, oDBSource);
151 propSetDBSource.setPropertyValue("URL", mysqlURL);
152 propSetDBSource.setPropertyValue("Info", info);
154 catch (com.sun.star.lang.WrappedTargetException e)
156 e.printStackTrace(log);
157 throw new StatusException(Status.failed(
158 "Couldn't set property value"));
160 catch (com.sun.star.lang.IllegalArgumentException e)
162 e.printStackTrace(log);
163 throw new StatusException(Status.failed(
164 "Couldn't set property value"));
166 catch (com.sun.star.beans.PropertyVetoException e)
168 e.printStackTrace(log);
169 throw new StatusException(Status.failed(
170 "Couldn't set property value"));
172 catch (com.sun.star.beans.UnknownPropertyException e)
174 e.printStackTrace(log);
175 throw new StatusException(Status.failed(
176 "Couldn't set property value"));
181 log.println("writing database file ...");
182 XDocumentDataSource xDDS = UnoRuntime.queryInterface(XDocumentDataSource.class, oDBSource);
183 store = UnoRuntime.queryInterface(XStorable.class,
184 xDDS.getDatabaseDocument());
186 aFile = utils.getOfficeTemp((XMultiServiceFactory) Param.getMSF())+"ConnectionLine.odb";
187 log.println("... filename will be "+aFile);
188 store.storeAsURL(aFile,new PropertyValue[]
189 {});
190 log.println("... done");
192 catch (com.sun.star.uno.Exception e)
194 e.printStackTrace(log);
195 throw new StatusException(Status.failed("Couldn't register object"));
198 isolConnection = UnoRuntime.queryInterface(
199 XIsolatedConnection.class,
200 oDBSource);
202 XConnection connection = null;
203 XStatement statement = null;
205 final String tbl_name1 = "tst_table1";
206 final String tbl_name2 = "tst_table2";
207 final String col_name1 = "id1";
208 final String col_name2 = "id2";
212 connection = isolConnection.getIsolatedConnection(user, password);
213 statement = connection.createStatement();
214 statement.executeUpdate("drop table if exists " + tbl_name1);
215 statement.executeUpdate("drop table if exists " + tbl_name2);
216 statement.executeUpdate("create table " + tbl_name1 + " (" +
217 col_name1 + " int)");
218 statement.executeUpdate("create table " + tbl_name2 + " (" +
219 col_name2 + " int)");
221 catch (com.sun.star.sdbc.SQLException e)
225 shortWait();
226 connection = isolConnection.getIsolatedConnection(user,
227 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 e2)
238 e2.printStackTrace(log);
239 throw new StatusException(Status.failed("SQLException"));
243 XQueryDefinitionsSupplier querySuppl = UnoRuntime.queryInterface(
244 XQueryDefinitionsSupplier.class,
245 oDBSource);
247 XNameAccess defContainer = querySuppl.getQueryDefinitions();
249 XPropertySet queryProp = UnoRuntime.queryInterface(
250 XPropertySet.class, newQuery);
254 final String query = "select * from " + tbl_name1 + ", " +
255 tbl_name2 + " where " + tbl_name1 + "." +
256 col_name1 + "=" + tbl_name2 + "." +
257 col_name2;
258 queryProp.setPropertyValue("Command", query);
260 catch (com.sun.star.lang.WrappedTargetException e)
262 e.printStackTrace(log);
263 throw new StatusException(Status.failed(
264 "Couldn't set property value"));
266 catch (com.sun.star.lang.IllegalArgumentException e)
268 e.printStackTrace(log);
269 throw new StatusException(Status.failed(
270 "Couldn't set property value"));
272 catch (com.sun.star.beans.PropertyVetoException e)
274 e.printStackTrace(log);
275 throw new StatusException(Status.failed(
276 "Couldn't set property value"));
278 catch (com.sun.star.beans.UnknownPropertyException e)
280 e.printStackTrace(log);
281 throw new StatusException(Status.failed(
282 "Couldn't set property value"));
285 XNameContainer queryContainer = UnoRuntime.queryInterface(
286 XNameContainer.class,
287 defContainer);
291 queryContainer.insertByName("Query1", newQuery);
292 store.store();
293 connection.close();
295 catch (com.sun.star.lang.WrappedTargetException e)
297 e.printStackTrace(log);
298 throw new StatusException(Status.failed("Couldn't insert query"));
300 catch (com.sun.star.container.ElementExistException e)
302 e.printStackTrace(log);
303 throw new StatusException(Status.failed("Couldn't insert query"));
305 catch (com.sun.star.lang.IllegalArgumentException e)
307 e.printStackTrace(log);
308 throw new StatusException(Status.failed("Couldn't insert query"));
310 catch (com.sun.star.io.IOException e)
312 e.printStackTrace(log);
313 throw new StatusException(Status.failed("Couldn't insert query"));
315 catch (com.sun.star.sdbc.SQLException e)
317 e.printStackTrace(log);
318 throw new StatusException(Status.failed("Couldn't insert query"));
321 PropertyValue[] loadProps = new PropertyValue[3];
322 loadProps[0] = new PropertyValue();
323 loadProps[0].Name = "QueryDesignView";
324 loadProps[0].Value = Boolean.TRUE;
326 loadProps[1] = new PropertyValue();
327 loadProps[1].Name = "CurrentQuery";
328 loadProps[1].Value = "Query1";
330 loadProps[2] = new PropertyValue();
331 loadProps[2].Name = "DataSource";
332 loadProps[2].Value = oDBSource;
334 QueryComponent = DesktopTools.loadDoc((XMultiServiceFactory) Param.getMSF(),".component:DB/QueryDesign",loadProps);
336 util.utils.shortWait(1000);
338 xWindow = UnoRuntime.queryInterface(XModel.class, QueryComponent).
339 getCurrentController().getFrame().getContainerWindow();
341 XAccessible xRoot = AccessibilityTools.getAccessibleObject(xWindow);
343 AccessibilityTools.printAccessibleTree (log,xRoot, Param.getBool(util.PropertyName.DEBUG_IS_ACTIVE));
345 oObj = AccessibilityTools.getAccessibleObjectForRoleIgnoreShowing(xRoot, AccessibleRole.UNKNOWN, "", "ConnectionLine");
347 log.println("ImplementationName " + util.utils.getImplName(oObj));
349 log.println("creating TestEnvironment");
351 TestEnvironment tEnv = new TestEnvironment(oObj);
353 shortWait();
355 final XWindow queryWin = xWindow;
357 tEnv.addObjRelation("EventProducer",
358 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer()
360 public void fireEvent()
362 Rectangle rect = queryWin.getPosSize();
363 queryWin.setPosSize(rect.X, rect.Y, rect.Height-5, rect.Width-5, PosSize.POSSIZE);
367 return tEnv;
368 } // finish method getTestEnvironment
371 * Closes the DatasourceAdministration dialog and Query Dialog.
373 protected void cleanup(TestParameters Param, PrintWriter log)
378 log.println("closing QueryComponent ...");
379 DesktopTools.closeDoc(QueryComponent);
380 log.println("... done");
381 XMultiServiceFactory xMSF = (XMultiServiceFactory)Param.getMSF();
382 Object sfa = xMSF.createInstance("com.sun.star.comp.ucb.SimpleFileAccess");
383 XSimpleFileAccess xSFA = UnoRuntime.queryInterface(XSimpleFileAccess.class, sfa);
384 log.println("deleting database file");
385 xSFA.kill(aFile);
386 log.println("Could delete file "+aFile+": "+!xSFA.exists(aFile));
388 catch (Exception e)
390 e.printStackTrace();
395 * Sleeps for 1.5 sec. to allow StarOffice to react on <code>
396 * reset</code> call.
398 private void shortWait()
402 Thread.sleep(1500);
404 catch (InterruptedException e)
406 log.println("While waiting :" + e);