tapestry-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hls...@apache.org
Subject svn commit: r481321 [2/2] - in /tapestry/tapestry5/tapestry-core/trunk/src: main/java/org/apache/tapestry/ main/java/org/apache/tapestry/annotations/ main/java/org/apache/tapestry/internal/services/ main/java/org/apache/tapestry/internal/util/ main/jav...
Date Fri, 01 Dec 2006 17:49:35 GMT
Added: tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/InjectAnonymousWorkerTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/InjectAnonymousWorkerTest.java?view=auto&rev=481321
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/InjectAnonymousWorkerTest.java
(added)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/InjectAnonymousWorkerTest.java
Fri Dec  1 09:49:32 2006
@@ -0,0 +1,95 @@
+// 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.services;
+
+import org.apache.tapestry.annotations.Inject;
+import org.apache.tapestry.internal.test.InternalBaseTestCase;
+import org.apache.tapestry.ioc.ServiceLocator;
+import org.apache.tapestry.model.MutableComponentModel;
+import org.apache.tapestry.services.ClassTransformation;
+import org.apache.tapestry.services.ComponentClassTransformWorker;
+import org.apache.tapestry.services.InjectionProvider;
+import org.apache.tapestry.services.WebRequest;
+import org.testng.annotations.Test;
+
+public class InjectAnonymousWorkerTest extends InternalBaseTestCase
+{
+    private static final String WEBREQUEST_CLASS_NAME = WebRequest.class.getName();
+
+    @Test
+    public void anonymous_injection()
+    {
+        ServiceLocator locator = newServiceLocator();
+        InjectionProvider ip = newMock(InjectionProvider.class);
+        Inject annotation = newMock(Inject.class);
+        ClassTransformation ct = newClassTransformation();
+        MutableComponentModel model = newMutableComponentModel();
+
+        train_findFieldsWithAnnotation(ct, Inject.class, "myfield");
+        train_getFieldAnnotation(ct, "myfield", Inject.class, annotation);
+
+        train_getFieldType(ct, "myfield", WEBREQUEST_CLASS_NAME);
+
+        train_provideInjection(ip, "myfield", WEBREQUEST_CLASS_NAME, locator, ct, model,
true);
+
+        ct.claimField("myfield", annotation);
+
+        replay();
+
+        ComponentClassTransformWorker worker = new InjectAnonymousWorker(locator, ip);
+
+        worker.transform(ct, model);
+
+        verify();
+    }
+
+    @Test
+    public void anonymous_injection_not_provided()
+    {
+        ServiceLocator locator = newServiceLocator();
+        InjectionProvider ip = newMock(InjectionProvider.class);
+        Inject annotation = newMock(Inject.class);
+        ClassTransformation ct = newClassTransformation();
+        MutableComponentModel model = newMutableComponentModel();
+
+        train_findFieldsWithAnnotation(ct, Inject.class, "myfield");
+        train_getFieldAnnotation(ct, "myfield", Inject.class, annotation);
+
+        train_getFieldType(ct, "myfield", WEBREQUEST_CLASS_NAME);
+
+        train_provideInjection(ip, "myfield", WEBREQUEST_CLASS_NAME, locator, ct, model,
false);
+
+        train_getClassName(ct, "foo.Baz");
+
+        replay();
+
+        ComponentClassTransformWorker worker = new InjectAnonymousWorker(locator, ip);
+
+        try
+        {
+            worker.transform(ct, model);
+            unreachable();
+        }
+        catch (RuntimeException ex)
+        {
+            assertEquals(ex.getMessage(), ServicesMessages.noInjectionFound(
+                    "foo.Baz",
+                    "myfield",
+                    WEBREQUEST_CLASS_NAME));
+        }
+
+        verify();
+    }
+}

