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.ucb;
25 
26 import lib.MultiMethodTest;
27 import lib.Status;
28 import lib.StatusException;
29 
30 import com.sun.star.sdbc.XResultSet;
31 import com.sun.star.ucb.XCachedContentResultSetFactory;
32 
33 /**
34 * Testing <code>com.sun.star.ucb.XCachedContentResultSetFactory</code>
35 * interface methods :
36 * <ul>
37 *  <li><code> createCachedContentResultSet()</code></li>
38 * </ul> <p>
39 * This test needs the following object relations :
40 * <ul>
41 *  <li> <code>'CachedContentResultSetStub'</code> (of type
42 *   <code>com.sun.star.sdbc.XResultSet</code>):
43 *   this must be an imlementation of <code>
44 *   com.sun.star.ucb.CachedContentResultSetStub</code> service.</li>
45 * <ul> <p>
46 * Test is <b> NOT </b> multithread compilant. <p>
47 * @see com.sun.star.ucb.XCachedContentResultSetFactory
48 */
49 public class _XCachedContentResultSetFactory extends MultiMethodTest {
50 
51     /**
52      * Conatins the tested object.
53      */
54     public XCachedContentResultSetFactory oObj;
55     private XResultSet resSetStub = null ;
56 
57     /**
58     * Retrieves object relation.
59     * @throws StatusException If relation not found.
60     */
before()61     public void before() {
62         resSetStub = (XResultSet)
63             tEnv.getObjRelation("CachedContentResultSetStub") ;
64         if (resSetStub == null) {
65             log.println("!!! Relation not found !!!") ;
66             throw new StatusException
67                 (Status.failed("!!! Relation not found !!!")) ;
68         }
69     }
70 
71     /**
72     * Creates result set from result set stub. After that number
73     * of rows from result set created and its stub are retrieved
74     * using their static representations and comared. <p>
75     * Has <b>OK</b> status if numbers of rows are equal and they are
76     * greater then 0 (because JAR file contains at least one entry).
77     */
_createCachedContentResultSet()78     public void _createCachedContentResultSet() {
79         boolean result = true ;
80 
81         XResultSet resSet = oObj.createCachedContentResultSet
82             (resSetStub, null) ;
83 
84         if (resSet == null) {
85             log.println("!!! Method returned null !!!") ;
86             result = false ;
87         } else {
88             try {
89                 resSetStub.last() ;
90                 int stubRowNum = resSetStub.getRow() ;
91 
92                 resSet.last() ;
93                 int setRowNum = resSet.getRow() ;
94 
95                 result = stubRowNum == setRowNum && setRowNum > 0 ;
96 
97                 log.println("Number of rows : stub=" + stubRowNum +
98                     " set=" + setRowNum) ;
99             } catch (com.sun.star.sdbc.SQLException e) {
100                 log.println("!!! Something wrong with result sets :") ;
101                 e.printStackTrace(log) ;
102                 result = false ;
103             }
104         }
105 
106         tRes.tested("createCachedContentResultSet()", result) ;
107 
108     }
109 }
110 
111