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