com.ail.coretest
Class TestCoreConfiguration

java.lang.Object
  extended by junit.framework.Assert
      extended by junit.framework.TestCase
          extended by com.ail.coretest.TestCoreConfiguration
All Implemented Interfaces:
ConfigurationOwner, CoreUser, java.io.Serializable, junit.framework.Test

public class TestCoreConfiguration
extends junit.framework.TestCase
implements CoreUser, ConfigurationOwner

The tests defined here exercise the Core system's configuration handling. They use the Core class as an Service or core client would. Note: These tests assume that the JDBCConfigurationLoader is being used.

Version:
$Revision: 1.8 $
See Also:
Serialized Form

Constructor Summary
TestCoreConfiguration(java.lang.String name)
          Constructs a test case with the given name.
 
Method Summary
 Configuration getConfiguration()
          Method demanded by the ConfigurationOwner interface.
 java.lang.String getConfigurationNamespace()
          Method demanded by the ConfigurationOwner interface.
 java.security.Principal getSecurityPrincipal()
          Get the security principal associated with this instance.
 VersionEffectiveDate getVersionEffectiveDate()
          Method demanded by the CoreUser interface.
static void main(java.lang.String[] args)
           
 void resetConfiguration()
          Method demanded by the ConfigurationOwner interface.
 void setConfiguration(Configuration config)
          Method demanded by the ConfigurationOwner interface.
static junit.framework.Test suite()
           
 void testConfigurationClass()
          Test Configuration class itself.
 void testConfigurationHistory()
          As new version of a configuration are stored, the core keeps hold of the old ones - so that callers who ask for yesterday's configuration (by setting their versionEffectiveDate to yesterdate) will get yesterdays configuration.
 void testConfigurationInheritance()
          As of version 2.0 of the core, configurations support the notion of inheritance.
 void testConfigurationTimeout()
          Check that the configuration timeout feature is working.
 void testGettingComplexGroupFromConfiguration()
          Test to ensure that "complex" groups are retrieved correctly from configuration.
 void testGettingComplexParameterValuesFromConfiguration()
          Test to ensure that "complex" parameters are retrieved correctly from configuration.
 void testGettingConfigurationSource()
          Test to ensure that the configuration's source is correctly returned by the core.
 void testGettingParametersAsProperties()
          Test that a group's parameters can be retrieved as a java.util.Properties.
 void testGettingParametersAsPropertiesForEmptyGroup()
          Test that attempting to fetch Parameters as Properties for a group that doesn't exist returns a null.
 void testGettingParametersAsPropertiesGroupThatDontExist()
          Test that attempting to fetch Parameters as Properties for a group that doesn't exist returns a null.
 void testGettingSimpleGroupFromConfiguration()
          Test to ensure that "simple" groups are retrieved correctly from configuration.
 void testGettingSimpleGroupThatDontExist()
          Check that an attempt to fetch a group that isn't defined is handled correctly.
 void testGettingSimpleParametersThatDontExist()
          Check that an attempt to fetch a parameter that isn't defined is handled correctly.
 void testGettingSimpleParameterValuesFromConfiguration()
          Test to ensure that "simple" parameters are retrieved correctly from configuration.
 void testGroupConfigurationBackStop()
          If a request is made by a configuration user for a setting (parameter, group, etc) which is not defined in that user's configuration, the core should check it's own configuration.
 void testParameterConfigurationBackStop()
          If a request is made by a configuration user for a setting (parameter, group, etc) which is not defined in that user's configuration, the core should check it's own configuration.
 void testSaveAndLoadConfiguration()
          Check that configuration can be save and re-loaded.
 void testSaveAndLoadVersioningConfiguration()
          Check that configuration access is correctly based on version effective date.
 void testSaveConfiguration()
          Check that the core class can be used to save configuration.
 void testTimoutCachePerformace()
          Test the effectiviness of the configuration timeout cache.
 void testUpdateCollisionDetection()
          Check that the configure system correctly detects and prevents update collisions.
 
Methods inherited from class junit.framework.TestCase
countTestCases, getName, run, run, runBare, setName, toString
 
Methods inherited from class junit.framework.Assert
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, fail, fail
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TestCoreConfiguration

public TestCoreConfiguration(java.lang.String name)
Constructs a test case with the given name.

