xref: /AOO41X/main/qadevOOo/tests/java/ifc/registry/_XImplementationRegistration.java (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir package ifc.registry;
29*cdf0e10cSrcweir 
30*cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory;
31*cdf0e10cSrcweir import com.sun.star.registry.CannotRegisterImplementationException;
32*cdf0e10cSrcweir import com.sun.star.registry.XImplementationRegistration;
33*cdf0e10cSrcweir import com.sun.star.registry.XSimpleRegistry;
34*cdf0e10cSrcweir import com.sun.star.uno.RuntimeException;
35*cdf0e10cSrcweir import lib.MultiMethodTest;
36*cdf0e10cSrcweir import util.RegistryTools;
37*cdf0e10cSrcweir import util.utils;
38*cdf0e10cSrcweir 
39*cdf0e10cSrcweir /**
40*cdf0e10cSrcweir * Testing <code>com.sun.star.registry.XImplementationRegistration</code>
41*cdf0e10cSrcweir * interface methods :
42*cdf0e10cSrcweir * <ul>
43*cdf0e10cSrcweir *  <li><code> registerImplementation()</code></li>
44*cdf0e10cSrcweir *  <li><code> revokeImplementation()</code></li>
45*cdf0e10cSrcweir *  <li><code> getImplementations()</code></li>
46*cdf0e10cSrcweir *  <li><code> checkInstantiation()</code></li>
47*cdf0e10cSrcweir * </ul> <p>
48*cdf0e10cSrcweir * The following predefined files needed to complete the test:
49*cdf0e10cSrcweir * <ul>
50*cdf0e10cSrcweir *  <li> <code>solibrary.jar</code> : jar file with implementation
51*cdf0e10cSrcweir *   classes. One of the required implementation must have name
52*cdf0e10cSrcweir *   <code>com.ivistaportal.solibrary.HistogramImpl</code> cause
53*cdf0e10cSrcweir *   it is checked in <code>getImplementations</code> method. </li>
54*cdf0e10cSrcweir * <ul> <p>
55*cdf0e10cSrcweir * Test is <b> NOT </b> multithread compilant. <p>
56*cdf0e10cSrcweir * After test completion object environment has to be recreated.
57*cdf0e10cSrcweir * @see com.sun.star.###
58*cdf0e10cSrcweir */
59*cdf0e10cSrcweir public class _XImplementationRegistration extends MultiMethodTest {
60*cdf0e10cSrcweir 
61*cdf0e10cSrcweir     public XImplementationRegistration oObj = null;
62*cdf0e10cSrcweir 
63*cdf0e10cSrcweir     private String url = null ;
64*cdf0e10cSrcweir     private String loader = null ;
65*cdf0e10cSrcweir     private XSimpleRegistry reg = null ;
66*cdf0e10cSrcweir 
67*cdf0e10cSrcweir     /**
68*cdf0e10cSrcweir     * First a registry created and opened in the temporary directory
69*cdf0e10cSrcweir     * of StarOffice. Then some implementations situated in JAR file
70*cdf0e10cSrcweir     * is registered in the registry opened. <p>
71*cdf0e10cSrcweir     * Has <b>OK</b> status if some information is written into registry.
72*cdf0e10cSrcweir     *
73*cdf0e10cSrcweir     */
74*cdf0e10cSrcweir     public void _registerImplementation()
75*cdf0e10cSrcweir         throws CannotRegisterImplementationException, RuntimeException
76*cdf0e10cSrcweir     {
77*cdf0e10cSrcweir         url = util.utils.getFullTestURL("qadevlibs/MyPersistObjectImpl.jar");
78*cdf0e10cSrcweir         loader = "com.sun.star.loader.Java2";
79*cdf0e10cSrcweir         boolean result = false ;
80*cdf0e10cSrcweir         String name = null;
81*cdf0e10cSrcweir 
82*cdf0e10cSrcweir         try {
83*cdf0e10cSrcweir             name = utils.getOfficeTempDir((XMultiServiceFactory)tParam.getMSF()) +
84*cdf0e10cSrcweir                 "XImplementationRegistration_tmp.rdb";
85*cdf0e10cSrcweir             reg = RegistryTools.openRegistry
86*cdf0e10cSrcweir                 (name, (XMultiServiceFactory)tParam.getMSF()) ;
87*cdf0e10cSrcweir 
88*cdf0e10cSrcweir             oObj.registerImplementation(loader, url, reg) ;
89*cdf0e10cSrcweir 
90*cdf0e10cSrcweir             RegistryTools.printRegistryInfo(reg.getRootKey(), log) ;
91*cdf0e10cSrcweir 
92*cdf0e10cSrcweir             String[] subKeys = reg.getRootKey().getKeyNames() ;
93*cdf0e10cSrcweir 
94*cdf0e10cSrcweir             result = subKeys != null && subKeys.length > 0 ;
95*cdf0e10cSrcweir 
96*cdf0e10cSrcweir         } catch (com.sun.star.uno.Exception e) {
97*cdf0e10cSrcweir             log.println("Can't open registry file: " + name) ;
98*cdf0e10cSrcweir             e.printStackTrace(log) ;
99*cdf0e10cSrcweir         }
100*cdf0e10cSrcweir         tRes.tested("registerImplementation()", result) ;
101*cdf0e10cSrcweir     }
102*cdf0e10cSrcweir 
103*cdf0e10cSrcweir     /**
104*cdf0e10cSrcweir     * Retrieves an array of implementation names and check them. <p>
105*cdf0e10cSrcweir     * Has <b>OK</b> status if among them an implementation name
106*cdf0e10cSrcweir     * <code>com.ivistaportal.solibrary.HistogramImpl</code> exists.
107*cdf0e10cSrcweir     * The following method tests are to be completed successfully before :
108*cdf0e10cSrcweir     * <ul>
109*cdf0e10cSrcweir     *  <li> <code> registerImplementation </code>  </li>
110*cdf0e10cSrcweir     * </ul>
111*cdf0e10cSrcweir     */
112*cdf0e10cSrcweir     public void _getImplementations() throws RuntimeException{
113*cdf0e10cSrcweir         requiredMethod("registerImplementation()") ;
114*cdf0e10cSrcweir 
115*cdf0e10cSrcweir         String[] impl = oObj.getImplementations(loader, url) ;
116*cdf0e10cSrcweir 
117*cdf0e10cSrcweir         if (impl.length == 0) log.println("getImplementations() "+
118*cdf0e10cSrcweir             "returns an empty array");
119*cdf0e10cSrcweir         boolean result = false ;
120*cdf0e10cSrcweir         log.println("Implementations found :") ;
121*cdf0e10cSrcweir         for (int i = 0; i < impl.length; i++) {
122*cdf0e10cSrcweir             log.println(" '" + impl[i] + "'") ;
123*cdf0e10cSrcweir             if ("com.sun.star.cmp.MyPersistObject".
124*cdf0e10cSrcweir                 equals(impl[i])) {
125*cdf0e10cSrcweir 
126*cdf0e10cSrcweir                 result = true ;
127*cdf0e10cSrcweir                 break ;
128*cdf0e10cSrcweir             }
129*cdf0e10cSrcweir         }
130*cdf0e10cSrcweir 
131*cdf0e10cSrcweir 
132*cdf0e10cSrcweir 
133*cdf0e10cSrcweir         tRes.tested("getImplementations()", result) ;
134*cdf0e10cSrcweir     }
135*cdf0e10cSrcweir 
136*cdf0e10cSrcweir     /**
137*cdf0e10cSrcweir     * Calls the method with
138*cdf0e10cSrcweir     * <code>com.sun.star.comp.stoc.JavaComponentLoader</code>
139*cdf0e10cSrcweir     * implementation name.<p>
140*cdf0e10cSrcweir     * Has <b>OK</b> status if not null array returned. <p>
141*cdf0e10cSrcweir     * The following method tests are to be completed successfully before :
142*cdf0e10cSrcweir     * <ul>
143*cdf0e10cSrcweir     *  <li> <code> registerImplementation </code>  </li>
144*cdf0e10cSrcweir     * </ul>
145*cdf0e10cSrcweir     */
146*cdf0e10cSrcweir     public void _checkInstantiation() throws RuntimeException {
147*cdf0e10cSrcweir         requiredMethod("registerImplementation()") ;
148*cdf0e10cSrcweir 
149*cdf0e10cSrcweir         String[] inst = oObj.checkInstantiation(
150*cdf0e10cSrcweir             "com.sun.star.comp.stoc.JavaComponentLoader") ;
151*cdf0e10cSrcweir 
152*cdf0e10cSrcweir         tRes.tested("checkInstantiation()", inst != null) ;
153*cdf0e10cSrcweir     }
154*cdf0e10cSrcweir 
155*cdf0e10cSrcweir     /**
156*cdf0e10cSrcweir     * Revokes implementations from registry, and checks if
157*cdf0e10cSrcweir     * all implementations' information is deleted. <p>
158*cdf0e10cSrcweir     * Has <b>OK</b> status if registry has no key entries. <p>
159*cdf0e10cSrcweir     * The following method tests are to be completed successfully before :
160*cdf0e10cSrcweir     * <ul>
161*cdf0e10cSrcweir     *  <li> <code> registerImplementation </code> : to have
162*cdf0e10cSrcweir     *   implementation registered in registry. </li>
163*cdf0e10cSrcweir     * </ul>
164*cdf0e10cSrcweir     * The following method tests are to be executed before :
165*cdf0e10cSrcweir     * <ul>
166*cdf0e10cSrcweir     *  <li> <code> getImplementations </code>
167*cdf0e10cSrcweir     *  <li> <code> checkInstantiation </code>
168*cdf0e10cSrcweir     * </ul>
169*cdf0e10cSrcweir     */
170*cdf0e10cSrcweir     public void _revokeImplementation() throws RuntimeException{
171*cdf0e10cSrcweir         boolean result = false ;
172*cdf0e10cSrcweir 
173*cdf0e10cSrcweir         requiredMethod("registerImplementation()") ;
174*cdf0e10cSrcweir 
175*cdf0e10cSrcweir         executeMethod("getImplementations()") ;
176*cdf0e10cSrcweir         executeMethod("checkInstantiation()") ;
177*cdf0e10cSrcweir 
178*cdf0e10cSrcweir         oObj.revokeImplementation(url, reg);
179*cdf0e10cSrcweir         RegistryTools.printRegistryInfo(reg, log) ;
180*cdf0e10cSrcweir 
181*cdf0e10cSrcweir         try {
182*cdf0e10cSrcweir             String[] subKeys = reg.getRootKey().getKeyNames() ;
183*cdf0e10cSrcweir 
184*cdf0e10cSrcweir             result = subKeys == null || subKeys.length == 0 ;
185*cdf0e10cSrcweir         } catch (com.sun.star.registry.InvalidRegistryException e) {
186*cdf0e10cSrcweir             log.println("!!! Exception retrieving keys from registry :") ;
187*cdf0e10cSrcweir             e.printStackTrace(log);
188*cdf0e10cSrcweir         }
189*cdf0e10cSrcweir 
190*cdf0e10cSrcweir         tRes.tested("revokeImplementation()", true) ;
191*cdf0e10cSrcweir     }
192*cdf0e10cSrcweir 
193*cdf0e10cSrcweir     public void after() {
194*cdf0e10cSrcweir         this.disposeEnvironment() ;
195*cdf0e10cSrcweir     }
196*cdf0e10cSrcweir }
197*cdf0e10cSrcweir 
198*cdf0e10cSrcweir 
199