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