tapestry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hls...@apache.org
Subject svn commit: r730456 [2/2] - in /tapestry/tapestry5/trunk: src/site/apt/ src/site/apt/guide/ tapestry-core/src/main/java/org/apache/tapestry5/ tapestry-core/src/main/java/org/apache/tapestry5/annotations/ tapestry-core/src/main/java/org/apache/tapestry5...
Date Wed, 31 Dec 2008 19:50:40 GMT
Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/SessionApplicationStatePersistenceStrategyTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/SessionApplicationStatePersistenceStrategyTest.java?rev=730456&r1=730455&r2=730456&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/SessionApplicationStatePersistenceStrategyTest.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/SessionApplicationStatePersistenceStrategyTest.java
Wed Dec 31 11:50:39 2008
@@ -14,27 +14,16 @@
 
 package org.apache.tapestry5.internal.services;
 
-import org.apache.tapestry5.OptimizedApplicationStateObject;
-import org.apache.tapestry5.internal.events.EndOfRequestListener;
 import org.apache.tapestry5.internal.test.InternalBaseTestCase;
 import org.apache.tapestry5.internal.transform.pages.ReadOnlyBean;
-import org.apache.tapestry5.ioc.internal.util.CollectionFactory;
 import org.apache.tapestry5.services.ApplicationStateCreator;
 import org.apache.tapestry5.services.ApplicationStatePersistenceStrategy;
 import org.apache.tapestry5.services.Request;
 import org.apache.tapestry5.services.Session;
-import org.easymock.Capture;
-import static org.easymock.EasyMock.capture;
-import static org.easymock.EasyMock.eq;
 import org.testng.annotations.Test;
 
-import java.util.Collections;
-import java.util.Map;
-
 public class SessionApplicationStatePersistenceStrategyTest extends InternalBaseTestCase
 {
-    private static final String ASO_MAP_ATTRIBUTE = SessionApplicationStatePersistenceStrategy.ASO_MAP_ATTRIBUTE;
-
     @SuppressWarnings("unchecked")
     @Test
     public void get_aso_already_exists()
@@ -45,23 +34,16 @@
         Object aso = new ReadOnlyBean();
         String key = "aso:" + asoClass.getName();
         ApplicationStateCreator creator = mockApplicationStateCreator();
-        Map<String, Object> asoMap = CollectionFactory.newMap();
 
         train_getSession(request, true, session);
         train_getAttribute(session, key, aso);
 
-        train_getAttribute(request, ASO_MAP_ATTRIBUTE, asoMap);
-
         replay();
 
         ApplicationStatePersistenceStrategy strategy = new SessionApplicationStatePersistenceStrategy(request);
 
         assertSame(strategy.get(asoClass, creator), aso);
 
-        // Check that the ASO Map was updated.
-
-        assertSame(asoMap.get(key), aso);
-
         verify();
     }
 
@@ -93,7 +75,6 @@
         Object aso = new ReadOnlyBean();
         String key = "aso:" + asoClass.getName();
         ApplicationStateCreator creator = mockApplicationStateCreator();
-        Map<String, Object> asoMap = CollectionFactory.newMap();
 
         // First for exists()
         train_getSession(request, false, session);
@@ -102,7 +83,6 @@
         // Second for get()
         train_getSession(request, true, session);
 
-        train_getAttribute(request, ASO_MAP_ATTRIBUTE, asoMap);
         // Not in map
         train_getAttribute(session, key, null);
 
@@ -124,8 +104,6 @@
 
         assertTrue(strategy.exists(asoClass));
 
-        assertSame(asoMap.get(key), aso);
-
         verify();
     }
 
@@ -138,237 +116,16 @@
         Class asoClass = ReadOnlyBean.class;
         Object aso = new ReadOnlyBean();
         String key = "aso:" + asoClass.getName();
