merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / mod / _cached / CachedContentResultSetFactory.java
blob0eb5899182e597637558ded3aa02e5c4dfbce5c3
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: CachedContentResultSetFactory.java,v $
10 * $Revision: 1.7 $
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 mod._cached;
33 import com.sun.star.beans.Property;
34 import com.sun.star.lang.XMultiServiceFactory;
35 import com.sun.star.sdbc.XResultSet;
36 import com.sun.star.ucb.Command;
37 import com.sun.star.ucb.NumberedSortingInfo;
38 import com.sun.star.ucb.OpenCommandArgument2;
39 import com.sun.star.ucb.OpenMode;
40 import com.sun.star.ucb.XCachedContentResultSetStubFactory;
41 import com.sun.star.ucb.XCommandProcessor;
42 import com.sun.star.ucb.XContent;
43 import com.sun.star.ucb.XContentIdentifier;
44 import com.sun.star.ucb.XContentIdentifierFactory;
45 import com.sun.star.ucb.XContentProvider;
46 import com.sun.star.ucb.XDynamicResultSet;
47 import com.sun.star.uno.UnoRuntime;
48 import com.sun.star.uno.XInterface;
49 import com.sun.star.uno.Type;
50 import com.sun.star.uno.AnyConverter;
51 import java.io.PrintWriter;
52 import lib.StatusException;
53 import lib.TestCase;
54 import lib.TestEnvironment;
55 import lib.TestParameters;
57 /**
58 * Test for object which is represented by service
59 * <code>com.sun.star.ucb.CachedContentResultSetFactory</code>. <p>
60 * Object implements the following interfaces :
61 * <ul>
62 * <li> <code>com::sun::star::ucb::XCachedContentResultSetFactory</code></li>
63 * </ul> <p>
64 * This object test <b> is NOT </b> designed to be run in several
65 * threads concurently.
66 * @see com.sun.star.ucb.XCachedContentResultSetFactory
67 * @see com.sun.star.ucb.CachedContentResultSetFactory
68 * @see ifc.ucb._XCachedContentResultSetFactory
70 public class CachedContentResultSetFactory extends TestCase {
72 /**
73 * Creating a Testenvironment for the interfaces to be tested.
74 * Creates an instance of the service
75 * <code>com.sun.star.ucb.CachedContentResultSetFactory</code>. <p>
76 * Object relations created :
77 * <ul>
78 * <li> <code>'CachedContentResultSetStub'</code> for
79 * {@link ifc.XCachedContentResultSetFactory} : the destination
80 * interface requires as its parameter an instance of
81 * <code>CachedContentResultSetStub</code> service. It is created
82 * using <code>UniversalContentBroker</code> and queriing it for
83 * <code>PackageContent</code> which represents JAR file mentioned
84 * above. Then the dynamic list of file contents (entries) is retrieved,
85 * and a static list is created from it. Using
86 * <code>CachedContentResultSetStubFactory</code> service a stub of
87 * Cached result set is created which is relation required.
88 * </li>
89 * </ul>
91 public TestEnvironment createTestEnvironment( TestParameters Param,
92 PrintWriter log )
93 throws StatusException {
94 XInterface oObj = null;
95 Object oInterface = null;
96 XMultiServiceFactory xMSF = (XMultiServiceFactory)Param.getMSF();
97 Object relationContainer = null ;
100 try {
101 oInterface = xMSF.createInstance
102 ( "com.sun.star.ucb.CachedContentResultSetFactory" );
104 // adding one child container
106 catch( com.sun.star.uno.Exception e ) {
107 log.println("Can't create an object." );
108 throw new StatusException( "Can't create an object", e );
111 oObj = (XInterface) oInterface;
113 TestEnvironment tEnv = new TestEnvironment( oObj );
115 // creating relation for XCachedContentResultSetFactory
116 XResultSet resSetStub = null ;
117 try {
118 Object oUCB = xMSF.createInstanceWithArguments
119 ("com.sun.star.ucb.UniversalContentBroker",
120 new Object[] {"Local", "Office"}) ;
122 XContentIdentifierFactory ciFac = (XContentIdentifierFactory)
123 UnoRuntime.queryInterface(XContentIdentifierFactory.class, oUCB) ;
125 String url = util.utils.getFullTestURL("SwXTextEmbeddedObject.sxw") ;
126 String escUrl = "" ;
128 // In base URL of a JAR file in content URL all directory
129 // separators ('/') must be replaced with escape symbol '%2F'.
130 int idx = url.indexOf("/") ;
131 int lastIdx = -1 ;
132 while (idx >= 0) {
133 escUrl += url.substring(lastIdx + 1, idx) + "%2F" ;
134 lastIdx = idx ;
135 idx = url.indexOf("/", idx + 1) ;
137 escUrl += url.substring(lastIdx + 1) ;
138 String cntUrl = "vnd.sun.star.pkg://" + escUrl + "/" ;
140 XContentIdentifier CI = ciFac.createContentIdentifier(cntUrl) ;
142 XContentProvider cntProv = (XContentProvider)
143 UnoRuntime.queryInterface(XContentProvider.class, oUCB) ;
145 XContent cnt = cntProv.queryContent(CI) ;
147 XCommandProcessor cmdProc = (XCommandProcessor)
148 UnoRuntime.queryInterface(XCommandProcessor.class, cnt) ;
150 Property prop = new Property() ;
151 prop.Name = "Title" ;
153 Command cmd = new Command("open", -1, new OpenCommandArgument2
154 (OpenMode.ALL, 10000, null, new Property[] {prop},
155 new NumberedSortingInfo[0])) ;
157 XDynamicResultSet dynResSet = null;
158 try {
159 dynResSet = (XDynamicResultSet)
160 AnyConverter.toObject(new Type(XDynamicResultSet.class),
161 cmdProc.execute(cmd, 0, null));
162 } catch (com.sun.star.lang.IllegalArgumentException iae) {
163 throw new StatusException("Couldn't convert Any ",iae);
166 XResultSet resSet = dynResSet.getStaticResultSet() ;
168 Object oStubFactory = xMSF.createInstance
169 ("com.sun.star.ucb.CachedContentResultSetStubFactory") ;
171 XCachedContentResultSetStubFactory xStubFactory =
172 (XCachedContentResultSetStubFactory) UnoRuntime.queryInterface
173 (XCachedContentResultSetStubFactory.class, oStubFactory) ;
175 resSetStub = xStubFactory.createCachedContentResultSetStub(resSet) ;
177 } catch (com.sun.star.uno.Exception e) {
178 log.println("Can't create relation." );
179 e.printStackTrace(log) ;
180 throw new StatusException( "Can't create relation", e );
183 tEnv.addObjRelation("CachedContentResultSetStub", resSetStub) ;
185 return tEnv;
186 } // finish method getTestEnvironment