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
.sdbc
.XResultSet
;
26 import com
.sun
.star
.ucb
.XCachedDynamicResultSetFactory
;
27 import com
.sun
.star
.ucb
.XCachedDynamicResultSetStubFactory
;
28 import com
.sun
.star
.ucb
.XDynamicResultSet
;
29 import com
.sun
.star
.uno
.UnoRuntime
;
32 * Testing <code>com.sun.star.ucb.XCachedDynamicResultSetStubFactory</code>
35 * <li><code> createCachedDynamicResultSetStub()</code></li>
36 * <li><code> connectToCache()</code></li>
38 * This test needs the following object relations :
40 * <li> <code>'DynamicResultSet'</code> (of type
41 * <code>com.sun.star.sdbc.XDynamicResultSet</code>):
42 * this must be an implementation of <code>
43 * com.sun.star.ucb.DynamicResultSet</code> service.</li>
45 * Test is <b> NOT </b> multithread compliant. <p>
46 * @see com.sun.star.ucb.XCachedDynamicResultSetStubFactory
48 public class _XCachedDynamicResultSetStubFactory
extends MultiMethodTest
{
51 * Contains the tested object.
53 public XCachedDynamicResultSetStubFactory oObj
;
54 private XDynamicResultSet resSet
= null ;
57 * Retrieves object relation.
58 * @throws StatusException If relation not found.
61 public void before() {
62 resSet
= (XDynamicResultSet
) tEnv
.getObjRelation("DynamicResultSet") ;
64 log
.println("!!! Relation not found !!!") ;
65 throw new StatusException(Status
.failed("!!! Relation not found !!!")) ;
70 * Creates result set stub from result set. After that number
71 * of rows from result set stub created and its source set are retrieved
72 * using their static representations and compared. <p>
73 * Has <b>OK</b> status if numbers of rows are equal and they are
74 * greater than 0 (because JAR file contains at least one entry).
76 public void _createCachedDynamicResultSetStub() {
77 boolean result
= true ;
79 XDynamicResultSet resSetStub
= oObj
.createCachedDynamicResultSetStub(resSet
) ;
81 if (resSetStub
== null) {
82 log
.println("!!! Method returned null !!!") ;
86 XResultSet resSetS
= resSet
.getStaticResultSet() ;
87 XResultSet resSetStubS
= resSetStub
.getStaticResultSet() ;
90 int stubRowNum
= resSetStubS
.getRow() ;
93 int setRowNum
= resSetS
.getRow() ;
95 result
= stubRowNum
== setRowNum
&& setRowNum
> 0 ;
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
) ;
103 } catch (com
.sun
.star
.ucb
.ListenerAlreadySetException e
) {
104 log
.println("!!! Can't get static result sets :") ;
105 e
.printStackTrace(log
) ;
110 tRes
.tested("createCachedDynamicResultSetStub()", result
) ;
114 * Creates an instance of <code>CachedDynamicResultSet</code> service
115 * which is not connected to any stub. Then tries to connect it to
116 * <code>DynamicResultSet</code> created and passed as relation.
117 * Connection is checked by retrieving and comparing of row numbers
118 * of connected set and its source set. <p>
119 * Has <b>OK</b> status if row numbers are equal and they are
120 * greater than 0 (because JAR file contains at least one entry).
122 public void _connectToCache() throws Exception
{
123 boolean result
= true ;
125 Object fac
= tParam
.getMSF().createInstance
126 ("com.sun.star.ucb.CachedDynamicResultSetFactory") ;
128 XCachedDynamicResultSetFactory setFac
= UnoRuntime
.queryInterface
129 (XCachedDynamicResultSetFactory
.class, fac
) ;
131 XDynamicResultSet rmtSet
= setFac
.createCachedDynamicResultSet(null, null) ;
134 oObj
.connectToCache(resSet
, rmtSet
, null, null) ;
135 } catch (com
.sun
.star
.ucb
.ListenerAlreadySetException e
) {
136 log
.println("!!! Unexpected exception :" + e
) ;
138 } catch (com
.sun
.star
.ucb
.AlreadyInitializedException e
) {
139 log
.println("!!! Unexpected exception :" + e
) ;
144 // checking connection to the source
146 XResultSet statRmtSet
= rmtSet
.getStaticResultSet() ;
147 XResultSet statResSet
= resSet
.getStaticResultSet() ;
150 int rmtRowNum
= statRmtSet
.getRow() ;
153 int resRowNum
= statResSet
.getRow() ;
155 result
= rmtRowNum
== resRowNum
&& resRowNum
> 0 ;
157 log
.println("Number of rows : destination=" + rmtRowNum
+
158 " source=" + resRowNum
) ;
159 } catch (com
.sun
.star
.sdbc
.SQLException e
) {
160 log
.println("!!! Something wrong with result sets :") ;
161 e
.printStackTrace(log
) ;
163 } catch (com
.sun
.star
.ucb
.ListenerAlreadySetException e
) {
164 log
.println("!!! Something wrong with result sets :") ;
165 e
.printStackTrace(log
) ;
170 tRes
.tested("connectToCache()", result
) ;