1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: _XRowSet.java,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
33 import ifc
.sdb
._XRowSetApproveBroadcaster
;
34 import lib
.MultiMethodTest
;
35 import lib
.StatusException
;
37 import com
.sun
.star
.lang
.EventObject
;
38 import com
.sun
.star
.sdbc
.SQLException
;
39 import com
.sun
.star
.sdbc
.XRowSet
;
40 import com
.sun
.star
.sdbc
.XRowSetListener
;
43 * Testing <code>com.sun.star.sdbc.XRowSet</code>
46 * <li><code> execute()</code></li>
47 * <li><code> addRowSetListener()</code></li>
48 * <li><code> removeRowSetListener()</code></li>
50 * Required object relations :
52 * <li> <code>'XRowSetApproveBroadcaster.ApproveChecker'</code>:
53 * implementation of inner interface
54 * <code>ifs.sdb._XRowSetApproveBroadcaster.RowSetApproveChecker</code>
55 * which can move cursor within a rowset, change row, and change the
58 * It is better to recreate the object after test, because of unknown
59 * actions made by <code>RowSetApproveChecker</code> interface implementation.
60 * @see com.sun.star.sdbc.XRowSet
61 * @see ifc.sdb._XRowSetApproveBroadcaster
63 public class _XRowSet
extends MultiMethodTest
{
65 // oObj filled by MultiMethodTest
66 public XRowSet oObj
= null ;
67 private _XRowSetApproveBroadcaster
.RowSetApproveChecker checker
= null ;
68 private TestListener listener
= new TestListener() ;
70 private class TestListener
implements XRowSetListener
{
71 public boolean cursorMoved
= false ;
72 public boolean rowChanged
= false ;
73 public boolean rowSetChanged
= false ;
78 rowSetChanged
= false ;
80 public void cursorMoved(EventObject ev
) {
83 public void rowChanged(EventObject ev
) {
86 public void rowSetChanged(EventObject ev
) {
87 rowSetChanged
= true ;
89 public void disposing(EventObject ev
) {}
94 * @throw StatusException If relation not found.
96 public void before() throws StatusException
{
97 checker
= (_XRowSetApproveBroadcaster
.RowSetApproveChecker
)
98 tEnv
.getObjRelation("XRowSetApproveBroadcaster.ApproveChecker") ;
100 if (checker
== null) {
101 log
.println("Required relation not found !!!") ;
102 throw new StatusException("Required relation not found !!!",
103 new NullPointerException()) ;
108 * Reexecutes the RowSet and checks that listener was called. <p>
109 * Has OK status if no exceptions were rised and listener was called.
111 public void _execute() {
112 requiredMethod("addRowSetListener()");
114 boolean result
= true ;
118 } catch (SQLException e
) {
119 log
.println("Exception occured :" + e
) ;
123 tRes
.tested("execute()", listener
.rowSetChanged
);
127 * Adds listener and calls methods moveCursor, changeRow,
128 * changeRowSet of the relation and then checks if appropriate
129 * methods of the listener were called. <p>
130 * Has OK status if all listener methods were called.
132 public void _addRowSetListener() {
133 boolean result
= true ;
135 oObj
.addRowSetListener(listener
) ;
137 checker
.moveCursor() ;
138 result
&= listener
.cursorMoved
;
139 if (!listener
.cursorMoved
)
140 log
.println("cursorMoved event wasn't called") ;
143 checker
.changeRow() ;
144 result
&= listener
.rowChanged
;
145 if (!listener
.rowChanged
)
146 log
.println("rowChanged event wasn't called") ;
149 checker
.changeRowSet() ;
150 result
&= listener
.rowSetChanged
;
151 if (!listener
.rowSetChanged
)
152 log
.println("rowSetChanged event wasn't called") ;
155 tRes
.tested("addRowSetListener()", result
) ;
159 * Removes listener added before, and checks for no listener
160 * methods were called on response to rowSet manipulations. <p>
161 * Methods to be successfully completed before :
163 * <li> <code>addRowSetListener()</code> </li>
165 * Has OK status if no listeners methods were called.
167 public void _removeRowSetListener() {
168 requiredMethod("addRowSetListener()") ;
170 boolean result
= true ;
172 oObj
.removeRowSetListener(listener
) ;
174 checker
.moveCursor() ;
175 result
&= !listener
.cursorMoved
;
178 checker
.changeRow() ;
179 result
&= !listener
.rowChanged
;
182 checker
.changeRowSet() ;
183 result
&= !listener
.rowSetChanged
;
185 tRes
.tested("removeRowSetListener()", result
) ;
189 * Disposes test environment.
191 public void after() {
192 disposeEnvironment() ;
195 } // finish class _XRowSet