2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 import com
.sun
.star
.beans
.PropertyValue
;
22 import com
.sun
.star
.beans
.PropertyVetoException
;
23 import com
.sun
.star
.lang
.WrappedTargetException
;
24 import lib
.MultiMethodTest
;
25 import com
.sun
.star
.beans
.UnknownPropertyException
;
26 import com
.sun
.star
.beans
.XPropertyAccess
;
28 import lib
.StatusException
;
31 * Testing <code>com.sun.star.beans.XPropertyAccess</code>
34 * <li><code>getPropertyValues()</code></li>
35 * <li><code>setPropertyValues()</code></li>
37 * @see com.sun.star.beans.XPropertyAccess
39 public class _XPropertyAccess
extends MultiMethodTest
{
42 * oObj filled by MultiMethodTest
44 public XPropertyAccess oObj
= null;// oObj filled by MultiMethodTest
47 * object relation X<CODE>PropertyAccess.propertyToChange</CODE><br>
48 * This relation must be filled from the module. It contains a property which must
49 * be kind of String property, available at <CODE>getPropertyValues()</CODE> and changeable by
50 * <CODE>setPropertyValues()</CODE>
52 public PropertyValue propertyToChange
= null;
55 * checks if the object relation <CODE>XPropertyAccess.propertyToChange</CODE>
59 public void before() {
60 propertyToChange
= (PropertyValue
) tEnv
.getObjRelation("XPropertyAccess.propertyToChange");
61 if (propertyToChange
== null) {
62 throw new StatusException(Status
.failed("Object raltion 'XPropertyAccess.propertyToChange' is null"));
67 * Test calls the method and checks if the returned sequence contains a property which is named
68 * in the object relation <code>XPropertyAccess.propertyToChange</code>.
70 public void _getPropertyValues() {
71 PropertyValue
[] properties
= oObj
.getPropertyValues();
75 if (properties
!= null){
77 boolean found
= false;
78 for (int i
=0; i
< properties
.length
; i
++){
79 if (properties
[i
].Name
.equals(propertyToChange
.Name
)) found
= true;
82 log
.println("ERROR: could not find desired property '"+ propertyToChange
.Name
+"'");
87 log
.println("ERROR: the method returned NULL");
91 tRes
.tested("getPropertyValues()", ok
);
95 * Test calls the method and checks if:
97 * <li>the property given by the object relation
98 * <CODE>XPropertyAccess.propertyToChange</CODE> has changed</LI>
99 * <li><CODE>com.sun.star.lang.IllegalArgumentException</CODE> was thrown if a <CODE>Integer</CODE>
100 * value was set to a <CODE>String</CODE> property</LI>
101 * <li><CODE>com.sun.star.beans.UnknownPropertyException</CODE> was thrown if an invalid property
105 public void _setPropertyValues(){
112 PropertyValue
[] newProps
= new PropertyValue
[1];
113 newProps
[0] = propertyToChange
;
115 log
.println("try to set property values given by object relation 'XPropertyAccess.propertyToChange'...");
116 oObj
.setPropertyValues(newProps
);
118 } catch (UnknownPropertyException ex
) {
119 log
.println("ERROR: Exception was thrown while trying to set property value: " +
122 } catch (PropertyVetoException ex
) {
123 log
.println("ERROR: Exception was thrown while trying to set property value: " +
126 } catch (WrappedTargetException ex
) {
127 log
.println("ERROR: Exception was thrown while trying to set property value: " +
130 } catch (com
.sun
.star
.lang
.IllegalArgumentException ex
) {
131 log
.println("ERROR: Exception was thrown while trying to set property value: " +
137 log
.println("... OK");
144 log
.println("try to set integer value to string property, " +
145 "expect 'com.sun.star.lang.IllegalArgumentException'...");
146 PropertyValue
[] newProps
= new PropertyValue
[1];
147 PropertyValue failedProp
= new PropertyValue();
148 failedProp
.Name
= propertyToChange
.Name
;
149 failedProp
.Value
= Integer
.valueOf(10);
150 newProps
[0] = failedProp
;
151 oObj
.setPropertyValues(newProps
);
152 } catch (PropertyVetoException ex
) {
153 log
.println("ERROR: unexpected exception was thrown while trying to set null value: " +
156 } catch (WrappedTargetException ex
) {
157 log
.println("ERROR: unexpected exception was thrown while trying to set null value: " +
160 } catch (com
.sun
.star
.lang
.IllegalArgumentException ex
) {
161 log
.println("OK: expected exception was thrown while trying to set null value: " +
165 } catch (UnknownPropertyException ex
) {
166 log
.println("ERROR: unexpected exception was thrown while trying to set null value: " +
172 log
.println("FAILED: expected exception 'UnknownPropertyException' was not thrown");
174 if (test
) log
.println("... OK");
182 log
.println("try to set values with invalid property name. " +
183 "Expect 'com.sun.star.beans.UnknownPropertyException'...");
185 PropertyValue
[] newProps
= new PropertyValue
[1];
186 PropertyValue newProp
= new PropertyValue();
187 newProp
.Name
= "XPropertyAccess.InvalidPropertyName";
188 newProp
.Value
= "invalid property";
189 newProps
[0] = newProp
;
191 oObj
.setPropertyValues(newProps
);
193 } catch (WrappedTargetException ex
) {
194 log
.println("ERROR: unexpected exception was thrown while trying to set invalid value: " +
197 } catch (com
.sun
.star
.lang
.IllegalArgumentException ex
) {
198 log
.println("ERROR: unexpected exception was thrown while trying to set invalid value: " +
201 } catch (PropertyVetoException ex
) {
202 log
.println("ERROR: unexpected exception was thrown while trying to set invalid value: " +
205 } catch (UnknownPropertyException ex
) {
206 log
.println("OK: Expected exception was thrown while trying to set invalid value: " +
215 log
.println("FAILED: expected exception 'UnknownPropertyException' was not thrown");
217 if (test
) log
.println("... OK");
220 tRes
.tested("setPropertyValues()", ok
);
223 } /// finish class XPropertyAccess