tdf#130857 qt weld: Introduce QtInstanceScrolledWindow
[LibreOffice.git] / qadevOOo / tests / java / mod / _dbaccess / JoinViewAccessibility.java
blob499779ebf62992880c30907d3b7cef03936fe146
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 String aFile = "";
73 XIsolatedConnection isolConnection = null;
74 XComponent QueryComponent = null;
75 String user = "";
76 String password="";
78 /**
79 * Creates a new DataSource and stores it.
80 * Creates a connection and using it
81 * creates two tables in database.
82 * Creates a new query and adds it to DefinitionContainer.
83 * Opens the QueryComponent.with loadComponentFromURL
84 * and gets the object with the role UNKNOWN and the implementation
85 * name that contains ConnectionLine
86 * @param Param test parameters
87 * @param log writer to log information while testing
88 * @return
89 * @throws StatusException
90 * @see TestEnvironment
92 @Override
93 protected TestEnvironment createTestEnvironment (TestParameters Param,
94 PrintWriter log) throws Exception
96 XInterface oObj = null;
98 Param.getMSF().createInstance("com.sun.star.sdb.DatabaseContext");
99 Object oDBSource = Param.getMSF()
100 .createInstance("com.sun.star.sdb.DataSource");
101 Object newQuery = Param.getMSF().createInstance(
102 "com.sun.star.sdb.QueryDefinition");
103 Param.getMSF().createInstance("com.sun.star.awt.Toolkit");
105 String mysqlURL = (String) Param.get ("mysql.url");
107 if (mysqlURL == null)
109 throw new StatusException (Status.failed (
110 "Couldn't get 'mysql.url' from ini-file"));
113 user = (String) Param.get ("jdbc.user");
114 password = (String) Param.get ("jdbc.password");
116 if ((user == null) || (password == null))
118 throw new StatusException (Status.failed (
119 "Couldn't get 'jdbc.user' or 'jdbc.password' from ini-file"));
122 PropertyValue[] info = new PropertyValue[2];
123 info[0] = new PropertyValue ();
124 info[0].Name = "user";
125 info[0].Value = user;
126 info[1] = new PropertyValue ();
127 info[1].Name = "password";
128 info[1].Value = password;
130 XPropertySet propSetDBSource = UnoRuntime.queryInterface (
131 XPropertySet.class, oDBSource);
133 propSetDBSource.setPropertyValue ("URL", mysqlURL);
134 propSetDBSource.setPropertyValue ("Info", info);
136 log.println ("writing database file ...");
137 XDocumentDataSource xDDS = UnoRuntime.queryInterface(XDocumentDataSource.class, oDBSource);
138 XStorable store = UnoRuntime.queryInterface(XStorable.class,
139 xDDS.getDatabaseDocument());
140 aFile = utils.getOfficeTemp (Param.getMSF ())+"JoinView.odb";
141 log.println ("... filename will be "+aFile);
142 store.storeAsURL (aFile,new PropertyValue[]{});
143 log.println ("... done");
145 isolConnection = UnoRuntime.queryInterface (
146 XIsolatedConnection.class,
147 oDBSource);
149 final String tbl_name1 = "tst_table1";
150 final String tbl_name2 = "tst_table2";
151 final String col_name1 = "id1";
152 final String col_name2 = "id2";
154 util.utils.waitForEventIdle(Param.getMSF());
155 XConnection connection = isolConnection.getIsolatedConnection (user, password);
156 XStatement statement = connection.createStatement ();
157 statement.executeUpdate ("drop table if exists " + tbl_name1);
158 statement.executeUpdate ("drop table if exists " + tbl_name2);
159 statement.executeUpdate ("create table " + tbl_name1 + " (" +
160 col_name1 + " int)");
161 statement.executeUpdate ("create table " + tbl_name2 + " (" +
162 col_name2 + " int)");
164 XQueryDefinitionsSupplier querySuppl = UnoRuntime.queryInterface (
165 XQueryDefinitionsSupplier.class,
166 oDBSource);
168 XNameAccess defContainer = querySuppl.getQueryDefinitions ();
170 XPropertySet queryProp = UnoRuntime.queryInterface (
171 XPropertySet.class, newQuery);
173 final String query = "select * from " + tbl_name1 + ", " +
174 tbl_name2 + " where " + tbl_name1 + "." +
175 col_name1 + "=" + tbl_name2 + "." +
176 col_name2;
177 queryProp.setPropertyValue ("Command", query);
179 XNameContainer queryContainer = UnoRuntime.queryInterface (
180 XNameContainer.class,
181 defContainer);
183 queryContainer.insertByName ("Query1", newQuery);
184 store.store ();
185 connection.close ();
187 PropertyValue[] loadProps = new PropertyValue[3];
188 loadProps[0] = new PropertyValue ();
189 loadProps[0].Name = "QueryDesignView";
190 loadProps[0].Value = Boolean.TRUE;
192 loadProps[1] = new PropertyValue ();
193 loadProps[1].Name = "CurrentQuery";
194 loadProps[1].Value = "Query1";
196 loadProps[2] = new PropertyValue ();
197 loadProps[2].Name = "DataSource";
198 loadProps[2].Value = oDBSource;
200 QueryComponent = DesktopTools.loadDoc (Param.getMSF (),".component:DB/QueryDesign",loadProps);
202 xWindow = UnoRuntime.queryInterface(XModel.class, QueryComponent).
203 getCurrentController().getFrame().getContainerWindow();
205 XAccessible xRoot = AccessibilityTools.getAccessibleObject (xWindow);
207 AccessibilityTools.printAccessibleTree (log,xRoot, Param.getBool(util.PropertyName.DEBUG_IS_ACTIVE));
209 oObj = AccessibilityTools.getAccessibleObjectForRole(xRoot, AccessibleRole.VIEW_PORT);
211 log.println("ImplementationName " + util.utils.getImplName(oObj));
213 log.println("creating TestEnvironment");
215 TestEnvironment tEnv = new TestEnvironment(oObj);
217 util.utils.waitForEventIdle(Param.getMSF());
219 final XWindow queryWin = xWindow;
221 tEnv.addObjRelation("EventProducer",
222 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
223 public void fireEvent() {
224 Rectangle rect = queryWin.getPosSize();
225 queryWin.setPosSize(rect.X, rect.Y, rect.Height-5, rect.Width-5, PosSize.POSSIZE);
229 return tEnv;
230 } // finish method getTestEnvironment
233 * Closes the DatasourceAdministration dialog and Query Dialog.
235 @Override
236 protected void cleanup(TestParameters Param, PrintWriter log) {
240 log.println ("closing QueryComponent ...");
241 DesktopTools.closeDoc (QueryComponent);
242 log.println ("... done");
243 XMultiServiceFactory xMSF = Param.getMSF ();
244 Object sfa = xMSF.createInstance ("com.sun.star.comp.ucb.SimpleFileAccess");
245 XSimpleFileAccess xSFA = UnoRuntime.queryInterface (XSimpleFileAccess.class, sfa);
246 log.println ("deleting database file");
247 xSFA.kill (aFile);
248 log.println ("Could delete file "+aFile+": "+!xSFA.exists (aFile));
249 } catch (Exception e)
251 e.printStackTrace ();