merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / ifc / ucb / _XCachedDynamicResultSetStubFactory.java
blob7f9fa9d149968f05d4ea3b815a48ad09cf5bf768
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: _XCachedDynamicResultSetStubFactory.java,v $
10 * $Revision: 1.5 $
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 ************************************************************************/
31 package ifc.ucb;
33 import lib.MultiMethodTest;
34 import lib.Status;
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;
44 /**
45 * Testing <code>com.sun.star.ucb.XCachedDynamicResultSetStubFactory</code>
46 * interface methods :
47 * <ul>
48 * <li><code> createCachedDynamicResultSetStub()</code></li>
49 * <li><code> connectToCache()</code></li>
50 * </ul> <p>
51 * This test needs the following object relations :
52 * <ul>
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>
57 * <ul> <p>
58 * Test is <b> NOT </b> multithread compilant. <p>
59 * @see com.sun.star.ucb.XCachedDynamicResultSetStubFactory
61 public class _XCachedDynamicResultSetStubFactory extends MultiMethodTest {
63 /**
64 * Conatins the tested object.
66 public XCachedDynamicResultSetStubFactory oObj;
67 private XDynamicResultSet resSet = null ;
68 private XDynamicResultSet resSetStub = null ;
70 /**
71 * Retrieves object relation.
72 * @throws StatusException If relation not found.
74 public void before() {
75 resSet = (XDynamicResultSet) tEnv.getObjRelation("DynamicResultSet") ;
76 if (resSet == null) {
77 log.println("!!! Relation not found !!!") ;
78 throw new StatusException(Status.failed("!!! Relation not found !!!")) ;
82 /**
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 !!!") ;
96 result = false ;
97 } else {
98 try {
99 XResultSet resSetS = resSet.getStaticResultSet() ;
100 XResultSet resSetStubS = resSetStub.getStaticResultSet() ;
102 resSetStubS.last() ;
103 int stubRowNum = resSetStubS.getRow() ;
105 resSetS.last() ;
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) ;
115 result = false ;
116 } catch (com.sun.star.ucb.ListenerAlreadySetException e) {
117 log.println("!!! Can't get static result sets :") ;
118 e.printStackTrace(log) ;
119 result = false ;
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 ;
140 try {
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) ;
149 result = false ;
152 XDynamicResultSet rmtSet = setFac.createCachedDynamicResultSet(null, null) ;
154 try {
155 oObj.connectToCache(resSet, rmtSet, null, null) ;
156 } catch (com.sun.star.ucb.ListenerAlreadySetException e) {
157 log.println("!!! Unexpected exception :" + e) ;
158 result = false ;
159 } catch (com.sun.star.ucb.AlreadyInitializedException e) {
160 log.println("!!! Unexpected exception :" + e) ;
161 result = false ;
164 if (result) {
165 // checking connection to the source
166 try {
167 XResultSet statRmtSet = rmtSet.getStaticResultSet() ;
168 XResultSet statResSet = resSet.getStaticResultSet() ;
170 statRmtSet.last() ;
171 int rmtRowNum = statRmtSet.getRow() ;
173 statResSet.last() ;
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) ;
183 result = false ;
184 } catch (com.sun.star.ucb.ListenerAlreadySetException e) {
185 log.println("!!! Something wrong with result sets :") ;
186 e.printStackTrace(log) ;
187 result = false ;
191 tRes.tested("connectToCache()", result) ;