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