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: ORootElementValueSetUpdateAccess.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
.container
.XNameReplace
;
44 import com
.sun
.star
.lang
.XMultiServiceFactory
;
45 import com
.sun
.star
.uno
.UnoRuntime
;
46 import com
.sun
.star
.uno
.XInterface
;
47 import com
.sun
.star
.util
.XChangesBatch
;
50 * Check the ORootElementValueSetUpdateAccess service.
51 * For this, the ExternalApss layer is used. Since this layer is empty (since
52 * cws cfgapi), some own values are created and written to the current user
53 * layer. The tests are then executed on these values.
55 public class ORootElementValueSetUpdateAccess
extends TestCase
{
56 /** Called to create an instance of <code>TestEnvironment</code> with an
57 * object to test and related objects. <br>
59 * An instance of com.sun.star.comp.configuration.ConfigurationProvider
60 * is created at the MultiServiceFactory of the Office<br>
61 * At this an instance of com.sun.star.configuration.ConfigurationAccess is created
62 * and from the resulting XNameAccess the first element is taken.
64 * @param tParam test parameters
65 * @param log writer to log information while testing
67 * @see TestEnvironment
68 * @see #getTestEnvironment()
71 protected TestEnvironment
createTestEnvironment(TestParameters tParam
,
73 XInterface oObj
= null;
74 Object instance
= null;
75 Object instance1
= null;
76 Object instance2
= null;
77 log
.println("creating the Environment");
79 PropertyValue
[] nodeArgs
= new PropertyValue
[1];
80 PropertyValue nodepath
= new PropertyValue();
81 nodepath
.Name
= "nodepath";
82 nodepath
.Value
= "org.openoffice.Office.Common/ExternalApps";
84 nodepath
.State
= PropertyState
.DEFAULT_VALUE
;
85 nodeArgs
[0] = nodepath
;
88 XInterface Provider
= (XInterface
) ((XMultiServiceFactory
)tParam
.getMSF())
89 .createInstance("com.sun.star.comp.configuration.ConfigurationProvider");
90 XMultiServiceFactory pMSF
= (XMultiServiceFactory
) UnoRuntime
.queryInterface(
91 XMultiServiceFactory
.class,
93 oObj
= (XNameAccess
) UnoRuntime
.queryInterface(XNameAccess
.class,
94 pMSF
.createInstanceWithArguments(
95 "com.sun.star.configuration.ConfigurationUpdateAccess",
98 } catch (com
.sun
.star
.uno
.Exception e
) {
102 log
.println("ImplementationName: " + utils
.getImplName(oObj
));
104 TestEnvironment tEnv
= new TestEnvironment(oObj
);
106 String
[] pNames
= new String
[] {
107 "file", "ftp", "dummy", "http"
110 String
[] pTypes
= new String
[] {
111 "String", "String", "String", "String"
114 createSomeEntries(oObj
);
116 tEnv
.addObjRelation("INSTANCE1", "NewOne1");
117 tEnv
.addObjRelation("NAMEREPLACE", pNames
[0]);
120 tEnv
.addObjRelation("INSTANCE", "NewOne2");
122 tEnv
.addObjRelation("XChangesBatch.PropertyName", pNames
[0]);
123 tEnv
.addObjRelation("XChangesBatch.ChangeElement", "NewOne3");
124 tEnv
.addObjRelation("XChangesBatch.NameReplace", (XNameReplace
)UnoRuntime
.queryInterface(XNameReplace
.class, oObj
));
126 tEnv
.addObjRelation("XChangesNotifier.PropertyName", pNames
[0]);
127 tEnv
.addObjRelation("XChangesNotifier.ChangeElement", "NewOne4");
128 tEnv
.addObjRelation("XChangesNotifier.ChangesBatch" , (XChangesBatch
)UnoRuntime
.queryInterface(XChangesBatch
.class, oObj
));
129 tEnv
.addObjRelation("XChangesNotifier.NameReplace", (XNameReplace
)UnoRuntime
.queryInterface(XNameReplace
.class, oObj
));
131 tEnv
.addObjRelation("XLocalizable.ReadOnly", "Locale of ORootElementValueSetUpdateAccess is read Only");
132 tEnv
.addObjRelation("NoSetName", "ORootElementValueSetUpdateAccess");
134 tEnv
.addObjRelation("HierachicalName", "/org.openoffice.Office");
135 tEnv
.addObjRelation("ElementName","http");
136 tEnv
.addObjRelation("TemplateName", "cfg:value/cfg:any");
138 tEnv
.addObjRelation("expectedName","http");
143 * Create entries in the ExternalApps layer, so there is something to test
144 * @param oObj The test object: used to create some entries.
146 private void createSomeEntries(XInterface oObj
) {
147 XNameContainer xCont
= (XNameContainer
)UnoRuntime
.queryInterface(XNameContainer
.class, oObj
);
148 insertOrUpdate(xCont
, "file", "just");
149 insertOrUpdate(xCont
, "ftp", "some");
150 insertOrUpdate(xCont
, "dummy", "arbitrary");
151 insertOrUpdate(xCont
, "http", "value");
152 // write the changes into the user layer.
153 XChangesBatch xBatch
= (XChangesBatch
)UnoRuntime
.queryInterface(XChangesBatch
.class, oObj
);
155 xBatch
.commitChanges();
157 catch(com
.sun
.star
.lang
.WrappedTargetException e
) {
158 // ignore: bug will be found with the interface test
163 * Insert a value in a name container or else update it
164 * @param xCont The name conationer to insert or update.
165 * @param name The name of the value.
166 * @param value The value itself.
168 private void insertOrUpdate(XNameContainer xCont
, String name
, String value
) {
169 boolean update
= false;
171 xCont
.insertByName(name
, value
);
173 catch(com
.sun
.star
.lang
.IllegalArgumentException e
) {
174 // ignore: bug will be found with the interface test
176 catch(com
.sun
.star
.lang
.WrappedTargetException e
) {
177 // ignore: bug will be found with the interface test
179 catch(com
.sun
.star
.container
.ElementExistException e
) {
184 xCont
.replaceByName(name
, value
);
186 catch(com
.sun
.star
.lang
.IllegalArgumentException e
) {
187 // ignore: bug will be found with the interface test
189 catch(com
.sun
.star
.container
.NoSuchElementException e
) {
190 // ignore: bug will be found with the interface test
192 catch(com
.sun
.star
.lang
.WrappedTargetException e
) {
193 // ignore: bug will be found with the interface test