1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir package ifc.sdb;
29*cdf0e10cSrcweir 
30*cdf0e10cSrcweir import lib.MultiPropertyTest;
31*cdf0e10cSrcweir 
32*cdf0e10cSrcweir import com.sun.star.beans.PropertyValue;
33*cdf0e10cSrcweir 
34*cdf0e10cSrcweir /**
35*cdf0e10cSrcweir  * Testing <code>com.sun.star.sdb.DataSource</code>
36*cdf0e10cSrcweir  * service properties :
37*cdf0e10cSrcweir  * <ul>
38*cdf0e10cSrcweir  *  <li><code> Name</code></li>
39*cdf0e10cSrcweir  *  <li><code> URL</code></li>
40*cdf0e10cSrcweir  *  <li><code> Info</code></li>
41*cdf0e10cSrcweir  *  <li><code> User</code></li>
42*cdf0e10cSrcweir  *  <li><code> Password</code></li>
43*cdf0e10cSrcweir  *  <li><code> IsPasswordRequired</code></li>
44*cdf0e10cSrcweir  *  <li><code> SuppressVersionColumns</code></li>
45*cdf0e10cSrcweir  *  <li><code> IsReadOnly</code></li>
46*cdf0e10cSrcweir  *  <li><code> NumberFormatsSupplier</code></li>
47*cdf0e10cSrcweir  *  <li><code> TableFilter</code></li>
48*cdf0e10cSrcweir  *  <li><code> TableTypeFilter</code></li>
49*cdf0e10cSrcweir  * </ul> <p>
50*cdf0e10cSrcweir  * Properties testing is automated by <code>lib.MultiPropertyTest</code> <p>.
51*cdf0e10cSrcweir * After this interface test <b>it's better to recreate</b> object tested.
52*cdf0e10cSrcweir * @see com.sun.star.beans.XPropertySet
53*cdf0e10cSrcweir * @see com.sun.star.beans.XPropertySetInfo
54*cdf0e10cSrcweir * @see com.sun.star.beans.Property
55*cdf0e10cSrcweir * @see com.sun.star.lang.XServiceInfo
56*cdf0e10cSrcweir */
57*cdf0e10cSrcweir public class _DataSource extends MultiPropertyTest {
58*cdf0e10cSrcweir 
59*cdf0e10cSrcweir     /**
60*cdf0e10cSrcweir     * This property is an array of additional parameters for database
61*cdf0e10cSrcweir     * connecting. Parameter is <code>PropertyValue</code> structure.
62*cdf0e10cSrcweir     * The test just changes existing array onto array with a single
63*cdf0e10cSrcweir     * element <code>("user", "API_QA_Tester")</code> <p>
64*cdf0e10cSrcweir     *
65*cdf0e10cSrcweir     * After testing old value is set for this property. <p>
66*cdf0e10cSrcweir     *
67*cdf0e10cSrcweir     * Result is OK: if property successfully changed with no excepions.
68*cdf0e10cSrcweir     * @see com.sun.star.beans.PropertyValue
69*cdf0e10cSrcweir     */
70*cdf0e10cSrcweir     public void _Info() {
71*cdf0e10cSrcweir         try {
72*cdf0e10cSrcweir             Object oldInfo = oObj.getPropertyValue("Info") ;
73*cdf0e10cSrcweir 
74*cdf0e10cSrcweir             testProperty("Info", new PropertyTester() {
75*cdf0e10cSrcweir                 protected Object getNewValue(String propName, Object oldValue) {
76*cdf0e10cSrcweir 
77*cdf0e10cSrcweir                     PropertyValue propUsr = new PropertyValue(),
78*cdf0e10cSrcweir                                   propPass = new PropertyValue() ;
79*cdf0e10cSrcweir 
80*cdf0e10cSrcweir                     propUsr.Name = "user" ;
81*cdf0e10cSrcweir                     propUsr.Value = "API_QA_Tester" ;
82*cdf0e10cSrcweir                     propPass.Name = "password" ;
83*cdf0e10cSrcweir                     propPass.Value = "guest" ;
84*cdf0e10cSrcweir 
85*cdf0e10cSrcweir                     return new PropertyValue[] { propUsr, propPass } ;
86*cdf0e10cSrcweir                 }
87*cdf0e10cSrcweir             }) ;
88*cdf0e10cSrcweir 
89*cdf0e10cSrcweir             oObj.setPropertyValue("Info", oldInfo) ;
90*cdf0e10cSrcweir         } catch(com.sun.star.beans.UnknownPropertyException e) {}
91*cdf0e10cSrcweir         catch(com.sun.star.beans.PropertyVetoException e) {}
92*cdf0e10cSrcweir         catch(com.sun.star.lang.IllegalArgumentException e) {}
93*cdf0e10cSrcweir         catch(com.sun.star.lang.WrappedTargetException e) {}
94*cdf0e10cSrcweir     }
95*cdf0e10cSrcweir 
96*cdf0e10cSrcweir     /**
97*cdf0e10cSrcweir     * Property is tested by the common method, but after testing
98*cdf0e10cSrcweir     * old value is set for this property.
99*cdf0e10cSrcweir     */
100*cdf0e10cSrcweir     public void _URL() {
101*cdf0e10cSrcweir         try {
102*cdf0e10cSrcweir             Object oldURL = oObj.getPropertyValue("URL") ;
103*cdf0e10cSrcweir 
104*cdf0e10cSrcweir             testProperty("URL") ;
105*cdf0e10cSrcweir 
106*cdf0e10cSrcweir             oObj.setPropertyValue("URL", oldURL) ;
107*cdf0e10cSrcweir         } catch(com.sun.star.beans.UnknownPropertyException e) {}
108*cdf0e10cSrcweir         catch(com.sun.star.beans.PropertyVetoException e) {}
109*cdf0e10cSrcweir         catch(com.sun.star.lang.IllegalArgumentException e) {}
110*cdf0e10cSrcweir         catch(com.sun.star.lang.WrappedTargetException e) {}
111*cdf0e10cSrcweir     }
112*cdf0e10cSrcweir 
113*cdf0e10cSrcweir     /**
114*cdf0e10cSrcweir     * Property is tested by the common method, but after testing
115*cdf0e10cSrcweir     * old value is set for this property.
116*cdf0e10cSrcweir     */
117*cdf0e10cSrcweir     public void _User() {
118*cdf0e10cSrcweir         try {
119*cdf0e10cSrcweir             Object oldUser = oObj.getPropertyValue("User") ;
120*cdf0e10cSrcweir 
121*cdf0e10cSrcweir             testProperty("User") ;
122*cdf0e10cSrcweir 
123*cdf0e10cSrcweir             oObj.setPropertyValue("User", oldUser) ;
124*cdf0e10cSrcweir         } catch(com.sun.star.beans.UnknownPropertyException e) {}
125*cdf0e10cSrcweir         catch(com.sun.star.beans.PropertyVetoException e) {}
126*cdf0e10cSrcweir         catch(com.sun.star.lang.IllegalArgumentException e) {}
127*cdf0e10cSrcweir         catch(com.sun.star.lang.WrappedTargetException e) {}
128*cdf0e10cSrcweir     }
129*cdf0e10cSrcweir 
130*cdf0e10cSrcweir     /**
131*cdf0e10cSrcweir     * Property is tested by the common method, but after testing
132*cdf0e10cSrcweir     * old value is set for this property.
133*cdf0e10cSrcweir     */
134*cdf0e10cSrcweir     public void _Password() {
135*cdf0e10cSrcweir         try {
136*cdf0e10cSrcweir             Object oldPass = oObj.getPropertyValue("Password") ;
137*cdf0e10cSrcweir 
138*cdf0e10cSrcweir             testProperty("Password") ;
139*cdf0e10cSrcweir 
140*cdf0e10cSrcweir             oObj.setPropertyValue("Password", oldPass) ;
141*cdf0e10cSrcweir         } catch(com.sun.star.beans.UnknownPropertyException e) {}
142*cdf0e10cSrcweir         catch(com.sun.star.beans.PropertyVetoException e) {}
143*cdf0e10cSrcweir         catch(com.sun.star.lang.IllegalArgumentException e) {}
144*cdf0e10cSrcweir         catch(com.sun.star.lang.WrappedTargetException e) {}
145*cdf0e10cSrcweir     }
146*cdf0e10cSrcweir 
147*cdf0e10cSrcweir     /**
148*cdf0e10cSrcweir     * New value for the test is always <code>null</code>.
149*cdf0e10cSrcweir     */
150*cdf0e10cSrcweir     public void _NumberFormatsSupplier() {
151*cdf0e10cSrcweir         testProperty("NumberFormatsSupplier", new PropertyTester() {
152*cdf0e10cSrcweir             protected Object getNewValue(String propName, Object oldValue) {
153*cdf0e10cSrcweir                 return null ;
154*cdf0e10cSrcweir             }
155*cdf0e10cSrcweir         }) ;
156*cdf0e10cSrcweir     }
157*cdf0e10cSrcweir 
158*cdf0e10cSrcweir     /**
159*cdf0e10cSrcweir     * If object test allows to recreate environment it is better to do it.
160*cdf0e10cSrcweir     */
161*cdf0e10cSrcweir     public void after() {
162*cdf0e10cSrcweir         try {
163*cdf0e10cSrcweir             oObj.setPropertyValue("IsPasswordRequired",new Boolean(false));
164*cdf0e10cSrcweir         } catch (Exception e) {
165*cdf0e10cSrcweir             log.println("Couldn't set 'IsPasswordRequired' to false");
166*cdf0e10cSrcweir         }
167*cdf0e10cSrcweir     }
168*cdf0e10cSrcweir 
169*cdf0e10cSrcweir }  // finish class _DataSource
170*cdf0e10cSrcweir 
171*cdf0e10cSrcweir 
172