com.ail.coretest
Class TestCoreFactory

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

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

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

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

Constructor Summary
TestCoreFactory()
           
TestCoreFactory(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.
 void setConfigurationNamespace(java.lang.String configurationNamespace)
           
static junit.framework.Test suite()
           
 void testBeanShellFactory()
          The BeanShellFactory provides support for types to be created by scripts embedded in the systems configuration.
 void testBeanShellFactoryCoreRef()
          The BeanShellFactory supports the notion of a type creation script that referrs to the 'core' - i.e.
 void testBeanShellFactoryExtends()
          The BeanShellFactory provides support for creating types from a BeanShell script.
 void testBeanShellFactoryUrlLoader()
          The BeanShell factory supports two type definition mechanisms.
 void testCastorXMLFactory()
          The CastorXMLFactory provides support for types to be created via embedded XML in the system configuration.
 void testCastorXMLFactoryUrlLoader()
          The Castor XML factory supports two type definition mechanisms.
 void testDoubleVersionPrototypeType()
          Configuration history should maintain types by date.
 void testFactoryClone()
          Test to check that modifications to an object cloned in the factory do no propogate to other instances of the same type.
 void testFactoryCloneOnTransientProperties()
          The Factory's clone method should null transient properties - to avoid the situation when all instances of the same type end up sharing one object.
 void testFactorySingleInstance()
           
 void testSimplePrototypeType()
          Check that the type factory creates 'prototyped' types correctly.
 void testSimpleType()
          Check that the type factory returns instances of a type as configured.
 void testUndefinedSimpleType()
          Check that the type factory correctly handles a request for a type that is not defined.
 void testXSLTFactoryWithExtends()
          The XSLTFactory provides support for creating types from an XSLT.
 void testXSLTFactoryWithoutExtends()
          The CastorXMLFactory provides support for types to be created via embedded XML in the system configuration.
 
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

TestCoreFactory

public TestCoreFactory()

TestCoreFactory

public TestCoreFactory(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

setConfigurationNamespace

public void setConfigurationNamespace(java.lang.String configurationNamespace)

resetConfiguration

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

Specified by:
resetConfiguration in interface ConfigurationOwner

testSimpleType

public void testSimpleType()
Check that the type factory returns instances of a type as configured. The configuration created but createConfigurationOne defines a type 'Version' to be an instance of com.ail.core.Version. This test ensures that an instance of com.ail.core.Version is returned when 'Version' is requested.
  1. Create a configuration using createConfigurationOne
  2. Use the type factory to create a 'Version' object.
  3. Fail if the object returned is not an instance of com.ail.core.Version
  4. Fail if any exceptions are thrown.


testUndefinedSimpleType

public void testUndefinedSimpleType()
Check that the type factory correctly handles a request for a type that is not defined. If asked to create a type that is not defined the factory should throw a ...
  1. Create a configuration using createConfigurationOne
  2. Use the type factory to create a 'Type-That-Does-Not-Exist' object.
  3. Fail if any object is returned
  4. Fail if any exceptions are thrown.


testSimplePrototypeType

public void testSimplePrototypeType()
Check that the type factory creates 'prototyped' types correctly. Prototyped types are types that have some or all of their properties defined in the configuration.
  1. Create an instance of the 'SetVersion' type.
  2. Fail if the returned object is not an instance of 'Version'.
  3. Fail if the returned version's 'author' property is not set to "Fred".
  4. Fail if the returned version's 'version' property is not set to "1.2".
  5. Fail if any exceptions are thrown.


testDoubleVersionPrototypeType

public void testDoubleVersionPrototypeType()
Configuration history should maintain types by date. This means that is should be possible to have two types by the same name active on different effectiveDates. These types may also have different initial settings. This test ensures that this is the case.

TestCoreFactory defines two configurations, both define a type called SetVersion, both define SetVersion with different initial settings. This test saves both configurations in different effective dates, then by shifting the effective date between the two settings we should get the two different SetVersions back from the factory.


testBeanShellFactory

public void testBeanShellFactory()
                          throws java.lang.Exception
The BeanShellFactory provides support for types to be created by scripts embedded in the systems configuration. This test checks that the factory responsible for processing these scripts is working.

The configuration used in this test defines two BeanShell scripted types, one (BeanShellVersion) should create a version object with author and version attributes set, the other (BadBeanShellVersion) contains a syntax error which should cause a FactoryConfigurationError.

  1. Create an instance of BeanShellVersion.
  2. Fail if the author attribute is not set correctly.
  3. Fail if the version attribute is not set correctly.
  4. Fail if any exceptions are thrown.
  5. Create an instance of BadBeanShellVersion.
  6. Fail if no exception is thrown.
  7. Fail if any exception other than FactoryConfigurationError is thrown.

Throws:
java.lang.Exception

testBeanShellFactoryCoreRef

public void testBeanShellFactoryCoreRef()
                                 throws java.lang.Exception
The BeanShellFactory supports the notion of a type creation script that referrs to the 'core' - i.e. the script that creates the type is given an instance of the core which it may use to access any of the normal core features - like logging, of the type factory. This test ensures that this feature us working.
  1. Create an instance of BeanShellVersionCoreRef (whose factory script simply uses the core to create an instance of the 'BeanShellVersion' type)..
  2. Fail if the author attribute is not set correctly.
  3. Fail if the version attribute is not set correctly.
  4. Fail if any exceptions are thrown.

Throws:
java.lang.Exception

testCastorXMLFactory

public void testCastorXMLFactory()
                          throws java.lang.Exception
The CastorXMLFactory provides support for types to be created via embedded XML in the system configuration. This test checks that the factory responsible for processing these XML types scripts is working.

  1. Create an instance of CastorXMLVersion.
  2. Fail if the author attribute is not set correctly.
  3. Fail if the version attribute is not set correctly.
  4. Fail if any exceptions are thrown.

Throws:
java.lang.Exception

testXSLTFactoryWithExtends

public void testXSLTFactoryWithExtends()
                                throws java.lang.Exception
The XSLTFactory provides support for creating types from an XSLT. The type definition contains an embedded XSLT which the factory runs to generate an XML type definition (which can be used by the CastorXMLFactory). The XSLTFactory optionally allows the type to define an "extends" parameter which names another type which should be used as input to the XSLT. The extends type is instantiated, translated to XML and passed into the XSLT. This test ensures that this mechanism is working.
  1. Create an instance of XSLTVersion.
  2. Fail if the author attribute is not set correctly.
  3. Fail if the version attribute is not set correctly.
  4. Fail if any exceptions are thrown.

Throws:
java.lang.Exception

testXSLTFactoryWithoutExtends

public void testXSLTFactoryWithoutExtends()
                                   throws java.lang.Exception
The CastorXMLFactory provides support for types to be created via embedded XML in the system configuration. This test checks that the factory responsible for processing these XML types scripts is working.

  1. Create an instance of CastorXMLVersion.
  2. Fail if the author attribute is not set correctly.
  3. Fail if the version attribute is not set correctly.
  4. Fail if any exceptions are thrown.

Throws:
java.lang.Exception

testBeanShellFactoryExtends

public void testBeanShellFactoryExtends()
                                 throws java.lang.Exception
The BeanShellFactory provides support for creating types from a BeanShell script. The type definition contains an embedded script which the factory runs to generate the type definition. It optionally allows the type to define an "extends" parameter which names another type which should be used as input to the script. The extends type is instantiated,and passed into the script as a variable named "type". This test ensures that this mechanism is working.
  1. Create an instance of XSLTVersion.
  2. Fail if the author attribute is not set correctly.
  3. Fail if the version attribute is not set correctly.
  4. Fail if any exceptions are thrown.

Throws:
java.lang.Exception

testFactoryClone

public void testFactoryClone()
                      throws java.lang.Exception
Test to check that modifications to an object cloned in the factory do no propogate to other instances of the same type.

Throws:
java.lang.Exception

testFactorySingleInstance

public void testFactorySingleInstance()
                               throws java.lang.Exception
Throws:
java.lang.Exception

testFactoryCloneOnTransientProperties

public void testFactoryCloneOnTransientProperties()
                                           throws java.lang.Exception
The Factory's clone method should null transient properties - to avoid the situation when all instances of the same type end up sharing one object. This test checks this behaviour.

Throws:
java.lang.Exception

testCastorXMLFactoryUrlLoader

public void testCastorXMLFactoryUrlLoader()
                                   throws java.lang.Exception
The Castor XML factory supports two type definition mechanisms. The normal "Script" mechanism, where the XML for the type definition is held with the type itself within the 'Script' parameter; and the "Url" mechanism, where the XML is read from a URL which is pointed to by the type's 'Url' parameter. This test exercises the Url mechanism.

Throws:
java.lang.Exception

testBeanShellFactoryUrlLoader

public void testBeanShellFactoryUrlLoader()
                                   throws java.lang.Exception
The BeanShell factory supports two type definition mechanisms. The normal "Script" mechanism, where the script for the type definition is held with the type itself within the 'Script' parameter; and the "Url" mechanism, where the script is read from a URL which is pointed to by the type's 'Url' parameter. This test exercises the Url mechanism.

Throws:
java.lang.Exception