bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _cached / CachedContentResultSetFactory.java
blobd55bc7db403d210ac0c73557783e75cdd3193cb9
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 mod._cached;
21 import com.sun.star.beans.Property;
22 import com.sun.star.lang.XMultiServiceFactory;
23 import com.sun.star.sdbc.XResultSet;
24 import com.sun.star.ucb.Command;
25 import com.sun.star.ucb.NumberedSortingInfo;
26 import com.sun.star.ucb.OpenCommandArgument2;
27 import com.sun.star.ucb.OpenMode;
28 import com.sun.star.ucb.XCachedContentResultSetStubFactory;
29 import com.sun.star.ucb.XCommandProcessor;
30 import com.sun.star.ucb.XContent;
31 import com.sun.star.ucb.XContentIdentifier;
32 import com.sun.star.ucb.XContentIdentifierFactory;
33 import com.sun.star.ucb.XContentProvider;
34 import com.sun.star.ucb.XDynamicResultSet;
35 import com.sun.star.uno.UnoRuntime;
36 import com.sun.star.uno.XInterface;
37 import com.sun.star.uno.Type;
38 import com.sun.star.uno.AnyConverter;
39 import java.io.PrintWriter;
40 import lib.StatusException;
41 import lib.TestCase;
42 import lib.TestEnvironment;
43 import lib.TestParameters;
45 /**
46 * Test for object which is represented by service
47 * <code>com.sun.star.ucb.CachedContentResultSetFactory</code>. <p>
48 * Object implements the following interfaces :
49 * <ul>
50 * <li> <code>com::sun::star::ucb::XCachedContentResultSetFactory</code></li>
51 * </ul> <p>
52 * This object test <b> is NOT </b> designed to be run in several
53 * threads concurently.
54 * @see com.sun.star.ucb.XCachedContentResultSetFactory
55 * @see com.sun.star.ucb.CachedContentResultSetFactory
56 * @see ifc.ucb._XCachedContentResultSetFactory
58 public class CachedContentResultSetFactory extends TestCase {
60 /**
61 * Creating a TestEnvironment for the interfaces to be tested.
62 * Creates an instance of the service
63 * <code>com.sun.star.ucb.CachedContentResultSetFactory</code>. <p>
64 * Object relations created :
65 * <ul>
66 * <li> <code>'CachedContentResultSetStub'</code> for
67 * {@link ifc.ucb._XCachedContentResultSetFactory} : the destination
68 * interface requires as its parameter an instance of
69 * <code>CachedContentResultSetStub</code> service. It is created
70 * using <code>UniversalContentBroker</code> and querying it for
71 * <code>PackageContent</code> which represents JAR file mentioned
72 * above. Then the dynamic list of file contents (entries) is retrieved,
73 * and a static list is created from it. Using
74 * <code>CachedContentResultSetStubFactory</code> service a stub of
75 * Cached result set is created which is relation required.
76 * </li>
77 * </ul>
79 public TestEnvironment createTestEnvironment( TestParameters Param,
80 PrintWriter log )
81 throws StatusException {
82 XInterface oObj = null;
83 Object oInterface = null;
84 XMultiServiceFactory xMSF = (XMultiServiceFactory)Param.getMSF();
85 try {
86 oInterface = xMSF.createInstance
87 ( "com.sun.star.ucb.CachedContentResultSetFactory" );
89 // adding one child container
91 catch( com.sun.star.uno.Exception e ) {
92 log.println("Can't create an object." );
93 throw new StatusException( "Can't create an object", e );
96 oObj = (XInterface) oInterface;
98 TestEnvironment tEnv = new TestEnvironment( oObj );
100 // creating relation for XCachedContentResultSetFactory
101 XResultSet resSetStub = null ;
102 try {
103 Object oUCB = xMSF.createInstanceWithArguments
104 ("com.sun.star.ucb.UniversalContentBroker",
105 new Object[0]) ;
107 XContentIdentifierFactory ciFac = UnoRuntime.queryInterface(XContentIdentifierFactory.class, oUCB) ;
109 String url = util.utils.getFullTestURL("SwXTextEmbeddedObject.sxw") ;
110 String escUrl = "" ;
112 // In base URL of a JAR file in content URL all directory
113 // separators ('/') must be replaced with escape symbol '%2F'.
114 int idx = url.indexOf("/") ;
115 int lastIdx = -1 ;
116 while (idx >= 0) {
117 escUrl += url.substring(lastIdx + 1, idx) + "%2F" ;
118 lastIdx = idx ;
119 idx = url.indexOf("/", idx + 1) ;
121 escUrl += url.substring(lastIdx + 1) ;
122 String cntUrl = "vnd.sun.star.pkg://" + escUrl + "/" ;
124 XContentIdentifier CI = ciFac.createContentIdentifier(cntUrl) ;
126 XContentProvider cntProv = UnoRuntime.queryInterface(XContentProvider.class, oUCB) ;
128 XContent cnt = cntProv.queryContent(CI) ;
130 XCommandProcessor cmdProc = UnoRuntime.queryInterface(XCommandProcessor.class, cnt) ;
132 Property prop = new Property() ;
133 prop.Name = "Title" ;
135 Command cmd = new Command("open", -1, new OpenCommandArgument2
136 (OpenMode.ALL, 10000, null, new Property[] {prop},
137 new NumberedSortingInfo[0])) ;
139 XDynamicResultSet dynResSet = null;
140 try {
141 dynResSet = (XDynamicResultSet)
142 AnyConverter.toObject(new Type(XDynamicResultSet.class),
143 cmdProc.execute(cmd, 0, null));
144 } catch (com.sun.star.lang.IllegalArgumentException iae) {
145 throw new StatusException("Couldn't convert Any ",iae);
148 XResultSet resSet = dynResSet.getStaticResultSet() ;
150 Object oStubFactory = xMSF.createInstance
151 ("com.sun.star.ucb.CachedContentResultSetStubFactory") ;
153 XCachedContentResultSetStubFactory xStubFactory =
154 UnoRuntime.queryInterface
155 (XCachedContentResultSetStubFactory.class, oStubFactory) ;
157 resSetStub = xStubFactory.createCachedContentResultSetStub(resSet) ;
159 } catch (com.sun.star.uno.Exception e) {
160 log.println("Can't create relation." );
161 e.printStackTrace(log) ;
162 throw new StatusException( "Can't create relation", e );
165 tEnv.addObjRelation("CachedContentResultSetStub", resSetStub) ;
167 return tEnv;
168 } // finish method getTestEnvironment