[jboss-cvs] jboss-seam/src/test/unit/org/jboss/seam/test/unit ...
Norman Richards
norman.richards at jboss.com
Fri Dec 14 22:41:53 EST 2007
User: nrichards
Date: 07/12/14 22:41:53
Modified: src/test/unit/org/jboss/seam/test/unit ContextTest.java
Log:
JBSEAM-2357
Revision Changes Path
1.2 +217 -201 jboss-seam/src/test/unit/org/jboss/seam/test/unit/ContextTest.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: ContextTest.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/src/test/unit/org/jboss/seam/test/unit/ContextTest.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- ContextTest.java 8 Oct 2007 18:15:47 -0000 1.1
+++ ContextTest.java 15 Dec 2007 03:41:53 -0000 1.2
@@ -1,8 +1,9 @@
-//$Id: ContextTest.java,v 1.1 2007/10/08 18:15:47 pmuir Exp $
+//$Id: ContextTest.java,v 1.2 2007/12/15 03:41:53 nrichards Exp $
package org.jboss.seam.test.unit;
import java.util.Map;
+import javax.el.ELContext;
import javax.faces.context.ExternalContext;
import javax.servlet.http.HttpServletRequest;
@@ -32,30 +33,32 @@
import org.jboss.seam.web.Session;
import org.testng.annotations.Test;
-public class ContextTest
-{
- private void installComponent(Context appContext, Class clazz)
- {
- appContext.set( Seam.getComponentName(clazz) + ".component", new Component(clazz) );
+public class ContextTest {
+ private void installComponent(Context appContext, Class clazz) {
+ appContext.set(Seam.getComponentName(clazz) + ".component",
+ new Component(clazz));
}
@Test
- public void testContextManagement() throws Exception
- {
+ public void testContextManagement() throws Exception {
+ ELContext elContext = EL.createELContext();
SeamELResolver seamVariableResolver = new SeamELResolver();
- //org.jboss.seam.bpm.SeamVariableResolver jbpmVariableResolver = new org.jboss.seam.bpm.SeamVariableResolver();
+ // 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() );
+ 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() );
+ appContext.set(Seam.getComponentName(Init.class), new Init());
installComponent(appContext, Bar.class);
installComponent(appContext, Foo.class);
@@ -83,10 +86,10 @@
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() != 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;
@@ -96,12 +99,12 @@
Contexts.getApplicationContext().set("zzz", "bar");
Contexts.getConversationContext().set("xxx", "yyy");
- Object bar = seamVariableResolver.getValue(EL.EL_CONTEXT, null, "bar");
- assert bar!=null;
+ Object bar = seamVariableResolver.getValue(elContext, null, "bar");
+ assert bar != null;
assert bar instanceof Bar;
- assert Contexts.getConversationContext().get("bar")==bar;
+ assert Contexts.getConversationContext().get("bar") == bar;
Object foo = Contexts.getSessionContext().get("foo");
- assert foo!=null;
+ assert foo != null;
assert foo instanceof Foo;
FacesLifecycle.endRequest(externalContext);
@@ -110,8 +113,10 @@
assert !Contexts.isSessionContextActive();
assert !Contexts.isConversationContextActive();
assert !Contexts.isApplicationContextActive();
- assert ((MockHttpSession)externalContext.getSession(false)).getAttributes().size()==4;
- assert ((MockServletContext)externalContext.getContext()).getAttributes().size()==10;
+ assert ((MockHttpSession) externalContext.getSession(false))
+ .getAttributes().size() == 4;
+ assert ((MockServletContext) externalContext.getContext())
+ .getAttributes().size() == 10;
FacesLifecycle.beginRequest(externalContext);
@@ -128,10 +133,10 @@
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() != 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;
@@ -140,22 +145,26 @@
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().get("bar") == bar;
+ assert Contexts.getSessionContext().get("foo") == foo;
- assert Contexts.getConversationContext().getNames().length==2;
- assert Contexts.getApplicationContext().getNames().length==10;
- assert Contexts.getSessionContext().getNames().length==2;
-
- assert seamVariableResolver.getValue(EL.EL_CONTEXT, null, "zzz").equals("bar");
- assert seamVariableResolver.getValue(EL.EL_CONTEXT, null, "xxx").equals("yyy");
- assert seamVariableResolver.getValue(EL.EL_CONTEXT, null, "bar")==bar;
- assert seamVariableResolver.getValue(EL.EL_CONTEXT, 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;*/
+ assert Contexts.getConversationContext().getNames().length == 2;
+ assert Contexts.getApplicationContext().getNames().length == 10;
+ 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;
+
+ /*
+ * 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);
@@ -164,46 +173,55 @@
assert !Contexts.isSessionContextActive();
assert !Contexts.isConversationContextActive();
assert !Contexts.isApplicationContextActive();
- assert ((MockHttpSession)externalContext.getSession(false)).getAttributes().size()==2;
- assert ((MockServletContext)externalContext.getContext()).getAttributes().size()==10;
+ assert ((MockHttpSession) externalContext.getSession(false))
+ .getAttributes().size() == 2;
+ assert ((MockServletContext) externalContext.getContext())
+ .getAttributes().size() == 10;
- ServletLifecycle.endSession( ( (HttpServletRequest) externalContext.getRequest() ).getSession() );
+ ServletLifecycle.endSession(((HttpServletRequest) externalContext
+ .getRequest()).getSession());
ServletLifecycle.endApplication();
}
@Test
- public void testContexts()
- {
+ public void testContexts() {
MockServletContext servletContext = new MockServletContext();
ServletLifecycle.beginApplication(servletContext);
MockHttpSession session = new MockHttpSession(servletContext);
MockHttpServletRequest request = new MockHttpServletRequest(session);
- ExternalContext externalContext = new MockExternalContext(servletContext, request);
+ ExternalContext externalContext = new MockExternalContext(
+ servletContext, request);
Map sessionAdaptor = new ServletRequestSessionMap(request);
Map requestAdaptor = new ServletRequestMap(request);
- Context appContext = new ApplicationContext( externalContext.getApplicationMap() );
+ Context appContext = new ApplicationContext(externalContext
+ .getApplicationMap());
installComponent(appContext, ConversationEntries.class);
installComponent(appContext, Manager.class);
- appContext.set( Seam.getComponentName(Init.class), new Init() );
+ appContext.set(Seam.getComponentName(Init.class), new Init());
FacesLifecycle.beginRequest(externalContext);
Manager.instance().setLongRunningConversation(true);
- testContext( new ApplicationContext( externalContext.getApplicationMap() ) );
- testContext( new SessionContext(sessionAdaptor) );
- testContext( new EventContext(requestAdaptor) );
- testContext( new ServerConversationContext(sessionAdaptor, "1") );
- testEquivalence( new ServerConversationContext(sessionAdaptor, "1"), new ServerConversationContext(sessionAdaptor, "1") );
- testEquivalence( new SessionContext(sessionAdaptor), new SessionContext(sessionAdaptor) );
- testEquivalence( new ApplicationContext( externalContext.getApplicationMap() ), new ApplicationContext( externalContext.getApplicationMap() ) );
- testIsolation( new ServerConversationContext(sessionAdaptor, "1"), new ServerConversationContext(sessionAdaptor, "2") );
- // testIsolation( new WebSessionContext(externalContext), new WebSessionContext( new MockExternalContext()) );
+ testContext(new ApplicationContext(externalContext.getApplicationMap()));
+ testContext(new SessionContext(sessionAdaptor));
+ testContext(new EventContext(requestAdaptor));
+ testContext(new ServerConversationContext(sessionAdaptor, "1"));
+ testEquivalence(new ServerConversationContext(sessionAdaptor, "1"),
+ new ServerConversationContext(sessionAdaptor, "1"));
+ testEquivalence(new SessionContext(sessionAdaptor), new SessionContext(
+ sessionAdaptor));
+ testEquivalence(new ApplicationContext(externalContext
+ .getApplicationMap()), new ApplicationContext(externalContext
+ .getApplicationMap()));
+ testIsolation(new ServerConversationContext(sessionAdaptor, "1"),
+ new ServerConversationContext(sessionAdaptor, "2"));
+ // testIsolation( new WebSessionContext(externalContext), new
+ // WebSessionContext( new MockExternalContext()) );
ServletLifecycle.endApplication();
}
- private void testEquivalence(Context ctx, Context cty)
- {
+ private void testEquivalence(Context ctx, Context cty) {
ctx.set("foo", "bar");
ctx.flush();
assert cty.get("foo").equals("bar");
@@ -212,8 +230,7 @@
assert !cty.isSet("foo");
}
- private void testIsolation(Context ctx, Context cty)
- {
+ private void testIsolation(Context ctx, Context cty) {
ctx.set("foo", "bar");
ctx.flush();
assert !cty.isSet("foo");
@@ -223,8 +240,7 @@
assert cty.get("foo").equals("bar");
}
- private void testContext(Context ctx)
- {
+ private void testContext(Context ctx) {
assert !ctx.isSet("foo");
ctx.set("foo", "bar");
assert ctx.isSet("foo");
More information about the jboss-cvs-commits
mailing list