1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: _XImplementationRegistration.java,v $
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 ************************************************************************/
33 import com
.sun
.star
.lang
.XMultiServiceFactory
;
34 import com
.sun
.star
.registry
.CannotRegisterImplementationException
;
35 import com
.sun
.star
.registry
.XImplementationRegistration
;
36 import com
.sun
.star
.registry
.XSimpleRegistry
;
37 import com
.sun
.star
.uno
.RuntimeException
;
38 import lib
.MultiMethodTest
;
39 import util
.RegistryTools
;
43 * Testing <code>com.sun.star.registry.XImplementationRegistration</code>
46 * <li><code> registerImplementation()</code></li>
47 * <li><code> revokeImplementation()</code></li>
48 * <li><code> getImplementations()</code></li>
49 * <li><code> checkInstantiation()</code></li>
51 * The following predefined files needed to complete the test:
53 * <li> <code>solibrary.jar</code> : jar file with implementation
54 * classes. One of the required implementation must have name
55 * <code>com.ivistaportal.solibrary.HistogramImpl</code> cause
56 * it is checked in <code>getImplementations</code> method. </li>
58 * Test is <b> NOT </b> multithread compilant. <p>
59 * After test completion object environment has to be recreated.
60 * @see com.sun.star.###
62 public class _XImplementationRegistration
extends MultiMethodTest
{
64 public XImplementationRegistration oObj
= null;
66 private String url
= null ;
67 private String loader
= null ;
68 private XSimpleRegistry reg
= null ;
71 * First a registry created and opened in the temporary directory
72 * of StarOffice. Then some implementations situated in JAR file
73 * is registered in the registry opened. <p>
74 * Has <b>OK</b> status if some information is written into registry.
77 public void _registerImplementation()
78 throws CannotRegisterImplementationException
, RuntimeException
80 url
= util
.utils
.getFullTestURL("qadevlibs/MyPersistObjectImpl.jar");
81 loader
= "com.sun.star.loader.Java2";
82 boolean result
= false ;
86 name
= utils
.getOfficeTempDir((XMultiServiceFactory
)tParam
.getMSF()) +
87 "XImplementationRegistration_tmp.rdb";
88 reg
= RegistryTools
.openRegistry
89 (name
, (XMultiServiceFactory
)tParam
.getMSF()) ;
91 oObj
.registerImplementation(loader
, url
, reg
) ;
93 RegistryTools
.printRegistryInfo(reg
.getRootKey(), log
) ;
95 String
[] subKeys
= reg
.getRootKey().getKeyNames() ;
97 result
= subKeys
!= null && subKeys
.length
> 0 ;
99 } catch (com
.sun
.star
.uno
.Exception e
) {
100 log
.println("Can't open registry file: " + name
) ;
101 e
.printStackTrace(log
) ;
103 tRes
.tested("registerImplementation()", result
) ;
107 * Retrieves an array of implementation names and check them. <p>
108 * Has <b>OK</b> status if among them an implementation name
109 * <code>com.ivistaportal.solibrary.HistogramImpl</code> exists.
110 * The following method tests are to be completed successfully before :
112 * <li> <code> registerImplementation </code> </li>
115 public void _getImplementations() throws RuntimeException
{
116 requiredMethod("registerImplementation()") ;
118 String
[] impl
= oObj
.getImplementations(loader
, url
) ;
120 if (impl
.length
== 0) log
.println("getImplementations() "+
121 "returns an empty array");
122 boolean result
= false ;
123 log
.println("Implementations found :") ;
124 for (int i
= 0; i
< impl
.length
; i
++) {
125 log
.println(" '" + impl
[i
] + "'") ;
126 if ("com.sun.star.cmp.MyPersistObject".
136 tRes
.tested("getImplementations()", result
) ;
140 * Calls the method with
141 * <code>com.sun.star.comp.stoc.JavaComponentLoader</code>
142 * implementation name.<p>
143 * Has <b>OK</b> status if not null array returned. <p>
144 * The following method tests are to be completed successfully before :
146 * <li> <code> registerImplementation </code> </li>
149 public void _checkInstantiation() throws RuntimeException
{
150 requiredMethod("registerImplementation()") ;
152 String
[] inst
= oObj
.checkInstantiation(
153 "com.sun.star.comp.stoc.JavaComponentLoader") ;
155 tRes
.tested("checkInstantiation()", inst
!= null) ;
159 * Revokes implementations from registry, and checks if
160 * all implementations' information is deleted. <p>
161 * Has <b>OK</b> status if registry has no key entries. <p>
162 * The following method tests are to be completed successfully before :
164 * <li> <code> registerImplementation </code> : to have
165 * implementation registered in registry. </li>
167 * The following method tests are to be executed before :
169 * <li> <code> getImplementations </code>
170 * <li> <code> checkInstantiation </code>
173 public void _revokeImplementation() throws RuntimeException
{
174 boolean result
= false ;
176 requiredMethod("registerImplementation()") ;
178 executeMethod("getImplementations()") ;
179 executeMethod("checkInstantiation()") ;
181 oObj
.revokeImplementation(url
, reg
);
182 RegistryTools
.printRegistryInfo(reg
, log
) ;
185 String
[] subKeys
= reg
.getRootKey().getKeyNames() ;
187 result
= subKeys
== null || subKeys
.length
== 0 ;
188 } catch (com
.sun
.star
.registry
.InvalidRegistryException e
) {
189 log
.println("!!! Exception retrieving keys from registry :") ;
190 e
.printStackTrace(log
);
193 tRes
.tested("revokeImplementation()", true) ;
196 public void after() {
197 this.disposeEnvironment() ;