Class LocalServiceTestCase

java.lang.Object
i5.las2peer.testing.LocalServiceTestCase

public abstract class LocalServiceTestCase extends Object
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 Details

  • Constructor Details

    • LocalServiceTestCase

      public LocalServiceTestCase()
  • Method Details

    • createServiceAgent

      This 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

      public void startServer() throws Exception
      start a node and launch the service given by the implementation of getServiceClass()
      Throws:
      Exception
    • getNode

      public LocalNode getNode()
      Returns:
      the node, the test is running on
    • getMyAgent

      public ServiceAgentImpl getMyAgent()
      Returns:
      the ServiceAgent responsible for the Service to be tested
    • getAgentPassphrase

      protected String getAgentPassphrase()
      Returns:
      the passphrase for the private key of the freshly generated service agent
    • getServiceInstance

      protected Service getServiceInstance() throws ServiceNotFoundException
      shortcut for getting the actual instance of the service class to test
      Returns:
      the running instance of the Service to test
      Throws:
      ServiceNotFoundException
    • getServiceClass

      public abstract Class<? extends Service> getServiceClass()
      define a service class to test, this service will be started in a LocalNode before starting the actual test
      Returns:
      the service class to be launched and tested
    • getServiceVersion

      public abstract String getServiceVersion()
      define a service version to test, this service will be started in a LocalNode before starting the actual test
      Returns:
      the service version to be launched and tested
    • invoke

      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 by getStartupDir() method and initialize the node with the agents and envelopes generated from these XML files
    • getStartupDir

      public String getStartupDir()
      get the name of a directory, which XML files are to be loaded on server Startup by the loadStartupDir() method. May be overridden in actual test cases.
      Returns:
      a directory name