Return-Path: Delivered-To: apmail-tapestry-commits-archive@locus.apache.org Received: (qmail 60917 invoked from network); 31 Dec 2008 19:51:07 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 31 Dec 2008 19:51:07 -0000 Received: (qmail 74849 invoked by uid 500); 31 Dec 2008 19:51:07 -0000 Delivered-To: apmail-tapestry-commits-archive@tapestry.apache.org Received: (qmail 74812 invoked by uid 500); 31 Dec 2008 19:51:07 -0000 Mailing-List: contact commits-help@tapestry.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@tapestry.apache.org Delivered-To: mailing list commits@tapestry.apache.org Received: (qmail 74803 invoked by uid 99); 31 Dec 2008 19:51:06 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 31 Dec 2008 11:51:06 -0800 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 31 Dec 2008 19:51:03 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 6188323889C0; Wed, 31 Dec 2008 11:50:42 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: commits@tapestry.apache.org From: hlship@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20081231195042.6188323889C0@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 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 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 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> 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 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 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 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 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 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 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 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 build(Class adapterType, Map registrations) + { + StrategyRegistry 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 build(StrategyRegistry registry); + + /** + * @param registrations map frm class to the adapter type + * @param + * @return the dispatcher + * @since 5.1.0.0 + */ + S build(Class adapterType, Map 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 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 buildStrategyRegistry() { - Map registrations = newMap(); + Map registrations = CollectionFactory.newMap(); registrations.put(Map.class, new KindOfImpl("MAP")); registrations.put(List.class, new KindOfImpl("LIST"));