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