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 import lib.StatusException; 32 33 import com.sun.star.sdbc.XConnection; 34 import com.sun.star.uno.AnyConverter; 35 import com.sun.star.uno.Type; 36 37 /** 38 * Testing <code>com.sun.star.sdb.RowSet</code> 39 * service properties : 40 * <ul> 41 * <li><code> ActiveConnection</code></li> 42 * <li><code> DataSourceName</code></li> 43 * <li><code> Command</code></li> 44 * <li><code> CommandType</code></li> 45 * <li><code> ActiveCommand</code></li> 46 * <li><code> IgnoreResult</code></li> 47 * <li><code> Filter</code></li> 48 * <li><code> ApplyFilter</code></li> 49 * <li><code> Order</code></li> 50 * <li><code> Privileges</code></li> 51 * <li><code> IsModified</code></li> 52 * <li><code> IsNew</code></li> 53 * <li><code> RowCount</code></li> 54 * <li><code> IsRowCountFinal</code></li> 55 * <li><code> UpdateTableName</code></li> 56 * <li><code> UpdateCatalogName</code></li> 57 * <li><code> UpdateSchemaName</code></li> 58 * </ul> <p> 59 * 60 * Properties are tested in a safe way, this means that old 61 * properties' values are restored to their previous values 62 * after testing. These values are meaningfull for further 63 * testing. <p> 64 * 65 * Properties testing is automated by <code>lib.MultiPropertyTest</code>. 66 * @see com.sun.star.sdb.RowSet 67 */ 68 public class _RowSet extends MultiPropertyTest { 69 70 /** 71 * The tester implementation which restores properties 72 * values after testing. 73 */ 74 protected class SafeTester extends PropertyTester { 75 Object oldValue = null ; 76 77 protected Object getNewValue(String prop, Object old) { 78 log.println("Testing with SafeTester ...") ; 79 oldValue = old ; 80 return super.getNewValue(prop, old) ; 81 } 82 83 protected void checkResult(String propName, Object oldValue, 84 Object newValue, Object resValue, Exception exception) 85 throws Exception { 86 87 super.checkResult(propName, oldValue, newValue, resValue, exception); 88 89 try { 90 oObj.setPropertyValue(propName, this.oldValue); 91 } catch (com.sun.star.lang.WrappedTargetException e) { 92 log.println("Exception while setting property to its old value '" + 93 this.oldValue + "' (ignoring) : " + e ); 94 } catch (com.sun.star.lang.IllegalArgumentException e) { 95 log.println("Exception while setting property to its old value '" + 96 this.oldValue + "' (ignoring) : " + e ); 97 } catch (com.sun.star.beans.PropertyVetoException e) { 98 log.println("Exception while setting property to its old value '" + 99 this.oldValue + "' (ignoring) : " + e ); 100 } catch (com.sun.star.beans.UnknownPropertyException e) { 101 log.println("Exception while setting property to its old value '" + 102 this.oldValue + "' (ignoring) : " + e ); 103 } 104 105 } 106 } 107 108 /** 109 * Overriden method which tests all the properties 110 * with <code>SafeTester</code>. 111 * 112 * @see #SafeTester 113 */ 114 protected void testProperty(String propName) { 115 testProperty(propName, new SafeTester()) ; 116 } 117 118 public void _ActiveConnection() { 119 boolean result = false; 120 try { 121 XConnection the_connection = null; 122 123 try { 124 the_connection = (XConnection) AnyConverter.toObject( 125 new Type(XConnection.class), 126 oObj.getPropertyValue("ActiveConnection")); 127 } catch (com.sun.star.lang.IllegalArgumentException iae) { 128 throw new StatusException("couldn't convert Any",iae); 129 } 130 131 result = (the_connection != null); 132 } catch (com.sun.star.beans.UnknownPropertyException e) { 133 log.println("the property is unknown"); 134 } catch (com.sun.star.lang.WrappedTargetException e) { 135 log.println(e.getMessage()); 136 } 137 138 tRes.tested("ActiveConnection", result) ; 139 } 140 141 /** 142 * Forces environment recreation. 143 */ 144 protected void after() { 145 disposeEnvironment(); 146 } 147 148 } // EOF DatasourceAdministrationDialog 149 150