bump product version to 5.0.4.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _dbaccess / ODatasourceBrowser.java
blob3fb3287d95cf2b8ad39669913c5d69fa7b6efda8
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.StatusException;
23 import lib.TestCase;
24 import lib.TestEnvironment;
25 import lib.TestParameters;
26 import util.DesktopTools;
27 import util.FormTools;
28 import util.SOfficeFactory;
29 import util.WriterTools;
31 import com.sun.star.awt.XControl;
32 import com.sun.star.awt.XControlModel;
33 import com.sun.star.awt.XWindow;
34 import com.sun.star.beans.PropertyValue;
35 import com.sun.star.drawing.XControlShape;
36 import com.sun.star.frame.XController;
37 import com.sun.star.frame.XDesktop;
38 import com.sun.star.frame.XDispatch;
39 import com.sun.star.frame.XDispatchProvider;
40 import com.sun.star.frame.XFrame;
41 import com.sun.star.frame.XModel;
42 import com.sun.star.lang.XInitialization;
43 import com.sun.star.text.XTextDocument;
44 import com.sun.star.uno.UnoRuntime;
45 import com.sun.star.uno.XInterface;
46 import com.sun.star.util.URL;
47 import com.sun.star.util.XCloseable;
48 import com.sun.star.view.XControlAccess;
51 /**
52 * Test for object which is represented by service
53 * <code>com.sun.star.sdb.DataSourceBrowser</code>. <p>
54 * Object implements the following interfaces :
55 * <ul>
56 * <li> <code>com::sun::star::container::XChild</code></li>
57 * <li> <code>com::sun::star::lang::XInitialization</code></li>
58 * <li> <code>com::sun::star::util::XModifyBroadcaster</code></li>
59 * <li> <code>com::sun::star::awt::XTabController</code></li>
60 * <li> <code>com::sun::star::form::XFormController</code></li>
61 * <li> <code>com::sun::star::container::XElementAccess</code></li>
62 * <li> <code>com::sun::star::frame::XDispatchProvider</code></li>
63 * <li> <code>com::sun::star::container::XEnumerationAccess</code></li>
64 * <li> <code>com::sun::star::frame::XController</code></li>
65 * <li> <code>com::sun::star::lang::XComponent</code></li>
66 * </ul> <p>
67 * This object test <b> is NOT </b> designed to be run in several
68 * threads concurently.
70 * @see com.sun.star.container.XChild
71 * @see com.sun.star.lang.XInitialization
72 * @see com.sun.star.util.XModifyBroadcaster
73 * @see com.sun.star.awt.XTabController
74 * @see com.sun.star.form.XFormController
75 * @see com.sun.star.container.XElementAccess
76 * @see com.sun.star.frame.XDispatchProvider
77 * @see com.sun.star.container.XEnumerationAccess
78 * @see com.sun.star.frame.XController
79 * @see com.sun.star.lang.XComponent
80 * @see ifc.container._XChild
81 * @see ifc.lang._XInitialization
82 * @see ifc.util._XModifyBroadcaster
83 * @see ifc.awt._XTabController
84 * @see ifc.form._XFormController
85 * @see ifc.container._XElementAccess
86 * @see ifc.frame._XDispatchProvider
87 * @see ifc.container._XEnumerationAccess
88 * @see ifc.frame._XController
89 * @see ifc.lang._XComponent
91 public class ODatasourceBrowser extends TestCase {
92 XDesktop the_Desk;
93 XTextDocument xTextDoc;
95 /**
96 * Creates the Desktop service (<code>com.sun.star.frame.Desktop</code>).
98 @Override
99 protected void initialize(TestParameters Param, PrintWriter log) {
100 the_Desk = UnoRuntime.queryInterface(XDesktop.class,
101 DesktopTools.createDesktop(
102 Param.getMSF()));
103 System.setProperty("hideMe", "false");
107 * Disposes the document, if exists, created in
108 * <code>createTestEnvironment</code> method.
110 @Override
111 protected void cleanup(TestParameters Param, PrintWriter log) {
112 log.println("disposing xTextDoc");
113 System.setProperty("hideMe", "true");
115 if (xTextDoc != null) {
116 log.println(" disposing xTextDoc ");
118 try {
119 XCloseable closer = UnoRuntime.queryInterface(
120 XCloseable.class, xTextDoc);
121 closer.close(true);
122 } catch (com.sun.star.util.CloseVetoException e) {
123 log.println("couldn't close document");
124 } catch (com.sun.star.lang.DisposedException e) {
125 log.println("couldn't close document");
131 * Creating a Testenvironment for the interfaces to be tested.
133 * Creates a new text document disposing the old one if it was
134 * created. Using <code>Desktop</code> service get the frame
135 * of the document and with its help creates
136 * <code>DataSourceBrowser</code> dispatching the URL
137 * <code>'.component:DB/DataSourceBrowser'</code>. The
138 * component for testing is the controller of the
139 * <code>Browser</code> and it's got by searching its
140 * frame with the help of TextDocument frame, and obtaining
141 * the frame's controller. <p>
143 * <b>Note</b>: after creating the text document a short
144 * pause is needed to give a possibility to a frame to be
145 * created for the document. Else
146 * <code>Desktop.getCurrentFrame()</code> method can return
147 * <code>null</code> value. <p>
149 * Object relations created :
150 * <ul>
151 * <li> <code>'XDispatchProvider.URL'</code> for
152 * {@link ifc.frame._XDispatchProvider} </li>
153 * <li> <code>'SecondModel'</code> for
154 * {@link ifc.frame._XController} : the model of
155 * the TextDocument. </li>
156 * <li> <code>'otherWindow'</code> for
157 * {@link ifc.frame._XController} : the window of
158 * the added shape. </li>
159 * <li> <code>'SecondController'</code> for
160 * {@link ifc.frame._XController} : the controller of
161 * the TextDocument. </li>
162 * <li> <code>'HasViewData'</code> for
163 * {@link ifc.frame._XController} : the
164 * <code>DataSourceBrowser</code> has no view data. </li>
165 * <li> <code>'XInitialization.args'</code> for
166 * {@link ifc.lang._XInitialization} : the arguments for
167 * tbe initialization</li>
168 * </ul>
170 * @see com.sun.star.frame.Desktop
171 * @see com.sun.star.frame.XModel
172 * @see com.sun.star.frame.XFrame
173 * @see com.sun.star.frame.XController
174 * @see com.sun.star.frame.XDispatchProvider
176 @Override
177 protected synchronized TestEnvironment createTestEnvironment(TestParameters Param,
178 PrintWriter log) {
179 log.println("creating a test environment");
181 if (xTextDoc != null) {
182 log.println(" disposing xTextDoc ");
184 try {
185 XCloseable closer = UnoRuntime.queryInterface(
186 XCloseable.class, xTextDoc);
187 closer.close(true);
188 } catch (com.sun.star.util.CloseVetoException e) {
189 log.println("couldn't close document");
190 } catch (com.sun.star.lang.DisposedException e) {
191 log.println("couldn't close document");
195 // get a soffice factory object
196 SOfficeFactory SOF = SOfficeFactory.getFactory((Param.getMSF()));
198 try {
199 log.println("creating a text document");
200 xTextDoc = SOF.createTextDoc(null);
201 } catch (com.sun.star.uno.Exception e) {
202 // Some exception occurs.FAILED
203 e.printStackTrace(log);
204 throw new StatusException("Couldn't create document", e);
207 util.utils.pause(5000);
209 XModel aModel1 = UnoRuntime.queryInterface(XModel.class,
210 xTextDoc);
212 XController secondController = aModel1.getCurrentController();
214 XFrame the_frame1 = the_Desk.getCurrentFrame();
216 if (the_frame1 == null) {
217 log.println("Current frame was not found !!!");
220 XDispatchProvider aProv = UnoRuntime.queryInterface(
221 XDispatchProvider.class, the_frame1);
223 XDispatch getting = null;
225 log.println("opening DatasourceBrowser");
227 URL the_url = new URL();
228 the_url.Complete = ".component:DB/DataSourceBrowser";
229 getting = aProv.queryDispatch(the_url, "_beamer", 12);
231 PropertyValue[] noArgs = new PropertyValue[0];
232 getting.dispatch(the_url, noArgs);
234 XFrame the_frame2 = the_frame1.findFrame("_beamer", 4);
236 the_frame2.setName("DatasourceBrowser");
238 XInterface oObj = the_frame2.getController();
240 Object[] params = new Object[3];
241 PropertyValue param1 = new PropertyValue();
242 param1.Name = "DataSourceName";
243 param1.Value = "Bibliography";
244 params[0] = param1;
246 PropertyValue param2 = new PropertyValue();
247 param2.Name = "CommandType";
248 param2.Value = Integer.valueOf(com.sun.star.sdb.CommandType.TABLE);
249 params[1] = param2;
251 PropertyValue param3 = new PropertyValue();
252 param3.Name = "Command";
253 param3.Value = "biblio";
254 params[2] = param3;
256 try {
257 XInitialization xInit = UnoRuntime.queryInterface(
258 XInitialization.class, oObj);
259 xInit.initialize(params);
260 } catch (com.sun.star.uno.Exception e) {
261 // Some exception occurs.FAILED
262 e.printStackTrace(log);
263 throw new StatusException("Couldn't initialize document", e);
266 util.utils.pause(5000);
268 XControlShape aShape = FormTools.createControlShape(xTextDoc, 3000,
269 4500, 15000, 10000,
270 "CommandButton");
271 WriterTools.getDrawPage(xTextDoc).add(aShape);
273 XControlModel shapeModel = aShape.getControl();
275 XControlAccess xCtrlAccess = UnoRuntime.queryInterface(
276 XControlAccess.class,
277 secondController);
278 XControl xCtrl = null;
280 try {
281 xCtrl = xCtrlAccess.getControl(shapeModel);
282 } catch (com.sun.star.uno.Exception e) {
283 // Some exception occurs.FAILED
284 e.printStackTrace(log);
287 XWindow docWindow = UnoRuntime.queryInterface(XWindow.class,
288 xCtrl);
289 log.println("creating a new environment for ODatasourceBrowser object");
291 TestEnvironment tEnv = new TestEnvironment(oObj);
294 //Adding ObjRelations for XInitialization
295 tEnv.addObjRelation("XInitialization.args", params);
298 //Adding ObjRelations for XController
299 tEnv.addObjRelation("Frame", the_frame1);
300 tEnv.addObjRelation("SecondModel", aModel1);
301 tEnv.addObjRelation("otherWindow", docWindow);
302 tEnv.addObjRelation("SecondController", secondController);
303 tEnv.addObjRelation("HasViewData", Boolean.FALSE);
306 // Addig relation for XDispatchProvider
307 tEnv.addObjRelation("XDispatchProvider.URL",
308 ".uno:DataSourceBrowser/FormLetter");
310 return tEnv;
311 } // finish method getTestEnvironment
312 } // finish class oDatasourceBrowser