2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 import lib
.MultiMethodTest
;
23 import lib
.StatusException
;
25 import com
.sun
.star
.lang
.XMultiServiceFactory
;
26 import com
.sun
.star
.sdbc
.XResultSet
;
27 import com
.sun
.star
.ucb
.XCachedDynamicResultSetFactory
;
28 import com
.sun
.star
.ucb
.XCachedDynamicResultSetStubFactory
;
29 import com
.sun
.star
.ucb
.XDynamicResultSet
;
30 import com
.sun
.star
.uno
.UnoRuntime
;
33 * Testing <code>com.sun.star.ucb.XCachedDynamicResultSetStubFactory</code>
36 * <li><code> createCachedDynamicResultSetStub()</code></li>
37 * <li><code> connectToCache()</code></li>
39 * This test needs the following object relations :
41 * <li> <code>'DynamicResultSet'</code> (of type
42 * <code>com.sun.star.sdbc.XDynamicResultSet</code>):
43 * this must be an imlementation of <code>
44 * com.sun.star.ucb.DynamicResultSet</code> service.</li>
46 * Test is <b> NOT </b> multithread compilant. <p>
47 * @see com.sun.star.ucb.XCachedDynamicResultSetStubFactory
49 public class _XCachedDynamicResultSetStubFactory
extends MultiMethodTest
{
52 * Conatins the tested object.
54 public XCachedDynamicResultSetStubFactory oObj
;
55 private XDynamicResultSet resSet
= null ;
56 private XDynamicResultSet resSetStub
= null ;
59 * Retrieves object relation.
60 * @throws StatusException If relation not found.
62 public void before() {
63 resSet
= (XDynamicResultSet
) tEnv
.getObjRelation("DynamicResultSet") ;
65 log
.println("!!! Relation not found !!!") ;
66 throw new StatusException(Status
.failed("!!! Relation not found !!!")) ;
71 * Creates result set stub from result set. After that number
72 * of rows from result set stub created and its source set are retrieved
73 * using their static representations and compared. <p>
74 * Has <b>OK</b> status if numbers of rows are equal and they are
75 * greater then 0 (because JAR file contains at least one entry).
77 public void _createCachedDynamicResultSetStub() {
78 boolean result
= true ;
80 resSetStub
= oObj
.createCachedDynamicResultSetStub(resSet
) ;
82 if (resSetStub
== null) {
83 log
.println("!!! Method returned null !!!") ;
87 XResultSet resSetS
= resSet
.getStaticResultSet() ;
88 XResultSet resSetStubS
= resSetStub
.getStaticResultSet() ;
91 int stubRowNum
= resSetStubS
.getRow() ;
94 int setRowNum
= resSetS
.getRow() ;
96 result
= stubRowNum
== setRowNum
&& setRowNum
> 0 ;
98 log
.println("Number of rows : stub=" + stubRowNum
+
99 " set=" + setRowNum
) ;
100 } catch (com
.sun
.star
.sdbc
.SQLException e
) {
101 log
.println("!!! Something wrong with result sets :") ;
102 e
.printStackTrace(log
) ;
104 } catch (com
.sun
.star
.ucb
.ListenerAlreadySetException e
) {
105 log
.println("!!! Can't get static result sets :") ;
106 e
.printStackTrace(log
) ;
111 tRes
.tested("createCachedDynamicResultSetStub()", result
) ;
115 * Creates an instance of <code>CachedDynamicResultSet</code> service
116 * which is not connected to any stub. Then tries to connect it to
117 * <code>DynaminResultSet</code> created and passed as relation.
118 * Connection is checked by retrieving and comparing of row numbers
119 * of connected set and its source set. <p>
120 * Has <b>OK</b> status if row numbers are equal and they are
121 * greater then 0 (because JAR file contains at least one entry).
123 public void _connectToCache() {
124 boolean result
= true ;
126 XCachedDynamicResultSetFactory setFac
= null ;
129 Object fac
= ((XMultiServiceFactory
)tParam
.getMSF()).createInstance
130 ("com.sun.star.ucb.CachedDynamicResultSetFactory") ;
132 setFac
= UnoRuntime
.queryInterface
133 (XCachedDynamicResultSetFactory
.class, fac
) ;
134 } catch (com
.sun
.star
.uno
.Exception e
) {
135 log
.println("Cant instantiate a service") ;
136 e
.printStackTrace(log
) ;
140 XDynamicResultSet rmtSet
= setFac
.createCachedDynamicResultSet(null, null) ;
143 oObj
.connectToCache(resSet
, rmtSet
, null, null) ;
144 } catch (com
.sun
.star
.ucb
.ListenerAlreadySetException e
) {
145 log
.println("!!! Unexpected exception :" + e
) ;
147 } catch (com
.sun
.star
.ucb
.AlreadyInitializedException e
) {
148 log
.println("!!! Unexpected exception :" + e
) ;
153 // checking connection to the source
155 XResultSet statRmtSet
= rmtSet
.getStaticResultSet() ;
156 XResultSet statResSet
= resSet
.getStaticResultSet() ;
159 int rmtRowNum
= statRmtSet
.getRow() ;
162 int resRowNum
= statResSet
.getRow() ;
164 result
= rmtRowNum
== resRowNum
&& resRowNum
> 0 ;
166 log
.println("Number of rows : destination=" + rmtRowNum
+
167 " source=" + resRowNum
) ;
168 } catch (com
.sun
.star
.sdbc
.SQLException e
) {
169 log
.println("!!! Something wrong with result sets :") ;
170 e
.printStackTrace(log
) ;
172 } catch (com
.sun
.star
.ucb
.ListenerAlreadySetException e
) {
173 log
.println("!!! Something wrong with result sets :") ;
174 e
.printStackTrace(log
) ;
179 tRes
.tested("connectToCache()", result
) ;