tapestry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hls...@apache.org
Subject svn commit: r423059 - in /tapestry/tapestry5/tapestry-core/trunk/src: main/java/org/apache/tapestry/internal/test/InternalBaseTestCase.java test/java/org/apache/tapestry/internal/ioc/InterceptorStackBuilderTest.java
Date Tue, 18 Jul 2006 12:04:58 GMT
Author: hlship
Date: Tue Jul 18 05:04:57 2006
New Revision: 423059

URL: http://svn.apache.org/viewvc?rev=423059&view=rev
Log:
Fill in the test suite for InterceptorStackBuilder

Added:
    tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/ioc/InterceptorStackBuilderTest.java
Modified:
    tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/test/InternalBaseTestCase.java

Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/test/InternalBaseTestCase.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/test/InternalBaseTestCase.java?rev=423059&r1=423058&r2=423059&view=diff
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/test/InternalBaseTestCase.java
(original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/test/InternalBaseTestCase.java
Tue Jul 18 05:04:57 2006
@@ -14,10 +14,13 @@
 
 package org.apache.tapestry.internal.test;
 
+import java.util.List;
+
 import org.apache.tapestry.internal.InternalComponentResources;
 import org.apache.tapestry.internal.ioc.InternalRegistry;
 import org.apache.tapestry.internal.ioc.Module;
 import org.apache.tapestry.internal.parser.ComponentTemplate;
+import org.apache.tapestry.ioc.ServiceDecorator;
 import org.apache.tapestry.ioc.ServiceLifecycle;
 import org.apache.tapestry.test.BaseTestCase;
 
@@ -50,5 +53,27 @@
     {
         registry.getServiceLifecycle(name);
         setReturnValue(lifecycle);
+    }
+
+    protected final void trainFindDecoratorsForService(Module module, String serviceId, List<ServiceDecorator>
decorators)
+    {
+        module.findDecoratorsForService(serviceId);
+        setReturnValue(decorators);
+    }
+
+    protected final Module newModule()
+    {
+        return newMock(Module.class);
+    }
+
+    protected final void trainCreateInterceptor(ServiceDecorator decorator, Object coreObject,
Object interceptor)
+    {
+        decorator.createInterceptor(coreObject);
+        setReturnValue(interceptor);
+    }
+
+    protected final ServiceDecorator newServiceDecorator()
+    {
+        return newMock(ServiceDecorator.class);
     }
 }

Added: tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/ioc/InterceptorStackBuilderTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/ioc/InterceptorStackBuilderTest.java?rev=423059&view=auto
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/ioc/InterceptorStackBuilderTest.java
(added)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/ioc/InterceptorStackBuilderTest.java
Tue Jul 18 05:04:57 2006
@@ -0,0 +1,119 @@
+// Copyright 2006 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.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package org.apache.tapestry.internal.ioc;
+
+import static java.util.Arrays.asList;
+import static org.apache.tapestry.util.CollectionFactory.newList;
+import static org.testng.Assert.assertSame;
+
+import java.util.List;
+
+import org.apache.tapestry.internal.annotations.SuppressNullCheck;
+import org.apache.tapestry.internal.test.InternalBaseTestCase;
+import org.apache.tapestry.ioc.ServiceCreator;
+import org.apache.tapestry.ioc.ServiceDecorator;
+import org.testng.annotations.Test;
+
+/**
+ * @author Howard M. Lewis Ship
+ */
+@SuppressNullCheck
+public class InterceptorStackBuilderTest extends InternalBaseTestCase
+{
+    private static final String SERVICE_ID = "foo.bar.Baz";
+
+    @Test
+    public void no_decorators()
+    {
+        ServiceCreator core = newServiceCreator();
+        Module module = newModule();
+        Object coreObject = new Object();
+        List<ServiceDecorator> decorators = newList();
+
+        trainCreateService(core, coreObject);
+
+        trainFindDecoratorsForService(module, SERVICE_ID, decorators);
+
+        replay();
+
+        ServiceCreator isb = new InterceptorStackBuilder(module, SERVICE_ID, core);
+
+        Object intercepted = isb.createService();
+
+        assertSame(intercepted, coreObject);
+
+        verify();
+    }
+
+    @Test
+    public void decorator_returns_null_interceptor()
+    {
+        ServiceCreator core = newServiceCreator();
+        Module module = newModule();
+        Object coreObject = new Object();
+        ServiceDecorator decorator = newServiceDecorator();
+
+        List<ServiceDecorator> decorators = asList(decorator);
+
+        trainCreateService(core, coreObject);
+
+        trainFindDecoratorsForService(module, SERVICE_ID, decorators);
+
+        trainCreateInterceptor(decorator, coreObject, null);
+
+        replay();
+
+        ServiceCreator isb = new InterceptorStackBuilder(module, SERVICE_ID, core);
+
+        Object intercepted = isb.createService();
+
+        assertSame(intercepted, coreObject);
+
+        verify();
+    }
+
+    @Test
+    public void decorator_orderering()
+    {
+        ServiceCreator core = newServiceCreator();
+        Module module = newModule();
+        Object coreObject = new Object();
+        Object interceptor1 = new Object();
+        Object interceptor2 = new Object();
+        ServiceDecorator decorator1 = newServiceDecorator();
+        ServiceDecorator decorator2 = newServiceDecorator();
+
+        List<ServiceDecorator> decorators = asList(decorator1, decorator2);
+
+        trainCreateService(core, coreObject);
+
+        trainFindDecoratorsForService(module, SERVICE_ID, decorators);
+
+        // Notice: reverse order!
+        
+        trainCreateInterceptor(decorator2, coreObject, interceptor2);
+        trainCreateInterceptor(decorator1, interceptor2, interceptor1);
+
+        replay();
+
+        ServiceCreator isb = new InterceptorStackBuilder(module, SERVICE_ID, core);
+
+        Object intercepted = isb.createService();
+
+        assertSame(intercepted, interceptor1);
+
+        verify();
+    }
+}



Mime
View raw message