Method Detail

suite

public static junit.framework.Test suite()

main

public static void main(java.lang.String[] args)

getSecurityPrincipal

public java.security.Principal getSecurityPrincipal()
Get the security principal associated with this instance.

Specified by:
getSecurityPrincipal in interface CoreUser
Returns:
The associated security principal - if defined, null otherwise.

getVersionEffectiveDate

public VersionEffectiveDate getVersionEffectiveDate()
Method demanded by the CoreUser interface.

Specified by:
getVersionEffectiveDate in interface CoreUser
Returns:
A date to use to selecte the corrent version of config info.

setConfiguration

public void setConfiguration(Configuration config)
Method demanded by the ConfigurationOwner interface.

Specified by:
setConfiguration in interface ConfigurationOwner
Parameters:
config - Configuration to use from now on.

getConfiguration

public Configuration getConfiguration()
Method demanded by the ConfigurationOwner interface.

Specified by:
getConfiguration in interface ConfigurationOwner
Returns:
The current configuration (at versionEffectiveDate).

getConfigurationNamespace

public java.lang.String getConfigurationNamespace()
Method demanded by the ConfigurationOwner interface.

Specified by:
getConfigurationNamespace in interface CoreUser
Returns:
The configuration namespace we're using

resetConfiguration

public void resetConfiguration()
Method demanded by the ConfigurationOwner interface.

Specified by:
resetConfiguration in interface ConfigurationOwner

testConfigurationClass

public void testConfigurationClass()
                            throws java.lang.Exception
Test Configuration class itself.

Throws:
java.lang.Exception

testSaveConfiguration

public void testSaveConfiguration()
Check that the core class can be used to save configuration. This test does not exsure that the configuration was stored OK, just that the store doesn't throw exceptions.
  1. Create a configuration
  2. Save the configuration (Core.saveConfiguration).
  3. Fail if any exceptions are thrown.


testSaveAndLoadConfiguration

public void testSaveAndLoadConfiguration()
Check that configuration can be save and re-loaded.
  1. Create a simple configuration.
  2. Save the configuration.
  3. sleep for 1ms, the set versionEffectiveDate to now.
  4. Load the configuration.
  5. Fail if the loaded configuration is different from the saved one.
  6. Fail if any exceptions are thrown.


testSaveAndLoadVersioningConfiguration

public void testSaveAndLoadVersioningConfiguration()
Check that configuration access is correctly based on version effective date.

Configurations are loaded with respect to their name, and the dates when they are valid. When a configuration is saved, only its start-date is filled in, the end-date is set when the configuration is updated. When a caller requests something from the core that requires the core to read from configuration it (the core) loadeds the configuration with respect to the date returned by the caller's getVersionEffectiveDate method. So, if you set your versionEffectiveDate to now, save your configuration and then try to re-load it you will find that it doesn't change.

  1. Create three different configurations 3ms apart, note the time when each was saved.
  2. Try to load the configuration.
  3. Fail if no execption is thrown - versionEffectiveDate is still set to when the test began, when there was no configuration.
  4. set versionEffectiveDate to each of the saved times in turn and load the configuration.
  5. Fail if any exceptions are thrown.
  6. Fail if the configurations loaded are not the same as they were saved.


testGettingSimpleParameterValuesFromConfiguration

public void testGettingSimpleParameterValuesFromConfiguration()
                                                       throws java.lang.Exception
Test to ensure that "simple" parameters are retrieved correctly from configuration. "Simple" parameters are parameters at the root level of the configuration, i.e. they are not in sub-groups.
  1. Set the current configuration to the on defined in this.createComplexConfiguration()
  2. Set the version effective date to now.
  3. Read the values of the 'tom', 'dick', and 'harry' root parameters.
  4. Fail if 'tom' doesn't return 'Thomas', 'dick' doesn't return 'Richard', or 'harry' doesn't return 'harold'.
  5. Fail if any excepations are thrown.

Throws:
java.lang.Exception

testGettingSimpleParametersThatDontExist

public void testGettingSimpleParametersThatDontExist()
                                              throws java.lang.Exception
