Update ooo320-m1
[ooovba.git] / qadevOOo / tests / java / ifc / sdbc / _XRowSet.java
blob88433afc2130bc6907be0657aab8bb3245943a5f
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: _XRowSet.java,v $
10 * $Revision: 1.4 $
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 ************************************************************************/
31 package ifc.sdbc;
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;
42 /**
43 * Testing <code>com.sun.star.sdbc.XRowSet</code>
44 * interface methods :
45 * <ul>
46 * <li><code> execute()</code></li>
47 * <li><code> addRowSetListener()</code></li>
48 * <li><code> removeRowSetListener()</code></li>
49 * </ul> <p>
50 * Required object relations :
51 * <ul>
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
56 * whole rowset. </li>
57 * </ul> <p>
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 ;
75 public void reset() {
76 cursorMoved = false ;
77 rowChanged = false ;
78 rowSetChanged = false ;
80 public void cursorMoved(EventObject ev) {
81 cursorMoved = true ;
83 public void rowChanged(EventObject ev) {
84 rowChanged = true ;
86 public void rowSetChanged(EventObject ev) {
87 rowSetChanged = true ;
89 public void disposing(EventObject ev) {}
92 /**
93 * Retrieves relation.
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()");
113 listener.reset();
114 boolean result = true ;
116 try {
117 oObj.execute() ;
118 } catch (SQLException e) {
119 log.println("Exception occured :" + e) ;
120 result = false ;
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") ;
141 listener.reset() ;
143 checker.changeRow() ;
144 result &= listener.rowChanged ;
145 if (!listener.rowChanged)
146 log.println("rowChanged event wasn't called") ;
147 listener.reset() ;
149 checker.changeRowSet() ;
150 result &= listener.rowSetChanged ;
151 if (!listener.rowSetChanged)
152 log.println("rowSetChanged event wasn't called") ;
153 listener.reset() ;
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 :
162 * <ul>
163 * <li> <code>addRowSetListener()</code> </li>
164 * </ul> <p>
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 ;
176 listener.reset() ;
178 checker.changeRow() ;
179 result &= !listener.rowChanged ;
180 listener.reset() ;
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