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: _XPropertyAccess.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
.PropertyValue
;
34 import com
.sun
.star
.beans
.PropertyVetoException
;
35 import com
.sun
.star
.lang
.WrappedTargetException
;
36 import lib
.MultiMethodTest
;
37 import com
.sun
.star
.beans
.UnknownPropertyException
;
38 import com
.sun
.star
.beans
.XPropertyAccess
;
40 import lib
.StatusException
;
43 * Testing <code>com.sun.star.beans.XPropertyAccess</code>
46 * <li><code>getPropertyValues()</code></li>
47 * <li><code>setPropertyValues()</code></li>
49 * @see com.sun.star.beans.XPropertyAccess
51 public class _XPropertyAccess
extends MultiMethodTest
{
54 * oObj filled by MultiMethodTest
56 public XPropertyAccess oObj
= null;// oObj filled by MultiMethodTest
59 * object relation X<CODE>PropertyAccess.propertyToChange</CODE><br>
60 * This relation must be filled from the module. It contains a property which must
61 * be kind of String property, available at <CODE>getPropertyValues()</CODE> and changeable by
62 * <CODE>setPropertyValues()</CODE>
64 public PropertyValue propertyToChange
= null;
67 * checks if the object relation <CODE>XPropertyAccess.propertyToChange</CODE>
70 public void before() {
71 propertyToChange
= (PropertyValue
) tEnv
.getObjRelation("XPropertyAccess.propertyToChange");
72 if (propertyToChange
== null) {
73 throw new StatusException(Status
.failed("Object raltion 'XPropertyAccess.propertyToChange' is null"));
78 * Test calls the method and checks if the returned sequenze contanis a propterty which is named
79 * in the object relation <code>XPropertyAccess.propertyToChange</code>.
81 public void _getPropertyValues() {
82 PropertyValue
[] properties
= oObj
.getPropertyValues();
86 if (properties
!= null){
88 boolean found
= false;
89 for (int i
=0; i
< properties
.length
; i
++){
90 if (properties
[i
].Name
.equals(propertyToChange
.Name
)) found
= true;
93 log
.println("ERROR: could not find desired property '"+ propertyToChange
.Name
+"'");
98 log
.println("ERROR: the method returned NULL");
102 tRes
.tested("getPropertyValues()", ok
);
107 * Test calls the method and checks if:
109 * <li>the property given by the object relation
110 * <CODE>XPropertyAccess.propertyToChange</CODE> has changed</LI>
111 * <li><CODE>com.sun.star.lang.IllegalArgumentException</CODE> was thrown if a <CODE>Integer</CODE>
112 * value was set to a <CODE>String</CODE> property</LI>
113 * <li><CODE>com.sun.star.beans.UnknownPropertyException</CODE> was throen if an invalid property
117 public void _setPropertyValues(){
124 PropertyValue
[] newProps
= new PropertyValue
[1];
125 newProps
[0] = propertyToChange
;
127 log
.println("try to set property vlaues given by object relation 'XPropertyAccess.propertyToChange'...");
128 oObj
.setPropertyValues(newProps
);
130 } catch (UnknownPropertyException ex
) {
131 log
.println("ERROR: Exception was thrown while trying to set property value: " +
134 } catch (PropertyVetoException ex
) {
135 log
.println("ERROR: Exception was thrown while trying to set property value: " +
138 } catch (WrappedTargetException ex
) {
139 log
.println("ERROR: Exception was thrown while trying to set property value: " +
142 } catch (com
.sun
.star
.lang
.IllegalArgumentException ex
) {
143 log
.println("ERROR: Exception was thrown while trying to set property value: " +
149 log
.println("... OK");
156 log
.println("try to set integer value to string property, " +
157 "expect 'com.sun.star.lang.IllegalArgumentException'...");
158 PropertyValue
[] newProps
= new PropertyValue
[1];
159 PropertyValue failedProp
= new PropertyValue();
160 failedProp
.Name
= propertyToChange
.Name
;
161 failedProp
.Value
= new Integer(10);
162 newProps
[0] = failedProp
;
163 oObj
.setPropertyValues(newProps
);
164 } catch (PropertyVetoException ex
) {
165 log
.println("ERROR: unexptected exception was thrown while trying to set null value: " +
168 } catch (WrappedTargetException ex
) {
169 log
.println("ERROR: unexptected exception was thrown while trying to set null value: " +
172 } catch (com
.sun
.star
.lang
.IllegalArgumentException ex
) {
173 log
.println("OK: exptected exception was thrown while trying to set null value: " +
177 } catch (UnknownPropertyException ex
) {
178 log
.println("ERROR: unexptected exception was thrown while trying to set null value: " +
184 log
.println("FAILED: expected exception 'UnknownPropertyException' was not thrown");
186 if (test
) log
.println("... OK");
194 log
.println("try to set values with invalid property name. " +
195 "Expect 'com.sun.star.beans.UnknownPropertyException'...");
197 PropertyValue
[] newProps
= new PropertyValue
[1];
198 PropertyValue newProp
= new PropertyValue();
199 newProp
.Name
= "XPropertyAccess.InvalidPropertyName";
200 newProp
.Value
= "invalid property";
201 newProps
[0] = newProp
;
203 oObj
.setPropertyValues(newProps
);
205 } catch (WrappedTargetException ex
) {
206 log
.println("ERROR: unexptected exception was thrown while trying to set invalid value: " +
209 } catch (com
.sun
.star
.lang
.IllegalArgumentException ex
) {
210 log
.println("ERROR: unexptected exception was thrown while trying to set invalid value: " +
213 } catch (PropertyVetoException ex
) {
214 log
.println("ERROR: unexptected exception was thrown while trying to set invalid value: " +
217 } catch (UnknownPropertyException ex
) {
218 log
.println("OK: Exptected exception was thrown while trying to set invalid value: " +
227 log
.println("FAILED: expected exception 'UnknownPropertyException' was not thrown");
229 if (test
) log
.println("... OK");
232 tRes
.tested("setPropertyValues()", ok
);
237 } /// finish class XPropertyAccess