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: OInnerValueSetUpdateAccess.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 ************************************************************************/
32 import java
.io
.PrintWriter
;
35 import lib
.TestEnvironment
;
36 import lib
.TestParameters
;
39 import com
.sun
.star
.beans
.PropertyState
;
40 import com
.sun
.star
.beans
.PropertyValue
;
41 import com
.sun
.star
.container
.XNameAccess
;
42 import com
.sun
.star
.container
.XNameContainer
;
43 import com
.sun
.star
.lang
.XMultiServiceFactory
;
44 import com
.sun
.star
.uno
.UnoRuntime
;
45 import com
.sun
.star
.uno
.XInterface
;
46 import com
.sun
.star
.util
.XChangesBatch
;
49 public class OInnerValueSetUpdateAccess
extends TestCase
{
50 /** Called to create an instance of <code>TestEnvironment</code> with an
51 * object to test and related objects. <br>
53 * An instance of com.sun.star.comp.configuration.ConfigurationProvider
54 * is created at the MultiServiceFactory of the Office<br>
55 * At this an instance of com.sun.star.configuration.ConfigurationAccess is created
56 * and from the resulting XNameAccess the first element is taken.
58 * @param tParam test parameters
59 * @param log writer to log information while testing
61 * @see TestEnvironment
62 * @see #getTestEnvironment()
65 protected TestEnvironment
createTestEnvironment(TestParameters tParam
,
67 XInterface oObj
= null;
69 log
.println("creating the Environment");
71 // create some entries for testing, use the ORootElementValueSetUpdateAccess
72 // service for this: see cfgmgr2.ORootElementValueSetUpdateAccess
73 createSomeEntries((XMultiServiceFactory
)tParam
.getMSF());
75 PropertyValue
[] nodeArgs
= new PropertyValue
[1];
76 PropertyValue nodepath
= new PropertyValue();
77 nodepath
.Name
= "nodepath";
78 nodepath
.Value
= "/org.openoffice.Office.Common";
80 nodepath
.State
= PropertyState
.DEFAULT_VALUE
;
81 nodeArgs
[0] = nodepath
;
84 XInterface Provider
= (XInterface
) ((XMultiServiceFactory
)tParam
.getMSF())
85 .createInstance("com.sun.star.comp.configuration.ConfigurationProvider");
86 XMultiServiceFactory pMSF
= (XMultiServiceFactory
) UnoRuntime
.queryInterface(
87 XMultiServiceFactory
.class,
89 XNameAccess names
= (XNameAccess
) UnoRuntime
.queryInterface(
91 pMSF
.createInstanceWithArguments(
92 "com.sun.star.configuration.ConfigurationUpdateAccess",
95 oObj
= (XInterface
) names
.getByName("ExternalApps");
97 names
= (XNameAccess
) UnoRuntime
.queryInterface(XNameAccess
.class,
100 String
[] theNames
= names
.getElementNames();
102 log
.println("Contains " + theNames
.length
+ " elements");
104 // for (int k = 0; k < theNames.length; k++) {
105 // System.out.println("child " + theNames[k]);
107 } catch (com
.sun
.star
.uno
.Exception e
) {
111 log
.println("ImplementationName: " + utils
.getImplName(oObj
));
113 String
[] pNames
= new String
[] {
114 "file", "ftp", "http", "https", "mailto"
117 String
[] pTypes
= new String
[] {
118 "String", "String", "String", "String", "String"
121 TestEnvironment tEnv
= new TestEnvironment(oObj
);
123 tEnv
.addObjRelation("cannotSwitchParent",
124 "configmgr: BasicElement::setParent: cannot move Entry");
126 String overwriteString
= "NewOne";
127 tEnv
.addObjRelation("INSTANCE1", overwriteString
);
128 tEnv
.addObjRelation("NAMEREPLACE", pNames
[1]);
130 tEnv
.addObjRelation("INSTANCE", overwriteString
);
132 tEnv
.addObjRelation("HierachicalName", "/org.openoffice.Office");
133 tEnv
.addObjRelation("ElementName", "file");
134 tEnv
.addObjRelation("NoSetName", "OInnerValueSetInfoAccess");
135 tEnv
.addObjRelation("TemplateName", "cfg:value/cfg:any");
136 tEnv
.addObjRelation("expectedName", "file");
142 * Create entries in the ExternalApps layer, so there is something to test
143 * @param oObj The test object: used to create some entries.
145 private void createSomeEntries(XMultiServiceFactory xMSF
) {
146 PropertyValue
[] nodeArgs
= new PropertyValue
[1];
147 PropertyValue nodepath
= new PropertyValue();
148 nodepath
.Name
= "nodepath";
149 nodepath
.Value
= "org.openoffice.Office.Common/ExternalApps";
150 nodepath
.Handle
= -1;
151 nodepath
.State
= PropertyState
.DEFAULT_VALUE
;
152 nodeArgs
[0] = nodepath
;
156 XInterface Provider
= (XInterface
) xMSF
.createInstance("com.sun.star.comp.configuration.ConfigurationProvider");
157 XMultiServiceFactory pMSF
= (XMultiServiceFactory
) UnoRuntime
.queryInterface(
158 XMultiServiceFactory
.class,
160 oObj
= (XNameAccess
) UnoRuntime
.queryInterface(XNameAccess
.class,
161 pMSF
.createInstanceWithArguments(
162 "com.sun.star.configuration.ConfigurationUpdateAccess",
165 } catch (com
.sun
.star
.uno
.Exception e
) {
168 XNameContainer xCont
= (XNameContainer
)UnoRuntime
.queryInterface(XNameContainer
.class, oObj
);
169 insertOrUpdate(xCont
, "file", "just");
170 insertOrUpdate(xCont
, "ftp", "some");
171 insertOrUpdate(xCont
, "dummy", "arbitrary");
172 insertOrUpdate(xCont
, "http", "value");
173 // write the changes into the user layer.
174 XChangesBatch xBatch
= (XChangesBatch
)UnoRuntime
.queryInterface(XChangesBatch
.class, oObj
);
176 xBatch
.commitChanges();
178 catch(com
.sun
.star
.lang
.WrappedTargetException e
) {
179 // ignore: bug will be found with the interface test
184 * Insert a value in a name container or else update it
185 * @param xCont The name conationer to insert or update.
186 * @param name The name of the value.
187 * @param value The value itself.
189 private void insertOrUpdate(XNameContainer xCont
, String name
, String value
) {
190 boolean update
= false;
192 xCont
.insertByName(name
, value
);
193 System
.out
.println("##### No Exception!");
195 catch(com
.sun
.star
.lang
.IllegalArgumentException e
) {
196 // ignore: bug will be found with the interface test
198 catch(com
.sun
.star
.lang
.WrappedTargetException e
) {
199 // ignore: bug will be found with the interface test
201 catch(com
.sun
.star
.container
.ElementExistException e
) {
206 xCont
.replaceByName(name
, value
);
208 catch(com
.sun
.star
.lang
.IllegalArgumentException e
) {
209 // ignore: bug will be found with the interface test
211 catch(com
.sun
.star
.container
.NoSuchElementException e
) {
212 // ignore: bug will be found with the interface test
214 catch(com
.sun
.star
.lang
.WrappedTargetException e
) {
215 // ignore: bug will be found with the interface test