-        Map<String, Object> asoMap = CollectionFactory.newMap();
-
-        train_getSession(request, true, session);
-        session.setAttribute(key, aso);
-
-        train_getAttribute(request, ASO_MAP_ATTRIBUTE, asoMap);
-
-        replay();
-
-        ApplicationStatePersistenceStrategy strategy = new SessionApplicationStatePersistenceStrategy(request);
-
-        strategy.set(asoClass, aso);
-
-        assertSame(asoMap.get(key), aso);
-
-        verify();
-    }
-
-    @Test
-    public void aso_map_created_as_needed()
-    {
-        Request request = mockRequest();
-        Session session = mockSession();
-        Class asoClass = ReadOnlyBean.class;
-        Object aso = new ReadOnlyBean();
-        String key = "aso:" + asoClass.getName();
-        Capture<Map<String, Object>> asoMapCapture = newCapture();
 
         train_getSession(request, true, session);
         session.setAttribute(key, aso);
 
-        train_getAttribute(request, ASO_MAP_ATTRIBUTE, null);
-
-        request.setAttribute(eq(ASO_MAP_ATTRIBUTE), capture(asoMapCapture));
-
         replay();
 
         ApplicationStatePersistenceStrategy strategy = new SessionApplicationStatePersistenceStrategy(request);
 
         strategy.set(asoClass, aso);
 
-        assertSame(asoMapCapture.getValue().get(key), aso);
-
-        verify();
-    }
-
-    @Test
-    public void restore_map_is_empty()
-    {
-        Request request = mockRequest();
-        Map<String, Object> asoMap = Collections.emptyMap();
-
-        train_getAttribute(request, ASO_MAP_ATTRIBUTE, asoMap);
-
-        replay();
-
-        EndOfRequestListener strategy = new SessionApplicationStatePersistenceStrategy(request);
-
-        strategy.requestDidComplete();
-
-        verify();
-    }
-
-    @Test
-    public void restore_aso_is_null()
-    {
-        Request request = mockRequest();
-        Map<String, Object> asoMap = CollectionFactory.newMap();
-        Session session = mockSession();
-
-        asoMap.put("some.key", null);
-
-        train_isInvalidated(session, false);
-        train_getAttribute(request, ASO_MAP_ATTRIBUTE, asoMap);
-
-        train_getSession(request, false, session);
-
-        replay();
-
-        EndOfRequestListener strategy = new SessionApplicationStatePersistenceStrategy(request);
-
-        strategy.requestDidComplete();
-
-        verify();
-    }
-
-
-    @Test
-    public void restore_non_optimized_object()
-    {
-        Request request = mockRequest();
-        Session session = mockSession();
-        Map<String, Object> asoMap = CollectionFactory.newMap();
-
-        String key = "foo:bar";
-        Object aso = new Object();
-
-        asoMap.put(key, aso);
-
-        train_getAttribute(request, ASO_MAP_ATTRIBUTE, asoMap);
-
-        train_getSession(request, false, session);
-        train_isInvalidated(session, false);
-
-        session.setAttribute(key, aso);
-
-        replay();
-
-        EndOfRequestListener strategy = new SessionApplicationStatePersistenceStrategy(request);
-
-        strategy.requestDidComplete();
-
         verify();
     }
