Added: 
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/MetaWorkerTest.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/MetaWorkerTest.java?view=auto&rev=499593
==============================================================================
--- 
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/MetaWorkerTest.java
 (added)
+++ 
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/MetaWorkerTest.java
 Wed Jan 24 14:26:02 2007
@@ -0,0 +1,61 @@
+// Copyright 2007 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.ComponentClass;
+import org.apache.tapestry.internal.test.InternalBaseTestCase;
+import org.apache.tapestry.model.MutableComponentModel;
+import org.apache.tapestry.services.ClassTransformation;
+import org.testng.annotations.Test;
+
+public class MetaWorkerTest extends InternalBaseTestCase
+{
+    @Test
+    public void no_annotation()
+    {
+        ClassTransformation ct = newClassTransformation();
+        MutableComponentModel model = newMutableComponentModel();
+
+        train_getAnnotation(ct, ComponentClass.class, null);
+
+        replay();
+
+        new MetaWorker().transform(ct, model);
+
+        verify();
+    }
+
+    @Test
+    public void has_meta_data()
+    {
+        ClassTransformation ct = newClassTransformation();
+        MutableComponentModel model = newMutableComponentModel();
+        ComponentClass annotation = newMock(ComponentClass.class);
+
+        train_getAnnotation(ct, ComponentClass.class, annotation);
+
+        expect(annotation.meta()).andReturn(new String[]
+        { "foo=bar", "baz=biff" });
+
+        model.setMeta("foo", "bar");
+        model.setMeta("baz", "biff");
+
+        replay();
+
+        new MetaWorker().transform(ct, model);
+
+        verify();
+    }
+}

Modified: 
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/NoOpPage.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/NoOpPage.java?view=diff&rev=499593&r1=499592&r2=499593
==============================================================================
--- 
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/NoOpPage.java
 (original)
+++ 
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/NoOpPage.java
 Wed Jan 24 14:26:02 2007
@@ -17,6 +17,7 @@
 import java.util.Locale;
 
 import org.apache.commons.logging.Log;
+import org.apache.tapestry.ComponentResources;
 import org.apache.tapestry.Link;
 import org.apache.tapestry.internal.structure.ComponentPageElement;
 import org.apache.tapestry.internal.structure.Page;
@@ -26,8 +27,9 @@
 public class NoOpPage implements Page
 {
     private final String _pageName;
+
     private final Locale _locale;
-    
+
     public NoOpPage(String pageName, Locale locale)
     {
         _pageName = pageName;
@@ -46,7 +48,7 @@
 
     public void setRootElement(ComponentPageElement component)
     {
-        
+
     }
 
     public ComponentPageElement getRootElement()
@@ -67,17 +69,17 @@
 
     public void attached()
     {
-        
+
     }
 
     public void loaded()
     {
-        
+
     }
 
     public void addLifecycleListener(PageLifecycleListener listener)
     {
-        
+
     }
 
     public Log getLog()
@@ -90,14 +92,15 @@
         return null;
     }
 
-    public Link createActionLink(ComponentPageElement element, String action, 
boolean forForm, Object... context)
+    public Link createActionLink(ComponentPageElement element, String action, 
boolean forForm,
+            Object... context)
     {
         return null;
     }
 
-    public void persistFieldChange(ComponentPageElement element, String 
fieldName, Object newValue)
+    public void persistFieldChange(ComponentResources resources, String 
fieldName,
+            Object newValue)
     {
-        
     }
 
     public Object getFieldChange(ComponentPageElement element, String 
fieldName)
@@ -107,12 +110,12 @@
 
     public void incrementDirtyCount()
     {
-        
+
     }
 
     public void decrementDirtyCount()
     {
-        
+
     }
 
 }

Modified: 
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/PersistentFieldManagerImplTest.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/PersistentFieldManagerImplTest.java?view=diff&rev=499593&r1=499592&r2=499593
==============================================================================
--- 
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/PersistentFieldManagerImplTest.java
 (original)
+++ 
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/PersistentFieldManagerImplTest.java
 Wed Jan 24 14:26:02 2007
@@ -20,8 +20,9 @@
 import java.util.Collection;
 import java.util.Map;
 
+import org.apache.tapestry.ComponentResources;
 import org.apache.tapestry.internal.test.InternalBaseTestCase;
-import org.apache.tapestry.ioc.internal.util.CollectionFactory;
+import org.apache.tapestry.model.ComponentModel;
 import org.apache.tapestry.services.PersistentFieldBundle;
 import org.apache.tapestry.services.PersistentFieldChange;
 import org.apache.tapestry.services.PersistentFieldManager;