Check that an attempt to fetch a parameter that isn't defined is handled correctly. When an attempt is made to retrieve an undefined parameter, code.getParameter() should return a null.
  1. Set the current configuration to the on defined in this.createComplexConfiguration()
  2. Set the version effective date to now.
  3. Attempt to fetch the parameter "param-that-does-not-exist".
  4. Fail if the parameter returned is not null.
  5. Fail if any exceptions are thrown.

Throws:
java.lang.Exception

testGettingComplexParameterValuesFromConfiguration

public void testGettingComplexParameterValuesFromConfiguration()
Test to ensure that "complex" parameters are retrieved correctly from configuration. "Simple" parameters are parameters nested within groups which are located using a dot sperated path.
  1. Set the current configuration to the on defined in this.createComplexConfiguration()
  2. Set the version effective date to now.
  3. Read the values of the 'tom', 'dick', and 'harry' root parameters.
  4. Fail if 'tom' doesn't return 'Thomas', 'dick' doesn't return 'Richard', or 'harry' doesn't return 'harold'.
  5. Fail if any excepations are thrown.


testGettingConfigurationSource

public void testGettingConfigurationSource()
Test to ensure that the configuration's source is correctly returned by the core. This source indicates where the configuration be being used by the core was loaded from.
  1. Set the current configuration to the on defined in this.createComplexConfiguration()
  2. Set the version effective date to now.
  3. Fail if the source isn't set to immediate.
  4. Fail if 'tom' doesn't return 'Thomas', 'dick' doesn't return 'Richard', or 'harry' doesn't return 'harold'.
  5. Fail if any excepations are thrown.


testGettingSimpleGroupFromConfiguration

public void testGettingSimpleGroupFromConfiguration()
Test to ensure that "simple" groups are retrieved correctly from configuration. "Simple" groups are groups at the root level of the configuration, i.e. they are not in sub-groups.
  1. Set the current configuration to the on defined in this.createComplexConfiguration()
  2. Set the version effective date to now.
  3. Fetch the "plants" group from configuration.
  4. Fail if the name of the group returned is not "plants".
  5. Fetch the "names" group from configuration.
  6. Fail if the name of the group returned is not "names".
  7. Fail if any excepations are thrown.


testGettingComplexGroupFromConfiguration

public void testGettingComplexGroupFromConfiguration()
Test to ensure that "complex" groups are retrieved correctly from configuration. "complex" groups are groups which are tested within other groups.
  1. Set the current configuration to the on defined in this.createComplexConfiguration()
  2. Set the version effective date to now.
  3. Fetch the "plants.trees.oak" group from configuration.
  4. Fail if the name of the group returned is not "oak".
  5. Fetch the "plants.trees.apple" group from configuration.
  6. Fail if the name of the group returned is not "apple".
  7. Fail if any excepations are thrown.


testGettingSimpleGroupThatDontExist

public void testGettingSimpleGroupThatDontExist()
Check that an attempt to fetch a group that isn't defined is handled correctly. When an attempt is made to retrieve an undefined group, code.getGroup() should return a null.
  1. Set the current configuration to the on defined in this.createComplexConfiguration()
  2. Set the version effective date to now.
  3. Attempt to fetch the group "param-that-does-not-exist".
  4. Fail if the group returned is not null.
  5. Fail if any exceptions are thrown.


testGettingParametersAsProperties

public void testGettingParametersAsProperties()
Test that a group's parameters can be retrieved as a java.util.Properties.
  1. Set the current configuration to the on defined in this.createComplexConfiguration()
  2. Set the version effective date to now.
  3. Attempt to the parameters from the root configuration as properties.
  4. Fail if null is returned
  5. Fail if the properties tom=Thomas, dick=Richard, and harry=Harold are not found.
  6. Fail if any exceptions are thrown.


testGettingParametersAsPropertiesForEmptyGroup

public void testGettingParametersAsPropertiesForEmptyGroup()
Test that attempting to fetch Parameters as Properties for a group that doesn't exist returns a null.
  1. Set the current configuration to the on defined in this.createComplexConfiguration()
  2. Set the version effective date to now.
  3. Attempt to the parameters for the group "group-that-does-not-exist".
  4. Fail if the return is not null.
  5. Fail if any exceptions are thrown.


testGettingParametersAsPropertiesGroupThatDontExist

