1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 package ifc.sdb;
25 
26 import lib.MultiPropertyTest;
27 
28 import com.sun.star.beans.PropertyValue;
29 
30 /**
31  * Testing <code>com.sun.star.sdb.DataSource</code>
32  * service properties :
33  * <ul>
34  *  <li><code> Name</code></li>
35  *  <li><code> URL</code></li>
36  *  <li><code> Info</code></li>
37  *  <li><code> User</code></li>
38  *  <li><code> Password</code></li>
39  *  <li><code> IsPasswordRequired</code></li>
40  *  <li><code> SuppressVersionColumns</code></li>
41  *  <li><code> IsReadOnly</code></li>
42  *  <li><code> NumberFormatsSupplier</code></li>
43  *  <li><code> TableFilter</code></li>
44  *  <li><code> TableTypeFilter</code></li>
45  * </ul> <p>
46  * Properties testing is automated by <code>lib.MultiPropertyTest</code> <p>.
47 * After this interface test <b>it's better to recreate</b> object tested.
48 * @see com.sun.star.beans.XPropertySet
49 * @see com.sun.star.beans.XPropertySetInfo
50 * @see com.sun.star.beans.Property
51 * @see com.sun.star.lang.XServiceInfo
52 */
53 public class _DataSource extends MultiPropertyTest {
54 
55     /**
56     * This property is an array of additional parameters for database
57     * connecting. Parameter is <code>PropertyValue</code> structure.
58     * The test just changes existing array onto array with a single
59     * element <code>("user", "API_QA_Tester")</code> <p>
60     *
61     * After testing old value is set for this property. <p>
62     *
63     * Result is OK: if property successfully changed with no excepions.
64     * @see com.sun.star.beans.PropertyValue
65     */
_Info()66     public void _Info() {
67         try {
68             Object oldInfo = oObj.getPropertyValue("Info") ;
69 
70             testProperty("Info", new PropertyTester() {
71                 protected Object getNewValue(String propName, Object oldValue) {
72 
73                     PropertyValue propUsr = new PropertyValue(),
74                                   propPass = new PropertyValue() ;
75 
76                     propUsr.Name = "user" ;
77                     propUsr.Value = "API_QA_Tester" ;
78                     propPass.Name = "password" ;
79                     propPass.Value = "guest" ;
80 
81                     return new PropertyValue[] { propUsr, propPass } ;
82                 }
83             }) ;
84 
85             oObj.setPropertyValue("Info", oldInfo) ;
86         } catch(com.sun.star.beans.UnknownPropertyException e) {}
87         catch(com.sun.star.beans.PropertyVetoException e) {}
88         catch(com.sun.star.lang.IllegalArgumentException e) {}
89         catch(com.sun.star.lang.WrappedTargetException e) {}
90     }
91 
92     /**
93     * Property is tested by the common method, but after testing
94     * old value is set for this property.
95     */
_URL()96     public void _URL() {
97         try {
98             Object oldURL = oObj.getPropertyValue("URL") ;
99 
100             testProperty("URL") ;
101 
102             oObj.setPropertyValue("URL", oldURL) ;
103         } catch(com.sun.star.beans.UnknownPropertyException e) {}
104         catch(com.sun.star.beans.PropertyVetoException e) {}
105         catch(com.sun.star.lang.IllegalArgumentException e) {}
106         catch(com.sun.star.lang.WrappedTargetException e) {}
107     }
108 
109     /**
110     * Property is tested by the common method, but after testing
111     * old value is set for this property.
112     */
_User()113     public void _User() {
114         try {
115             Object oldUser = oObj.getPropertyValue("User") ;
116 
117             testProperty("User") ;
118 
119             oObj.setPropertyValue("User", oldUser) ;
120         } catch(com.sun.star.beans.UnknownPropertyException e) {}
121         catch(com.sun.star.beans.PropertyVetoException e) {}
122         catch(com.sun.star.lang.IllegalArgumentException e) {}
123         catch(com.sun.star.lang.WrappedTargetException e) {}
124     }
125 
126     /**
127     * Property is tested by the common method, but after testing
128     * old value is set for this property.
129     */
_Password()130     public void _Password() {
131         try {
132             Object oldPass = oObj.getPropertyValue("Password") ;
133 
134             testProperty("Password") ;
135 
136             oObj.setPropertyValue("Password", oldPass) ;
137         } catch(com.sun.star.beans.UnknownPropertyException e) {}
138         catch(com.sun.star.beans.PropertyVetoException e) {}
139         catch(com.sun.star.lang.IllegalArgumentException e) {}
140         catch(com.sun.star.lang.WrappedTargetException e) {}
141     }
142 
143     /**
144     * New value for the test is always <code>null</code>.
145     */
_NumberFormatsSupplier()146     public void _NumberFormatsSupplier() {
147         testProperty("NumberFormatsSupplier", new PropertyTester() {
148             protected Object getNewValue(String propName, Object oldValue) {
149                 return null ;
150             }
151         }) ;
152     }
153 
154     /**
155     * If object test allows to recreate environment it is better to do it.
156     */
after()157     public void after() {
158         try {
159             oObj.setPropertyValue("IsPasswordRequired",new Boolean(false));
160         } catch (Exception e) {
161             log.println("Couldn't set 'IsPasswordRequired' to false");
162         }
163     }
164 
165 }  // finish class _DataSource
166 
167 
168