org.apache.qpid.junit.extensions.util
Class TestContextProperties

java.lang.Object
  extended by java.util.Dictionary<K,V>
      extended by java.util.Hashtable<Object,Object>
          extended by java.util.Properties
              extended by org.apache.qpid.junit.extensions.util.ParsedProperties
                  extended by org.apache.qpid.junit.extensions.util.TestContextProperties
All Implemented Interfaces:
Serializable, Cloneable, Map<Object,Object>

public class TestContextProperties
extends ParsedProperties

TestContextProperties is an extension of ParsedProperties that keeps track of property key/value pairs that are used by tests being run under the TKTestRunner. To keep the test runner notified of configurable test parameters, tests should establish their required property values by initiliazing fields or statics or in the constructor, through this class. The tk test runner automatically places any additional properties specified on the command line into the this class, and these are held statically.

Here is an example:

 public class MyTestClass extends TestCase {
     ParsedProperties testProps = TestContextProperties.getInstance();
     private int testParam = testProps.setPropertyIfNull("testParam", 1);
 ...
 

This has the effect of setting up the field testParam with the default value of 1, unless it is overridden by values passed to the tk test runner. It also notifies the tk test runner of the name and value of the test parameter actually used for the test, so that this can be logged in the test output file.

CRC Card
Responsibilities Collaborations
Log all name/value pairs read or written.

See Also:
Serialized Form

Field Summary
 
Fields inherited from class java.util.Properties
defaults
 
Method Summary
static Properties getAccessedProps()
          Gets all of the properties (with their most recent values) that have been set or read through this class.
static ParsedProperties getInstance()
          Gets the singleton instance of the test context properties.
static ParsedProperties getInstance(Properties defaults)
          Gets the singleton instance of the test context properties, applying a specified set of default properties to it, if they are not already set.
 String getProperty(String key)
          Looks up a property value relative to the environment, callers class and method.
 Object setProperty(String key, String value)
          Calls the Hashtable method put.
 String setPropertyIfNull(String key, String value)
          Helper method for setting properties to defaults when they are not already set.
 
Methods inherited from class org.apache.qpid.junit.extensions.util.ParsedProperties
getPropertyAsBoolean, getPropertyAsInteger, getPropertyAsLong, setProperty, setProperty, setProperty, setProperty, setProperty, setProperty, setPropertyIfNull, setPropertyIfNull, setPropertyIfNull, setPropertyIfNull, setPropertyIfNull, setPropertyIfNull, setSysPropertyIfNull, setSysPropertyIfNull, setSysPropertyIfNull, setSysPropertyIfNull, setSysPropertyIfNull, setSysPropertyIfNull, setSysPropertyIfNull
 
Methods inherited from class java.util.Properties
getProperty, list, list, load, load, loadFromXML, propertyNames, save, store, store, storeToXML, storeToXML, stringPropertyNames
 
Methods inherited from class java.util.Hashtable
clear, clone, contains, containsKey, containsValue, elements, entrySet, equals, get, hashCode, isEmpty, keys, keySet, put, putAll, rehash, remove, size, toString, values
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Method Detail

getInstance

public static ParsedProperties getInstance()
Gets the singleton instance of the test context properties.

Returns:
The singleton instance of the test context properties.

getInstance

public static ParsedProperties getInstance(Properties defaults)
Gets the singleton instance of the test context properties, applying a specified set of default properties to it, if they are not already set.

Parameters:
defaults - The defaults to apply for properties not already set.
Returns:
The singleton instance of the test context properties.

getAccessedProps

public static Properties getAccessedProps()
Gets all of the properties (with their most recent values) that have been set or read through this class.

Returns:
All of the properties accessed through this class.

getProperty

public String getProperty(String key)
Looks up a property value relative to the environment, callers class and method. The default environment will be checked for a matching property if defaults are being used. The property key/value pair is remembered and made available to TKTestRunner.

Overrides:
getProperty in class Properties
Parameters:
key - The property key.
Returns:
The value of this property searching from the most specific definition (environment, class, method, key) to the most general (key only), unless use of default environments is turned off in which case the most general proeprty searched is (environment, key).

setProperty

public Object setProperty(String key,
                          String value)
Calls the Hashtable method put. Provided for parallelism with the getProperty method. Enforces use of strings for property keys and values. The value returned is the result of the Hashtable call to put. The property key/value pair is remembered and made available to TKTestRunner.

Overrides:
setProperty in class Properties
Parameters:
key - The key to be placed into this property list.
value - The value corresponding to key.
Returns:
The previous value of the specified key in this property list, or null if it did not have one.

setPropertyIfNull

public String setPropertyIfNull(String key,
                                String value)
Helper method for setting properties to defaults when they are not already set. The property key/value pair is remembered and made available to TKTestRunner.

Overrides:
setPropertyIfNull in class ParsedProperties
Parameters:
key - The name of the system property to set.
value - The value to set it to.
Returns:
The value of the property, which will be the value passed in if it was null, or the existing value otherwise.


Licensed to the Apache Software Foundation