public void testGettingParametersAsPropertiesGroupThatDontExist()
Test that attempting to fetch Parameters as Properties for a group that doesn't exist returns a null.
  1. Set the current configuration to the on defined in this.createComplexConfiguration()
  2. Set the version effective date to now.
  3. Attempt to the parameters for the group "plants".
  4. Fail if the return is null.
  5. Fail if any exceptions are thrown.


testParameterConfigurationBackStop

public void testParameterConfigurationBackStop()
If a request is made by a configuration user for a setting (parameter, group, etc) which is not defined in that user's configuration, the core should check it's own configuration. This test ensures that this is the case for parameters.

The setup method saves a core configuration which defines TestParameter with the value 'SavedInCoreConfig'.

  1. Save a configuration that doesn't define "TestParameter".
  2. Get the parameter "TestParameter".
  3. Fail if null is returned, or if the parameter's value is not "SavedInCoreConfig"
  4. Save a configuration that defines "TestParameter" as "SavedLocally"
  5. Get the parameter "TestParameter".
  6. Fail if null is returned, or if the parameter's value is not "SavedLocally"
  7. Fail if any exceptions are thrown.


testGroupConfigurationBackStop

public void testGroupConfigurationBackStop()
If a request is made by a configuration user for a setting (parameter, group, etc) which is not defined in that user's configuration, the core should check it's own configuration. This test ensures that this is the case for groups.

The setup method saves a core configuration which defines TestGroup.

  1. Save a configuration that doesn't define "TestGroup".
  2. Get the group "TestGroup".
  3. Fail if null is returned.
  4. Save a configuration that defines "TestGroup" as "SavedLocally"
  5. Get the parameter "TestParameter".
  6. Fail if null is returned, or if the parameter's value is not "SavedLocally"
  7. Fail if any exceptions are thrown.


testConfigurationTimeout

public void testConfigurationTimeout()
Check that the configuration timeout feature is working. Configurations specify their own timeout value which defines when they should be reloaded. Updating a configuration in the database (via saveConfiguration) does not make that configuration live, it simply updates the database records. It will only become live when the current configuration's timeout expires, and forces a re-load.
  1. Create a configuration with a TestParameter set to "one".
  2. Save the configuration with a timeout of 100ms.
  3. Fetch "TestParameter", and check that its value is "one".
  4. Create a configuration with TestParameter set to "two".
  5. Save the configuration.
  6. Fetch "TestParameter", and check that its value is still "one".
  7. Sleep for 100ms.
  8. Fetch "TestParameter", and check that its value is now "two".
  9. Fail if any exceptions are thrown.


testTimoutCachePerformace

public void testTimoutCachePerformace()
Test the effectiviness of the configuration timeout cache. With a timeout set to zero the database should be hit on each request for 'new' configuration. Setting the timeout to a more realistic value (1000), should result in database hits only every 1000ms.
  1. Save a configuration with a timeout of zero.
  2. Time how long it takes to make 1000 configuration queries.
  3. Save the same configuration again, but this time with a timeout of 1000.
  4. Time how long it now takes to make 1000 configuration queries.
  5. File if any exceptions are thrown.
  6. Fail if the second time is more that 1/100th of the first.


testUpdateCollisionDetection

public void testUpdateCollisionDetection()
                                  throws java.lang.Exception
Check that the configure system correctly detects and prevents update collisions. This is the scenario where:
  1. User A reads configuration.
  2. User B reads configuration.
  3. User A modifies their in memory configuration, and saves.
  4. User B modifies their in memory configuration, and attempts to save. *Error should be thrown here*

Throws:
java.lang.Exception

testConfigurationHistory

public void testConfigurationHistory()
                              throws java.lang.Exception
As new version of a configuration are stored, the core keeps hold of the old ones - so that callers who ask for yesterday's configuration (by setting their versionEffectiveDate to yesterdate) will get yesterdays configuration. It also offers a service to return details of all the versions of a specific configuration that it knows about. This test creates a number of configurations, then calls the history service and checks that the details returned match up this those of the configurations it created.

Throws:
java.lang.Exception

testConfigurationInheritance

public void testConfigurationInheritance()
                                  throws java.lang.Exception
As of version 2.0 of the core, configurations support the notion of inheritance. That is, a configuration names another as being it's parent. The parent may in turn inherit from another and so on. This text checks that basic inheritance works.

Throws:
java.lang.Exception