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