cdx.scorebot.net.tests
Class Test<S extends Service>

java.lang.Object
  extended by cdx.scorebot.net.tests.Test<S>
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
FileIntegrityCheck, Ping, ReadFile, ResolveHostname, ResolveIP, Sendmail, SendMessage, WriteFile

public abstract class Test<S extends Service>
extends java.lang.Object
implements java.io.Serializable

An abstract test which is the skeleton for individual tests on particular services. The constructor takes derivative of the Service class to specify the service the test can run on (or the abstract Service if it is service-independent).

Author:
David Underhill
See Also:
Serialized Form

Constructor Summary
  Test(S service)
          Instantiates a test (with no configuration) for the purpose of instantiating tests of this type with different configurations later.
protected Test(S service, Configuration config)
          Instantiates a test with the specified config (verify that it includes all needed configuration options).
protected Test(S service, java.util.HashMap<java.lang.String,ConfigOption> options)
          Instantiates a test with the specified config (verify that it includes all needed configuration options).
 
Method Summary
 boolean equals(Test t)
           
 Configuration getConfig()
          gets the options used to configure the test
 java.lang.Object getConfig(java.lang.String optionName)
          gets the value of the requested option used to configure the test (null is returned if there is no option by this name)
protected abstract  java.util.HashMap<java.lang.String,ConfigOption> getDefaultConfigValues()
          returns a key-value pair of what options are available for configuration along with their default values
 Configuration getDefaultConfigValuesCopy()
          returns a COPY of the key-value pairs of what options are available for configuration along with their default values
 Configuration getInitialConfigCopy()
          returns a complete COPY of the key-value pairs of what options are available for configuration along with their default values
 S getService()
          gets the service the test is running on
abstract  Test instantiate(java.util.HashMap<java.lang.String,ConfigOption> config)
          Instantiates a test of this type with the specified config (verify that it includes all needed configuration options).
protected abstract  void prepareDefaultResults(TestEvent results)
          give all results the test returns some default value
protected abstract  void run(TestEvent result)
          run the test and put all results into the results TestEvent object
 TestEvent run(TestItem ti)
          wrapper for run(TestEvent): creates the TestEvent and ensures timestamping is done
 void setService(S s)
          sets the service the test is running on
 void verifyConfig(Configuration configuration, java.util.HashMap<java.lang.String,ConfigOption> neededConfig)
          Checks the config to ensure it has all the properties in neededConfig.
abstract  void verifyConfigValue(java.lang.String optionName, ConfigOption optionValue)
          Determine whether the specified configuration option is a valid value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Test

public Test(S service)
Instantiates a test (with no configuration) for the purpose of instantiating tests of this type with different configurations later.

Parameters:
service - the service this test will run against

Test

protected Test(S service,
               Configuration config)
Instantiates a test with the specified config (verify that it includes all needed configuration options).

Parameters:
service - the service this test will run against
config - the test configuration information used when the test is run (warning: these options may change when verified)

Test

protected Test(S service,
               java.util.HashMap<java.lang.String,ConfigOption> options)
Instantiates a test with the specified config (verify that it includes all needed configuration options). Provided mostly for backwards compatability.

Parameters:
options - a hash of the test configuration information used when the test is run (warning: these options may change when verified)
Method Detail

equals

public boolean equals(Test t)

getDefaultConfigValuesCopy

public Configuration getDefaultConfigValuesCopy()
returns a COPY of the key-value pairs of what options are available for configuration along with their default values

Returns:
a COPY of the options which may be used to configure the test

getInitialConfigCopy

public Configuration getInitialConfigCopy()
returns a complete COPY of the key-value pairs of what options are available for configuration along with their default values

Returns:
a COPY of the options which may be used to configure the test

getDefaultConfigValues

protected abstract java.util.HashMap<java.lang.String,ConfigOption> getDefaultConfigValues()
returns a key-value pair of what options are available for configuration along with their default values

Returns:
options which may be used to configure the test

getService

public S getService()
gets the service the test is running on

Returns:
the service the test is running on

setService

public void setService(S s)
sets the service the test is running on


instantiate

public abstract Test instantiate(java.util.HashMap<java.lang.String,ConfigOption> config)
Instantiates a test of this type with the specified config (verify that it includes all needed configuration options).

Parameters:
config - the test configuration information used when the test is run (warning: these options may change when verified)
Returns:
returns a new instantiation of this Test with the specified configuration.

prepareDefaultResults

protected abstract void prepareDefaultResults(TestEvent results)
give all results the test returns some default value


run

public final TestEvent run(TestItem ti)
wrapper for run(TestEvent): creates the TestEvent and ensures timestamping is done

Parameters:
ti - the TestItem which contained this test
Returns:
results of the Test

run

protected abstract void run(TestEvent result)
run the test and put all results into the results TestEvent object

Parameters:
result - the results of the Test are stored here

verifyConfig

public void verifyConfig(Configuration configuration,
                         java.util.HashMap<java.lang.String,ConfigOption> neededConfig)
Checks the config to ensure it has all the properties in neededConfig. Any missing properties are added along with the default values from the method getDefaultConfigValues(). Each ConfigOption will be verified to ensure it meets the following criteria: 1) If it is an ANY paramter, it will be passed to the method verifyConfigValue(String,ConfigOption) to see if it is a valid value. If it is an invalid value, the value will be coerced to the default. 2) If it is a BINARY parameter, it will be restricted to the values Boolean.TRUE and Boolean.FALSE. Any deviation from those two values will be coerced to the default value. 3) If it is a MULTI parameter, it will be restricted to the values allowed by ConfigOption.getPossValues(). Any deviation from those values will be coerced to the default value.

Parameters:
configuration - the configuration to check (and fix as needed)
neededConfig - the configuration options which are required (along with default values)

verifyConfigValue

public abstract void verifyConfigValue(java.lang.String optionName,
                                       ConfigOption optionValue)
                                throws TestMisconfigurationException
Determine whether the specified configuration option is a valid value. If it is not, should throw a TestMisconfigurationException

Parameters:
optionName - the name of the option (the key in the config HashMap)
optionValue - the value of the option (the value in the config HashMap); will not be null
Throws:
TestMisconfigurationException

getConfig

public Configuration getConfig()
gets the options used to configure the test


getConfig

public java.lang.Object getConfig(java.lang.String optionName)
gets the value of the requested option used to configure the test (null is returned if there is no option by this name)