Branch libreoffice-5-0-4
[LibreOffice.git] / qadevOOo / tests / java / mod / _dbaccess / ConnectionLineAccessibility.java
blobbfffdfd7ce3cc1fd6879dcde92239a59dc376c56
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 @Override
96 protected TestEnvironment createTestEnvironment(TestParameters Param,
97 PrintWriter log)
99 XInterface oObj = null;
101 Object oDBSource = null;
102 Object newQuery = null;
103 XStorable store = null;
107 Param.getMSF()
108 .createInstance("com.sun.star.sdb.DatabaseContext");
109 oDBSource = Param.getMSF()
110 .createInstance("com.sun.star.sdb.DataSource");
111 newQuery = Param.getMSF()
112 .createInstance("com.sun.star.sdb.QueryDefinition");
113 Param.getMSF()
114 .createInstance("com.sun.star.awt.Toolkit");
116 catch (com.sun.star.uno.Exception e)
118 throw new StatusException(e, 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 throw new StatusException(e, Status.failed(
157 "Couldn't set property value"));
159 catch (com.sun.star.lang.IllegalArgumentException e)
161 throw new StatusException(e, Status.failed(
162 "Couldn't set property value"));
164 catch (com.sun.star.beans.PropertyVetoException e)
166 throw new StatusException(e, Status.failed(
167 "Couldn't set property value"));
169 catch (com.sun.star.beans.UnknownPropertyException e)
171 throw new StatusException(e, Status.failed(
172 "Couldn't set property value"));
177 log.println("writing database file ...");
178 XDocumentDataSource xDDS = UnoRuntime.queryInterface(XDocumentDataSource.class, oDBSource);
179 store = UnoRuntime.queryInterface(XStorable.class,
180 xDDS.getDatabaseDocument());
182 aFile = utils.getOfficeTemp(Param.getMSF())+"ConnectionLine.odb";
183 log.println("... filename will be "+aFile);
184 store.storeAsURL(aFile,new PropertyValue[]
185 {});
186 log.println("... done");
188 catch (com.sun.star.uno.Exception e)
190 throw new StatusException(e, Status.failed("Couldn't register object"));
193 isolConnection = UnoRuntime.queryInterface(
194 XIsolatedConnection.class,
195 oDBSource);
197 XConnection connection = null;
198 XStatement statement = null;
200 final String tbl_name1 = "tst_table1";
201 final String tbl_name2 = "tst_table2";
202 final String col_name1 = "id1";
203 final String col_name2 = "id2";
207 connection = isolConnection.getIsolatedConnection(user, password);
208 statement = connection.createStatement();
209 statement.executeUpdate("drop table if exists " + tbl_name1);
210 statement.executeUpdate("drop table if exists " + tbl_name2);
211 statement.executeUpdate("create table " + tbl_name1 + " (" +
212 col_name1 + " int)");
213 statement.executeUpdate("create table " + tbl_name2 + " (" +
214 col_name2 + " int)");
216 catch (com.sun.star.sdbc.SQLException e)
220 util.utils.pause(1500);
221 connection = isolConnection.getIsolatedConnection(user,
222 password);
223 statement = connection.createStatement();
224 statement.executeUpdate("drop table if exists " + tbl_name1);
225 statement.executeUpdate("drop table if exists " + tbl_name2);
226 statement.executeUpdate("create table " + tbl_name1 + " (" +
227 col_name1 + " int)");
228 statement.executeUpdate("create table " + tbl_name2 + " (" +
229 col_name2 + " int)");
231 catch (com.sun.star.sdbc.SQLException e2)
233 throw new StatusException(e2, Status.failed("SQLException"));
237 XQueryDefinitionsSupplier querySuppl = UnoRuntime.queryInterface(
238 XQueryDefinitionsSupplier.class,
239 oDBSource);
241 XNameAccess defContainer = querySuppl.getQueryDefinitions();
243 XPropertySet queryProp = UnoRuntime.queryInterface(
244 XPropertySet.class, newQuery);
248 final String query = "select * from " + tbl_name1 + ", " +
249 tbl_name2 + " where " + tbl_name1 + "." +
250 col_name1 + "=" + tbl_name2 + "." +
251 col_name2;
252 queryProp.setPropertyValue("Command", query);
254 catch (com.sun.star.lang.WrappedTargetException e)
256 throw new StatusException(e, Status.failed(
257 "Couldn't set property value"));
259 catch (com.sun.star.lang.IllegalArgumentException e)
261 throw new StatusException(e, Status.failed(
262 "Couldn't set property value"));
264 catch (com.sun.star.beans.PropertyVetoException e)
266 throw new StatusException(e, Status.failed(
267 "Couldn't set property value"));
269 catch (com.sun.star.beans.UnknownPropertyException e)
271 throw new StatusException(e, Status.failed(
272 "Couldn't set property value"));
275 XNameContainer queryContainer = UnoRuntime.queryInterface(
276 XNameContainer.class,
277 defContainer);
281 queryContainer.insertByName("Query1", newQuery);
282 store.store();
283 connection.close();
285 catch (com.sun.star.lang.WrappedTargetException e)
287 throw new StatusException(e, Status.failed("Couldn't insert query"));
289 catch (com.sun.star.container.ElementExistException e)
291 throw new StatusException(e, Status.failed("Couldn't insert query"));
293 catch (com.sun.star.lang.IllegalArgumentException e)
295 throw new StatusException(e, Status.failed("Couldn't insert query"));
297 catch (com.sun.star.io.IOException e)
299 throw new StatusException(e, Status.failed("Couldn't insert query"));
301 catch (com.sun.star.sdbc.SQLException e)
303 throw new StatusException(e, Status.failed("Couldn't insert query"));
306 PropertyValue[] loadProps = new PropertyValue[3];
307 loadProps[0] = new PropertyValue();
308 loadProps[0].Name = "QueryDesignView";
309 loadProps[0].Value = Boolean.TRUE;
311 loadProps[1] = new PropertyValue();
312 loadProps[1].Name = "CurrentQuery";
313 loadProps[1].Value = "Query1";
315 loadProps[2] = new PropertyValue();
316 loadProps[2].Name = "DataSource";
317 loadProps[2].Value = oDBSource;
319 QueryComponent = DesktopTools.loadDoc(Param.getMSF(),".component:DB/QueryDesign",loadProps);
321 util.utils.pause(1000);
323 xWindow = UnoRuntime.queryInterface(XModel.class, QueryComponent).
324 getCurrentController().getFrame().getContainerWindow();
326 XAccessible xRoot = AccessibilityTools.getAccessibleObject(xWindow);
328 AccessibilityTools.printAccessibleTree (log,xRoot, Param.getBool(util.PropertyName.DEBUG_IS_ACTIVE));
330 oObj = AccessibilityTools.getAccessibleObjectForRoleIgnoreShowing(xRoot, AccessibleRole.UNKNOWN, "", "ConnectionLine");
332 log.println("ImplementationName " + util.utils.getImplName(oObj));
334 log.println("creating TestEnvironment");
336 TestEnvironment tEnv = new TestEnvironment(oObj);
338 util.utils.pause(1500);
340 final XWindow queryWin = xWindow;
342 tEnv.addObjRelation("EventProducer",
343 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer()
345 public void fireEvent()
347 Rectangle rect = queryWin.getPosSize();
348 queryWin.setPosSize(rect.X, rect.Y, rect.Height-5, rect.Width-5, PosSize.POSSIZE);
352 return tEnv;
353 } // finish method getTestEnvironment
356 * Closes the DatasourceAdministration dialog and Query Dialog.
358 @Override
359 protected void cleanup(TestParameters Param, PrintWriter log)
364 log.println("closing QueryComponent ...");
365 DesktopTools.closeDoc(QueryComponent);
366 log.println("... done");
367 XMultiServiceFactory xMSF = Param.getMSF();
368 Object sfa = xMSF.createInstance("com.sun.star.comp.ucb.SimpleFileAccess");
369 XSimpleFileAccess xSFA = UnoRuntime.queryInterface(XSimpleFileAccess.class, sfa);
370 log.println("deleting database file");
371 xSFA.kill(aFile);
372 log.println("Could delete file "+aFile+": "+!xSFA.exists(aFile));
374 catch (Exception e)
376 e.printStackTrace();