Copied: tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/InjectNamedWorkerTest.java
(from r480115, tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/InjectWorkerTest.java)
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/InjectNamedWorkerTest.java?view=diff&rev=481321&p1=tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/InjectWorkerTest.java&r1=480115&p2=tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/InjectNamedWorkerTest.java&r2=481321
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/InjectWorkerTest.java
(original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/InjectNamedWorkerTest.java
Fri Dec  1 09:49:32 2006
@@ -20,14 +20,10 @@
 import org.apache.tapestry.ioc.ServiceLocator;
 import org.apache.tapestry.model.MutableComponentModel;
 import org.apache.tapestry.services.ClassTransformation;
-import org.apache.tapestry.services.InjectionProvider;
 import org.apache.tapestry.services.WebRequest;
 import org.testng.annotations.Test;
 
-/**
- * 
- */
-public class InjectWorkerTest extends InternalBaseTestCase
+public class InjectNamedWorkerTest extends InternalBaseTestCase
 {
 
     private static final String WEBREQUEST_CLASS_NAME = WebRequest.class.getName();
@@ -37,7 +33,6 @@
     {
         ObjectProvider provider = newObjectProvider();
         ServiceLocator locator = newServiceLocator();
-        InjectionProvider ip = newMock(InjectionProvider.class);
         Inject annotation = newMock(Inject.class);
         ClassTransformation ct = newClassTransformation();
         MutableComponentModel model = newMutableComponentModel();
@@ -59,91 +54,10 @@
 
         replay();
 
-        InjectWorker worker = new InjectWorker(provider, locator, ip);
+        InjectNamedWorker worker = new InjectNamedWorker(provider, locator);
 
         worker.transform(ct, model);
 
         verify();
-    }
-
-    @Test
-    public void no_value_for_annotation()
-    {
-        ObjectProvider provider = newObjectProvider();
-        ServiceLocator locator = newServiceLocator();
-        InjectionProvider ip = newMock(InjectionProvider.class);
-        Inject annotation = newMock(Inject.class);
-        ClassTransformation ct = newClassTransformation();
-        MutableComponentModel model = newMutableComponentModel();
-
-        train_findFieldsWithAnnotation(ct, Inject.class, "myfield");
-        train_getFieldAnnotation(ct, "myfield", Inject.class, annotation);
-
-        train_value(annotation, "");
-
-        train_getFieldType(ct, "myfield", WEBREQUEST_CLASS_NAME);
-
-        train_provideInjection(ip, "myfield", WEBREQUEST_CLASS_NAME, locator, ct, model,
true);
-
-        ct.claimField("myfield", annotation);
-
-        replay();
-
-        InjectWorker worker = new InjectWorker(provider, locator, ip);
-
-        worker.transform(ct, model);
-
-        verify();
-    }
-
-    @Test
-    public void anonymous_injection_not_provided()
-    {
-        ObjectProvider provider = newObjectProvider();
-        ServiceLocator locator = newServiceLocator();
-        InjectionProvider ip = newMock(InjectionProvider.class);
-        Inject annotation = newMock(Inject.class);
-        ClassTransformation ct = newClassTransformation();
-        MutableComponentModel model = newMutableComponentModel();
-
-        train_findFieldsWithAnnotation(ct, Inject.class, "myfield");
-        train_getFieldAnnotation(ct, "myfield", Inject.class, annotation);
-
-        train_value(annotation, "");
-
-        train_getFieldType(ct, "myfield", WEBREQUEST_CLASS_NAME);
-
-        train_provideInjection(ip, "myfield", WEBREQUEST_CLASS_NAME, locator, ct, model,
false);
-
-        train_getClassName(ct, "foo.Baz");
-
-        replay();
-
-        InjectWorker worker = new InjectWorker(provider, locator, ip);
-
-        try
-        {
-            worker.transform(ct, model);
-            unreachable();
-        }
-        catch (RuntimeException ex)
-        {
-            assertEquals(ex.getMessage(), ServicesMessages.noInjectionFound(
-                    "foo.Baz",
-                    "myfield",
-                    WEBREQUEST_CLASS_NAME));
-        }
-
-        verify();
-    }
-
-    protected void train_getClassName(ClassTransformation transformation, String className)
-    {
-        expect(transformation.getClassName()).andReturn(className);
-    }
-
-    private void train_value(Inject annotation, String value)
-    {
-        expect(annotation.value()).andReturn(value);
     }
 }

Modified: tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/InternalClassTransformationImplTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/InternalClassTransformationImplTest.java?view=diff&rev=481321&r1=481320&r2=481321
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/InternalClassTransformationImplTest.java
(original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/InternalClassTransformationImplTest.java
Fri Dec  1 09:49:32 2006
@@ -45,6 +45,7 @@
 import org.apache.tapestry.internal.transform.pages.ChildClassInheritsAnnotation;
 import org.apache.tapestry.internal.transform.pages.ClaimedFields;
 import org.apache.tapestry.internal.transform.pages.EventHandlerTarget;
+import org.apache.tapestry.internal.transform.pages.FindFieldClass;
 import org.apache.tapestry.internal.transform.pages.ParentClass;
 import org.apache.tapestry.internal.transform.pages.TargetObject;
 import org.apache.tapestry.internal.transform.pages.TargetObjectSubclass;
@@ -223,6 +224,64 @@
 
         assertEquals(fields.size(), 1);
         assertEquals(fields.get(0), "_annotatedField");
+
+        verify();
+    }
+
+    @Test
+    public void find_fields_of_type() throws Exception
+    {
+        Log log = newLog();
+
+        replay();
+
+        ClassTransformation ct = createClassTransformation(FindFieldClass.class, log);
+
+        checkFindFields(ct, "boolean", "_booleanValue");
+        checkFindFields(ct, "int[]", "_intArrayValue");
+        checkFindFields(ct, "java.lang.String", "_stringValue");
+        checkFindFields(ct, "java.util.Date[]", "_dateArrayValue");
+
+        verify();
+    }
+
+    @Test
+    public void find_fields_of_type_excludes_claimed_fields() throws Exception
+    {
+        Log log = newLog();
+
+        replay();
+
+        ClassTransformation ct = createClassTransformation(FindFieldClass.class, log);
+
+        ct.claimField("_booleanValue", this);
+
+        checkFindFields(ct, "boolean");
+
+        verify();
+    }
+
+    private void checkFindFields(ClassTransformation ct, String fieldType, String... expectedNames)
+    {
+        List<String> actual = ct.findFieldsOfType(fieldType);
+
+        assertEquals(actual, Arrays.asList(expectedNames));
+    }
+
+    @Test
+    public void find_fields_with_annotation_excludes_claimed_files() throws Exception
+    {
+        Log log = newLog();
+
+        replay();
+
+        ClassTransformation ct = createClassTransformation(ParentClass.class, log);
+
+        ct.claimField("_annotatedField", this);
+
+        List<String> fields = ct.findFieldsWithAnnotation(Retain.class);
+
+        assertTrue(fields.isEmpty());
 
         verify();
     }

Modified: tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/OnEventWorkerTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/OnEventWorkerTest.java?view=diff&rev=481321&r1=481320&r2=481321
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/OnEventWorkerTest.java
(original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/OnEventWorkerTest.java
Fri Dec  1 09:49:32 2006
@@ -16,7 +16,6 @@
 
 import static java.lang.String.format;
 
-import java.lang.annotation.Annotation;
 import java.lang.reflect.Modifier;
 import java.util.Collections;
 import java.util.List;
@@ -440,11 +439,6 @@
         return newMock(OnEvent.class);
     }
 
-    protected final void train_getClassName(ClassTransformation ct, String className)
-    {
-        expect(ct.getClassName()).andReturn(className);
-    }
-
     protected final void train_value(OnEvent annotation, String[] values)
     {
         expect(annotation.value()).andReturn(values);
@@ -453,11 +447,5 @@
     protected final void train_component(OnEvent annotation, String[] values)
     {
         expect(annotation.component()).andReturn(values);
-    }
-
-    protected final <T extends Annotation> void train_getMethodAnnotation(ClassTransformation
ct,
-            MethodSignature signature, Class<T> annotationClass, T annotation)
-    {
-        expect(ct.getMethodAnnotation(signature, annotationClass)).andReturn(annotation);
     }
 }

Added: tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/transform/pages/FindFieldClass.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/transform/pages/FindFieldClass.java?view=auto&rev=481321
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/transform/pages/FindFieldClass.java
(added)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/transform/pages/FindFieldClass.java
Fri Dec  1 09:49:32 2006
@@ -0,0 +1,72 @@
+// 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.transform.pages;
+
+import java.util.Date;
+
+import org.apache.tapestry.annotations.ComponentClass;
+
+@ComponentClass
+public class FindFieldClass
+{
+    private boolean _booleanValue;
+
+    private int[] _intArrayValue;
+
+    private String _stringValue;
+
+    private Date[] _dateArrayValue;
+
+    public boolean isBooleanValue()
+    {
+        return _booleanValue;
+    }
+
+    public void setBooleanValue(boolean booleanValue)
+    {
+        _booleanValue = booleanValue;
+    }
+
+    public Date[] getDateArrayValue()
+    {
+        return _dateArrayValue;
+    }
+
+    public void setDateArrayValue(Date[] dateArrayValue)
+    {
+        _dateArrayValue = dateArrayValue;
+    }
+
+    public int[] getIntArrayValue()
+    {
+        return _intArrayValue;
+    }
+
+    public void setIntArrayValue(int[] intArrayValue)
+    {
+        _intArrayValue = intArrayValue;
+    }
+
+    public String getStringValue()
+    {
+        return _stringValue;
+    }
+
+    public void setStringValue(String stringValue)
+    {
+        _stringValue = stringValue;
+    }
+
+}

Added: tapestry/tapestry5/tapestry-core/trunk/src/test/resources/org/apache/tapestry/integration/app1/pages/AssetDemo.html
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/resources/org/apache/tapestry/integration/app1/pages/AssetDemo.html?view=auto&rev=481321
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/resources/org/apache/tapestry/integration/app1/pages/AssetDemo.html
(added)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/resources/org/apache/tapestry/integration/app1/pages/AssetDemo.html
Fri Dec  1 09:49:32 2006
@@ -0,0 +1,13 @@
+<t:comp type="Border" xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
+    
+    <p>
+        This page demonstrates the ability to inject assets into components and pass them
around as parameters.
+    </p>
+    
+    <p>
+        The Tapestry banner:
+    </p>
+    
+    <t:comp type="Img" src="icon"/>
+    
+</t:comp>
\ No newline at end of file



Mime
View raw message