org.gcube.common.mycontainer
Class MyContainer

java.lang.Object
  extended by org.gcube.common.mycontainer.MyContainer

public class MyContainer
extends Object

An embedded gCore container for integration testing.

The container is partially embedded, in that it requires an installation on the local file system. It can be configured with the following properties:

Note: since the container relies on statics, starting it and stopping it multiple times within the same runtime may have undesirable effects. For test isolation and reproducibility, the container is best started once per JVM, typically for the execution of a single test suite. IDEs typically fork JVMs per test suites, but build systems such as Ant or Maven may have to be explicitly configured for this.

Author:
Fabio Simeoni

Constructor Summary
MyContainer(Gar... gars)
          Creates an instance configured with: the properties found in a Utils.PROPERTY_FILE zero or more Gars Note that:
MyContainer(Properties properties, boolean merge, Gar... gars)
          An overload of MyContainer(Properties, Gar...) where the configuration properties passed in input can augment or override those in a Utils.PROPERTY_FILE.
MyContainer(Properties properties, Gar... gars)
          Creates an instance configured with: given properties zero or more Gars Note that the Gars are deployed when the container is started.
MyContainer(String location, Gar... gars)
          Creates an instance configured: a given location default properties zero or more Gars Note that the Gars are deployed when the container is started.
 
Method Summary
 URI address(String wsddName)
          Returns the address of a service running in the container started at the default port.
 URI address(String name, int port)
          Returns the address of a service running in a container started at a given port.
 void cleanState()
           
 File configLocation()
          Returns the container's configuration folder.
 File deploymentsLocation()
          Returns the container's deployment folders.
<T> T
endpoint(String name, Class<T> clazz)
          Returns the implementation of service deployed in the container with application scope.
 boolean isRunning()
          
 File libLocation()
          Returns the container's library folder.
 File location()
          Returns the location of the container's installation.
 org.apache.axis.message.addressing.EndpointReferenceType reference(String name)
          Returns a reference to a service running in the container on the default port.
 org.apache.axis.message.addressing.EndpointReferenceType reference(String name, int port)
          Returns a reference to a service running in the container started at a given port.
 org.apache.axis.message.addressing.EndpointReferenceType reference(String name, String namespace, String key)
          Returns a reference to an instance of a service running in the container started at the default port.
 org.apache.axis.message.addressing.EndpointReferenceType reference(String name, String namespace, String key, int port)
          Returns a reference to an instance of a service running in the container started at a given port.
 void setEndpoint(String name, Object endpoint)
           
 void start()
          Starts the container, deploying the GARs with which it was configured.
 void stop()
          Stops the container.
 File storageLocation()
          Returns the container's storage folder.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MyContainer

public MyContainer(Gar... gars)
            throws IllegalStateException,
                   IllegalArgumentException
Creates an instance configured with: Note that:

Parameters:
gars - the Gars
Throws:
IllegalStateException - if the Utils.PROPERTY_FILE cannot be found
IllegalArgumentException - if the Utils.PROPERTY_FILE is found but contains invalid properties

MyContainer

public MyContainer(String location,
                   Gar... gars)
            throws IllegalStateException,
                   IllegalArgumentException
Creates an instance configured: Note that the Gars are deployed when the container is started. Gars which are already deployed in the container are re-deployed only if they have changed since. Changes are computed based on the last modification date of their assets.

Parameters:
location - the location of the container's installation.
gars - the Gars
Throws:
IllegalStateException - if the Utils.PROPERTY_FILE cannot be found
IllegalArgumentException - if the Utils.PROPERTY_FILE is found but contains invalid properties

MyContainer

public MyContainer(Properties properties,
                   Gar... gars)
            throws IllegalArgumentException
Creates an instance configured with: Note that the Gars are deployed when the container is started. Gars which are already deployed in the container are re-deployed only if they have changed since. Changes are computed based on the last modification date of their assets.

Parameters:
properties - the properties
gars - the Gars
Throws:
IllegalArgumentException - if the the properties are invalid.

MyContainer

