[seam-commits] Seam SVN: r9492 - in trunk/src: test/unit/org/jboss/seam/test/unit and 1 other directory.

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Mon Nov 3 19:57:53 EST 2008


Author: youngm
Date: 2008-11-03 19:57:53 -0500 (Mon, 03 Nov 2008)
New Revision: 9492

Modified:
   trunk/src/main/org/jboss/seam/contexts/ServerConversationContext.java
   trunk/src/test/unit/org/jboss/seam/test/unit/ContextTest.java
Log:
JBSEAM-3655

Modified: trunk/src/main/org/jboss/seam/contexts/ServerConversationContext.java
===================================================================
--- trunk/src/main/org/jboss/seam/contexts/ServerConversationContext.java	2008-11-04 00:41:07 UTC (rev 9491)
+++ trunk/src/main/org/jboss/seam/contexts/ServerConversationContext.java	2008-11-04 00:57:53 UTC (rev 9492)
@@ -36,6 +36,7 @@
    private final Set<String> removals = new HashSet<String>();
    private final String id;
    private final List<String> idStack;
+   private final Map<String, Object> cache = new HashMap<String, Object>();
    
    private List<String> getIdStack()
    {
@@ -81,9 +82,18 @@
       this.idStack = new LinkedList<String>();
       idStack.add(id);
    }
-      
-    public Object get(String name) 
-    {
+
+   public Object get(String name)
+   {
+      if (!cache.containsKey(name))
+      {
+         cache.put(name, resolveValue(name));
+      }
+      return cache.get(name);
+   }
+
+   protected Object resolveValue(String name)
+   {
       Object result = additions.get(name);
       if (result!=null)
       {
@@ -148,6 +158,7 @@
    public void set(String name, Object value) 
    {
       if ( Events.exists() ) Events.instance().raiseEvent("org.jboss.seam.preSetVariable." + name);
+      cache.remove(name);
       if (value==null)
       {
          //yes, we need this
@@ -185,6 +196,7 @@
 	public void remove(String name) 
    {
       if ( Events.exists() ) Events.instance().raiseEvent("org.jboss.seam.preRemoveVariable." + name);
+      cache.remove(name);
       additions.remove(name);
       removals.add(name);
       if ( Events.exists() ) Events.instance().raiseEvent("org.jboss.seam.postRemoveVariable." + name);
@@ -245,6 +257,7 @@
    
    public void clear()
    {
+      cache.clear();
       additions.clear();
       removals.addAll( getNamesFromSession() );
    }

Modified: trunk/src/test/unit/org/jboss/seam/test/unit/ContextTest.java
===================================================================
--- trunk/src/test/unit/org/jboss/seam/test/unit/ContextTest.java	2008-11-04 00:41:07 UTC (rev 9491)
+++ trunk/src/test/unit/org/jboss/seam/test/unit/ContextTest.java	2008-11-04 00:57:53 UTC (rev 9492)
@@ -191,9 +191,9 @@
         ServletLifecycle.beginApplication(servletContext);
         MockHttpSession session = new MockHttpSession(servletContext);
         MockHttpServletRequest request = new MockHttpServletRequest(session);
-        ExternalContext externalContext = new MockExternalContext(
+        final ExternalContext externalContext = new MockExternalContext(
                 servletContext, request);
-        Map sessionAdaptor = new ServletRequestSessionMap(request);
+        final Map sessionAdaptor = new ServletRequestSessionMap(request);
         Map requestAdaptor = new ServletRequestMap(request);
         Context appContext = new ApplicationContext(externalContext
                 .getApplicationMap());
@@ -206,13 +206,21 @@
         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()));
+        testEquivalence(new ContextCreator() {
+            public Context createContext() {
+                return new ServerConversationContext(sessionAdaptor, "1");
+            }
+        });
+        testEquivalence(new ContextCreator() {
+            public Context createContext() {
+                return new SessionContext(sessionAdaptor);
+            }
+        });
+        testEquivalence(new ContextCreator() {
+            public Context createContext() {
+                return new ApplicationContext(externalContext.getApplicationMap());
+            }
+        });
         testIsolation(new ServerConversationContext(sessionAdaptor, "1"),
                 new ServerConversationContext(sessionAdaptor, "2"));
         // testIsolation( new WebSessionContext(externalContext), new
@@ -220,14 +228,32 @@
 
         ServletLifecycle.endApplication();
     }
+    
+    private interface ContextCreator {
+        Context createContext();
+    }
 
-    private void testEquivalence(Context ctx, Context cty) {
-        ctx.set("foo", "bar");
-        ctx.flush();
-        assert cty.get("foo").equals("bar");
-        ctx.remove("foo");
-        ctx.flush();
-        assert !cty.isSet("foo");
+    private void testEquivalence(ContextCreator creator) {
+       //Creates a new context for each action to better simulate these operations
+       //happening in different call contexts.
+        { //Test Adding
+            Context ctx = creator.createContext();
+            ctx.set("foo", "bar");
+            ctx.flush();
+        }
+        { //Is Added?
+            Context ctx = creator.createContext();
+            assert ctx.get("foo").equals("bar");
+        }
+        { // Test Removing
+            Context ctx = creator.createContext();
+            ctx.remove("foo");
+            ctx.flush();
+        }
+        { // Is Removed?
+            Context ctx = creator.createContext();
+            assert !ctx.isSet("foo");
+        }
     }
 
     private void testIsolation(Context ctx, Context cty) {




More information about the seam-commits mailing list