1ef39d40dSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3ef39d40dSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4ef39d40dSAndrew Rist * or more contributor license agreements. See the NOTICE file 5ef39d40dSAndrew Rist * distributed with this work for additional information 6ef39d40dSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7ef39d40dSAndrew Rist * to you under the Apache License, Version 2.0 (the 8ef39d40dSAndrew Rist * "License"); you may not use this file except in compliance 9ef39d40dSAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11ef39d40dSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13ef39d40dSAndrew Rist * Unless required by applicable law or agreed to in writing, 14ef39d40dSAndrew Rist * software distributed under the License is distributed on an 15ef39d40dSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16ef39d40dSAndrew Rist * KIND, either express or implied. See the License for the 17ef39d40dSAndrew Rist * specific language governing permissions and limitations 18ef39d40dSAndrew Rist * under the License. 19cdf0e10cSrcweir * 20ef39d40dSAndrew Rist *************************************************************/ 21ef39d40dSAndrew Rist 22ef39d40dSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir package ifc.sdb; 25cdf0e10cSrcweir 26cdf0e10cSrcweir import lib.MultiPropertyTest; 27cdf0e10cSrcweir import lib.StatusException; 28cdf0e10cSrcweir 29cdf0e10cSrcweir import com.sun.star.sdbc.XConnection; 30cdf0e10cSrcweir import com.sun.star.uno.AnyConverter; 31cdf0e10cSrcweir import com.sun.star.uno.Type; 32cdf0e10cSrcweir 33cdf0e10cSrcweir /** 34cdf0e10cSrcweir * Testing <code>com.sun.star.sdb.RowSet</code> 35cdf0e10cSrcweir * service properties : 36cdf0e10cSrcweir * <ul> 37cdf0e10cSrcweir * <li><code> ActiveConnection</code></li> 38cdf0e10cSrcweir * <li><code> DataSourceName</code></li> 39cdf0e10cSrcweir * <li><code> Command</code></li> 40cdf0e10cSrcweir * <li><code> CommandType</code></li> 41cdf0e10cSrcweir * <li><code> ActiveCommand</code></li> 42cdf0e10cSrcweir * <li><code> IgnoreResult</code></li> 43cdf0e10cSrcweir * <li><code> Filter</code></li> 44cdf0e10cSrcweir * <li><code> ApplyFilter</code></li> 45cdf0e10cSrcweir * <li><code> Order</code></li> 46cdf0e10cSrcweir * <li><code> Privileges</code></li> 47cdf0e10cSrcweir * <li><code> IsModified</code></li> 48cdf0e10cSrcweir * <li><code> IsNew</code></li> 49cdf0e10cSrcweir * <li><code> RowCount</code></li> 50cdf0e10cSrcweir * <li><code> IsRowCountFinal</code></li> 51cdf0e10cSrcweir * <li><code> UpdateTableName</code></li> 52cdf0e10cSrcweir * <li><code> UpdateCatalogName</code></li> 53cdf0e10cSrcweir * <li><code> UpdateSchemaName</code></li> 54cdf0e10cSrcweir * </ul> <p> 55cdf0e10cSrcweir * 56cdf0e10cSrcweir * Properties are tested in a safe way, this means that old 57cdf0e10cSrcweir * properties' values are restored to their previous values 58cdf0e10cSrcweir * after testing. These values are meaningfull for further 59cdf0e10cSrcweir * testing. <p> 60cdf0e10cSrcweir * 61cdf0e10cSrcweir * Properties testing is automated by <code>lib.MultiPropertyTest</code>. 62cdf0e10cSrcweir * @see com.sun.star.sdb.RowSet 63cdf0e10cSrcweir */ 64cdf0e10cSrcweir public class _RowSet extends MultiPropertyTest { 65cdf0e10cSrcweir 66cdf0e10cSrcweir /** 67cdf0e10cSrcweir * The tester implementation which restores properties 68cdf0e10cSrcweir * values after testing. 69cdf0e10cSrcweir */ 70cdf0e10cSrcweir protected class SafeTester extends PropertyTester { 71cdf0e10cSrcweir Object oldValue = null ; 72cdf0e10cSrcweir 73cdf0e10cSrcweir protected Object getNewValue(String prop, Object old) { 74cdf0e10cSrcweir log.println("Testing with SafeTester ...") ; 75cdf0e10cSrcweir oldValue = old ; 76cdf0e10cSrcweir return super.getNewValue(prop, old) ; 77cdf0e10cSrcweir } 78cdf0e10cSrcweir 79cdf0e10cSrcweir protected void checkResult(String propName, Object oldValue, 80cdf0e10cSrcweir Object newValue, Object resValue, Exception exception) 81cdf0e10cSrcweir throws Exception { 82cdf0e10cSrcweir 83cdf0e10cSrcweir super.checkResult(propName, oldValue, newValue, resValue, exception); 84cdf0e10cSrcweir 85cdf0e10cSrcweir try { 86cdf0e10cSrcweir oObj.setPropertyValue(propName, this.oldValue); 87cdf0e10cSrcweir } catch (com.sun.star.lang.WrappedTargetException e) { 88cdf0e10cSrcweir log.println("Exception while setting property to its old value '" + 89cdf0e10cSrcweir this.oldValue + "' (ignoring) : " + e ); 90cdf0e10cSrcweir } catch (com.sun.star.lang.IllegalArgumentException e) { 91cdf0e10cSrcweir log.println("Exception while setting property to its old value '" + 92cdf0e10cSrcweir this.oldValue + "' (ignoring) : " + e ); 93cdf0e10cSrcweir } catch (com.sun.star.beans.PropertyVetoException e) { 94cdf0e10cSrcweir log.println("Exception while setting property to its old value '" + 95cdf0e10cSrcweir this.oldValue + "' (ignoring) : " + e ); 96cdf0e10cSrcweir } catch (com.sun.star.beans.UnknownPropertyException e) { 97cdf0e10cSrcweir log.println("Exception while setting property to its old value '" + 98cdf0e10cSrcweir this.oldValue + "' (ignoring) : " + e ); 99cdf0e10cSrcweir } 100cdf0e10cSrcweir 101cdf0e10cSrcweir } 102cdf0e10cSrcweir } 103cdf0e10cSrcweir 104cdf0e10cSrcweir /** 105cdf0e10cSrcweir * Overriden method which tests all the properties 106cdf0e10cSrcweir * with <code>SafeTester</code>. 107cdf0e10cSrcweir * 108*5496b966SPedro Giffuni * @see SafeTester 109cdf0e10cSrcweir */ 110cdf0e10cSrcweir protected void testProperty(String propName) { 111cdf0e10cSrcweir testProperty(propName, new SafeTester()) ; 112cdf0e10cSrcweir } 113cdf0e10cSrcweir 114cdf0e10cSrcweir public void _ActiveConnection() { 115cdf0e10cSrcweir boolean result = false; 116cdf0e10cSrcweir try { 117cdf0e10cSrcweir XConnection the_connection = null; 118cdf0e10cSrcweir 119cdf0e10cSrcweir try { 120cdf0e10cSrcweir the_connection = (XConnection) AnyConverter.toObject( 121cdf0e10cSrcweir new Type(XConnection.class), 122cdf0e10cSrcweir oObj.getPropertyValue("ActiveConnection")); 123cdf0e10cSrcweir } catch (com.sun.star.lang.IllegalArgumentException iae) { 124cdf0e10cSrcweir throw new StatusException("couldn't convert Any",iae); 125cdf0e10cSrcweir } 126cdf0e10cSrcweir 127cdf0e10cSrcweir result = (the_connection != null); 128cdf0e10cSrcweir } catch (com.sun.star.beans.UnknownPropertyException e) { 129cdf0e10cSrcweir log.println("the property is unknown"); 130cdf0e10cSrcweir } catch (com.sun.star.lang.WrappedTargetException e) { 131cdf0e10cSrcweir log.println(e.getMessage()); 132cdf0e10cSrcweir } 133cdf0e10cSrcweir 134cdf0e10cSrcweir tRes.tested("ActiveConnection", result) ; 135cdf0e10cSrcweir } 136cdf0e10cSrcweir 137cdf0e10cSrcweir /** 138cdf0e10cSrcweir * Forces environment recreation. 139cdf0e10cSrcweir */ 140cdf0e10cSrcweir protected void after() { 141cdf0e10cSrcweir disposeEnvironment(); 142cdf0e10cSrcweir } 143cdf0e10cSrcweir 144cdf0e10cSrcweir } // EOF DatasourceAdministrationDialog 145cdf0e10cSrcweir 146