Skip to content

Commit

Permalink
WELD-220
Browse files Browse the repository at this point in the history
  • Loading branch information
pmuir committed Oct 29, 2009
1 parent 8a202e3 commit 68fc9c8
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 33 deletions.
Expand Up @@ -79,7 +79,7 @@ protected MockDeployment getDeployment()
return deployment;
}

protected WeldBootstrap getBootstrap()
public WeldBootstrap getBootstrap()
{
return bootstrap;
}
Expand Down
60 changes: 30 additions & 30 deletions tests/src/main/java/org/jboss/weld/mock/TestContainer.java
Expand Up @@ -8,6 +8,19 @@
/**
* Control of the container, used for tests. Wraps up common operations.
*
* If you require more control over the container bootstrap lifecycle you should
* use the {@link #getLifecycle()} method. For example:
*
* <code>TestContainer container = new TestContainer(...);
* container.getLifecycle().initialize();
* container.getLifecycle().getBootstrap().startInitialization();
* container.getLifecycle().getBootstrap().deployBeans();
* container.getLifecycle().getBootstrap().validateBeans();
* container.getLifecycle().getBootstrap().endInitialization();
* container.getLifecycle().stopContainer();</code>
*
* Note that we can easily mix fine-grained calls to bootstrap, and coarse grained calls to {@link TestContainer}.
*
* @author pmuir
*
*/
Expand Down Expand Up @@ -52,6 +65,7 @@ public TestContainer(MockServletLifecycle lifecycle, Collection<Class<?>> classe
this.lifecycle = lifecycle;
this.classes = classes;
this.beansXml = beansXml;
configureArchive();
}

/**
Expand All @@ -77,35 +91,21 @@ public Status startContainerAndReturnStatus()
*/
public void startContainer()
{
startContainer(true);
getLifecycle().initialize();
getLifecycle().beginApplication();
}

/**
* Starts the container
* @param beginApplication whether or not beginApplication() should be called
* Configure's the archive with the classes and beans.xml
*/
public void startContainer(boolean beginApplication)
protected void configureArchive()
{
MockBeanDeploymentArchive archive = lifecycle.getDeployment().getArchive();
archive.setBeanClasses(classes);
if (beansXml != null)
{
archive.setBeansXmlFiles(beansXml);
}
lifecycle.initialize();
if (beginApplication)
{
beginApplication();
}
}

/**
* Deploys the application. Intended use is in conjunction with {@link #startContainer(boolean)}.
* {@link #startContainer()} does this step automatically
*/
public void beginApplication()
{
lifecycle.beginApplication();
}

/**
Expand All @@ -120,12 +120,12 @@ public MockServletLifecycle getLifecycle()

public BeanManagerImpl getBeanManager()
{
return lifecycle.getBootstrap().getManager(getDeployment().getArchive());
return getLifecycle().getBootstrap().getManager(getDeployment().getArchive());
}

public MockDeployment getDeployment()
{
return lifecycle.getDeployment();
return getLifecycle().getDeployment();
}

/**
Expand All @@ -134,13 +134,13 @@ public MockDeployment getDeployment()
*/
public void ensureRequestActive()
{
if (!lifecycle.isSessionActive())
if (!getLifecycle().isSessionActive())
{
lifecycle.beginSession();
getLifecycle().beginSession();
}
if (!lifecycle.isRequestActive())
if (!getLifecycle().isRequestActive())
{
lifecycle.beginRequest();
getLifecycle().beginRequest();
}
}

Expand All @@ -150,17 +150,17 @@ public void ensureRequestActive()
*/
public void stopContainer()
{
if (lifecycle.isRequestActive())
if (getLifecycle().isRequestActive())
{
lifecycle.endRequest();
getLifecycle().endRequest();
}
if (lifecycle.isSessionActive())
if (getLifecycle().isSessionActive())
{
lifecycle.endSession();
getLifecycle().endSession();
}
if (lifecycle.isApplicationActive())
if (getLifecycle().isApplicationActive())
{
lifecycle.endApplication();
getLifecycle().endApplication();
}
}

Expand Down
Expand Up @@ -41,7 +41,7 @@ public void test()
List<Class<?>> classes = new ArrayList<Class<?>>();
classes.add(WeldBean.class);
TestContainer container = new TestContainer(new MockEELifecycle(), classes, null);
container.startContainer(false);
container.getLifecycle().initialize();

BeanManager bootstrapManager = container.getBeanManager();
assert bootstrapManager != null;
Expand All @@ -52,7 +52,7 @@ public void test()


//Start the application
container.beginApplication();
container.getLifecycle().beginApplication();
container.ensureRequestActive();

//Check the manager is the same as before
Expand Down

0 comments on commit 68fc9c8

Please sign in to comment.