Author: kmenard
Date: Sun Mar  8 05:02:49 2009
New Revision: 751366

URL: http://svn.apache.org/viewvc?rev=751366&view=rev
Log:
Fixed TAP5-564: Add StringPropertySelectModel.

Added:
    
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/util/StringSelectModel.java
    
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/util/StringSelectModelTest.java

Added: 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/util/StringSelectModel.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/util/StringSelectModel.java?rev=751366&view=auto
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/util/StringSelectModel.java
 (added)
+++ 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/util/StringSelectModel.java
 Sun Mar  8 05:02:49 2009
@@ -0,0 +1,58 @@
+// Copyright 2009 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.tapestry5.util;
+
+import org.apache.tapestry5.OptionGroupModel;
+import org.apache.tapestry5.OptionModel;
+import org.apache.tapestry5.internal.TapestryInternalUtils;
+import org.apache.tapestry5.internal.OptionModelImpl;
+import org.apache.tapestry5.ioc.Messages;
+import static org.apache.tapestry5.ioc.internal.util.Defense.notNull;
+import org.apache.tapestry5.ioc.internal.util.CollectionFactory;
+
+import java.io.Serializable;
+import java.util.List;
+import java.util.Collections;
+import java.util.Arrays;
+
+/**
+ * A basic select model for a collection of Strings.
+ */
+public class StringSelectModel extends AbstractSelectModel implements 
Serializable
+{
+    private List<OptionModel> options = CollectionFactory.newList();
+
+    public StringSelectModel(List<String> values)
+    {
+        notNull(values, "values");
+
+        options = 
Collections.unmodifiableList(TapestryInternalUtils.toOptionModels(values));
+    }
+
+    public StringSelectModel(String... values)
+    {
+        this(Arrays.asList(values));
+    }
+
+    public List<OptionGroupModel> getOptionGroups()
+    {
+        return null;
+    }
+
+    public List<OptionModel> getOptions()
+    {
+        return options;
+    }
+}

Added: 
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/util/StringSelectModelTest.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/util/StringSelectModelTest.java?rev=751366&view=auto
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/util/StringSelectModelTest.java
 (added)
+++ 
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/util/StringSelectModelTest.java
 Sun Mar  8 05:02:49 2009
@@ -0,0 +1,74 @@
+// Copyright 2009 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.tapestry5.util;
+
+import org.apache.tapestry5.test.TapestryTestCase;
+import org.apache.tapestry5.SelectModel;
+import org.apache.tapestry5.OptionModel;
+import org.testng.annotations.Test;
+
+import java.util.List;
+import java.util.Arrays;
+
+public class StringSelectModelTest extends TapestryTestCase
+{
+    @Test
+    public void generated_option_models_list_constructor()
+    {
+        replay();
+
+        List<String> stooges = Arrays.asList("Moe", "Larry", "Curly Joe");
+        SelectModel model = new StringSelectModel(stooges);
+
+        List<OptionModel> options = model.getOptions();
+
+        assertEquals(options.size(), stooges.size());
+
+        for (int i = 0; i < options.size(); i++)
+        {
+            checkOption(options, i, stooges.get(i));
+        }
+
+        verify();
+    }
+
+    @Test
+    public void generated_option_models_vararg_constructor()
+    {
+        replay();
+
+        SelectModel model = new StringSelectModel("Moe", "Larry", "Curly Joe");
+
+        List<OptionModel> options = model.getOptions();
+
+        assertEquals(options.size(), 3);
+
+        checkOption(options, 0, "Moe");
+        checkOption(options, 1, "Larry");
+        checkOption(options, 2, "Curly Joe");
+
+        verify();
+    }
+
+    private void checkOption(List<OptionModel> options, int i, String value)
+    {
+        OptionModel model = options.get(i);
+
+        assertEquals(model.getLabel(), value);
+        assertFalse(model.isDisabled());
+        assertSame(model.getValue(), value);
+        assertNull(model.getAttributes());
+    }
+}


Reply via email to