1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: _XCachedDynamicResultSetStubFactory.java,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
33 import lib
.MultiMethodTest
;
35 import lib
.StatusException
;
37 import com
.sun
.star
.lang
.XMultiServiceFactory
;
38 import com
.sun
.star
.sdbc
.XResultSet
;
39 import com
.sun
.star
.ucb
.XCachedDynamicResultSetFactory
;
40 import com
.sun
.star
.ucb
.XCachedDynamicResultSetStubFactory
;
41 import com
.sun
.star
.ucb
.XDynamicResultSet
;
42 import com
.sun
.star
.uno
.UnoRuntime
;
45 * Testing <code>com.sun.star.ucb.XCachedDynamicResultSetStubFactory</code>
48 * <li><code> createCachedDynamicResultSetStub()</code></li>
49 * <li><code> connectToCache()</code></li>
51 * This test needs the following object relations :
53 * <li> <code>'DynamicResultSet'</code> (of type
54 * <code>com.sun.star.sdbc.XDynamicResultSet</code>):
55 * this must be an imlementation of <code>
56 * com.sun.star.ucb.DynamicResultSet</code> service.</li>
58 * Test is <b> NOT </b> multithread compilant. <p>
59 * @see com.sun.star.ucb.XCachedDynamicResultSetStubFactory
61 public class _XCachedDynamicResultSetStubFactory
extends MultiMethodTest
{
64 * Conatins the tested object.
66 public XCachedDynamicResultSetStubFactory oObj
;
67 private XDynamicResultSet resSet
= null ;
68 private XDynamicResultSet resSetStub
= null ;
71 * Retrieves object relation.
72 * @throws StatusException If relation not found.
74 public void before() {
75 resSet
= (XDynamicResultSet
) tEnv
.getObjRelation("DynamicResultSet") ;
77 log
.println("!!! Relation not found !!!") ;
78 throw new StatusException(Status
.failed("!!! Relation not found !!!")) ;
83 * Creates result set stub from result set. After that number
84 * of rows from result set stub created and its source set are retrieved
85 * using their static representations and compared. <p>
86 * Has <b>OK</b> status if numbers of rows are equal and they are
87 * greater then 0 (because JAR file contains at least one entry).
89 public void _createCachedDynamicResultSetStub() {
90 boolean result
= true ;
92 resSetStub
= oObj
.createCachedDynamicResultSetStub(resSet
) ;
94 if (resSetStub
== null) {
95 log
.println("!!! Method returned null !!!") ;
99 XResultSet resSetS
= resSet
.getStaticResultSet() ;
100 XResultSet resSetStubS
= resSetStub
.getStaticResultSet() ;
103 int stubRowNum
= resSetStubS
.getRow() ;
106 int setRowNum
= resSetS
.getRow() ;
108 result
= stubRowNum
== setRowNum
&& setRowNum
> 0 ;
110 log
.println("Number of rows : stub=" + stubRowNum
+
111 " set=" + setRowNum
) ;
112 } catch (com
.sun
.star
.sdbc
.SQLException e
) {
113 log
.println("!!! Something wrong with result sets :") ;
114 e
.printStackTrace(log
) ;
116 } catch (com
.sun
.star
.ucb
.ListenerAlreadySetException e
) {
117 log
.println("!!! Can't get static result sets :") ;
118 e
.printStackTrace(log
) ;
123 tRes
.tested("createCachedDynamicResultSetStub()", result
) ;
127 * Creates an instance of <code>CachedDynamicResultSet</code> service
128 * which is not connected to any stub. Then tries to connect it to
129 * <code>DynaminResultSet</code> created and passed as relation.
130 * Connection is checked by retrieving and comparing of row numbers
131 * of connected set and its source set. <p>
132 * Has <b>OK</b> status if row numbers are equal and they are
133 * greater then 0 (because JAR file contains at least one entry).
135 public void _connectToCache() {
136 boolean result
= true ;
138 XCachedDynamicResultSetFactory setFac
= null ;
141 Object fac
= ((XMultiServiceFactory
)tParam
.getMSF()).createInstance
142 ("com.sun.star.ucb.CachedDynamicResultSetFactory") ;
144 setFac
= (XCachedDynamicResultSetFactory
) UnoRuntime
.queryInterface
145 (XCachedDynamicResultSetFactory
.class, fac
) ;
146 } catch (com
.sun
.star
.uno
.Exception e
) {
147 log
.println("Cant instantiate a service") ;
148 e
.printStackTrace(log
) ;
152 XDynamicResultSet rmtSet
= setFac
.createCachedDynamicResultSet(null, null) ;
155 oObj
.connectToCache(resSet
, rmtSet
, null, null) ;
156 } catch (com
.sun
.star
.ucb
.ListenerAlreadySetException e
) {
157 log
.println("!!! Unexpected exception :" + e
) ;
159 } catch (com
.sun
.star
.ucb
.AlreadyInitializedException e
) {
160 log
.println("!!! Unexpected exception :" + e
) ;
165 // checking connection to the source
167 XResultSet statRmtSet
= rmtSet
.getStaticResultSet() ;
168 XResultSet statResSet
= resSet
.getStaticResultSet() ;
171 int rmtRowNum
= statRmtSet
.getRow() ;
174 int resRowNum
= statResSet
.getRow() ;
176 result
= rmtRowNum
== resRowNum
&& resRowNum
> 0 ;
178 log
.println("Number of rows : destination=" + rmtRowNum
+
179 " source=" + resRowNum
) ;
180 } catch (com
.sun
.star
.sdbc
.SQLException e
) {
181 log
.println("!!! Something wrong with result sets :") ;
182 e
.printStackTrace(log
) ;
184 } catch (com
.sun
.star
.ucb
.ListenerAlreadySetException e
) {
185 log
.println("!!! Something wrong with result sets :") ;
186 e
.printStackTrace(log
) ;
191 tRes
.tested("connectToCache()", result
) ;