Package i5.las2peer.testing
Class LocalServiceTestCase
java.lang.Object
i5.las2peer.testing.LocalServiceTestCase
Helper class to implement JUnit-Test for services to be published in a las2peer environment.
As standard, for each Test a new agent (coming along with a new encryption key pair and an own passphrase) is
generated. If you want to use a specific agent, you can define the static Strings AGENT_XML_FILE and AGENT_PASSPHRASE
as final class constants.
If you want to use any other procedure to create or define the agent for your service to test, you can override the
method
createServiceAgent()
.
In the launching phase of the LocalNode
, the test case looks into the subdirectory
startup of the current working directory for XML files containing agents an envelopes to load into the node.
If you want to use any other directory, just override the method getStartupDir()
.-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionThis method creates the ServiceAgent to use with the las2peer node to run the service to test.protected String
getNode()
define a service class to test, this service will be started in aLocalNode
before starting the actual testprotected Service
shortcut for getting the actual instance of the service class to testabstract String
define a service version to test, this service will be started in aLocalNode
before starting the actual testget the name of a directory, which XML files are to be loaded on server Startup by theloadStartupDir()
method.invoke
(AgentImpl executing, String method, Serializable... parameters) invoke a method of the service to testvoid
load the XML file contained in the directory given bygetStartupDir()
method and initialize the node with the agents and envelopes generated from these XML filesvoid
start a node and launch the service given by the implementation ofgetServiceClass()
-
Field Details
-
DEFAULT_STARTUP_DIR
- See Also:
-
-
Constructor Details
-
LocalServiceTestCase
public LocalServiceTestCase()
-
-
Method Details
-
createServiceAgent
public ServiceAgentImpl createServiceAgent() throws CryptoException, InternalSecurityException, AgentExceptionThis method creates the ServiceAgent to use with the las2peer node to run the service to test. First it is tested, if the actual test case defines the constants AGENT_XML_FILE and AGENT_PASSPHRASE. If so, this information is used to load the ServiceAgent. Otherwise a completely fresh ServiceAgent is generated. Test cases may override this method to use any other arbitrary procedure to create a service agent for the service to test.- Returns:
- the service agent either created or loaded
- Throws:
CryptoException
InternalSecurityException
AgentException
-
startServer
start a node and launch the service given by the implementation ofgetServiceClass()
- Throws:
Exception
-
getNode
- Returns:
- the node, the test is running on
-
getMyAgent
- Returns:
- the ServiceAgent responsible for the Service to be tested
-
getAgentPassphrase
- Returns:
- the passphrase for the private key of the freshly generated service agent
-
getServiceInstance
shortcut for getting the actual instance of the service class to test- Returns:
- the running instance of the Service to test
- Throws:
ServiceNotFoundException
-
getServiceClass
define a service class to test, this service will be started in aLocalNode
before starting the actual test- Returns:
- the service class to be launched and tested
-
getServiceVersion
define a service version to test, this service will be started in aLocalNode
before starting the actual test- Returns:
- the service version to be launched and tested
-
invoke
public Serializable invoke(AgentImpl executing, String method, Serializable... parameters) throws InterruptedException, ServiceInvocationException, AgentLockedException invoke a method of the service to test- Parameters:
executing
-method
-parameters
-- Returns:
- result of the invocation
- Throws:
InterruptedException
ServiceInvocationException
AgentLockedException
-
loadStartupDir
public void loadStartupDir()load the XML file contained in the directory given bygetStartupDir()
method and initialize the node with the agents and envelopes generated from these XML files -
getStartupDir
get the name of a directory, which XML files are to be loaded on server Startup by theloadStartupDir()
method. May be overridden in actual test cases.- Returns:
- a directory name
-