-
-    @Test
-    public void restore_optimized_object_is_dirty()
-    {
-        Request request = mockRequest();
-        Session session = mockSession();
-        Map<String, Object> asoMap = CollectionFactory.newMap();
-
-        String key = "foo:bar";
-        OptimizedApplicationStateObject aso = mockOptimizedApplicationStateObject(true);
-
-        asoMap.put(key, aso);
-
-        train_getAttribute(request, ASO_MAP_ATTRIBUTE, asoMap);
-
-        train_getSession(request, false, session);
-        train_isInvalidated(session, false);
-
-        session.setAttribute(key, aso);
-
-        replay();
-
-        EndOfRequestListener strategy = new SessionApplicationStatePersistenceStrategy(request);
-
-        strategy.requestDidComplete();
-
-        verify();
-    }
-
-    @Test
-    public void need_to_create_session_to_restore_optimized_object()
-    {
-        Request request = mockRequest();
-        Session session = mockSession();
-        Map<String, Object> asoMap = CollectionFactory.newMap();
-
-        String key = "foo:bar";
-        OptimizedApplicationStateObject aso = mockOptimizedApplicationStateObject(true);
-
-        asoMap.put(key, aso);
-
-        train_getAttribute(request, ASO_MAP_ATTRIBUTE, asoMap);
-
-        train_getSession(request, false, null);
-
-        train_getSession(request, true, session);
-
-        session.setAttribute(key, aso);
-
-        replay();
-
-        EndOfRequestListener strategy = new SessionApplicationStatePersistenceStrategy(request);
-
-        strategy.requestDidComplete();
-
-        verify();
-    }
-
-    @Test
-    public void session_invalidated()
-    {
-        Request request = mockRequest();
-        Session session = mockSession();
-        Map<String, Object> asoMap = CollectionFactory.newMap();
-
-        String key = "foo:bar";
-        Object aso = new Object();
-
-        asoMap.put(key, aso);
-
-        train_getAttribute(request, ASO_MAP_ATTRIBUTE, asoMap);
-
-        train_getSession(request, false, session);
-
-        train_isInvalidated(session, true);
-
-        replay();
-
-        EndOfRequestListener strategy = new SessionApplicationStatePersistenceStrategy(request);
-
-        strategy.requestDidComplete();
-
-        verify();
-    }
-
-    @Test
-    public void restore_optimized_object_is_clean()
-    {
-        Request request = mockRequest();
-        Session session = mockSession();
-        Map<String, Object> asoMap = CollectionFactory.newMap();
-
-        String key = "foo:bar";
-        OptimizedApplicationStateObject aso = mockOptimizedApplicationStateObject(false);
-
-        asoMap.put(key, aso);
-
-        train_getAttribute(request, ASO_MAP_ATTRIBUTE, asoMap);
-
-        train_getSession(request, false, session);
-        train_isInvalidated(session, false);
-
-        replay();
-
-        EndOfRequestListener strategy = new SessionApplicationStatePersistenceStrategy(request);
-
-        strategy.requestDidComplete();
-
-        verify();
-    }
-
-    private OptimizedApplicationStateObject mockOptimizedApplicationStateObject(boolean dirty)
-    {
-        OptimizedApplicationStateObject object = newMock(OptimizedApplicationStateObject.class);
-
-        expect(object.isApplicationStateObjectDirty()).andReturn(dirty);
-
-        return object;
-    }
 }

Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/SessionImplTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/SessionImplTest.java?rev=730456&r1=730455&r2=730456&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/SessionImplTest.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/SessionImplTest.java
Wed Dec 31 11:50:39 2008
@@ -1,4 +1,4 @@
-// Copyright 2006, 2007 The Apache Software Foundation
+// Copyright 2006, 2007, 2008 The Apache Software Foundation
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
@@ -35,7 +35,7 @@
 
         replay();
 
-        Session session = new SessionImpl(hs);
+        Session session = new SessionImpl(hs, null);
 
         assertEquals(session.getAttributeNames(), Arrays.asList("barney", "fred"));
 
@@ -52,7 +52,7 @@
 
         replay();
 
-        Session session = new SessionImpl(hs);
+        Session session = new SessionImpl(hs, null);
 
         assertEquals(session.getAttributeNames("f"), Arrays.asList("fanny", "fred"));
 
@@ -68,7 +68,7 @@
 
         replay();
 
-        Session session = new SessionImpl(hs);
+        Session session = new SessionImpl(hs, null);
 
         session.invalidate();
 
@@ -85,7 +85,7 @@
 
         replay();
 
-        Session session = new SessionImpl(hs);
+        Session session = new SessionImpl(hs, null);
 
         session.setMaxInactiveInterval(seconds);
 
@@ -102,7 +102,7 @@
 
         replay();
 
-        Session session = new SessionImpl(hs);
+        Session session = new SessionImpl(hs, null);
 
         assertEquals(session.getMaxInactiveInterval(), seconds);
 

Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/services/StrategyBuilderImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/services/StrategyBuilderImpl.java?rev=730456&r1=730455&r2=730456&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/services/StrategyBuilderImpl.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/services/StrategyBuilderImpl.java
Wed Dec 31 11:50:39 2008
@@ -1,4 +1,4 @@
-// Copyright 2006, 2007 The Apache Software Foundation
+// Copyright 2006, 2007, 2008 The Apache Software Foundation
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
@@ -19,6 +19,7 @@
 import org.apache.tapestry5.ioc.util.StrategyRegistry;
 
 import java.lang.reflect.Modifier;
