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: _XPropertyContainer.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
.beans
.IllegalTypeException
;
34 import com
.sun
.star
.beans
.NotRemoveableException
;
35 import com
.sun
.star
.beans
.PropertyExistException
;
36 import com
.sun
.star
.uno
.Any
;
37 import lib
.MultiMethodTest
;
38 import com
.sun
.star
.beans
.UnknownPropertyException
;
39 import com
.sun
.star
.beans
.XPropertyContainer
;
41 import lib
.StatusException
;
44 * Testing <code>com.sun.star.beans.XPropertyAccess</code>
47 * <li><code>addProperty()</code></li>
48 * <li><code>removeProperty()</code></li>
50 * @see com.sun.star.beans.XPropertyAccess
52 public class _XPropertyContainer
extends MultiMethodTest
{
55 * oObj filled by MultiMethodTest
57 public XPropertyContainer oObj
= null;// oObj filled by MultiMethodTest
60 * object relation X<CODE>PropertyAccess.propertyNotRemovable</CODE><br>
61 * This relation must be filled from the module. It contains a property which must
62 * be a property of the implementaion object.
64 private String propertyNotRemovable
= null;
67 * checks if the object relation <CODE>XPropertyAccess.propertyNotRemovable</CODE>
70 public void before() {
71 propertyNotRemovable
= (String
) tEnv
.getObjRelation("XPropertyContainer.propertyNotRemovable");
72 if (propertyNotRemovable
== null) {
73 throw new StatusException(Status
.failed("Object raltion 'XPropertyAccess.propertyNotRemovable' is null"));
80 * Test calls the method and checks if the returned sequence contanis a propterty which is named
81 * in the object relation <code>XPropertyAccess.propertyNotRemovable</code>.
83 public void _addProperty() {
90 log
.println("try to add following property:\n" +
91 "\t('myXPropertContainerProperty', com.sun.star.beans.PropertyAttribute.MAYBEVOID, null) ...");
92 oObj
.addProperty("myXPropertContainerProperty" , com
.sun
.star
.beans
.PropertyAttribute
.MAYBEVOID
, null);
93 } catch (com
.sun
.star
.lang
.IllegalArgumentException ex
) {
94 log
.println("ERROR: Exception was thrown while adding following property: " +
95 "('myXPropertContainerProperty', com.sun.star.beans.PropertyAttribute.MAYBEVOID, null) : " +
97 log
.println("... FAILED");
99 } catch (PropertyExistException ex
) {
100 log
.println("ERROR: Exception was thrown while adding following property: " +
101 "('myXPropertContainerProperty', com.sun.star.beans.PropertyAttribute.MAYBEVOID, null) : " +
103 log
.println("... FAILED");
105 } catch (IllegalTypeException ex
) {
106 log
.println("ERROR: Exception was thrown while adding following property: " +
107 "('myXPropertContainerProperty', com.sun.star.beans.PropertyAttribute.MAYBEVOID, null) : " +
109 log
.println("... FAILED");
114 log
.println("... OK");
121 log
.println("add following property second time:\n" +
122 "\t('myXPropertContainerProperty', com.sun.star.beans.PropertyAttribute.MAYBEVOID, null) ...");
123 oObj
.addProperty("myXPropertContainerProperty" , com
.sun
.star
.beans
.PropertyAttribute
.MAYBEVOID
, null);
124 } catch (com
.sun
.star
.lang
.IllegalArgumentException ex
) {
125 log
.println("ERROR: wrong Exception was thrown while adding following property: " +
126 "('myXPropertContainerProperty', com.sun.star.beans.PropertyAttribute.MAYBEVOID, null) : " +
127 "Expected: 'PropertyExistException'\n" +
128 "Got: 'IllegalArgumentException\n" +
130 log
.println("... FAILED");
132 } catch (PropertyExistException ex
) {
133 log
.println("OK: expected Exception was thrown." + ex
.toString());
136 } catch (IllegalTypeException ex
) {
137 log
.println("ERROR: wrong Exception was thrown while adding following property: " +
138 "('myXPropertContainerProperty', com.sun.star.beans.PropertyAttribute.MAYBEVOID, null) : " +
139 "Expected: 'PropertyExistException'\n" +
140 "Got: 'IllegalTypeException\n" +
142 log
.println("... FAILED");
146 log
.println("FAILED: expected exception 'UnknownPropertyException' was not thrown");
148 if (test
) log
.println("... OK");
155 log
.println("try to add following property:\n" +
156 "\t('IllegalTypeProperty', com.sun.star.beans.PropertyAttribute.MAYBEVOID, Any.VOID) ...");
157 oObj
.addProperty("IllegalTypeProperty", com
.sun
.star
.beans
.PropertyAttribute
.MAYBEVOID
, Any
.VOID
);
158 } catch (com
.sun
.star
.lang
.IllegalArgumentException ex
) {
159 log
.println("ERROR: wrong Exception was thrown while adding following property: " +
160 "'', com.sun.star.beans.PropertyAttribute.MAYBEVOID, null\n" +
161 "Expected: 'IllegalTypeException'\n" +
162 "Got: 'IllegalArgumentException\n" +
164 log
.println("... FAILED");
166 } catch (PropertyExistException ex
) {
167 log
.println("ERROR: wrong Exception was thrown while adding following property: " +
168 "'', com.sun.star.beans.PropertyAttribute.MAYBEVOID, null\n" +
169 "Expected: 'IllegalArgumentException'\n" +
170 "Got: 'PropertyExistException\n" +
172 log
.println("... FAILED");
174 } catch (IllegalTypeException ex
) {
175 log
.println("OK: expected Exception was thrown." + ex
.toString());
181 log
.println("FAILED: expected exception 'IllegalTypeException' was not thrown");
183 if (test
) log
.println("... OK");
191 log
.println("add following property:\n" +
192 "'', -1, new Object");
193 oObj
.addProperty("", attrib
, null);
194 } catch (com
.sun
.star
.lang
.IllegalArgumentException ex
) {
195 log
.println("OK: expected Exception was thrown." + ex
.toString());
198 } catch (PropertyExistException ex
) {
199 log
.println("ERROR: wrong Exception was thrown while adding following property: " +
200 "'invalidPropertyAttribute', -1, null\n" +
201 "Expected: 'IllegalTypeException'\n" +
202 "Got: 'PropertyExistException\n" +
204 log
.println("... FAILED");
206 } catch (IllegalTypeException ex
) {
207 log
.println("ERROR: unexpected Exception was thrown while adding following property: " +
209 "Expected: 'IllegalArgumentException'\n" +
210 "Got: 'IllegalTypeException\n" +
212 log
.println("... FAILED");
217 log
.println("FAILED: expected exception 'IllegalArgumentException' was not thrown");
219 if (test
) log
.println("... OK");
224 tRes
.tested("addProperty()", ok
);
229 * Test calls the method and checks if the returned sequence contanis a propterty which is named
230 * in the object relation <code>XPropertyAccess.propertyNotRemovable</code>.
232 public void _removeProperty() {
234 requiredMethod("addProperty()");
241 log
.println("remove 'myXPropertContainerProperty'");
242 oObj
.removeProperty("myXPropertContainerProperty");
243 } catch (NotRemoveableException ex
) {
244 log
.println("ERROR: could not remote property 'myXPropertContainerProperty'" + ex
.toString());
245 log
.println("... FAILED");
247 } catch (UnknownPropertyException ex
) {
248 log
.println("ERROR: could not remote property 'myXPropertContainerProperty'" + ex
.toString());
249 log
.println("... FAILED");
253 log
.println("... OK");
261 log
.println("remove not removeable property '" + propertyNotRemovable
+ "'") ;
262 oObj
.removeProperty(propertyNotRemovable
);
263 } catch (NotRemoveableException ex
) {
264 log
.println("OK: expected Exception was thrown: " + ex
.toString());
267 } catch (UnknownPropertyException ex
) {
268 log
.println("ERROR: wrong exception was thrown.\n" +
269 "Expected: 'NotRemoveableException'\n" +
270 "Got: 'UnknownPropertyException'\n" +
272 log
.println("... FAILED");
277 log
.println("FAILED: expected exception 'NotRemoveableException' was not thrown");
279 if (test
) log
.println("... OK");
287 log
.println("remove property 'thisPropertyDoesNotExist'");
288 oObj
.removeProperty("thisPropertyDoesNotExist");
289 } catch (UnknownPropertyException ex
) {
290 log
.println("OK: expected Exception was thrown: " + ex
.toString());
293 } catch (NotRemoveableException ex
) {
294 log
.println("ERROR: wrong exception was thrown.\n" +
295 "Expected: 'UnknownPropertyException'\n" +
296 "Got: 'NotRemoveableException\n" +
298 log
.println("... FAILED");
302 log
.println("FAILED: expected exception 'UnknownPropertyException' was not thrown");
304 if (test
) log
.println("... OK");
307 tRes
.tested("removeProperty()", ok
);
312 } /// finish class XPropertyContainer