@@ -33,20 +34,28 @@
     @Test
     public void post_change_with_unknown_strategy()
     {
+        String fieldName = "field";
+
         PersistentFieldStrategy strat1 = newPersistentFieldStrategy();
         PersistentFieldStrategy strat2 = newPersistentFieldStrategy();
+        ComponentResources resources = newComponentResources();
+        ComponentModel model = newComponentModel();
 
-        Map<String, PersistentFieldStrategy> strategies = 
CollectionFactory.newMap();
+        Map<String, PersistentFieldStrategy> strategies = newMap();
         strategies.put("foo", strat1);
         strategies.put("bar", strat2);
 
+        train_getComponentModel(resources, model);
+
+        train_getFieldPersistenceStrategy(model, fieldName, "braveheart");
+
         replay();
 
         PersistentFieldManager manager = new 
PersistentFieldManagerImpl(strategies);
 
         try
         {
-            manager.postChange("foo.Bar", null, "field", "braveheart", null);
+            manager.postChange("foo.Bar", resources, fieldName, null);
             unreachable();
         }
         catch (RuntimeException ex)
@@ -62,22 +71,152 @@
     @Test
     public void post_change()
     {
+        String pageName = "foo.Bar";
+        String nestedId = "nested";
+        String fieldName = "field";
+        String strategyName = "foo";
+
+        ComponentResources resources = newComponentResources();
+        ComponentModel model = newComponentModel();
         PersistentFieldStrategy strat = newPersistentFieldStrategy();
+        Object value = new Object();
+
+        Map<String, PersistentFieldStrategy> strategies = newMap();
+        strategies.put(strategyName, strat);
+
+        train_getComponentModel(resources, model);
+
+        train_getFieldPersistenceStrategy(model, fieldName, strategyName);
+
+        train_getNestedId(resources, nestedId);
+
+        strat.postChange(pageName, nestedId, fieldName, value);
+
+        replay();
+
+        PersistentFieldManager manager = new 
PersistentFieldManagerImpl(strategies);
+
+        manager.postChange(pageName, resources, fieldName, value);
+
+        verify();
+    }
 
-        Map<String, PersistentFieldStrategy> strategies = 
CollectionFactory.newMap();
-        strategies.put("foo", strat);
+    @Test
+    public void post_change_strategy_by_meta_data()
+    {
+        String pageName = "foo.Bar";
+        String nestedId = "nested";
+        String fieldName = "field";
+        String strategyName = "foo";
 
+        ComponentResources resources = newComponentResources();
+        ComponentModel model = newComponentModel();
+        PersistentFieldStrategy strat = newPersistentFieldStrategy();
         Object value = new Object();
 
-        strat.postChange("foo.Bar", "nested", "field", value);
+        Map<String, PersistentFieldStrategy> strategies = newMap();
+        strategies.put(strategyName, strat);
+
+        train_getComponentModel(resources, model);
+
+        train_getFieldPersistenceStrategy(model, fieldName, "");
+
+        train_getMeta(model, PersistentFieldManagerImpl.META_KEY, 
strategyName);
+
+        train_getNestedId(resources, nestedId);
+
+        strat.postChange(pageName, nestedId, fieldName, value);
 
         replay();
 
         PersistentFieldManager manager = new 
PersistentFieldManagerImpl(strategies);
 
-        manager.postChange("foo.Bar", "nested", "field", "foo", value);
+        manager.postChange(pageName, resources, fieldName, value);
 
         verify();
+    }
+
+    @Test
+    public void post_change_strategy_by_container_meta_data()
+    {
+        String pageName = "foo.Bar";
+        String nestedId = "nested";
+        String fieldName = "field";
+        String strategyName = "foo";
+
+        ComponentResources resources = newComponentResources();
+        ComponentModel model = newComponentModel();
+        ComponentResources containerResources = newComponentResources();
+        ComponentModel containerModel = newComponentModel();
+        PersistentFieldStrategy strat = newPersistentFieldStrategy();
+        Object value = new Object();
+
+        Map<String, PersistentFieldStrategy> strategies = newMap();
+        strategies.put(strategyName, strat);
+
+        train_getComponentModel(resources, model);
+
+        train_getFieldPersistenceStrategy(model, fieldName, "");
+
+        train_getMeta(model, PersistentFieldManagerImpl.META_KEY, null);
+
+        train_getContainerResources(resources, containerResources);
+        train_getComponentModel(containerResources, containerModel);
+
+        train_getMeta(containerModel, PersistentFieldManagerImpl.META_KEY, 
strategyName);
+
+        train_getNestedId(resources, nestedId);
+
+        strat.postChange(pageName, nestedId, fieldName, value);
+
+        replay();
+
+        PersistentFieldManager manager = new 
PersistentFieldManagerImpl(strategies);
+
+        manager.postChange(pageName, resources, fieldName, value);
+
+        verify();
+    }
+
+    @Test
+    public void post_change_with_ultimate_default_strategy()
+    {
+        String pageName = "foo.Bar";
+        String nestedId = "nested";
+        String fieldName = "field";
+
+        ComponentResources resources = newComponentResources();
+        ComponentModel model = newComponentModel();
+        PersistentFieldStrategy strat = newPersistentFieldStrategy();
+        Object value = new Object();
+
+        Map<String, PersistentFieldStrategy> strategies = newMap();
+        strategies.put(PersistentFieldManagerImpl.DEFAULT_STRATEGY, strat);
+
+        train_getComponentModel(resources, model);
+
+        train_getFieldPersistenceStrategy(model, fieldName, "");
+
+        train_getMeta(model, PersistentFieldManagerImpl.META_KEY, null);
+
+        train_getContainerResources(resources, null);
+
+        train_getNestedId(resources, nestedId);
+
+        strat.postChange(pageName, nestedId, fieldName, value);
+
+        replay();
+
+        PersistentFieldManager manager = new 
PersistentFieldManagerImpl(strategies);
+
+        manager.postChange(pageName, resources, fieldName, value);
+
+        verify();
+    }
+
+    protected final void train_getMeta(ComponentModel model, String key, 
String value)
+    {
+        expect(model.getMeta(key)).andReturn(value).atLeastOnce();
     }
 
     private PersistentFieldStrategy newPersistentFieldStrategy()

Modified: 
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/structure/ComponentPageElementImplTest.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/structure/ComponentPageElementImplTest.java?view=diff&rev=499593&r1=499592&r2=499593
==============================================================================
--- 
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/structure/ComponentPageElementImplTest.java
 (original)
+++ 
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/structure/ComponentPageElementImplTest.java
 Wed Jan 24 14:26:02 2007
@@ -177,6 +177,7 @@
     {
         Page page = newPage();
         ComponentPageElement container = newComponentPageElement();
+        InternalComponentResources containerResources = 
newInternalComponentResources();
         Component component = newComponent();
         ComponentModel model = newComponentModel();
         ParameterModel pmodel = newParameterModel();
@@ -184,6 +185,8 @@
         TypeCoercer coercer = newTypeCoercer();
 
         Instantiator ins = newInstantiator(component, model);
+
+        train_getComponentResources(container, containerResources);
 
         train_getNestedId(container, null);
         train_getName(page, "foo.pages.MyPage");

Modified: 
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/structure/InternalComponentResourcesImplTest.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/structure/InternalComponentResourcesImplTest.java?view=diff&rev=499593&r1=499592&r2=499593
==============================================================================
--- 
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/structure/InternalComponentResourcesImplTest.java
 (original)
+++ 
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/structure/InternalComponentResourcesImplTest.java
 Wed Jan 24 14:26:02 2007
@@ -41,8 +41,8 @@
 
         replay();
 
-        InternalComponentResources resources = new 
InternalComponentResourcesImpl(element, ins,
-                coercer, null);
+        InternalComponentResources resources = new 
InternalComponentResourcesImpl(element, null,
+                ins, coercer, null);
 
         resources.renderInformalParameters(writer);
 
@@ -67,8 +67,8 @@
 
         replay();
 
-        InternalComponentResources resources = new 
InternalComponentResourcesImpl(element, ins,
-                coercer, null);
+        InternalComponentResources resources = new 
InternalComponentResourcesImpl(element, null,
+                ins, coercer, null);
 
         resources.addParameter("fred", binding);
 
@@ -102,8 +102,8 @@
 
         replay();
 
-        InternalComponentResources resources = new 
InternalComponentResourcesImpl(element, ins,
-                coercer, null);
+        InternalComponentResources resources = new 
InternalComponentResourcesImpl(element, null,
+                ins, coercer, null);
 
         resources.addParameter("fred", binding);
 

Added: 
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/transform/InheritedAnnotation.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/transform/InheritedAnnotation.java?view=auto&rev=499593
==============================================================================
--- 
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/transform/InheritedAnnotation.java
 (added)
+++ 
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/transform/InheritedAnnotation.java
 Wed Jan 24 14:26:02 2007
@@ -0,0 +1,31 @@
+// Copyright 2007 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;
+
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Inherited;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
[EMAIL PROTECTED](TYPE)
[EMAIL PROTECTED](RUNTIME)
[EMAIL PROTECTED]
[EMAIL PROTECTED]
+public @interface InheritedAnnotation {
+
+}

Modified: 
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/transform/pages/ParentClass.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/transform/pages/ParentClass.java?view=diff&rev=499593&r1=499592&r2=499593
==============================================================================
--- 
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/transform/pages/ParentClass.java
 (original)
+++ 
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/transform/pages/ParentClass.java
 Wed Jan 24 14:26:02 2007
@@ -16,6 +16,7 @@
 
 import org.apache.tapestry.annotations.ComponentClass;
 import org.apache.tapestry.annotations.Retain;
+import org.apache.tapestry.internal.transform.InheritedAnnotation;
 
 /**
  * Test class used with
@@ -23,7 +24,8 @@
  * 
  * 
  */
[EMAIL PROTECTED]
[EMAIL PROTECTED]
[EMAIL PROTECTED]
 public class ParentClass
 {
     private int _parentField;


Reply via email to