Branch libreoffice-5-0-4
[LibreOffice.git] / qadevOOo / tests / java / mod / _dbaccess / JoinViewAccessibility.java
blob4d944239d6e0c1c393a1a820537a6d7a184bf28d
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 JoinViewAccessibility extends TestCase {
71 XWindow xWindow = null;
72 Object oDBSource = null;
73 String aFile = "";
74 XConnection connection = null;
75 XIsolatedConnection isolConnection = null;
76 XComponent QueryComponent = null;
77 String user = "";
78 String password="";
80 /**
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
90 * @return
91 * @throws StatusException
92 * @see TestEnvironment
94 @Override
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 Param.getMSF ()
107 .createInstance ("com.sun.star.sdb.DatabaseContext");
108 oDBSource = Param.getMSF ()
109 .createInstance ("com.sun.star.sdb.DataSource");
110 newQuery = Param.getMSF ()
111 .createInstance ("com.sun.star.sdb.QueryDefinition");
112 Param.getMSF ()
113 .createInstance ("com.sun.star.awt.Toolkit");
114 } catch (com.sun.star.uno.Exception e)
116 throw new StatusException(e, 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 throw new StatusException(e, Status.failed("Couldn't set property value"));
154 } catch (com.sun.star.lang.IllegalArgumentException e)
156 throw new StatusException(e, Status.failed("Couldn't set property value"));
157 } catch (com.sun.star.beans.PropertyVetoException e)
159 throw new StatusException(e, Status.failed("Couldn't set property value"));
160 } catch (com.sun.star.beans.UnknownPropertyException e)
162 throw new StatusException(e, Status.failed("Couldn't set property value"));
167 log.println ("writing database file ...");
168 XDocumentDataSource xDDS = UnoRuntime.queryInterface(XDocumentDataSource.class, oDBSource);
169 store = UnoRuntime.queryInterface(XStorable.class,
170 xDDS.getDatabaseDocument());
171 aFile = utils.getOfficeTemp (Param.getMSF ())+"JoinView.odb";
172 log.println ("... filename will be "+aFile);
173 store.storeAsURL (aFile,new PropertyValue[]
174 {});
175 log.println ("... done");
176 } catch (com.sun.star.uno.Exception e)
178 throw new StatusException(e, Status.failed ("Couldn't register object"));
181 isolConnection = UnoRuntime.queryInterface (
182 XIsolatedConnection.class,
183 oDBSource);
185 XConnection connection = null;
186 XStatement statement = null;
188 final String tbl_name1 = "tst_table1";
189 final String tbl_name2 = "tst_table2";
190 final String col_name1 = "id1";
191 final String col_name2 = "id2";
195 connection = isolConnection.getIsolatedConnection (user, password);
196 statement = connection.createStatement ();
197 statement.executeUpdate ("drop table if exists " + tbl_name1);
198 statement.executeUpdate ("drop table if exists " + tbl_name2);
199 statement.executeUpdate ("create table " + tbl_name1 + " (" +
200 col_name1 + " int)");
201 statement.executeUpdate ("create table " + tbl_name2 + " (" +
202 col_name2 + " int)");
203 } catch (com.sun.star.sdbc.SQLException e)
207 util.utils.pause(1500);
208 connection = isolConnection.getIsolatedConnection (user,
209 password);
210 statement = connection.createStatement ();
211 statement.executeUpdate ("drop table if exists " + tbl_name1);
212 statement.executeUpdate ("drop table if exists " + tbl_name2);
213 statement.executeUpdate ("create table " + tbl_name1 + " (" +
214 col_name1 + " int)");
215 statement.executeUpdate ("create table " + tbl_name2 + " (" +
216 col_name2 + " int)");
217 } catch (com.sun.star.sdbc.SQLException e2)
219 throw new StatusException(e, Status.failed ("SQLException"));
223 XQueryDefinitionsSupplier querySuppl = UnoRuntime.queryInterface (
224 XQueryDefinitionsSupplier.class,
225 oDBSource);
227 XNameAccess defContainer = querySuppl.getQueryDefinitions ();
229 XPropertySet queryProp = UnoRuntime.queryInterface (
230 XPropertySet.class, newQuery);
234 final String query = "select * from " + tbl_name1 + ", " +
235 tbl_name2 + " where " + tbl_name1 + "." +
236 col_name1 + "=" + tbl_name2 + "." +
237 col_name2;
238 queryProp.setPropertyValue ("Command", query);
239 } catch (com.sun.star.lang.WrappedTargetException e)
241 throw new StatusException(e, Status.failed("Couldn't set property value"));
242 } catch (com.sun.star.lang.IllegalArgumentException e)
244 throw new StatusException(e, Status.failed("Couldn't set property value"));
245 } catch (com.sun.star.beans.PropertyVetoException e)
247 throw new StatusException(e, Status.failed("Couldn't set property value"));
248 } catch (com.sun.star.beans.UnknownPropertyException e)
250 throw new StatusException(e, Status.failed("Couldn't set property value"));
253 XNameContainer queryContainer = UnoRuntime.queryInterface (
254 XNameContainer.class,
255 defContainer);
259 queryContainer.insertByName ("Query1", newQuery);
260 store.store ();
261 connection.close ();
262 } catch (com.sun.star.lang.WrappedTargetException e)
264 throw new StatusException(e, Status.failed ("Couldn't insert query"));
265 } catch (com.sun.star.container.ElementExistException e)
267 throw new StatusException(e, Status.failed ("Couldn't insert query"));
268 } catch (com.sun.star.lang.IllegalArgumentException e)
270 throw new StatusException(e, Status.failed ("Couldn't insert query"));
271 } catch (com.sun.star.io.IOException e)
273 throw new StatusException(e, Status.failed ("Couldn't insert query"));
274 } catch (com.sun.star.sdbc.SQLException e)
276 throw new StatusException(e, Status.failed ("Couldn't insert query"));
279 PropertyValue[] loadProps = new PropertyValue[3];
280 loadProps[0] = new PropertyValue ();
281 loadProps[0].Name = "QueryDesignView";
282 loadProps[0].Value = Boolean.TRUE;
284 loadProps[1] = new PropertyValue ();
285 loadProps[1].Name = "CurrentQuery";
286 loadProps[1].Value = "Query1";
288 loadProps[2] = new PropertyValue ();
289 loadProps[2].Name = "DataSource";
290 loadProps[2].Value = oDBSource;
292 QueryComponent = DesktopTools.loadDoc (Param.getMSF (),".component:DB/QueryDesign",loadProps);
294 xWindow = UnoRuntime.queryInterface(XModel.class, QueryComponent).
295 getCurrentController().getFrame().getContainerWindow();
297 XAccessible xRoot = AccessibilityTools.getAccessibleObject (xWindow);
299 AccessibilityTools.printAccessibleTree (log,xRoot, Param.getBool(util.PropertyName.DEBUG_IS_ACTIVE));
301 oObj = AccessibilityTools.getAccessibleObjectForRole(xRoot, AccessibleRole.VIEW_PORT);
303 log.println("ImplementationName " + util.utils.getImplName(oObj));
305 log.println("creating TestEnvironment");
307 TestEnvironment tEnv = new TestEnvironment(oObj);
309 util.utils.pause(1500);
311 final XWindow queryWin = xWindow;
313 tEnv.addObjRelation("EventProducer",
314 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
315 public void fireEvent() {
316 Rectangle rect = queryWin.getPosSize();
317 queryWin.setPosSize(rect.X, rect.Y, rect.Height-5, rect.Width-5, PosSize.POSSIZE);
321 return tEnv;
322 } // finish method getTestEnvironment
325 * Closes the DatasourceAdministration dialog and Query Dialog.
327 @Override
328 protected void cleanup(TestParameters Param, PrintWriter log) {
332 log.println ("closing QueryComponent ...");
333 DesktopTools.closeDoc (QueryComponent);
334 log.println ("... done");
335 XMultiServiceFactory xMSF = Param.getMSF ();
336 Object sfa = xMSF.createInstance ("com.sun.star.comp.ucb.SimpleFileAccess");
337 XSimpleFileAccess xSFA = UnoRuntime.queryInterface (XSimpleFileAccess.class, sfa);
338 log.println ("deleting database file");
339 xSFA.kill (aFile);
340 log.println ("Could delete file "+aFile+": "+!xSFA.exists (aFile));
341 } catch (Exception e)
343 e.printStackTrace ();