org.glassfish.fighterfish.test.util
Class TestContext

java.lang.Object
  extended by org.glassfish.fighterfish.test.util.TestContext

public class TestContext
extends java.lang.Object

A TestContext is a facade through which a test interacts with underlying OSGi or Java EE platform. It provides functionality like installing/uninstalling bundles, configuring Java EE resources like JDBC data sources, JMS destinations, etc. Each test method is accompanied by a single TestContext object. A TestContext object's life cycle is scoped to a test method for this reason. Each test method must create a TestContext by calling the factory method create(Class) at the beginning of the test method and destroy it by calling destroy() at the end of the test method. When a test context is destroyed, all changes done so far will be rolled back. This includes any bundles deployed. any domain configuration made, etc.

Author:
Sanjeeb.Sahoo@Sun.COM

Method Summary
 void configureEmbeddedDerby()
           
static TestContext create(java.lang.Class testClass)
           
 void createJmsCF(java.lang.String cfName)
           
 void createJmsTopic(java.lang.String topicName)
           
 EjbBundle deployEjbBundle(org.osgi.framework.Bundle bundle, java.lang.String[] services)
          Deploy the given EJB OSGi bundle.
 EjbBundle deployEjbBundle(java.lang.String location, java.lang.String[] services)
           
 EntityBundle deployEntityBundle(org.osgi.framework.Bundle bundle)
          Deploy the given JPA Entities bundle.
 EntityBundle deployEntityBundle(java.lang.String location)
           
 WebAppBundle deployWebAppBundle(org.osgi.framework.Bundle bundle)
          Deploy the given OSGi Web Application Bundle.
 WebAppBundle deployWebAppBundle(java.lang.String location)
           
 void destroy()
           
 org.osgi.framework.BundleContext getBundleContext()
           
 org.glassfish.embeddable.GlassFish getGlassFish()
           
 org.osgi.framework.Bundle installBundle(java.lang.String location)
          Install an OSGi bundle by reading its content from a given location URI.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

create

public static TestContext create(java.lang.Class testClass)
                          throws org.glassfish.embeddable.GlassFishException,
                                 java.lang.InterruptedException
Throws:
org.glassfish.embeddable.GlassFishException
java.lang.InterruptedException

destroy

public void destroy()
             throws org.osgi.framework.BundleException,
                    org.glassfish.embeddable.GlassFishException
Throws:
org.osgi.framework.BundleException
org.glassfish.embeddable.GlassFishException

deployWebAppBundle

public WebAppBundle deployWebAppBundle(org.osgi.framework.Bundle bundle)
                                throws org.osgi.framework.BundleException,
                                       java.lang.InterruptedException
Deploy the given OSGi Web Application Bundle. WAB deployment happens asynchronously when a WAB is activated. It waits for a configured amount time for deployment to take place successfully. If deployment fails or does not happen within the configured times, it throws TimeoutException.

Parameters:
bundle -
Returns:
ServletContext associated with the deployed web application
Throws:
org.osgi.framework.BundleException
java.lang.InterruptedException

deployWebAppBundle

public WebAppBundle deployWebAppBundle(java.lang.String location)
                                throws org.osgi.framework.BundleException,
                                       java.lang.InterruptedException
Throws:
org.osgi.framework.BundleException
java.lang.InterruptedException

deployEntityBundle

public EntityBundle deployEntityBundle(org.osgi.framework.Bundle bundle)
                                throws org.osgi.framework.BundleException,
                                       java.lang.InterruptedException
Deploy the given JPA Entities bundle. If a service of type EntityManagerFactory does not get registered in the specified time, assume the deployment has failed and throw a TimeoutException.

Parameters:
bundle - Entity bundle to be deployed
Returns:
a handle to the deployed application
Throws:
org.osgi.framework.BundleException
java.lang.InterruptedException
TimeoutException

deployEntityBundle

public EntityBundle deployEntityBundle(java.lang.String location)
                                throws org.osgi.framework.BundleException,
                                       java.lang.InterruptedException
Throws:
org.osgi.framework.BundleException
java.lang.InterruptedException

deployEjbBundle

public EjbBundle deployEjbBundle(org.osgi.framework.Bundle bundle,
                                 java.lang.String[] services)
                          throws org.osgi.framework.BundleException,
                                 java.lang.InterruptedException
Deploy the given EJB OSGi bundle. Deployment is triggered asynchronously by starting the bundle. If none of the user specified services show up in service registry in the specified amount of time, it assumes the operation has failed and throws TimeoutOperation.

Parameters:
bundle - EJB Bundle to be deployed
services - Services that are expected to be made available by this EJB bundle if deployment is successful.
Returns:
a handle to the deployed application
Throws:
org.osgi.framework.BundleException
java.lang.InterruptedException
TimeoutException

deployEjbBundle

public EjbBundle deployEjbBundle(java.lang.String location,
                                 java.lang.String[] services)
                          throws org.osgi.framework.BundleException,
                                 java.lang.InterruptedException
Throws:
org.osgi.framework.BundleException
java.lang.InterruptedException

getGlassFish

public org.glassfish.embeddable.GlassFish getGlassFish()
                                                throws org.glassfish.embeddable.GlassFishException,
                                                       java.lang.InterruptedException
Throws:
org.glassfish.embeddable.GlassFishException
java.lang.InterruptedException

configureEmbeddedDerby

public void configureEmbeddedDerby()
                            throws org.glassfish.embeddable.GlassFishException,
                                   java.lang.InterruptedException
Throws:
org.glassfish.embeddable.GlassFishException
java.lang.InterruptedException

getBundleContext

public org.osgi.framework.BundleContext getBundleContext()

installBundle

public org.osgi.framework.Bundle installBundle(java.lang.String location)
                                        throws org.osgi.framework.BundleException
Install an OSGi bundle by reading its content from a given location URI. This method does not activate the bundle; it just installs it.

Parameters:
location - a URI string from which the bundle content will be read
Returns:
installed bundle object
Throws:
org.osgi.framework.BundleException

createJmsCF

public void createJmsCF(java.lang.String cfName)
                 throws org.glassfish.embeddable.GlassFishException,
                        java.lang.InterruptedException
Throws:
org.glassfish.embeddable.GlassFishException
java.lang.InterruptedException

createJmsTopic

public void createJmsTopic(java.lang.String topicName)
                    throws org.glassfish.embeddable.GlassFishException,
                           java.lang.InterruptedException
Throws:
org.glassfish.embeddable.GlassFishException
java.lang.InterruptedException


Copyright © 2013. All Rights Reserved.