// org.jboss.seam.bpm.SeamVariableResolver jbpmVariableResolver = new
// org.jboss.seam.bpm.SeamVariableResolver();
MockServletContext servletContext = new MockServletContext();
ServletLifecycle.beginApplication(servletContext);
MockExternalContext externalContext = new MockExternalContext(
servletContext);
Context appContext = new ApplicationContext(externalContext
.getApplicationMap());
// appContext.set( Seam.getComponentName(Init.class), new Init() );
installComponent(appContext, ConversationEntries.class);
installComponent(appContext, Manager.class);
installComponent(appContext, Session.class);
installComponent(appContext, ServletContexts.class);
installComponent(appContext, Parameters.class);
appContext.set(Seam.getComponentName(Init.class), new Init());
installComponent(appContext, Bar.class);
installComponent(appContext, Foo.class);
appContext.set("otherFoo", new Foo());
assert !Contexts.isEventContextActive();
assert !Contexts.isSessionContextActive();
assert !Contexts.isConversationContextActive();
assert !Contexts.isApplicationContextActive();
FacesLifecycle.beginRequest(externalContext);
assert Contexts.isEventContextActive();
assert Contexts.isSessionContextActive();
assert !Contexts.isConversationContextActive();
assert Contexts.isApplicationContextActive();
Manager.instance().setCurrentConversationId("3");
FacesLifecycle.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 EventContext;
assert Contexts.getSessionContext() instanceof SessionContext;
assert Contexts.getConversationContext() instanceof ServerConversationContext;
assert Contexts.getApplicationContext() instanceof ApplicationContext;
Contexts.getSessionContext().set("zzz", "bar");
Contexts.getApplicationContext().set("zzz", "bar");
Contexts.getConversationContext().set("xxx", "yyy");
Object bar = seamVariableResolver.getValue(elContext, 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;
FacesLifecycle.endRequest(externalContext);
assert !Contexts.isEventContextActive();
assert !Contexts.isSessionContextActive();
assert !Contexts.isConversationContextActive();
assert !Contexts.isApplicationContextActive();
assert ((MockHttpSession) externalContext.getSession(false))
.getAttributes().size() == 4;
assert ((MockServletContext) externalContext.getContext())
.getAttributes().size() == 12;
FacesLifecycle.beginRequest(externalContext);
assert Contexts.isEventContextActive();
assert Contexts.isSessionContextActive();
assert !Contexts.isConversationContextActive();
assert Contexts.isApplicationContextActive();
Manager.instance().setCurrentConversationId("3");
FacesLifecycle.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 EventContext;
assert Contexts.getSessionContext() instanceof SessionContext;
assert Contexts.getConversationContext() instanceof ServerConversationContext;
assert Contexts.getApplicationContext() instanceof ApplicationContext;
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 == 12;
assert Contexts.getSessionContext().getNames().length == 2;
assert seamVariableResolver.getValue(elContext, null, "zzz").equals(
"bar");
assert seamVariableResolver.getValue(elContext, null, "xxx").equals(
"yyy");
assert seamVariableResolver.getValue(elContext, null, "bar") == bar;
assert seamVariableResolver.getValue(elContext, null, "foo") == foo;
// JBSEAM-3077
assert EL.EL_RESOLVER.getValue(elContext, new Namespace("org.jboss.seam.core."), "conversationEntries") instanceof ConversationEntries;
try {
assert EL.EL_RESOLVER.getValue(elContext, new Namespace("org.jboss.seam."), "caughtException") == null;
} catch (Exception e) {
Assert.fail("An exception should not be thrown when a qualified name resolves to null", e);
}
/*
* 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);
FacesLifecycle.endRequest(externalContext);
assert !Contexts.isEventContextActive();
assert !Contexts.isSessionContextActive();
assert !Contexts.isConversationContextActive();
assert !Contexts.isApplicationContextActive();
assert ((MockHttpSession) externalContext.getSession(false))
.getAttributes().size() == 3; // foo, zzz, org.jboss.seam.core.conversationEntries
assert ((MockServletContext) externalContext.getContext())
.getAttributes().size() == 12;
ServletLifecycle.endSession(((HttpServletRequest) externalContext
.getRequest()).getSession());
ServletLifecycle.endApplication();
}