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 lib.MultiMethodTest;
27 import lib.StatusException;
28 
29 import com.sun.star.sdbc.SQLException;
30 import com.sun.star.sdbc.XCloseable;
31 import com.sun.star.sdbc.XResultSet;
32 import com.sun.star.uno.UnoRuntime;
33 
34 /**
35 * Testing <code>com.sun.star.sdbc.XCloseable</code>
36 * interface methods :
37 * <ul>
38 *  <li><code> close()</code></li>
39 * </ul> <p>
40 * After test object must be recreated.
41 * @see com.sun.star.sdbc.XCloseable
42 */
43 public class _XCloseable extends MultiMethodTest {
44 
45     // oObj filled by MultiMethodTest
46     public XCloseable oObj = null ;
47 
48     /**
49     * Closes row set. If the component implements the interface
50     * <code>com.sun.star.sdbc.XResutlSet</code> then tries to move
51     * the cursor to the first row in the result set.
52     * Has OK status if no exceptions were thrown during first call and
53     * if expected SQL exception was thrown during cursor moving.
54     */
55     public void _close() throws StatusException {
56         boolean res = false;
57         try {
58             oObj.close();
59             res = true;
60         } catch (SQLException e) {
61             log.println("Unexpected SQL Exception occured:" + e) ;
62             res = false;
63         }
64 
65         XResultSet resSet = (XResultSet)
66             UnoRuntime.queryInterface(XResultSet.class, oObj);
67 
68         if (resSet != null) {
69             try {
70                 resSet.first();
71                 log.println("Expected SQLException not occured !");
72                 res = false;
73             } catch(SQLException e) {
74                 log.println("Expected SQLException occured");
75                 res = true;
76             }
77         }
78 
79         tRes.tested("close()", res);
80     }
81 
82     /**
83     * Forces environment recreation.
84     */
85     public void after() {
86         disposeEnvironment() ;
87     }
88 
89 }  // finish class _XCloseable
90 
91