Skip to content

Commit

Permalink
Add ContainersImpl, fix a nasty problem where mock contexts weren't b…
Browse files Browse the repository at this point in the history
…eing reset

git-svn-id: http://anonsvn.jboss.org/repos/weld/ri/trunk@1001 1c488680-804c-0410-94cd-c6b725194a0e
  • Loading branch information
pmuir committed Jan 16, 2009
1 parent d9f5033 commit 325bb39
Show file tree
Hide file tree
Showing 12 changed files with 96 additions and 27 deletions.
2 changes: 1 addition & 1 deletion webbeans-ri/pom.xml
Expand Up @@ -159,7 +159,7 @@
</executions>
<configuration>
<outputDirectory>${project.build.directory}/surefire-reports</outputDirectory>
<outputName>index</outputName>
<outputName>test-report</outputName>
</configuration>
</plugin>
</plugins>
Expand Down
Expand Up @@ -31,7 +31,7 @@
public class DependentContext extends AbstractContext
{

public static final DependentContext INSTANCE = new DependentContext();
public static DependentContext INSTANCE = new DependentContext();

private ThreadLocal<AtomicInteger> reentrantActiveCount;

Expand Down
Expand Up @@ -5,7 +5,6 @@
import javax.webbeans.manager.Context;

import org.jboss.webbeans.bean.SimpleBean;
import org.jboss.webbeans.context.AbstractBeanMapContext;
import org.jboss.webbeans.context.RequestContext;
import org.jboss.webbeans.test.beans.FishFarmOffice;
import org.testng.annotations.Test;
Expand All @@ -24,9 +23,7 @@ public void testInjectingManager()
@Test(expectedExceptions={ContextNotActiveException.class}, groups={"manager"}) @SpecAssertion(section="8.6")
public void testGetContextWithNoActiveContextsFails()
{
Context requestContext = new RequestContext() {};
((AbstractBeanMapContext)requestContext).setActive(false);
manager.addContext(requestContext);
RequestContext.INSTANCE.setActive(false);
manager.getContext(RequestScoped.class);
}

Expand All @@ -51,11 +48,7 @@ public void testGetContextWithNoRegisteredContextsFails()
@Test(groups={"manager"}) @SpecAssertion(section="8.6")
public void testGetContextReturnsActiveContext()
{
Context requestContext = new RequestContext() {};
manager.addContext(requestContext);
Context testContext = manager.getContext(RequestScoped.class);
assert testContext == requestContext;

manager.getContext(RequestScoped.class);
}

@Test(groups={"stub", "manager", "ejb3"}) @SpecAssertion(section="5.8")
Expand Down
@@ -0,0 +1,16 @@
package org.jboss.webbeans.test.mock;

import org.jboss.webbeans.context.ApplicationContext;
import org.jboss.webbeans.context.beanmap.SimpleBeanMap;

public class MockApplicationContext extends ApplicationContext
{

public MockApplicationContext()
{
super();
ApplicationContext.INSTANCE = this;
setBeanMap(new SimpleBeanMap());
}

}
Expand Up @@ -18,11 +18,6 @@
import org.jboss.webbeans.bootstrap.WebBeansBootstrap;
import org.jboss.webbeans.bootstrap.spi.EjbDiscovery;
import org.jboss.webbeans.bootstrap.spi.WebBeanDiscovery;
import org.jboss.webbeans.context.ApplicationContext;
import org.jboss.webbeans.context.DependentContext;
import org.jboss.webbeans.context.RequestContext;
import org.jboss.webbeans.context.SessionContext;
import org.jboss.webbeans.context.beanmap.SimpleBeanMap;
import org.jboss.webbeans.ejb.spi.EjbResolver;
import org.jboss.webbeans.resource.AbstractNaming;
import org.jboss.webbeans.resources.spi.Naming;
Expand Down Expand Up @@ -173,14 +168,15 @@ public MockBootstrap()
this.mockNaming = new MockNaming();
initManager(mockNaming, MOCK_EJB_RESOLVER, resourceLoader);
registerStandardBeans();

// Set up the mock contexts
getManager().addContext(RequestContext.INSTANCE);
SessionContext.INSTANCE.setBeanMap(new SimpleBeanMap());
getManager().addContext(SessionContext.INSTANCE);
ApplicationContext.INSTANCE.setBeanMap(new SimpleBeanMap());
getManager().addContext(ApplicationContext.INSTANCE);
getManager().addContext(DependentContext.INSTANCE);
setupContexts();
}

protected void setupContexts()
{
getManager().addContext(new MockRequestContext());
getManager().addContext(new MockSessionContext());
getManager().addContext(new MockApplicationContext());
getManager().addContext(new MockDependentContext());
}

protected void registerStandardBeans()
Expand Down
@@ -0,0 +1,14 @@
package org.jboss.webbeans.test.mock;

import org.jboss.webbeans.context.DependentContext;

public class MockDependentContext extends DependentContext
{

public MockDependentContext()
{
super();
DependentContext.INSTANCE = this;
}

}
@@ -0,0 +1,14 @@
package org.jboss.webbeans.test.mock;

import org.jboss.webbeans.context.RequestContext;

public class MockRequestContext extends RequestContext
{

public MockRequestContext()
{
super();
RequestContext.INSTANCE = this;
}

}
@@ -0,0 +1,16 @@
package org.jboss.webbeans.test.mock;

import org.jboss.webbeans.context.SessionContext;
import org.jboss.webbeans.context.beanmap.SimpleBeanMap;

public class MockSessionContext extends SessionContext
{

public MockSessionContext()
{
super();
SessionContext.INSTANCE = this;
setBeanMap(new SimpleBeanMap());
}

}
@@ -0,0 +1,19 @@
package org.jboss.webbeans.test.tck;

import javax.webbeans.manager.Manager;

import org.jboss.webbeans.tck.api.Containers;
import org.jboss.webbeans.test.mock.MockBootstrap;
import org.jboss.webbeans.test.mock.MockWebBeanDiscovery;

public class ContainersImpl implements Containers
{

public Manager deploy(Class<?>... classes)
{
MockBootstrap bootstrap = new MockBootstrap();
bootstrap.setWebBeanDiscovery(new MockWebBeanDiscovery(classes));
bootstrap.boot();
return bootstrap.getManager();
}
}
Expand Up @@ -10,7 +10,7 @@ public class ContextsImpl implements Contexts<AbstractContext>

public RequestContext getRequestContext()
{
throw new UnsupportedOperationException("Not yet implemented");
return RequestContext.INSTANCE;
}

public void setActive(AbstractContext context)
Expand Down
@@ -1,3 +1,4 @@
org.jboss.webbeans.tck.api.Managers=org.jboss.webbeans.test.tck.ManagersImpl
org.jboss.webbeans.tck.api.Beans=org.jboss.webbeans.test.tck.BeansImpl
org.jboss.webbeans.tck.api.Contexts=org.jboss.webbeans.test.tck.ContextsImpl
org.jboss.webbeans.tck.api.Contexts=org.jboss.webbeans.test.tck.ContextsImpl
org.jboss.webbeans.tck.api.Containers=org.jboss.webbeans.test.tck.ContainersImpl
2 changes: 1 addition & 1 deletion webbeans-ri/src/test/resources/log4j.xml
Expand Up @@ -13,7 +13,7 @@

<!-- ############### Embedded EJB3 ################# -->
<category name="org.jboss">
<priority value="WARN"/>
<priority value="ERROR"/>
</category>
<category name="com.arjuna">
<priority value="ERROR"/>
Expand Down

0 comments on commit 325bb39

Please sign in to comment.