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 lib; 25 26 import java.util.Hashtable; 27 import util.PropertyName; 28 import com.sun.star.beans.XPropertySet; 29 import com.sun.star.uno.XComponentContext; 30 31 //import com.sun.star.lang.XMultiServiceFactory; 32 33 /** 34 * TestParameters describes a parameters (in a form of pairs: name, value) to 35 * be passed to tests and which may affect the test behaviour. That can be, 36 * for example, standard paths, connection strings, etc. The TestParameters 37 * also provides XMultiServiceFactory for the test (tests). 38 */ 39 public class TestParameters extends Hashtable { 40 41 /** 42 * The ConnectionString for Office Connection<br> 43 * default is 'socket,host=localhost,port=8100' 44 */ 45 46 public String ConnectionString="socket,host=localhost,port=8100"; 47 48 /** 49 * The AppProvider contains the Application Provider<br> 50 * to control the ServiceFactory. 51 */ 52 53 public Object AppProvider=null; 54 55 /** 56 * The Process contains the Process handler<br> 57 * to control the Application. 58 */ 59 60 public Object ProcessHandler=null; 61 62 /** 63 * The AppExecutionCmd contains the full qualified<br> 64 * command to an Application to be started. 65 */ 66 67 public String AppExecutionCommand=""; 68 69 /** 70 * If this parameter is <CODE>true</CODE> the <CODE>OfficeProvider</CODE> tries 71 * to get the URL to the binary of the office and to fill the 72 * <CODE>AppExecutionCommand</CODE> with useful content if needet 73 */ 74 public boolean AutoRestart = false; 75 76 /** 77 * Shoert wait time for the Office: default is 500 milliseconds 78 */ 79 public int ShortWait = 500; 80 81 82 /** 83 * The OfficeProvider contains the full qualified 84 * class that provides a connection to StarOffice<br> 85 * default is helper.OfficeProvider 86 */ 87 88 public String OfficeProvider = "helper.OfficeProvider"; 89 90 /** 91 * The Testbase to be executed by the runner<br> 92 * default is 'java_fat' 93 */ 94 95 public String TestBase="java_fat"; 96 97 /** 98 * The ServiceFactory to create instances 99 */ 100 101 public Object ServiceFactory; 102 103 /** 104 * The Path to the component description 105 */ 106 107 public String DescriptionPath; 108 109 /** 110 * The Path to the test documents that are loaded during the test <br> 111 */ 112 113 public String TestDocumentPath="unknown"; 114 115 /** 116 * 'true' is a log should be written, 'false' elsewhere <br> 117 * these will be provided by the testcases<br> 118 * default is true 119 */ 120 121 public boolean LoggingIsActive=true; 122 123 /** 124 * 'true' is a debug information should be written, 'false' elsewhere 125 * these will be provided by the framework.<br> 126 * Debug information will always be written on standard out.<br> 127 * default is true 128 */ 129 130 public boolean DebugIsActive=false; 131 132 /* 133 * This parameter contains the testjob to be executed<br> 134 * by the framework 135 */ 136 137 public Object TestJob; 138 139 /* 140 * This parameter contains the class used<br> 141 * for Logging 142 */ 143 144 public String LogWriter="stats.SimpleLogWriter"; 145 146 /* 147 * This parameter contains the class used<br> 148 * for Logging 149 */ 150 151 public String OutProducer="stats.SimpleOutProducer"; 152 153 /* 154 * This parameter contains the timeout used<br> 155 * by the watcher 156 */ 157 public Integer TimeOut = new Integer(3000000); 158 159 /* 160 * This parameter contains the timeout used<br> 161 * by the complex tests 162 */ 163 public Integer ThreadTimeOut = new Integer(3000000); 164 165 /* 166 * This parameter contains the time which the office could use to close for 167 * itself before its destroyed. Default is 15000 ms 168 */ 169 public Integer OfficeCloseTimeOut = new Integer(15000); 170 171 /** 172 * Wraper around "get()" with some debug output 173 * @param key A key of this table. 174 * @return The value of this key. 175 * @see java.util.Hashtable 176 */ get(Object key)177 public Object get(Object key) { 178 Object val = super.get(key); 179 if (val == null && DebugIsActive) { 180 System.out.print("Have been asked for key \""+key.toString()); 181 System.out.println("\" which is not part of params."); 182 } 183 return val; 184 } 185 186 /** 187 * Special get method for boolean values: for convenience. 188 * Will return 'false' if the value is not of "Boolean" type. 189 * @param key A key of this table. 190 * @return The value of this key, castet to a boolean type. 191 */ getBool(Object key)192 public boolean getBool(Object key) { 193 Object val = super.get(key); 194 if (val != null) { 195 if (val instanceof String) { 196 String sVal = (String)val; 197 if (sVal.equalsIgnoreCase("true") || 198 sVal.equalsIgnoreCase("yes")) { 199 return true; 200 } 201 else if (sVal.equalsIgnoreCase("false") || 202 sVal.equalsIgnoreCase("no")) { 203 return false; 204 } 205 } 206 if (val instanceof Boolean) 207 return ((Boolean)val).booleanValue(); 208 } 209 return false; 210 } 211 212 /** 213 * Special get method for integer values: for convenience. 214 * Will return 0 if the value cannot be interpreted as Integer. 215 * @param key A key of this table. 216 * @return The value of this key, castet to an int type. 217 */ getInt(Object key)218 public int getInt(Object key) { 219 Object val = super.get(key); 220 if ( val != null ) { 221 if (val instanceof Integer) { 222 return ((Integer)val).intValue(); 223 } 224 else { 225 try { 226 if ( val instanceof String ) { 227 Integer nr = new Integer((String)val); 228 if (nr.intValue() > 0) return nr.intValue(); 229 } 230 } catch ( java.lang.NumberFormatException nfe) {} 231 } 232 } 233 return 0; 234 } 235 236 237 /** 238 * Wraper around "put()" 239 * @param key A key of this table. 240 * @param val The value of the key. 241 * @return The value of this key. 242 * @see java.util.Hashtable 243 */ put(Object key, Object val)244 public Object put(Object key, Object val) { 245 return super.put(key,val); 246 } 247 248 /** 249 * Constructor, defaults for Parameters are set. 250 */ TestParameters()251 public TestParameters() { 252 //fill the propertyset 253 String user = System.getProperty("user.name"); 254 if ( user != null) 255 { 256 String PipeConnectionString = "pipe,name=" + user; 257 put(PropertyName.PIPE_CONNECTION_STRING,PipeConnectionString); 258 put(PropertyName.USE_PIPE_CONNECTION, Boolean.TRUE); 259 } 260 put(PropertyName.CONNECTION_STRING,ConnectionString); 261 put(PropertyName.TEST_BASE,TestBase); 262 put(PropertyName.TEST_DOCUMENT_PATH,TestDocumentPath); 263 put(PropertyName.LOGGING_IS_ACTIVE,LoggingIsActive?Boolean.TRUE:Boolean.FALSE); 264 put(PropertyName.DEBUG_IS_ACTIVE,DebugIsActive?Boolean.TRUE:Boolean.FALSE); 265 put(PropertyName.OUT_PRODUCER,OutProducer); 266 put(PropertyName.SHORT_WAIT,new Integer(ShortWait)); 267 put(PropertyName.OFFICE_PROVIDER,OfficeProvider); 268 put(PropertyName.LOG_WRITER,LogWriter); 269 put(PropertyName.APP_EXECUTION_COMMAND,AppExecutionCommand); 270 put(PropertyName.TIME_OUT,TimeOut); 271 put(PropertyName.THREAD_TIME_OUT,ThreadTimeOut); 272 put(PropertyName.AUTO_RESTART,AutoRestart?Boolean.TRUE:Boolean.FALSE); 273 put(PropertyName.OFFICE_CLOSE_TIME_OUT, OfficeCloseTimeOut); 274 275 // get the operating system 276 put(PropertyName.OPERATING_SYSTEM, getSOCompatibleOSName()); 277 278 //For compatibility Reasons 279 put("CNCSTR",ConnectionString); 280 put("DOCPTH",TestDocumentPath); 281 System.setProperty("DOCPTH",TestDocumentPath); 282 } 283 284 /** 285 * @return a XMultiServiceFactory to be used by a test (tests). 286 */ getMSF()287 public Object getMSF() { 288 Object ret = null; 289 ret = get("ServiceFactory"); 290 return ret; 291 } 292 getComponentContext()293 public XComponentContext getComponentContext() { 294 Object context = get( "ComponentContext" ); 295 if ( context == null ) 296 { 297 XPropertySet factoryProps = (XPropertySet)com.sun.star.uno.UnoRuntime.queryInterface( 298 XPropertySet.class, getMSF() ); 299 try 300 { 301 context = com.sun.star.uno.UnoRuntime.queryInterface( 302 XComponentContext.class, factoryProps.getPropertyValue( "DefaultContext" ) ); 303 put( "ComponentContext", context ); 304 } 305 catch( com.sun.star.beans.UnknownPropertyException e ) { } 306 catch( com.sun.star.lang.WrappedTargetException e ) { } 307 } 308 return (XComponentContext)context; 309 } 310 311 /** 312 * Convert the system dependent operating system name to a name according 313 * to OOo rules. 314 * @return A valid OS name, or "" if the name is not known. 315 */ getSOCompatibleOSName()316 String getSOCompatibleOSName() { 317 String osname = System.getProperty ("os.name").toLowerCase (); 318 String osarch = System.getProperty ("os.arch"); 319 String operatingSystem = ""; 320 if (osname.indexOf ("windows")>-1) { 321 operatingSystem = PropertyName.WNTMSCI; 322 } else if (osname.indexOf ("linux")>-1) { 323 operatingSystem = PropertyName.UNXLNGI; 324 } else if (osname.indexOf ("sunos")>-1) { 325 if (osarch.equals ("x86")) { 326 operatingSystem = PropertyName.UNXSOLI; 327 } else { 328 operatingSystem = PropertyName.UNXSOLS; 329 } 330 } else if (osname.indexOf ("mac")>-1) { 331 operatingSystem = PropertyName.UNXMACXI; 332 } else if (osname.equals("freebsd")) { 333 operatingSystem = PropertyName.UNXFBSDX; 334 } else { 335 System.out.println("ERROR: not supported platform: " + osname); 336 System.exit(1); 337 } 338 return operatingSystem; 339 } 340 341 }// finish class TestParamenters 342