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