+import java.util.Map;
 
 public class StrategyBuilderImpl implements StrategyBuilder
 {
@@ -49,6 +50,13 @@
         }
     }
 
+    public <S> S build(Class<S> adapterType, Map<Class, S> registrations)
+    {
+        StrategyRegistry<S> registry = StrategyRegistry.newInstance(adapterType, registrations);
+
+        return build(registry);
+    }
+
     private Class createImplClass(Class interfaceClass)
     {
         ClassFab cf = classFactory.newClass(interfaceClass);
@@ -57,7 +65,7 @@
 
         cf.addField("_registry", Modifier.PRIVATE | Modifier.FINAL, StrategyRegistry.class);
         cf.addConstructor(new Class[]
-                { StrategyRegistry.class }, null, "_registry = $1;");
+                {StrategyRegistry.class}, null, "_registry = $1;");
 
         BodyBuilder builder = new BodyBuilder();
 
@@ -82,7 +90,6 @@
             builder.end();
 
             cf.addMethod(Modifier.PUBLIC, sig, builder.toString());
-
         }
 
         if (!mi.getToString())

Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/StrategyBuilder.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/StrategyBuilder.java?rev=730456&r1=730455&r2=730456&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/StrategyBuilder.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/StrategyBuilder.java
Wed Dec 31 11:50:39 2008
@@ -1,4 +1,4 @@
-// Copyright 2006 The Apache Software Foundation
+// Copyright 2006, 2008 The Apache Software Foundation
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
@@ -16,6 +16,8 @@
 
 import org.apache.tapestry5.ioc.util.StrategyRegistry;
 
+import java.util.Map;
+
 /**
  * A service implementation builder that operates around a {@link StrategyRegistry}, implementing
a version of the Gang
  * of Four Strategy pattern.
@@ -38,4 +40,12 @@
      * @return a service implementation
      */
     <S> S build(StrategyRegistry<S> registry);
+
+    /**
+     * @param registrations map frm class to the adapter type
+     * @param <S>
+     * @return the dispatcher
+     * @since 5.1.0.0
+     */
+    <S> S build(Class<S> adapterType, Map<Class, S> registrations);
 }

Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/services/StrategyBuilderImplTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/services/StrategyBuilderImplTest.java?rev=730456&r1=730455&r2=730456&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/services/StrategyBuilderImplTest.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/services/StrategyBuilderImplTest.java
Wed Dec 31 11:50:39 2008
@@ -1,4 +1,4 @@
-// Copyright 2006 The Apache Software Foundation
+// Copyright 2006, 2008 The Apache Software Foundation
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
@@ -15,7 +15,7 @@
 package org.apache.tapestry5.ioc.internal.services;
 
 import org.apache.tapestry5.ioc.internal.IOCInternalTestCase;
-import static org.apache.tapestry5.ioc.internal.util.CollectionFactory.newMap;
+import org.apache.tapestry5.ioc.internal.util.CollectionFactory;
 import org.apache.tapestry5.ioc.services.StrategyBuilder;
 import org.apache.tapestry5.ioc.util.StrategyRegistry;
 import org.testng.annotations.Test;
@@ -39,7 +39,6 @@
         {
             return this.value;
         }
-
     }
 
     @Test
@@ -68,9 +67,24 @@
         }
     }
 
+    @Test
+    public void using_registration_map()
+    {
+        Map<Class, KindOf> registrations = CollectionFactory.newMap();
+
+        registrations.put(Map.class, new KindOfImpl("MAP"));
+        registrations.put(List.class, new KindOfImpl("LIST"));
+        StrategyBuilder builder = getService(StrategyBuilder.class);
+
+        KindOf service = builder.build(KindOf.class, registrations);
+
+        assertEquals(service.kindOf(Collections.EMPTY_MAP), "MAP");
+        assertEquals(service.kindOf(Collections.EMPTY_LIST), "LIST");
+    }
+
     private StrategyRegistry<KindOf> buildStrategyRegistry()
     {
-        Map<Class, KindOf> registrations = newMap();
+        Map<Class, KindOf> registrations = CollectionFactory.newMap();
 
         registrations.put(Map.class, new KindOfImpl("MAP"));
         registrations.put(List.class, new KindOfImpl("LIST"));



Mime
View raw message