{
SeamVariableResolver seamVariableResolver = new SeamVariableResolver(VARIABLE_RESOLVER);
org.jboss.seam.jbpm.SeamVariableResolver jbpmVariableResolver = new org.jboss.seam.jbpm.SeamVariableResolver();
MockServletContext servletContext = new MockServletContext();
MockExternalContext externalContext = new MockExternalContext(servletContext);
Context appContext = new FacesApplicationContext(externalContext);
//appContext.set( Seam.getComponentName(Init.class), new Init() );
appContext.set(
Seam.getComponentName(ConversationEntries.class) + ".component",
new Component(ConversationEntries.class, appContext)
);
appContext.set(
Seam.getComponentName(Manager.class) + ".component",
new Component(Manager.class, appContext)
);
appContext.set( Seam.getComponentName(Init.class), new Init() );
appContext.set(
Seam.getComponentName(Bar.class) + ".component",
new Component(Bar.class, appContext)
);
appContext.set(
Seam.getComponentName(Foo.class) + ".component",
new Component(Foo.class, appContext)
);
appContext.set("otherFoo", new Foo());
assert !Contexts.isEventContextActive();
assert !Contexts.isSessionContextActive();
assert !Contexts.isConversationContextActive();
assert !Contexts.isApplicationContextActive();
Lifecycle.beginRequest(externalContext);
assert Contexts.isEventContextActive();
assert Contexts.isSessionContextActive();
assert !Contexts.isConversationContextActive();
assert Contexts.isApplicationContextActive();
Manager.instance().setCurrentConversationId("3");
Lifecycle.resumeConversation(externalContext);
Manager.instance().setLongRunningConversation(true);
assert Contexts.isEventContextActive();
assert Contexts.isSessionContextActive();
assert Contexts.isConversationContextActive();
assert Contexts.isApplicationContextActive();
assert !Contexts.isPageContextActive();
assert Contexts.getEventContext()!=null;
assert Contexts.getSessionContext()!=null;
assert Contexts.getConversationContext()!=null;
assert Contexts.getApplicationContext()!=null;
assert Contexts.getEventContext() instanceof WebRequestContext;
assert Contexts.getSessionContext() instanceof WebSessionContext;
assert Contexts.getConversationContext() instanceof ServerConversationContext;
assert Contexts.getApplicationContext() instanceof FacesApplicationContext;
Contexts.getSessionContext().set("zzz", "bar");
Contexts.getApplicationContext().set("zzz", "bar");
Contexts.getConversationContext().set("xxx", "yyy");
Object bar = seamVariableResolver.resolveVariable(null, "bar");
assert bar!=null;
assert bar instanceof Bar;
assert Contexts.getConversationContext().get("bar")==bar;
Object foo = Contexts.getSessionContext().get("foo");
assert foo!=null;
assert foo instanceof Foo;
Lifecycle.endRequest(externalContext);
assert !Contexts.isEventContextActive();
assert !Contexts.isSessionContextActive();
assert !Contexts.isConversationContextActive();
assert !Contexts.isApplicationContextActive();
assert ((MockHttpSession)externalContext.getSession(false)).getAttributes().size()==5;
assert ((MockServletContext)externalContext.getContext()).getAttributes().size()==7;
Lifecycle.beginRequest(externalContext);
assert Contexts.isEventContextActive();
assert Contexts.isSessionContextActive();
assert !Contexts.isConversationContextActive();
assert Contexts.isApplicationContextActive();
Manager.instance().setCurrentConversationId("3");
Lifecycle.resumeConversation(externalContext);
assert Contexts.isEventContextActive();
assert Contexts.isSessionContextActive();
assert Contexts.isConversationContextActive();
assert Contexts.isApplicationContextActive();
assert Contexts.getEventContext()!=null;
assert Contexts.getSessionContext()!=null;
assert Contexts.getConversationContext()!=null;
assert Contexts.getApplicationContext()!=null;
assert Contexts.getEventContext() instanceof WebRequestContext;
assert Contexts.getSessionContext() instanceof WebSessionContext;
assert Contexts.getConversationContext() instanceof ServerConversationContext;
assert Contexts.getApplicationContext() instanceof FacesApplicationContext;
assert Contexts.getSessionContext().get("zzz").equals("bar");
assert Contexts.getApplicationContext().get("zzz").equals("bar");
assert Contexts.getConversationContext().get("xxx").equals("yyy");
assert Contexts.getConversationContext().get("bar")==bar;
assert Contexts.getSessionContext().get("foo")==foo;
assert Contexts.getConversationContext().getNames().length==2;
assert Contexts.getApplicationContext().getNames().length==7;
assert Contexts.getSessionContext().getNames().length==3;
assert seamVariableResolver.resolveVariable(null, "zzz").equals("bar");
assert seamVariableResolver.resolveVariable(null, "xxx").equals("yyy");
assert seamVariableResolver.resolveVariable(null, "bar")==bar;
assert seamVariableResolver.resolveVariable(null, "foo")==foo;
assert jbpmVariableResolver.resolveVariable("zzz").equals("bar");
assert jbpmVariableResolver.resolveVariable("xxx").equals("yyy");
assert jbpmVariableResolver.resolveVariable("bar")==bar;
assert jbpmVariableResolver.resolveVariable("foo")==foo;
Manager.instance().setLongRunningConversation(false);
Lifecycle.endRequest(externalContext);
assert !Contexts.isEventContextActive();
assert !Contexts.isSessionContextActive();
assert !Contexts.isConversationContextActive();
assert !Contexts.isApplicationContextActive();
assert ((MockHttpSession)externalContext.getSession(false)).getAttributes().size()==3;
assert ((MockServletContext)externalContext.getContext()).getAttributes().size()==7;
Lifecycle.endSession( servletContext, new ServletSessionImpl( (HttpSession) externalContext.getSession(true) ) );
Lifecycle.endApplication(servletContext);
}