tapestry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hls...@apache.org
Subject svn commit: r503936 [2/2] - in /tapestry/tapestry5/tapestry-core/trunk: ./ src/main/java/org/apache/tapestry/beaneditor/ src/main/java/org/apache/tapestry/internal/beaneditor/ src/main/java/org/apache/tapestry/internal/bindings/ src/main/java/org/apach...
Date Tue, 06 Feb 2007 00:36:50 GMT
Modified: tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/BeanEditorModelSourceImplTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/BeanEditorModelSourceImplTest.java?view=diff&rev=503936&r1=503935&r2=503936
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/BeanEditorModelSourceImplTest.java
(original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/BeanEditorModelSourceImplTest.java
Mon Feb  5 16:36:48 2007
@@ -15,6 +15,7 @@
 package org.apache.tapestry.internal.services;
 
 import java.util.Arrays;
+import java.util.Collections;
 
 import org.apache.tapestry.ComponentResources;
 import org.apache.tapestry.beaneditor.BeanEditorModel;
@@ -172,12 +173,8 @@
         verify();
     }
 
-    /**
-     * You can add anything you like as a property, but you'll have to fill in details such
as type
-     * and conduit.
-     */
     @Test
-    public void default_values_for_missing_property()
+    public void order_via_annotation()
     {
         ComponentResources resources = newComponentResources();
         Messages messages = newMessages();
@@ -187,20 +184,15 @@
 
         replay();
 
-        BeanEditorModel model = _source.create(SimpleBean.class, resources);
-
-        PropertyEditModel pm = model.add("frobozz");
+        BeanEditorModel model = _source.create(StoogeBean.class, resources);
 
-        assertEquals(pm.getLabel(), "Frobozz");
-        assertEquals(pm.getOrder(), 0);
-        assertNull(pm.getConduit());
-        assertSame(pm.getPropertyType(), Object.class);
+        assertEquals(model.getPropertyNames(), Arrays.asList("larry", "moe", "shemp", "curly"));
 
         verify();
     }
 
     @Test
-    public void order_via_annotation()
+    public void edit_property_label()
     {
         ComponentResources resources = newComponentResources();
         Messages messages = newMessages();
@@ -210,15 +202,16 @@
 
         replay();
 
-        BeanEditorModel model = _source.create(StoogeBean.class, resources);
+        BeanEditorModel model = _source.create(SimpleBean.class, resources).get("age").label(
+                "Decrepitude").model();
 
-        assertEquals(model.getPropertyNames(), Arrays.asList("larry", "moe", "shemp", "curly"));
+        assertEquals(model.get("age").getLabel(), "Decrepitude");
 
         verify();
     }
 
     @Test
-    public void edit_property_label()
+    public void label_from_component_messages()
     {
         ComponentResources resources = newComponentResources();
         Messages messages = newMessages();
@@ -226,10 +219,12 @@
         train_getMessages(resources, messages);
         stub_contains(messages, false);
 
+        train_contains(messages, "age-label", true);
+        train_get(messages, "age-label", "Decrepitude");
+
         replay();
 
-        BeanEditorModel model = _source.create(SimpleBean.class, resources).get("age").label(
-                "Decrepitude").model();
+        BeanEditorModel model = _source.create(SimpleBean.class, resources);
 
         assertEquals(model.get("age").getLabel(), "Decrepitude");
 
@@ -237,7 +232,7 @@
     }
 
     @Test
-    public void label_from_component_messages()
+    public void array_type_bean()
     {
         ComponentResources resources = newComponentResources();
         Messages messages = newMessages();
@@ -245,34 +240,72 @@
         train_getMessages(resources, messages);
         stub_contains(messages, false);
 
-        train_contains(messages, "age-label", true);
-        train_get(messages, "age-label", "Decrepitude");
-
         replay();
 
-        BeanEditorModel model = _source.create(SimpleBean.class, resources);
+        BeanEditorModel model = _source.create(StringArrayBean.class, resources);
 
-        assertEquals(model.get("age").getLabel(), "Decrepitude");
+        // There's not editor for string arrays yet, so it won't show up normally.
+
+        PropertyEditModel propertyModel = model.add("array");
+
+        assertSame(propertyModel.getPropertyType(), String[].class);
+
+        String[] value =
+        { "foo", "bar" };
+
+        StringArrayBean bean = new StringArrayBean();
+
+        PropertyConduit conduit = propertyModel.getConduit();
+
+        conduit.set(bean, value);
+
+        assertSame(bean.getArray(), value);
+
+        assertSame(conduit.get(bean), value);
 
         verify();
     }
 
     @Test
-    public void override_conduit()
+    public void composite_bean()
     {
         ComponentResources resources = newComponentResources();
         Messages messages = newMessages();
-        PropertyConduit conduit = newMock(PropertyConduit.class);
 
         train_getMessages(resources, messages);
         stub_contains(messages, false);
 
+        train_contains(messages, "age-label", true);
+        train_get(messages, "age-label", "Years of Age");
+
         replay();
 
-        BeanEditorModel model = _source.create(SimpleBean.class, resources).get("age").conduit(
-                conduit).model();
+        BeanEditorModel model = _source.create(CompositeBean.class, resources);
+
+        // No editor for CompositeBean, so this will be empty.
+
+        assertEquals(model.getPropertyNames(), Collections.emptyList());
+
+        // There's not editor for string arrays yet, so it won't show up normally.
+
+        PropertyEditModel firstName = model.add("simple.firstName");
+
+        assertEquals(firstName.getLabel(), "First Name");
+
+        PropertyEditModel age = model.add("simple.age");
+        assertEquals(age.getLabel(), "Years of Age");
+
+        CompositeBean bean = new CompositeBean();
+
+        firstName.getConduit().set(bean, "Fred");
+        age.getConduit().set(bean, "97");
+
+        assertEquals(bean.getSimple().getFirstName(), "Fred");
+        assertEquals(bean.getSimple().getAge(), 97);
+
+        bean.getSimple().setAge(24);
 
-        assertSame(model.get("age").getConduit(), conduit);
+        assertEquals(age.getConduit().get(bean), new Integer(24));
 
         verify();
     }

Added: tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/CompositeBean.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/CompositeBean.java?view=auto&rev=503936
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/CompositeBean.java
(added)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/CompositeBean.java
Mon Feb  5 16:36:48 2007
@@ -0,0 +1,30 @@
+// 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;
+
+public class CompositeBean
+{
+    private SimpleBean _simple = new SimpleBean();
+
+    public SimpleBean getSimple()
+    {
+        return _simple;
+    }
+
+    public void setSimple(SimpleBean simple)
+    {
+        _simple = simple;
+    }
+}

Added: tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/StringArrayBean.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/StringArrayBean.java?view=auto&rev=503936
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/StringArrayBean.java
(added)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/StringArrayBean.java
Mon Feb  5 16:36:48 2007
@@ -0,0 +1,30 @@
+// 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;
+
+public class StringArrayBean
+{
+    private String[] _array;
+
+    public String[] getArray()
+    {
+        return _array;
+    }
+
+    public void setArray(String[] array)
+    {
+        _array = array;
+    }
+}



Mime
View raw message