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
;
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
.lang
.XMultiServiceFactory
;
44 import com
.sun
.star
.text
.XTextDocument
;
45 import com
.sun
.star
.uno
.UnoRuntime
;
46 import com
.sun
.star
.uno
.XInterface
;
47 import com
.sun
.star
.util
.URL
;
48 import com
.sun
.star
.util
.XCloseable
;
49 import com
.sun
.star
.view
.XControlAccess
;
53 * Test for object which is represented by service
54 * <code>com.sun.star.sdb.DataSourceBrowser</code>. <p>
55 * Object implements the following interfaces :
57 * <li> <code>com::sun::star::container::XChild</code></li>
58 * <li> <code>com::sun::star::lang::XInitialization</code></li>
59 * <li> <code>com::sun::star::util::XModifyBroadcaster</code></li>
60 * <li> <code>com::sun::star::awt::XTabController</code></li>
61 * <li> <code>com::sun::star::form::XFormController</code></li>
62 * <li> <code>com::sun::star::container::XElementAccess</code></li>
63 * <li> <code>com::sun::star::frame::XDispatchProvider</code></li>
64 * <li> <code>com::sun::star::container::XEnumerationAccess</code></li>
65 * <li> <code>com::sun::star::frame::XController</code></li>
66 * <li> <code>com::sun::star::lang::XComponent</code></li>
68 * This object test <b> is NOT </b> designed to be run in several
69 * threads concurently.
71 * @see com.sun.star.container.XChild
72 * @see com.sun.star.lang.XInitialization
73 * @see com.sun.star.util.XModifyBroadcaster
74 * @see com.sun.star.awt.XTabController
75 * @see com.sun.star.form.XFormController
76 * @see com.sun.star.container.XElementAccess
77 * @see com.sun.star.frame.XDispatchProvider
78 * @see com.sun.star.container.XEnumerationAccess
79 * @see com.sun.star.frame.XController
80 * @see com.sun.star.lang.XComponent
81 * @see ifc.container._XChild
82 * @see ifc.lang._XInitialization
83 * @see ifc.util._XModifyBroadcaster
84 * @see ifc.awt._XTabController
85 * @see ifc.form._XFormController
86 * @see ifc.container._XElementAccess
87 * @see ifc.frame._XDispatchProvider
88 * @see ifc.container._XEnumerationAccess
89 * @see ifc.frame._XController
90 * @see ifc.lang._XComponent
92 public class ODatasourceBrowser
extends TestCase
{
94 XTextDocument xTextDoc
;
97 * Creates the Desktop service (<code>com.sun.star.frame.Desktop</code>).
99 protected void initialize(TestParameters Param
, PrintWriter log
) {
100 the_Desk
= UnoRuntime
.queryInterface(XDesktop
.class,
101 DesktopTools
.createDesktop(
102 (XMultiServiceFactory
)Param
.getMSF()));
103 System
.setProperty("hideMe", "false");
107 * Disposes the document, if exists, created in
108 * <code>createTestEnvironment</code> method.
110 protected void cleanup(TestParameters Param
, PrintWriter log
) {
111 log
.println("disposing xTextDoc");
112 System
.setProperty("hideMe", "true");
114 if (xTextDoc
!= null) {
115 log
.println(" disposing xTextDoc ");
118 XCloseable closer
= UnoRuntime
.queryInterface(
119 XCloseable
.class, xTextDoc
);
121 } catch (com
.sun
.star
.util
.CloseVetoException e
) {
122 log
.println("couldn't close document");
123 } catch (com
.sun
.star
.lang
.DisposedException e
) {
124 log
.println("couldn't close document");
130 * Creating a Testenvironment for the interfaces to be tested.
132 * Creates a new text document disposing the old one if it was
133 * created. Using <code>Desktop</code> service get the frame
134 * of the document and with its help creates
135 * <code>DataSourceBrowser</code> dispatching the URL
136 * <code>'.component:DB/DataSourceBrowser'</code>. The
137 * component for testing is the controller of the
138 * <code>Browser</code> and it's got by searching its
139 * frame with the help of TextDocument frame, and obtaining
140 * the frame's controller. <p>
142 * <b>Note</b>: after creating the text document a short
143 * pause is needed to give a possibility to a frame to be
144 * created for the document. Else
145 * <code>Desktop.getCurrentFrame()</code> method can return
146 * <code>null</code> value. <p>
148 * Object relations created :
150 * <li> <code>'XDispatchProvider.URL'</code> for
151 * {@link ifc.frame._XDispatchProvider} </li>
152 * <li> <code>'SecondModel'</code> for
153 * {@link ifc.frame._XController} : the model of
154 * the TextDocument. </li>
155 * <li> <code>'otherWindow'</code> for
156 * {@link ifc.frame._XController} : the window of
157 * the added shape. </li>
158 * <li> <code>'SecondController'</code> for
159 * {@link ifc.frame._XController} : the controller of
160 * the TextDocument. </li>
161 * <li> <code>'HasViewData'</code> for
162 * {@link ifc.frame._XController} : the
163 * <code>DataSourceBrowser</code> has no view data. </li>
164 * <li> <code>'XInitialization.args'</code> for
165 * {@link ifc.lang._XInitialization} : the arguments for
166 * tbe initialization</li>
169 * @see com.sun.star.frame.Desktop
170 * @see com.sun.star.frame.XModel
171 * @see com.sun.star.frame.XFrame
172 * @see com.sun.star.frame.XController
173 * @see com.sun.star.frame.XDispatchProvider
175 protected synchronized TestEnvironment
createTestEnvironment(TestParameters Param
,
177 log
.println("creating a test environment");
179 if (xTextDoc
!= null) {
180 log
.println(" disposing xTextDoc ");
183 XCloseable closer
= UnoRuntime
.queryInterface(
184 XCloseable
.class, xTextDoc
);
186 } catch (com
.sun
.star
.util
.CloseVetoException e
) {
187 log
.println("couldn't close document");
188 } catch (com
.sun
.star
.lang
.DisposedException e
) {
189 log
.println("couldn't close document");
193 // get a soffice factory object
194 SOfficeFactory SOF
= SOfficeFactory
.getFactory(((XMultiServiceFactory
) Param
.getMSF()));
197 log
.println("creating a text document");
198 xTextDoc
= SOF
.createTextDoc(null);
199 } catch (com
.sun
.star
.uno
.Exception e
) {
200 // Some exception occurs.FAILED
201 e
.printStackTrace(log
);
202 throw new StatusException("Couldn't create document", e
);
207 XModel aModel1
= UnoRuntime
.queryInterface(XModel
.class,
210 XController secondController
= aModel1
.getCurrentController();
212 XFrame the_frame1
= the_Desk
.getCurrentFrame();
214 if (the_frame1
== null) {
215 log
.println("Current frame was not found !!!");
218 XDispatchProvider aProv
= UnoRuntime
.queryInterface(
219 XDispatchProvider
.class, the_frame1
);
221 XDispatch getting
= null;
223 log
.println("opening DatasourceBrowser");
225 URL the_url
= new URL();
226 the_url
.Complete
= ".component:DB/DataSourceBrowser";
227 getting
= aProv
.queryDispatch(the_url
, "_beamer", 12);
229 PropertyValue
[] noArgs
= new PropertyValue
[0];
230 getting
.dispatch(the_url
, noArgs
);
232 XFrame the_frame2
= the_frame1
.findFrame("_beamer", 4);
234 the_frame2
.setName("DatasourceBrowser");
236 XInterface oObj
= the_frame2
.getController();
238 Object
[] params
= new Object
[3];
239 PropertyValue param1
= new PropertyValue();
240 param1
.Name
= "DataSourceName";
241 param1
.Value
= "Bibliography";
244 PropertyValue param2
= new PropertyValue();
245 param2
.Name
= "CommandType";
246 param2
.Value
= new Integer(com
.sun
.star
.sdb
.CommandType
.TABLE
);
249 PropertyValue param3
= new PropertyValue();
250 param3
.Name
= "Command";
251 param3
.Value
= "biblio";
255 XInitialization xInit
= UnoRuntime
.queryInterface(
256 XInitialization
.class, oObj
);
257 xInit
.initialize(params
);
258 } catch (com
.sun
.star
.uno
.Exception e
) {
259 // Some exception occurs.FAILED
260 e
.printStackTrace(log
);
261 throw new StatusException("Couldn't initialize document", e
);
266 XControlShape aShape
= FormTools
.createControlShape(xTextDoc
, 3000,
269 WriterTools
.getDrawPage(xTextDoc
).add(aShape
);
271 XControlModel shapeModel
= aShape
.getControl();
273 XControlAccess xCtrlAccess
= UnoRuntime
.queryInterface(
274 XControlAccess
.class,
276 XControl xCtrl
= null;
279 xCtrl
= xCtrlAccess
.getControl(shapeModel
);
280 } catch (com
.sun
.star
.uno
.Exception e
) {
281 // Some exception occurs.FAILED
282 e
.printStackTrace(log
);
285 XWindow docWindow
= UnoRuntime
.queryInterface(XWindow
.class,
287 log
.println("creating a new environment for ODatasourceBrowser object");
289 TestEnvironment tEnv
= new TestEnvironment(oObj
);
292 //Adding ObjRelations for XInitialization
293 tEnv
.addObjRelation("XInitialization.args", params
);
296 //Adding ObjRelations for XController
297 tEnv
.addObjRelation("Frame", the_frame1
);
298 tEnv
.addObjRelation("SecondModel", aModel1
);
299 tEnv
.addObjRelation("otherWindow", docWindow
);
300 tEnv
.addObjRelation("SecondController", secondController
);
301 tEnv
.addObjRelation("HasViewData", new Boolean(false));
304 // Addig relation for XDispatchProvider
305 tEnv
.addObjRelation("XDispatchProvider.URL",
306 ".uno:DataSourceBrowser/FormLetter");
309 } // finish method getTestEnvironment
312 * Sleeps for 0.2 sec. to allow StarOffice to react on <code>
315 private void shortWait() {
318 } catch (InterruptedException e
) {
319 System
.out
.println("While waiting :" + e
);
322 } // finish class oDatasourceBrowser