1*ef39d40dSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*ef39d40dSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*ef39d40dSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*ef39d40dSAndrew Rist  * distributed with this work for additional information
6*ef39d40dSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*ef39d40dSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*ef39d40dSAndrew Rist  * "License"); you may not use this file except in compliance
9*ef39d40dSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*ef39d40dSAndrew Rist  *
11*ef39d40dSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*ef39d40dSAndrew Rist  *
13*ef39d40dSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*ef39d40dSAndrew Rist  * software distributed under the License is distributed on an
15*ef39d40dSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*ef39d40dSAndrew Rist  * KIND, either express or implied.  See the License for the
17*ef39d40dSAndrew Rist  * specific language governing permissions and limitations
18*ef39d40dSAndrew Rist  * under the License.
19*ef39d40dSAndrew Rist  *
20*ef39d40dSAndrew Rist  *************************************************************/
21*ef39d40dSAndrew Rist 
22*ef39d40dSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir package ifc.sdbc;
25cdf0e10cSrcweir 
26cdf0e10cSrcweir import ifc.sdb._XRowSetApproveBroadcaster;
27cdf0e10cSrcweir import lib.MultiMethodTest;
28cdf0e10cSrcweir import lib.StatusException;
29cdf0e10cSrcweir 
30cdf0e10cSrcweir import com.sun.star.lang.EventObject;
31cdf0e10cSrcweir import com.sun.star.sdbc.SQLException;
32cdf0e10cSrcweir import com.sun.star.sdbc.XRowSet;
33cdf0e10cSrcweir import com.sun.star.sdbc.XRowSetListener;
34cdf0e10cSrcweir 
35cdf0e10cSrcweir /**
36cdf0e10cSrcweir * Testing <code>com.sun.star.sdbc.XRowSet</code>
37cdf0e10cSrcweir * interface methods :
38cdf0e10cSrcweir * <ul>
39cdf0e10cSrcweir *  <li><code> execute()</code></li>
40cdf0e10cSrcweir *  <li><code> addRowSetListener()</code></li>
41cdf0e10cSrcweir *  <li><code> removeRowSetListener()</code></li>
42cdf0e10cSrcweir * </ul> <p>
43cdf0e10cSrcweir * Required object relations :
44cdf0e10cSrcweir * <ul>
45cdf0e10cSrcweir * <li> <code>'XRowSetApproveBroadcaster.ApproveChecker'</code>:
46cdf0e10cSrcweir *      implementation of inner interface
47cdf0e10cSrcweir *      <code>ifs.sdb._XRowSetApproveBroadcaster.RowSetApproveChecker</code>
48cdf0e10cSrcweir *      which can move cursor within a rowset, change row, and change the
49cdf0e10cSrcweir *      whole rowset. </li>
50cdf0e10cSrcweir * </ul> <p>
51cdf0e10cSrcweir * It is better to recreate the object after test, because of unknown
52cdf0e10cSrcweir * actions made by <code>RowSetApproveChecker</code> interface implementation.
53cdf0e10cSrcweir * @see com.sun.star.sdbc.XRowSet
54cdf0e10cSrcweir * @see ifc.sdb._XRowSetApproveBroadcaster
55cdf0e10cSrcweir */
56cdf0e10cSrcweir public class _XRowSet extends MultiMethodTest {
57cdf0e10cSrcweir 
58cdf0e10cSrcweir     // oObj filled by MultiMethodTest
59cdf0e10cSrcweir     public XRowSet oObj = null ;
60cdf0e10cSrcweir     private _XRowSetApproveBroadcaster.RowSetApproveChecker checker = null ;
61cdf0e10cSrcweir     private TestListener listener = new TestListener() ;
62cdf0e10cSrcweir 
63cdf0e10cSrcweir     private class TestListener implements XRowSetListener {
64cdf0e10cSrcweir         public boolean cursorMoved = false ;
65cdf0e10cSrcweir         public boolean rowChanged = false ;
66cdf0e10cSrcweir         public boolean rowSetChanged = false ;
67cdf0e10cSrcweir 
68cdf0e10cSrcweir         public void reset() {
69cdf0e10cSrcweir             cursorMoved = false ;
70cdf0e10cSrcweir             rowChanged = false ;
71cdf0e10cSrcweir             rowSetChanged = false ;
72cdf0e10cSrcweir         }
73cdf0e10cSrcweir         public void cursorMoved(EventObject ev) {
74cdf0e10cSrcweir             cursorMoved = true ;
75cdf0e10cSrcweir         }
76cdf0e10cSrcweir         public void rowChanged(EventObject ev) {
77cdf0e10cSrcweir             rowChanged = true ;
78cdf0e10cSrcweir         }
79cdf0e10cSrcweir         public void rowSetChanged(EventObject ev) {
80cdf0e10cSrcweir             rowSetChanged = true ;
81cdf0e10cSrcweir         }
82cdf0e10cSrcweir         public void disposing(EventObject ev) {}
83cdf0e10cSrcweir     }
84cdf0e10cSrcweir 
85cdf0e10cSrcweir     /**
86cdf0e10cSrcweir     * Retrieves relation.
87cdf0e10cSrcweir     * @throw StatusException If relation not found.
88cdf0e10cSrcweir     */
89cdf0e10cSrcweir     public void before() throws StatusException {
90cdf0e10cSrcweir         checker = (_XRowSetApproveBroadcaster.RowSetApproveChecker)
91cdf0e10cSrcweir             tEnv.getObjRelation("XRowSetApproveBroadcaster.ApproveChecker") ;
92cdf0e10cSrcweir 
93cdf0e10cSrcweir         if (checker == null) {
94cdf0e10cSrcweir             log.println("Required relation not found !!!") ;
95cdf0e10cSrcweir             throw new StatusException("Required relation not found !!!",
96cdf0e10cSrcweir                 new NullPointerException()) ;
97cdf0e10cSrcweir         }
98cdf0e10cSrcweir     }
99cdf0e10cSrcweir 
100cdf0e10cSrcweir     /**
101cdf0e10cSrcweir     * Reexecutes the RowSet and checks that listener was called. <p>
102cdf0e10cSrcweir     * Has OK status if no exceptions were rised and listener was called.
103cdf0e10cSrcweir     */
104cdf0e10cSrcweir     public void _execute() {
105cdf0e10cSrcweir         requiredMethod("addRowSetListener()");
106cdf0e10cSrcweir         listener.reset();
107cdf0e10cSrcweir         boolean result = true ;
108cdf0e10cSrcweir 
109cdf0e10cSrcweir         try {
110cdf0e10cSrcweir             oObj.execute() ;
111cdf0e10cSrcweir         } catch (SQLException e) {
112cdf0e10cSrcweir             log.println("Exception occured :" + e) ;
113cdf0e10cSrcweir             result = false ;
114cdf0e10cSrcweir         }
115cdf0e10cSrcweir 
116cdf0e10cSrcweir         tRes.tested("execute()", listener.rowSetChanged);
117cdf0e10cSrcweir     }
118cdf0e10cSrcweir 
119cdf0e10cSrcweir     /**
120cdf0e10cSrcweir     * Adds listener and calls methods moveCursor, changeRow,
121cdf0e10cSrcweir     * changeRowSet of the relation and then checks if appropriate
122cdf0e10cSrcweir     * methods of the listener were called. <p>
123cdf0e10cSrcweir     * Has OK status if all listener methods were called.
124cdf0e10cSrcweir     */
125cdf0e10cSrcweir     public void _addRowSetListener() {
126cdf0e10cSrcweir         boolean result = true ;
127cdf0e10cSrcweir 
128cdf0e10cSrcweir         oObj.addRowSetListener(listener) ;
129cdf0e10cSrcweir 
130cdf0e10cSrcweir         checker.moveCursor() ;
131cdf0e10cSrcweir         result &= listener.cursorMoved ;
132cdf0e10cSrcweir         if (!listener.cursorMoved)
133cdf0e10cSrcweir             log.println("cursorMoved event wasn't called") ;
134cdf0e10cSrcweir         listener.reset() ;
135cdf0e10cSrcweir 
136cdf0e10cSrcweir         checker.changeRow() ;
137cdf0e10cSrcweir         result &= listener.rowChanged ;
138cdf0e10cSrcweir         if (!listener.rowChanged)
139cdf0e10cSrcweir             log.println("rowChanged event wasn't called") ;
140cdf0e10cSrcweir         listener.reset() ;
141cdf0e10cSrcweir 
142cdf0e10cSrcweir         checker.changeRowSet() ;
143cdf0e10cSrcweir         result &= listener.rowSetChanged ;
144cdf0e10cSrcweir         if (!listener.rowSetChanged)
145cdf0e10cSrcweir             log.println("rowSetChanged event wasn't called") ;
146cdf0e10cSrcweir         listener.reset() ;
147cdf0e10cSrcweir 
148cdf0e10cSrcweir         tRes.tested("addRowSetListener()", result) ;
149cdf0e10cSrcweir     }
150cdf0e10cSrcweir 
151cdf0e10cSrcweir     /*
152cdf0e10cSrcweir     * Removes listener added before, and checks for no listener
153cdf0e10cSrcweir     * methods were called on response to rowSet manipulations. <p>
154cdf0e10cSrcweir     * Methods to be successfully completed before :
155cdf0e10cSrcweir     * <ul>
156cdf0e10cSrcweir     * <li> <code>addRowSetListener()</code> </li>
157cdf0e10cSrcweir     * </ul> <p>
158cdf0e10cSrcweir     * Has OK status if no listeners methods were called.
159cdf0e10cSrcweir     */
160cdf0e10cSrcweir     public void _removeRowSetListener() {
161cdf0e10cSrcweir         requiredMethod("addRowSetListener()") ;
162cdf0e10cSrcweir 
163cdf0e10cSrcweir         boolean result = true ;
164cdf0e10cSrcweir 
165cdf0e10cSrcweir         oObj.removeRowSetListener(listener) ;
166cdf0e10cSrcweir 
167cdf0e10cSrcweir         checker.moveCursor() ;
168cdf0e10cSrcweir         result &= !listener.cursorMoved ;
169cdf0e10cSrcweir         listener.reset() ;
170cdf0e10cSrcweir 
171cdf0e10cSrcweir         checker.changeRow() ;
172cdf0e10cSrcweir         result &= !listener.rowChanged ;
173cdf0e10cSrcweir         listener.reset() ;
174cdf0e10cSrcweir 
175cdf0e10cSrcweir         checker.changeRowSet() ;
176cdf0e10cSrcweir         result &= !listener.rowSetChanged ;
177cdf0e10cSrcweir 
178cdf0e10cSrcweir         tRes.tested("removeRowSetListener()", result) ;
179cdf0e10cSrcweir     }
180cdf0e10cSrcweir 
181cdf0e10cSrcweir     /**
182cdf0e10cSrcweir     * Disposes test environment.
183cdf0e10cSrcweir     */
184cdf0e10cSrcweir     public void after() {
185cdf0e10cSrcweir         disposeEnvironment() ;
186cdf0e10cSrcweir     }
187cdf0e10cSrcweir 
188cdf0e10cSrcweir }  // finish class _XRowSet
189cdf0e10cSrcweir 
190