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