public MyContainer(Properties properties,
                   boolean merge,
                   Gar... gars)
            throws IllegalArgumentException,
                   IllegalStateException
An overload of MyContainer(Properties, Gar...) where the configuration properties passed in input can augment or override those in a Utils.PROPERTY_FILE.

Parameters:
properties - the properties
merge - true if the properties are to augment or override those in a Utils.PROPERTY_FILE. The discovery of Utils.PROPERTY_FILE is delegated to Utils.findContainerProperties()
gars - the Gars.
Throws:
IllegalArgumentException - if the properties are invalid
IllegalStateException - if the properties cannot be merged because Utils.PROPERTY_FILE cannot be found
Method Detail

location

public File location()
Returns the location of the container's installation.

Returns:
the location

storageLocation

public File storageLocation()
Returns the container's storage folder.

Returns:
the folder

configLocation

public File configLocation()
Returns the container's configuration folder.

Returns:
the folder

deploymentsLocation

public File deploymentsLocation()
Returns the container's deployment folders.

Returns:
the folder

libLocation

public File libLocation()
Returns the container's library folder.

Returns:
the folder

endpoint

public <T> T endpoint(String name,
                      Class<T> clazz)
           throws IllegalStateException
Returns the implementation of service deployed in the container with application scope.

Type Parameters:
T - the type of the implementation
Parameters:
name - the WSDD name of the service
clazz - the runtime representation of the implementation type
Throws:
IllegalStateException - if the container is not running or a service with the WSDD name is not running in the container
ClassCastException - if the port-type implementation cannot be cast to the given type

setEndpoint

public void setEndpoint(String name,
                        Object endpoint)
                 throws IllegalStateException
Throws:
IllegalStateException

address

public URI address(String wsddName)
            throws IllegalStateException
Returns the address of a service running in the container started at the default port.

Parameters:
wsddName - the WSDD name of the service
Returns:
the address
Throws:
IllegalStateException - if the container is not running or a service with a the given WSDD name is not running in the container

address

public URI address(String name,
                   int port)
            throws IllegalStateException
Returns the address of a service running in a container started at a given port.

Parameters:
name - the WSDD name of the service
port - the port
Returns:
the address
Throws:
IllegalStateException - if the container is not running or a service with a the given WSDD name is not running in the container

reference

public org.apache.axis.message.addressing.EndpointReferenceType reference(String name)
                                                                   throws IllegalStateException
Returns a reference to a service running in the container on the default port.

Parameters:
name - the WSDD name of the service
Returns:
the reference
Throws:
IllegalStateException - if the container is not running or a service with the given WSDD name is not running in the container

reference

public org.apache.axis.message.addressing.EndpointReferenceType reference(String name,
                                                                          int port)
                                                                   throws IllegalStateException
Returns a reference to a service running in the container started at a given port.

Parameters:
name - the WSDD name of the service
port - the port
Returns:
the reference
Throws:
IllegalStateException - if the container is not running or a service with the given WSDD name is not running in the container

reference

public org.apache.axis.message.addressing.EndpointReferenceType reference(String name,
                                                                          String namespace,
                                                                          String key)
                                                                   throws IllegalStateException
Returns a reference to an instance of a service running in the container started at the default port.

Parameters:
name - the WSDD name of the service
key - the namespace of the service
key - the key of the service instance
Returns:
the reference
Throws:
IllegalStateException - if the container is not running or a service with a given WSDD name is not running in the container

reference

public org.apache.axis.message.addressing.EndpointReferenceType reference(String name,
                                                                          String namespace,
                                                                          String key,
                                                                          int port)
                                                                   throws IllegalStateException
Returns a reference to an instance of a service running in the container started at a given port.

Parameters:
name - the WSDD name of the service
namespace - the namespace of the service
key - the key of the service instance
port - the port
Returns:
the reference
Throws:
IllegalStateException - if the container is not running or a service with the given WSDD name is not running in the container

isRunning

public boolean isRunning()


start

public void start()
Starts the container, deploying the GARs with which it was configured.


stop

public void stop()
Stops the container.


cleanState

public void cleanState()


Copyright © 2012. All Rights Reserved.