Branch libreoffice-5-0-4
[LibreOffice.git] / qadevOOo / tests / java / ifc / ucb / _XCachedDynamicResultSetStubFactory.java
blob41e8ff16917f565a036bb1e339724adf480f3426
1 /*
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 .
19 package ifc.ucb;
21 import lib.MultiMethodTest;
22 import lib.Status;
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;
31 /**
32 * Testing <code>com.sun.star.ucb.XCachedDynamicResultSetStubFactory</code>
33 * interface methods :
34 * <ul>
35 * <li><code> createCachedDynamicResultSetStub()</code></li>
36 * <li><code> connectToCache()</code></li>
37 * </ul> <p>
38 * This test needs the following object relations :
39 * <ul>
40 * <li> <code>'DynamicResultSet'</code> (of type
41 * <code>com.sun.star.sdbc.XDynamicResultSet</code>):
42 * this must be an imlementation of <code>
43 * com.sun.star.ucb.DynamicResultSet</code> service.</li>
44 * <ul> <p>
45 * Test is <b> NOT </b> multithread compliant. <p>
46 * @see com.sun.star.ucb.XCachedDynamicResultSetStubFactory
48 public class _XCachedDynamicResultSetStubFactory extends MultiMethodTest {
50 /**
51 * Conatins the tested object.
53 public XCachedDynamicResultSetStubFactory oObj;
54 private XDynamicResultSet resSet = null ;
56 /**
57 * Retrieves object relation.
58 * @throws StatusException If relation not found.
60 @Override
61 public void before() {
62 resSet = (XDynamicResultSet) tEnv.getObjRelation("DynamicResultSet") ;
63 if (resSet == null) {
64 log.println("!!! Relation not found !!!") ;
65 throw new StatusException(Status.failed("!!! Relation not found !!!")) ;
69 /**
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 then 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 !!!") ;
83 result = false ;
84 } else {
85 try {
86 XResultSet resSetS = resSet.getStaticResultSet() ;
87 XResultSet resSetStubS = resSetStub.getStaticResultSet() ;
89 resSetStubS.last() ;
90 int stubRowNum = resSetStubS.getRow() ;
92 resSetS.last() ;
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) ;
102 result = false ;
103 } catch (com.sun.star.ucb.ListenerAlreadySetException e) {
104 log.println("!!! Can't get static result sets :") ;
105 e.printStackTrace(log) ;
106 result = false ;
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>DynaminResultSet</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 then 0 (because JAR file contains at least one entry).
122 public void _connectToCache() {
123 boolean result = true ;
125 XCachedDynamicResultSetFactory setFac = null ;
127 try {
128 Object fac = tParam.getMSF().createInstance
129 ("com.sun.star.ucb.CachedDynamicResultSetFactory") ;
131 setFac = UnoRuntime.queryInterface
132 (XCachedDynamicResultSetFactory.class, fac) ;
133 } catch (com.sun.star.uno.Exception e) {
134 log.println("Can't instantiate a service") ;
135 e.printStackTrace(log) ;
136 result = false ;
139 XDynamicResultSet rmtSet = setFac.createCachedDynamicResultSet(null, null) ;
141 try {
142 oObj.connectToCache(resSet, rmtSet, null, null) ;
143 } catch (com.sun.star.ucb.ListenerAlreadySetException e) {
144 log.println("!!! Unexpected exception :" + e) ;
145 result = false ;
146 } catch (com.sun.star.ucb.AlreadyInitializedException e) {
147 log.println("!!! Unexpected exception :" + e) ;
148 result = false ;
151 if (result) {
152 // checking connection to the source
153 try {
154 XResultSet statRmtSet = rmtSet.getStaticResultSet() ;
155 XResultSet statResSet = resSet.getStaticResultSet() ;
157 statRmtSet.last() ;
158 int rmtRowNum = statRmtSet.getRow() ;
160 statResSet.last() ;
161 int resRowNum = statResSet.getRow() ;
163 result = rmtRowNum == resRowNum && resRowNum > 0 ;
165 log.println("Number of rows : destination=" + rmtRowNum +
166 " source=" + resRowNum) ;
167 } catch (com.sun.star.sdbc.SQLException e) {
168 log.println("!!! Something wrong with result sets :") ;
169 e.printStackTrace(log) ;
170 result = false ;
171 } catch (com.sun.star.ucb.ListenerAlreadySetException e) {
172 log.println("!!! Something wrong with result sets :") ;
173 e.printStackTrace(log) ;
174 result = false ;
178 tRes.tested("connectToCache()", result) ;