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