Branch libreoffice-5-0-4
[LibreOffice.git] / qadevOOo / tests / java / mod / _forms / ODatabaseForm.java
blob72755f0cc44941c052dbf7cbab007480de5b6e4c
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._forms;
20 import ifc.form._XDatabaseParameterBroadcaster;
21 import ifc.sdb._XCompletedExecution;
23 import java.io.PrintWriter;
24 import java.util.ArrayList;
25 import lib.Status;
26 import lib.StatusException;
27 import lib.TestCase;
28 import lib.TestEnvironment;
29 import lib.TestParameters;
30 import util.DBTools;
31 import util.DrawTools;
32 import util.FormTools;
33 import util.WriterTools;
34 import util.utils;
36 import com.sun.star.awt.XControl;
37 import com.sun.star.awt.XControlModel;
38 import com.sun.star.beans.PropertyValue;
39 import com.sun.star.beans.XPropertySet;
40 import com.sun.star.container.XIndexAccess;
41 import com.sun.star.container.XNameContainer;
42 import com.sun.star.container.XNamed;
43 import com.sun.star.drawing.XControlShape;
44 import com.sun.star.drawing.XShapes;
45 import com.sun.star.form.DatabaseParameterEvent;
46 import com.sun.star.form.XForm;
47 import com.sun.star.form.XLoadable;
48 import com.sun.star.lang.EventObject;
49 import com.sun.star.sdb.CommandType;
50 import com.sun.star.sdb.ParametersRequest;
51 import com.sun.star.sdb.RowChangeEvent;
52 import com.sun.star.sdbc.SQLException;
53 import com.sun.star.sdbc.XConnection;
54 import com.sun.star.sdbc.XResultSet;
55 import com.sun.star.sdbc.XResultSetUpdate;
56 import com.sun.star.sdbc.XRow;
57 import com.sun.star.sdbc.XRowSet;
58 import com.sun.star.sdbc.XRowUpdate;
59 import com.sun.star.task.XInteractionRequest;
60 import com.sun.star.text.XTextDocument;
61 import com.sun.star.uno.AnyConverter;
62 import com.sun.star.uno.Type;
63 import com.sun.star.uno.UnoRuntime;
64 import com.sun.star.uno.XInterface;
65 import com.sun.star.util.Date;
66 import com.sun.star.util.DateTime;
67 import com.sun.star.util.Time;
68 import com.sun.star.util.XCloseable;
69 import com.sun.star.view.XControlAccess;
72 /**
73 * Test for object which is represented by service
74 * <code>com.sun.star.form.component.DatabaseForm</code>. <p>
76 * Object implements the following interfaces :
77 * <ul>
78 * <li> <code>com::sun::star::script::XEventAttacherManager</code></li>
79 * <li> <code>com::sun::star::container::XElementAccess</code></li>
80 * <li> <code>com::sun::star::sdbcx::ResultSet</code></li>
81 * <li> <code>com::sun::star::container::XChild</code></li>
82 * <li> <code>com::sun::star::sdbc::XResultSetUpdate</code></li>
83 * <li> <code>com::sun::star::sdb::XResultSetAccess</code></li>
84 * <li> <code>com::sun::star::form::FormComponent</code></li>
85 * <li> <code>com::sun::star::form::component::DataForm</code></li>
86 * <li> <code>com::sun::star::sdbc::XResultSetMetaDataSupplier</code></li>
87 * <li> <code>com::sun::star::container::XEnumerationAccess</code></li>
88 * <li> <code>com::sun::star::sdbcx::XDeleteRows</code></li>
89 * <li> <code>com::sun::star::sdb::RowSet</code></li>
90 * <li> <code>com::sun::star::lang::XComponent</code></li>
91 * <li> <code>com::sun::star::sdbc::XRowSet</code></li>
92 * <li> <code>com::sun::star::sdbc::XRowUpdate</code></li>
93 * <li> <code>com::sun::star::form::XLoadable</code></li>
94 * <li> <code>com::sun::star::container::XNamed</code></li>
95 * <li> <code>com::sun::star::container::XIndexReplace</code></li>
96 * <li> <code>com::sun::star::io::XPersistObject</code></li>
97 * <li> <code>com::sun::star::container::XNameReplace</code></li>
98 * <li> <code>com::sun::star::container::XIndexContainer</code></li>
99 * <li> <code>com::sun::star::container::XNameAccess</code></li>
100 * <li> <code>com::sun::star::sdbc::XParameters</code></li>
101 * <li> <code>com::sun::star::util::XCancellable</code></li>
102 * <li> <code>com::sun::star::form::XReset</code></li>
103 * <li> <code>com::sun::star::sdbc::XCloseable</code></li>
104 * <li> <code>com::sun::star::sdbcx::XColumnsSupplier</code></li>
105 * <li> <code>com::sun::star::sdb::XRowSetApproveBroadcaster</code></li>
106 * <li> <code>com::sun::star::sdbc::ResultSet</code></li>
107 * <li> <code>com::sun::star::sdbc::XResultSet</code></li>
108 * <li> <code>com::sun::star::sdbc::XRow</code></li>
109 * <li> <code>com::sun::star::sdbc::XColumnLocate</code></li>
110 * <li> <code>com::sun::star::awt::XTabControllerModel</code></li>
111 * <li> <code>com::sun::star::container::XIndexAccess</code></li>
112 * <li> <code>com::sun::star::form::XSubmit</code></li>
113 * <li> <code>com::sun::star::form::component::HTMLForm</code></li>
114 * <li> <code>com::sun::star::sdbcx::XRowLocate</code></li>
115 * <li> <code>com::sun::star::sdbc::XWarningsSupplier</code></li>
116 * <li> <code>com::sun::star::container::XNameContainer</code></li>
117 * <li> <code>com::sun::star::beans::XPropertyAccess</code></li>
118 * <li> <code>com::sun::star::beans::XPropertyContainer</code></li>
119 * <li> <code>com::sun::star::beans::XPropertySet</code></li>
120 * <li> <code>com::sun::star::sdbc::RowSet</code></li>
121 * </ul> <p>
123 * This object test <b> is NOT </b> designed to be run in several
124 * threads concurently.
125 * The following parameters in ini-file used by this test:
126 * <ul>
127 * <li><code>test.db.url</code> - URL to MySQL database.
128 * For example: <code>mysql://mercury:3306/api_current</code></li>
129 * <li><code>test.db.user</code> - user for MySQL database</li>
130 * <li><code>test.db.password</code> - password for MySQL database</li>
131 * </ul><p>
133 * @see com.sun.star.script.XEventAttacherManager
134 * @see com.sun.star.container.XElementAccess
135 * @see com.sun.star.sdbcx.ResultSet
136 * @see com.sun.star.container.XChild
137 * @see com.sun.star.sdbc.XResultSetUpdate
138 * @see com.sun.star.sdb.XResultSetAccess
139 * @see com.sun.star.form.FormComponent
140 * @see com.sun.star.form.component.DataForm
141 * @see com.sun.star.sdbc.XResultSetMetaDataSupplier
142 * @see com.sun.star.container.XEnumerationAccess
143 * @see com.sun.star.sdbcx.XDeleteRows
144 * @see com.sun.star.sdb.RowSet
145 * @see com.sun.star.lang.XComponent
146 * @see com.sun.star.sdbc.XRowSet
147 * @see com.sun.star.sdbc.XRowUpdate
148 * @see com.sun.star.form.XLoadable
149 * @see com.sun.star.container.XNamed
150 * @see com.sun.star.container.XIndexReplace
151 * @see com.sun.star.io.XPersistObject
152 * @see com.sun.star.container.XNameReplace
153 * @see com.sun.star.container.XIndexContainer
154 * @see com.sun.star.container.XNameAccess
155 * @see com.sun.star.sdbc.XParameters
156 * @see com.sun.star.util.XCancellable
157 * @see com.sun.star.form.XReset
158 * @see com.sun.star.sdbc.XCloseable
159 * @see com.sun.star.sdbcx.XColumnsSupplier
160 * @see com.sun.star.sdb.XRowSetApproveBroadcaster
161 * @see com.sun.star.sdbc.ResultSet
162 * @see com.sun.star.sdbc.XResultSet
163 * @see com.sun.star.sdbc.XRow
164 * @see com.sun.star.sdbc.XColumnLocate
165 * @see com.sun.star.awt.XTabControllerModel
166 * @see com.sun.star.container.XIndexAccess
167 * @see com.sun.star.form.XSubmit
168 * @see com.sun.star.form.component.HTMLForm
169 * @see com.sun.star.sdbcx.XRowLocate
170 * @see com.sun.star.sdbc.XWarningsSupplier
171 * @see com.sun.star.container.XNameContainer
172 * @see com.sun.star.beans.XPropertySet
173 * @see com.sun.star.sdbc.RowSet
174 * @see ifc.script._XEventAttacherManager
175 * @see ifc.container._XElementAccess
176 * @see ifc.sdbcx._ResultSet
177 * @see ifc.container._XChild
178 * @see ifc.sdbc._XResultSetUpdate
179 * @see ifc.sdb._XResultSetAccess
180 * @see ifc.form._FormComponent
181 * @see ifc.form.component._DataForm
182 * @see ifc.sdbc._XResultSetMetaDataSupplier
183 * @see ifc.container._XEnumerationAccess
184 * @see ifc.sdbcx._XDeleteRows
185 * @see ifc.sdb._RowSet
186 * @see ifc.lang._XComponent
187 * @see ifc.sdbc._XRowSet
188 * @see ifc.sdbc._XRowUpdate
189 * @see ifc.form._XLoadable
190 * @see ifc.container._XNamed
191 * @see ifc.container._XIndexReplace
192 * @see ifc.io._XPersistObject
193 * @see ifc.container._XNameReplace
194 * @see ifc.container._XIndexContainer
195 * @see ifc.container._XNameAccess
196 * @see ifc.sdbc._XParameters
197 * @see ifc.util._XCancellable
198 * @see ifc.form._XReset
199 * @see ifc.sdbc._XCloseable
200 * @see ifc.sdbcx._XColumnsSupplier
201 * @see ifc.sdb._XRowSetApproveBroadcaster
202 * @see ifc.sdbc._ResultSet
203 * @see ifc.sdbc._XResultSet
204 * @see ifc.sdbc._XRow
205 * @see ifc.sdbc._XColumnLocate
206 * @see ifc.awt._XTabControllerModel
207 * @see ifc.container._XIndexAccess
208 * @see ifc.form._XSubmit
209 * @see ifc.form.component._HTMLForm
210 * @see ifc.sdbcx._XRowLocate
211 * @see ifc.sdbc._XWarningsSupplier
212 * @see ifc.container._XNameContainer
213 * @see ifc.beans._XPropertyAccess
214 * @see ifc.beans._XPropertyContainer
215 * @see ifc.beans._XPropertySet
216 * @see ifc.sdbc._RowSet
218 public class ODatabaseForm extends TestCase {
219 protected final static String dbSourceName = "ODatabaseFormDataSource";
220 private static int uniqueSuffix = 0;
221 private static String origDB = null;
222 private static String tmpDir = null;
223 protected XTextDocument xTextDoc = null;
224 private DBTools dbTools = null;
225 String tableName = null;
226 DBTools.DataSourceInfo srcInf = null;
227 boolean isMySQLDB = false;
228 protected XConnection conn = null;
229 private Object dbSrc = null;
231 @Override
232 protected void initialize(TestParameters tParam, PrintWriter log) {
233 tmpDir = utils.getOfficeTemp((tParam.getMSF()));
235 origDB = util.utils.getFullTestDocName("TestDB/testDB.dbf");
237 dbTools = new DBTools( tParam.getMSF() );
239 // creating DataSource and registering it in DatabaseContext
240 String dbURL = (String) tParam.get("test.db.url");
241 String dbUser = (String) tParam.get("test.db.user");
242 String dbPassword = (String) tParam.get("test.db.password");
244 log.println("Creating and registering DataSource ...");
245 srcInf = dbTools.newDataSourceInfo();
247 if ((dbURL != null) && (dbUser != null) && (dbPassword != null)) {
248 isMySQLDB = true;
249 log.println("dbURL = " + dbURL);
250 log.println("dbUSER = " + dbUser);
251 log.println("dbPASSWORD = " + dbPassword);
253 //DataSource for mysql db
254 try {
255 tableName = "soffice_test_table";
256 srcInf.URL = "jdbc:" + dbURL;
257 srcInf.IsPasswordRequired = Boolean.TRUE;
258 srcInf.Password = dbPassword;
259 srcInf.User = dbUser;
261 PropertyValue[] propInfo = new PropertyValue[1];
262 propInfo[0] = new PropertyValue();
263 propInfo[0].Name = "JavaDriverClass";
264 propInfo[0].Value = "util.dddriver.Driver";
265 srcInf.Info = propInfo;
267 dbSrc = srcInf.getDataSourceService();
268 dbTools.reRegisterDB(dbSourceName, dbSrc);
269 } catch (com.sun.star.uno.Exception e) {
270 log.println("Error while object test initialization :");
271 e.printStackTrace(log);
272 throw new StatusException("Error while object test" +
273 " initialization", e);
275 } else {
276 //DataSource for sdbc db
277 try {
278 String myDbUrl = "sdbc:dbase:" + DBTools.dirToUrl(tmpDir);
279 srcInf.URL = myDbUrl;
281 log.println("try to register '"+myDbUrl+"' as '"+dbSourceName+"'");
283 dbSrc = srcInf.getDataSourceService();
284 dbTools.reRegisterDB(dbSourceName, dbSrc);
285 } catch (com.sun.star.uno.Exception e) {
286 log.println("Error while object test initialization :");
287 e.printStackTrace(log);
288 throw new StatusException(
289 "Error while object test initialization", e);
292 String oldF = null;
293 String newF = null;
295 do {
296 tableName = "ODatabaseForm_tmp" + uniqueSuffix;
297 oldF = utils.getFullURL(origDB);
298 newF = utils.getOfficeTemp(tParam.getMSF()) + tableName +
299 ".dbf";
300 } while (!utils.tryOverwriteFile((tParam.getMSF()), oldF, newF) &&
301 (uniqueSuffix++ < 50));
306 * * creating a Testenvironment for the interfaces to be tested
308 @Override
309 protected synchronized TestEnvironment createTestEnvironment(TestParameters Param,
310 PrintWriter log) {
311 if (xTextDoc != null) {
312 try {
313 XCloseable closer = UnoRuntime.queryInterface(
314 XCloseable.class, xTextDoc);
315 closer.close(true);
316 } catch (com.sun.star.util.CloseVetoException e) {
317 log.println("couldn't close document");
318 } catch (com.sun.star.lang.DisposedException e) {
319 log.println("couldn't close document");
322 log.println("Existing document disposed");
325 log.println("creating a text document");
326 xTextDoc = WriterTools.createTextDoc((Param.getMSF()));
328 //initialize test table
329 if (isMySQLDB) {
330 try {
331 dbTools.initTestTableUsingJDBC(tableName, srcInf);
332 } catch (java.sql.SQLException e) {
333 throw new StatusException(e, Status.failed("Couldn't " + " init test table. SQLException..."));
334 } catch (java.lang.ClassNotFoundException e) {
335 throw new StatusException(e, Status.failed("Couldn't " + "register mysql driver"));
339 XInterface oObj = null;
340 XShapes oShapes = null;
341 XInterface oInstance = null;
342 XConnection connection = null;
345 // creation of testobject here
346 // first we write what we are intend to do to log file
347 log.println("creating a test environment");
349 XNameContainer forms = FormTools.getForms(WriterTools.getDrawPage(
350 xTextDoc));
352 try {
353 String[] formNames = forms.getElementNames();
355 for (int i = 0; i < formNames.length; i++) {
356 log.println("Removing form '" + formNames[i] + "' ...");
357 forms.removeByName(formNames[i]);
359 } catch (com.sun.star.lang.WrappedTargetException e) {
360 e.printStackTrace(log);
361 } catch (com.sun.star.container.NoSuchElementException e) {
362 e.printStackTrace(log);
365 String[] formNames = forms.getElementNames();
366 FormTools.insertForm(xTextDoc, forms, "MyForm");
367 formNames = forms.getElementNames();
369 XLoadable formLoader = null;
371 try {
372 formLoader = FormTools.bindForm(xTextDoc, "MyForm", dbSourceName,
373 tableName);
374 } catch (com.sun.star.uno.Exception e) {
375 log.println("Cann't bind the form to source '" + dbSourceName +
376 "', table '" + tableName + "' :");
377 e.printStackTrace(log);
378 throw new StatusException("Cann't bind a form", e);
382 // DEBUG
383 log.println("Forms before adding controls : ");
384 formNames = forms.getElementNames();
386 for (int i = 0; i < formNames.length; i++) {
387 log.println(" '" + formNames[i] + "'");
390 XControlShape shape1 = null;
391 XControlShape shape2 = null;
393 try {
395 log.println("Elements in the 'MyForm' :");
397 XIndexAccess formElements1 = UnoRuntime.queryInterface(
398 XIndexAccess.class,
399 forms.getByName("MyForm"));
401 for (int i = 0; i < formElements1.getCount(); i++) {
402 XNamed elemName = UnoRuntime.queryInterface(
403 XNamed.class,
404 formElements1.getByIndex(i));
405 log.println(" '" + elemName.getName() + "'");
409 // END DEBUG
410 //put something on the drawpage
411 log.println("inserting some ControlShapes");
412 oShapes = DrawTools.getShapes(WriterTools.getDrawPage(xTextDoc));
413 shape1 = FormTools.createControlShape(xTextDoc, 3000, 4500, 15000,
414 1000, "CommandButton");
415 shape2 = FormTools.createControlShape(xTextDoc, 5000, 3500, 7500,
416 5000, "TextField");
418 XControlShape shape3 = FormTools.createControlShape(xTextDoc, 2000,
419 1500, 1000,
420 1000,
421 "CheckBox");
422 oShapes.add(shape1);
423 oShapes.add(shape2);
424 oShapes.add(shape3);
425 } catch (Exception e) {
426 e.printStackTrace(log);
429 log.println("Forms after adding controls : ");
430 formNames = forms.getElementNames();
432 for (int i = 0; i < formNames.length; i++) {
433 log.println(" '" + formNames[i] + "'");
436 try {
437 log.println("Elements in the 'MyForm' :");
439 XIndexAccess formElements1 = UnoRuntime.queryInterface(
440 XIndexAccess.class,
441 forms.getByName("MyForm"));
443 for (int i = 0; i < formElements1.getCount(); i++) {
444 XNamed elemName = UnoRuntime.queryInterface(
445 XNamed.class,
446 formElements1.getByIndex(i));
447 log.println(" '" + elemName.getName() + "'");
449 } catch (Exception e) {
450 e.printStackTrace(log);
453 formLoader.load();
455 try {
456 oObj = (XForm) AnyConverter.toObject(new Type(XForm.class),
457 (FormTools.getForms(
458 WriterTools.getDrawPage(
459 xTextDoc)))
460 .getByName("MyForm"));
462 XPropertySet xSetProp = UnoRuntime.queryInterface(
463 XPropertySet.class, oObj);
464 connection = (XConnection) AnyConverter.toObject(
465 new Type(XConnection.class),
466 xSetProp.getPropertyValue("ActiveConnection"));
467 } catch (com.sun.star.uno.Exception e) {
468 log.println("Couldn't get Form");
469 e.printStackTrace(log);
473 // get a control
474 oInstance = FormTools.createControl(xTextDoc, "TextField");
476 log.println("creating a new environment for drawpage object");
478 TestEnvironment tEnv = new TestEnvironment(oObj);
481 // adding relation for closing connection while environment disposing.
482 this.conn = connection;
484 // adding relation for XSubmit
485 XControlModel the_Model = shape2.getControl();
486 XControlAccess the_access = UnoRuntime.queryInterface(
487 XControlAccess.class,
488 xTextDoc.getCurrentController());
489 XControl cntrl = null;
491 //now get the OEditControl
492 try {
493 cntrl = the_access.getControl(the_Model);
494 log.println(cntrl.getClass().getName());
495 } catch (com.sun.star.container.NoSuchElementException e) {
496 log.println("Couldn't get OEditControl");
497 e.printStackTrace(log);
498 throw new StatusException("Couldn't get OEditControl", e);
501 XResultSet the_set = UnoRuntime.queryInterface(
502 XResultSet.class, oObj);
504 try {
505 the_set.first();
506 } catch (SQLException e) {
507 log.println("Cann't move cursor to the first row.");
508 e.printStackTrace();
509 throw new StatusException("Can't move cursor to the first row.", e);
512 tEnv.addObjRelation("Model1", shape1.getControl());
513 tEnv.addObjRelation("Model2", shape2.getControl());
516 // adding an object for XNameReplace testing
517 log.println("adding oInstace as obj relation to environment");
518 tEnv.addObjRelation("INSTANCE", oInstance);
521 // INDEX : _XNameContainer
522 log.println("adding INDEX as obj relation to environment");
523 tEnv.addObjRelation("INDEX", "0");
526 // INDEX : _XNameReplace
527 log.println("adding NameReplaceIndex as obj relation to environment");
528 tEnv.addObjRelation("XNameReplaceINDEX", "2");
531 // INSTANCEn : _XNameContainer; _XNameReplace
532 log.println("adding INSTANCEn as obj relation to environment");
534 String tc = (String) Param.get("THRCNT");
535 int THRCNT = 1;
537 if (tc != null) {
538 THRCNT = Integer.parseInt(tc);
541 for (int n = 1; n < (2 * (THRCNT + 1)); n++) {
542 log.println("adding INSTANCE" + n +
543 " as obj relation to environment");
544 tEnv.addObjRelation("INSTANCE" + n,
545 FormTools.createControl(xTextDoc, "CheckBox"));
549 // adding relation for XNameContainer
550 tEnv.addObjRelation("XNameContainer.AllowDuplicateNames", new Object());
553 // adding relation for XPersistObject
554 tEnv.addObjRelation("OBJNAME", "stardiv.one.form.component.Form");
556 if (the_set != null) {
557 log.println("The Form has a not empty ResultSet");
560 // Adding obj relation for XRowSetApproveBroadcaster test
561 final XResultSet xResSet = UnoRuntime.queryInterface(
562 XResultSet.class, oObj);
563 final XResultSetUpdate xResSetUpdate = UnoRuntime.queryInterface(
564 XResultSetUpdate.class,
565 oObj);
566 final XRowSet xRowSet = UnoRuntime.queryInterface(
567 XRowSet.class, oObj);
568 final PrintWriter logF = log;
569 tEnv.addObjRelation("XRowSetApproveBroadcaster.ApproveChecker",
570 new ifc.sdb._XRowSetApproveBroadcaster.RowSetApproveChecker() {
571 public void moveCursor() {
572 try {
573 xResSet.beforeFirst();
574 xResSet.afterLast();
575 } catch (com.sun.star.sdbc.SQLException e) {
576 logF.println("### _XRowSetApproveBroadcaster." + "RowSetApproveChecker.moveCursor() :");
577 e.printStackTrace(logF);
581 public RowChangeEvent changeRow() {
582 try {
583 xResSet.first();
585 XRowUpdate row = UnoRuntime.queryInterface(
586 XRowUpdate.class, xResSet);
587 row.updateString(1, "1");
588 xResSetUpdate.updateRow();
589 } catch (com.sun.star.sdbc.SQLException e) {
590 logF.println("### _XRowSetApproveBroadcaster." + "RowSetApproveChecker.changeRow() :");
591 e.printStackTrace(logF);
594 RowChangeEvent ev = new RowChangeEvent();
595 ev.Action = com.sun.star.sdb.RowChangeAction.UPDATE;
596 ev.Rows = 1;
598 return ev;
601 public void changeRowSet() {
602 try {
603 xRowSet.execute();
604 } catch (com.sun.star.sdbc.SQLException e) {
605 logF.println("### _XRowSetApproveBroadcaster." + "RowSetApproveChecker.changeRowSet() :");
606 e.printStackTrace(logF);
612 // Adding relation for XColumnLocate test
613 tEnv.addObjRelation("XColumnLocate.ColumnName", DBTools.TST_STRING_F);
615 // Adding relation for XParameters ifc test
616 ArrayList<Object> params = new ArrayList<Object>();
619 /***** statement parameter types and their initial
620 values must be added here as relation. */
621 params.add("SAU99") ;
622 params.add(Boolean.FALSE) ;
623 params.add(Byte.valueOf((byte) 123)) ;
624 params.add(Short.valueOf((short) 234)) ;
625 params.add(Integer.valueOf(12345)) ;
626 params.add(Long.valueOf(23456)) ;
627 params.add(new Float(1.234)) ;
628 params.add(new Double(2.345)) ;
629 params.add(new byte[] {1, 2, 3}) ;
630 Date d = new Date();
631 d.Day = 26; d.Month = 1; d.Year = 2001;
632 params.add(d) ;
633 Time t = new Time();
634 t.Hours = 1; t.NanoSeconds = 123456789; t.Minutes = 25; t.Seconds = 14;
635 params.add(t) ;
636 DateTime dt = new DateTime();
637 dt.Day = 26; dt.Month = 1; dt.Year = 2001; dt.Hours = 1;
638 dt.NanoSeconds = 123456789; dt.Minutes = 25; dt.Seconds = 14;
639 params.add(dt) ;
640 tEnv.addObjRelation("XParameters.ParamValues", params);
642 // Adding relation for XCompletedExecution
643 tEnv.addObjRelation("InteractionHandlerChecker", new InteractionHandlerImpl());
645 // Adding for XWarningSupplier
646 tEnv.addObjRelation("CheckWarningsSupplier", Boolean.valueOf(isMySQLDB));
648 // Adding relation for XDatabaseParameterBroadcaster
649 tEnv.addObjRelation("ParameterListenerChecker", new ODatabaseForm.ParameterListenerImpl());
650 XPropertySet xSetProp = UnoRuntime.queryInterface
651 (XPropertySet.class, oObj) ;
652 try {
653 xSetProp.setPropertyValue("DataSourceName", dbSourceName) ;
654 if(isMySQLDB) {
655 xSetProp.setPropertyValue("Command", "SELECT Column0 FROM soffice_test_table WHERE ( ( Column0 = :param1 ) )");
657 else {
658 xSetProp.setPropertyValue("Command", "SELECT \"_TEXT\" FROM \"ODatabaseForm_tmp0\" WHERE ( ( \"_TEXT\" = :param1 ) )");
661 xSetProp.setPropertyValue("CommandType",
662 Integer.valueOf(CommandType.COMMAND)) ;
664 catch(Exception e) {
667 // Adding relation for XResultSetUpdate
668 final XRowUpdate xRowUpdate = UnoRuntime.queryInterface(
669 XRowUpdate.class, oObj);
670 final XRow xRow = UnoRuntime.queryInterface(XRow.class, oObj);
672 tEnv.addObjRelation("XResultSetUpdate.UpdateTester",
673 new ifc.sdbc._XResultSetUpdate.UpdateTester() {
674 String lastUpdate = null;
676 public int rowCount() throws SQLException {
677 int prevPos = xResSet.getRow();
678 xResSet.last();
680 int count = xResSet.getRow();
681 xResSet.absolute(prevPos);
683 return count;
686 public void update() throws SQLException {
687 lastUpdate = xRow.getString(1);
688 lastUpdate += "_";
689 xRowUpdate.updateString(1, lastUpdate);
692 public boolean wasUpdated() throws SQLException {
693 String getStr = xRow.getString(1);
695 return lastUpdate.equals(getStr);
698 public int currentRow() throws SQLException {
699 return xResSet.getRow();
703 // Adding relations for XRow as a Vector with all data
704 // of current row of RowSet.
706 ArrayList<Object> rowData = new ArrayList<Object>();
708 for (int i = 0; i < DBTools.TST_TABLE_VALUES[0].length; i++) {
709 rowData.add(DBTools.TST_TABLE_VALUES[0][i]);
712 tEnv.addObjRelation("CurrentRowData", rowData);
714 // Adding relation for XRowUpdate
715 XRow row = UnoRuntime.queryInterface(XRow.class, oObj);
716 tEnv.addObjRelation("XRowUpdate.XRow", row);
719 tEnv.addObjRelation("XPropertyContainer.propertyNotRemovable", "Cycle");
721 PropertyValue propVal = new PropertyValue();
722 propVal.Name = "Name";
723 propVal.Value = "Text since XPropertyAccess";
725 tEnv.addObjRelation("XPropertyAccess.propertyToChange", propVal);
727 return tEnv;
728 } // finish method getTestEnvironment
731 * Closes connection of <code>RowSet</code> instance created.
733 @Override
734 protected void cleanup(TestParameters Param, PrintWriter log) {
735 log.println("closing connection...");
736 try {
737 conn.close();
738 } catch (com.sun.star.uno.Exception e) {
739 log.println("Can't close the connection");
740 e.printStackTrace(log);
741 } catch (com.sun.star.lang.DisposedException e) {
742 log.println("Connection was already closed. It's OK.");
746 log.println("closing data source...");
747 try {
748 XCloseable closer = UnoRuntime.queryInterface(
749 XCloseable.class, dbSrc);
750 closer.close(true);
751 } catch (com.sun.star.util.CloseVetoException e) {
752 log.println("couldn't close data source");
753 } catch (com.sun.star.lang.DisposedException e) {
754 log.println("couldn't close data source");
758 log.println("closing document...");
760 try {
761 XCloseable closer = UnoRuntime.queryInterface(
762 XCloseable.class, xTextDoc);
763 closer.close(true);
764 } catch (com.sun.star.util.CloseVetoException e) {
765 log.println("couldn't close document");
766 } catch (com.sun.star.lang.DisposedException e) {
767 log.println("couldn't close document");
770 log.println("revoking data source...");
771 try {
772 dbTools.revokeDB(dbSourceName);
773 } catch (com.sun.star.container.NoSuchElementException e){
774 } catch (com.sun.star.uno.Exception e) {
775 log.println("Error while object test cleaning up :");
776 e.printStackTrace(log);
777 throw new StatusException("Error while object test cleaning up", e);
782 * Implementation of interface _XDatabaseParameterBroadcaster.CheckParameterListener
783 * for the XDatabaseParameterBroadcaster test
784 * @see ifc.form._XDatabaseParameterBroadcaster
786 private class ParameterListenerImpl implements _XDatabaseParameterBroadcaster.CheckParameterListener {
787 private boolean listenerWasCalled = false;
788 private PrintWriter log = new PrintWriter(System.out);
791 * Return true, if the listener was called, false otherwise.
792 * @return True, if any other method of the listener was called.
794 public boolean checkListener() {
795 return listenerWasCalled;
799 * Take the DataBaseParameterEvent and fill it with a meaningful value.
800 * @param e The database parameter that will be filled with a value.
801 * @return True, if the value could be filled.
803 public boolean approveParameter(DatabaseParameterEvent e) {
804 log.println("### ParameterListenerImpl: approve called.");
805 XIndexAccess params = e.Parameters;
806 int count = params.getCount();
807 try {
808 for(int i=0; i<count; i++) {
809 log.println("### _XDatabaseParameterBroadcaster.ParameterListenerImpl: Parameter "+i+": "+params.getByIndex(i));
810 XPropertySet xProp = UnoRuntime.queryInterface(XPropertySet.class, params.getByIndex(i));
811 log.println("### _XDatabaseParameterBroadcaster.ParameterListenerImpl: Parameter Name: '"+xProp.getPropertyValue("Name") + "' is set to Value '1'");
812 xProp.setPropertyValue("Value", Integer.valueOf(1));
813 listenerWasCalled = true;
816 catch(Exception eI) {
817 log.println("### _XDatabaseParameterBroadcaster.ParameterListenerImpl: Exception!");
818 eI.printStackTrace(log);
819 return false;
821 return true;
825 * Dummy implemetnation. Do nothing, just log
826 * @param o Ignore.
828 public void disposing(EventObject o) {
829 log.println("### _XDatabaseParameterBroadcaster.ParameterListenerImpl: disposing");
833 * Set a log writer, so messages go to log instead of Standard.out
834 * @param log The log messages get printed to.
836 public void setLog(PrintWriter log) {
837 this.log = log;
844 * Implementation of interface _XCompletedExecution.CheckInteractionHandler
845 * for the XCompletedExecution test
846 * @see ifc.sdb._XCompletedExecution
848 private class InteractionHandlerImpl implements _XCompletedExecution.CheckInteractionHandler {
849 private boolean handlerWasUsed = false;
850 private PrintWriter log = new PrintWriter(System.out);
852 public boolean checkInteractionHandler() {
853 return handlerWasUsed;
856 public void handle(XInteractionRequest xInteractionRequest) {
857 log.println("### _XCompletedExecution.InteractionHandlerImpl: handle called.");
858 handlerWasUsed = true;
860 Object o = xInteractionRequest.getRequest();
861 ParametersRequest req = (ParametersRequest)o;
862 XIndexAccess params = req.Parameters;
863 int count = params.getCount();
864 try {
865 for(int i=0; i<count; i++) {
866 params.getByIndex(i);
867 log.println("### _XCompletedExecution.InteractionHandlerImpl: Parameter "+i+": "+params.getByIndex(i));
868 XPropertySet xProp = UnoRuntime.queryInterface(XPropertySet.class, params.getByIndex(i));
869 log.println("### _XCompletedExecution.InteractionHandlerImpl: Parameter Name: '"+xProp.getPropertyValue("Name") + "' is set to Value '1'");
870 xProp.setPropertyValue("Value", Integer.valueOf(1));
871 handlerWasUsed = true;
874 catch(Exception eI) {
875 log.println("### _XCompletedExecution.InteractionHandlerImpl: Exception!");
876 eI.printStackTrace(log);
880 public void setLog(PrintWriter log) {
881 this.log = log;
885 } // finish class ODatabaseForm