1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
30 import com
.sun
.star
.beans
.PropertyValue
;
31 import com
.sun
.star
.beans
.PropertyVetoException
;
32 import com
.sun
.star
.lang
.WrappedTargetException
;
33 import lib
.MultiMethodTest
;
34 import com
.sun
.star
.beans
.UnknownPropertyException
;
35 import com
.sun
.star
.beans
.XPropertyAccess
;
37 import lib
.StatusException
;
40 * Testing <code>com.sun.star.beans.XPropertyAccess</code>
43 * <li><code>getPropertyValues()</code></li>
44 * <li><code>setPropertyValues()</code></li>
46 * @see com.sun.star.beans.XPropertyAccess
48 public class _XPropertyAccess
extends MultiMethodTest
{
51 * oObj filled by MultiMethodTest
53 public XPropertyAccess oObj
= null;// oObj filled by MultiMethodTest
56 * object relation X<CODE>PropertyAccess.propertyToChange</CODE><br>
57 * This relation must be filled from the module. It contains a property which must
58 * be kind of String property, available at <CODE>getPropertyValues()</CODE> and changeable by
59 * <CODE>setPropertyValues()</CODE>
61 public PropertyValue propertyToChange
= null;
64 * checks if the object relation <CODE>XPropertyAccess.propertyToChange</CODE>
67 public void before() {
68 propertyToChange
= (PropertyValue
) tEnv
.getObjRelation("XPropertyAccess.propertyToChange");
69 if (propertyToChange
== null) {
70 throw new StatusException(Status
.failed("Object raltion 'XPropertyAccess.propertyToChange' is null"));
75 * Test calls the method and checks if the returned sequenze contanis a propterty which is named
76 * in the object relation <code>XPropertyAccess.propertyToChange</code>.
78 public void _getPropertyValues() {
79 PropertyValue
[] properties
= oObj
.getPropertyValues();
83 if (properties
!= null){
85 boolean found
= false;
86 for (int i
=0; i
< properties
.length
; i
++){
87 if (properties
[i
].Name
.equals(propertyToChange
.Name
)) found
= true;
90 log
.println("ERROR: could not find desired property '"+ propertyToChange
.Name
+"'");
95 log
.println("ERROR: the method returned NULL");
99 tRes
.tested("getPropertyValues()", ok
);
104 * Test calls the method and checks if:
106 * <li>the property given by the object relation
107 * <CODE>XPropertyAccess.propertyToChange</CODE> has changed</LI>
108 * <li><CODE>com.sun.star.lang.IllegalArgumentException</CODE> was thrown if a <CODE>Integer</CODE>
109 * value was set to a <CODE>String</CODE> property</LI>
110 * <li><CODE>com.sun.star.beans.UnknownPropertyException</CODE> was throen if an invalid property
114 public void _setPropertyValues(){
121 PropertyValue
[] newProps
= new PropertyValue
[1];
122 newProps
[0] = propertyToChange
;
124 log
.println("try to set property vlaues given by object relation 'XPropertyAccess.propertyToChange'...");
125 oObj
.setPropertyValues(newProps
);
127 } catch (UnknownPropertyException ex
) {
128 log
.println("ERROR: Exception was thrown while trying to set property value: " +
131 } catch (PropertyVetoException ex
) {
132 log
.println("ERROR: Exception was thrown while trying to set property value: " +
135 } catch (WrappedTargetException ex
) {
136 log
.println("ERROR: Exception was thrown while trying to set property value: " +
139 } catch (com
.sun
.star
.lang
.IllegalArgumentException ex
) {
140 log
.println("ERROR: Exception was thrown while trying to set property value: " +
146 log
.println("... OK");
153 log
.println("try to set integer value to string property, " +
154 "expect 'com.sun.star.lang.IllegalArgumentException'...");
155 PropertyValue
[] newProps
= new PropertyValue
[1];
156 PropertyValue failedProp
= new PropertyValue();
157 failedProp
.Name
= propertyToChange
.Name
;
158 failedProp
.Value
= new Integer(10);
159 newProps
[0] = failedProp
;
160 oObj
.setPropertyValues(newProps
);
161 } catch (PropertyVetoException ex
) {
162 log
.println("ERROR: unexptected exception was thrown while trying to set null value: " +
165 } catch (WrappedTargetException ex
) {
166 log
.println("ERROR: unexptected exception was thrown while trying to set null value: " +
169 } catch (com
.sun
.star
.lang
.IllegalArgumentException ex
) {
170 log
.println("OK: exptected exception was thrown while trying to set null value: " +
174 } catch (UnknownPropertyException ex
) {
175 log
.println("ERROR: unexptected exception was thrown while trying to set null value: " +
181 log
.println("FAILED: expected exception 'UnknownPropertyException' was not thrown");
183 if (test
) log
.println("... OK");
191 log
.println("try to set values with invalid property name. " +
192 "Expect 'com.sun.star.beans.UnknownPropertyException'...");
194 PropertyValue
[] newProps
= new PropertyValue
[1];
195 PropertyValue newProp
= new PropertyValue();
196 newProp
.Name
= "XPropertyAccess.InvalidPropertyName";
197 newProp
.Value
= "invalid property";
198 newProps
[0] = newProp
;
200 oObj
.setPropertyValues(newProps
);
202 } catch (WrappedTargetException ex
) {
203 log
.println("ERROR: unexptected exception was thrown while trying to set invalid value: " +
206 } catch (com
.sun
.star
.lang
.IllegalArgumentException ex
) {
207 log
.println("ERROR: unexptected exception was thrown while trying to set invalid value: " +
210 } catch (PropertyVetoException ex
) {
211 log
.println("ERROR: unexptected exception was thrown while trying to set invalid value: " +
214 } catch (UnknownPropertyException ex
) {
215 log
.println("OK: Exptected exception was thrown while trying to set invalid value: " +
224 log
.println("FAILED: expected exception 'UnknownPropertyException' was not thrown");
226 if (test
) log
.println("... OK");
229 tRes
.tested("setPropertyValues()", ok
);
234 } /// finish class XPropertyAccess