struts-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From musa...@apache.org
Subject svn commit: r726799 - in /struts/sandbox/trunk/struts2-javatemplates-plugin/src: main/java/org/apache/struts2/views/java/simple/ test/java/org/apache/struts2/views/java/simple/
Date Mon, 15 Dec 2008 21:01:56 GMT
Author: musachy
Date: Mon Dec 15 13:01:55 2008
New Revision: 726799

URL: http://svn.apache.org/viewvc?rev=726799&view=rev
Log:
Add div, actionerror, actionmessage, fielderror handlers

Added:
    struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/simple/AbstractMessageListHandler.java
    struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/simple/ActionMessageHandler.java
    struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/simple/DivHandler.java
    struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/simple/FieldErrorHandler.java
    struts/sandbox/trunk/struts2-javatemplates-plugin/src/test/java/org/apache/struts2/views/java/simple/ActionMessageTest.java
    struts/sandbox/trunk/struts2-javatemplates-plugin/src/test/java/org/apache/struts2/views/java/simple/DivTest.java
    struts/sandbox/trunk/struts2-javatemplates-plugin/src/test/java/org/apache/struts2/views/java/simple/FieldErrorTest.java
Modified:
    struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/simple/ActionErrorHandler.java
    struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/simple/SimpleTheme.java
    struts/sandbox/trunk/struts2-javatemplates-plugin/src/test/java/org/apache/struts2/views/java/simple/ActionErrorTest.java
    struts/sandbox/trunk/struts2-javatemplates-plugin/src/test/java/org/apache/struts2/views/java/simple/AnchorTest.java
    struts/sandbox/trunk/struts2-javatemplates-plugin/src/test/java/org/apache/struts2/views/java/simple/FormTest.java
    struts/sandbox/trunk/struts2-javatemplates-plugin/src/test/java/org/apache/struts2/views/java/simple/SelectTest.java
    struts/sandbox/trunk/struts2-javatemplates-plugin/src/test/java/org/apache/struts2/views/java/simple/TextFieldTest.java

Added: struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/simple/AbstractMessageListHandler.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/simple/AbstractMessageListHandler.java?rev=726799&view=auto
==============================================================================
--- struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/simple/AbstractMessageListHandler.java
(added)
+++ struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/simple/AbstractMessageListHandler.java
Mon Dec 15 13:01:55 2008
@@ -0,0 +1,73 @@
+/*
+ * $Id: AbstractTagHandler.java 726340 2008-12-14 02:45:05Z musachy $
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.struts2.views.java.simple;
+
+import org.apache.struts2.views.java.TagGenerator;
+import org.apache.struts2.views.java.Attributes;
+import org.apache.struts2.util.MakeIterator;
+
+import java.io.IOException;
+import java.util.Map;
+import java.util.Iterator;
+
+public abstract class AbstractMessageListHandler extends AbstractTagHandler implements TagGenerator
{
+    @Override
+    public void generate() throws IOException {
+        Map<String, Object> params = context.getParameters();
+        Object errorsObj = findValue(getListExpression());
+
+        if (errorsObj != null) {
+            Iterator itt = MakeIterator.convert(errorsObj);
+            if (itt.hasNext()) {
+                start("ul", null);
+                while (itt.hasNext()) {
+                    String error = (String) itt.next();
+
+                    //li for each error
+                    start("li", null);
+
+                    //span for error
+                    Attributes attrs = new Attributes();
+                    attrs.addIfExists("style", params.get("cssStyle"))
+                            .add("class", params.containsKey("cssClass") ? (String) params.get("cssClass")
: getItemClass());
+
+                    start("span", attrs);
+                    characters(error);
+                    end("span");
+                    end("li");
+
+                }
+                end("ul");
+            }
+        }
+    }
+
+    /*
+     * Expression used to get list from stack
+     */
+    protected abstract String getListExpression(); 
+
+    /*
+     * default class for span element
+     */
+    protected abstract String getItemClass();
+}
+

Modified: struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/simple/ActionErrorHandler.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/simple/ActionErrorHandler.java?rev=726799&r1=726798&r2=726799&view=diff
==============================================================================
--- struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/simple/ActionErrorHandler.java
(original)
+++ struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/simple/ActionErrorHandler.java
Mon Dec 15 13:01:55 2008
@@ -28,35 +28,13 @@
 import java.util.Map;
 import java.util.Iterator;
 
-public class ActionErrorHandler extends AbstractTagHandler implements TagGenerator {
-    @Override
-    public void generate() throws IOException {
-        Map<String, Object> params = context.getParameters();
-        Object errorsObj = findValue("actionErrors");
-
-        if (errorsObj != null) {
-            Iterator itt = MakeIterator.convert(errorsObj);
-            if (itt.hasNext()) {
-                start("ul", null);
-                while (itt.hasNext()) {
-                    String error = (String) itt.next();
-
-                    //li for each error
-                    start("li", null);
-
-                    //span for error
-                    Attributes attrs = new Attributes();
-                    attrs.addIfExists("style", params.get("cssStyle"))
-                            .add("class", params.containsKey("cssClass") ? (String) params.get("cssClass")
: "errorMessage");
-
-                    start("span", attrs);
-                    characters(error);
-                    end("span");
-                    end("li");
+public class ActionErrorHandler extends AbstractMessageListHandler {
+    protected String getListExpression() {
+        return "actionErrors";
+    }
 
-                }
-                end("ul");
-            }
-        }
+    @Override
+    protected String getItemClass() {
+        return "errorMessage"; 
     }
 }

Added: struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/simple/ActionMessageHandler.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/simple/ActionMessageHandler.java?rev=726799&view=auto
==============================================================================
--- struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/simple/ActionMessageHandler.java
(added)
+++ struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/simple/ActionMessageHandler.java
Mon Dec 15 13:01:55 2008
@@ -0,0 +1,12 @@
+package org.apache.struts2.views.java.simple;
+
+public class ActionMessageHandler extends AbstractMessageListHandler {
+     protected String getListExpression() {
+        return "actionMessages";
+    }
+
+    @Override
+    protected String getItemClass() {
+        return "actionMessage";
+    }
+}

Added: struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/simple/DivHandler.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/simple/DivHandler.java?rev=726799&view=auto
==============================================================================
--- struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/simple/DivHandler.java
(added)
+++ struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/simple/DivHandler.java
Mon Dec 15 13:01:55 2008
@@ -0,0 +1,42 @@
+/*
+ * $Id: CommonAttributesHandler.java 726340 2008-12-14 02:45:05Z musachy $
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.struts2.views.java.simple;
+
+import org.apache.struts2.views.java.TagGenerator;
+import org.apache.struts2.views.java.Attributes;
+
+import java.io.IOException;
+import java.util.Map;
+
+public class DivHandler extends AbstractTagHandler implements TagGenerator {
+    @Override
+    public void generate() throws IOException {
+        Map<String, Object> params = context.getParameters();
+        Attributes attrs = new Attributes();
+        attrs.addIfExists("name", params.get("name"))
+                .addIfExists("id", params.get("id"))
+                .addIfExists("class", params.get("cssClass"))
+                .addIfExists("style", params.get("cssStyle"))
+                .addIfExists("title", params.get("title"));
+        start("div", attrs);
+        end("div");
+    }
+}

Added: struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/simple/FieldErrorHandler.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/simple/FieldErrorHandler.java?rev=726799&view=auto
==============================================================================
--- struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/simple/FieldErrorHandler.java
(added)
+++ struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/simple/FieldErrorHandler.java
Mon Dec 15 13:01:55 2008
@@ -0,0 +1,81 @@
+/*
+ * $Id$
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.struts2.views.java.simple;
+
+import org.apache.struts2.views.java.TagGenerator;
+import org.apache.struts2.views.java.Attributes;
+import org.apache.struts2.util.MakeIterator;
+
+import java.io.IOException;
+import java.util.Map;
+import java.util.Iterator;
+import java.util.List;
+
+public class FieldErrorHandler extends AbstractTagHandler implements TagGenerator {
+    @Override
+    public void generate() throws IOException {
+        Map<String, Object> params = context.getParameters();
+        Map<String, List<String>> errors = (Map<String, List<String>>)
findValue("fieldErrors");
+        List<String> fieldErrorFieldNames = (List<String>) findValue("fieldErrorFieldNames");
+
+        if (fieldErrorFieldNames != null && !fieldErrorFieldNames.isEmpty()) {
+            //wrapping ul
+            Attributes attrs = new Attributes();
+            attrs.addIfExists("style", params.get("cssStyle"))
+                    .add("class", params.containsKey("cssClass") ? (String) params.get("cssClass")
: "errorMessage");
+            start("ul", attrs);
+
+            //iterate over field error names
+            for (String fieldErrorFieldName : fieldErrorFieldNames) {
+                List<String> fieldErrors = errors.get(fieldErrorFieldName);
+                if (fieldErrors != null) {
+                    for (String fieldError : fieldErrors) {
+                        start("li", null);
+                        start("span", null);
+                        characters(fieldError);
+                        end("span");
+                        end("li");
+                    }
+                }
+            }
+
+            end("ul");
+        } else if (errors != null && !errors.isEmpty()) {
+            //wrapping ul
+            Attributes attrs = new Attributes();
+            attrs.addIfExists("style", params.get("cssStyle"))
+                    .add("class", params.containsKey("cssClass") ? (String) params.get("cssClass")
: "errorMessage");
+            start("ul", attrs);
+
+            for (Map.Entry<String, List<String>> errorEntry : errors.entrySet())
{
+                for (String fieldError : errorEntry.getValue()) {
+                    start("li", null);
+                    start("span", null);
+                    characters(fieldError);
+                    end("span");
+                    end("li");
+                }
+            }
+
+            end("ul");
+        }
+    }
+}

Modified: struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/simple/SimpleTheme.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/simple/SimpleTheme.java?rev=726799&r1=726798&r2=726799&view=diff
==============================================================================
--- struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/simple/SimpleTheme.java
(original)
+++ struts/sandbox/trunk/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/simple/SimpleTheme.java
Mon Dec 15 13:01:55 2008
@@ -40,6 +40,9 @@
             put("a", new FactoryList(AnchorHandler.class, ScriptingEventsHandler.class, CommonAttributesHandler.class));
             put("checkbox", new FactoryList(CheckboxHandler.class, ScriptingEventsHandler.class,
CommonAttributesHandler.class));
             put("actionerror", new FactoryList(ActionErrorHandler.class));
+            put("actionmessage", new FactoryList(ActionMessageHandler.class));
+            put("fielderror", new FactoryList(FieldErrorHandler.class));
+            put("div", new FactoryList(DivHandler.class, ScriptingEventsHandler.class, CommonAttributesHandler.class));
             put("empty", new FactoryList(EmptyHandler.class));
         }});
         setName("simple");

Modified: struts/sandbox/trunk/struts2-javatemplates-plugin/src/test/java/org/apache/struts2/views/java/simple/ActionErrorTest.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-javatemplates-plugin/src/test/java/org/apache/struts2/views/java/simple/ActionErrorTest.java?rev=726799&r1=726798&r2=726799&view=diff
==============================================================================
--- struts/sandbox/trunk/struts2-javatemplates-plugin/src/test/java/org/apache/struts2/views/java/simple/ActionErrorTest.java
(original)
+++ struts/sandbox/trunk/struts2-javatemplates-plugin/src/test/java/org/apache/struts2/views/java/simple/ActionErrorTest.java
Mon Dec 15 13:01:55 2008
@@ -65,7 +65,7 @@
 
     @Override
     protected void setUp() throws Exception {
-        this.errors = new ArrayList();
+        this.errors = new ArrayList<String>();
         this.errors.add("this clas is bad");
         this.errors.add("baaaaad");
 

Added: struts/sandbox/trunk/struts2-javatemplates-plugin/src/test/java/org/apache/struts2/views/java/simple/ActionMessageTest.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-javatemplates-plugin/src/test/java/org/apache/struts2/views/java/simple/ActionMessageTest.java?rev=726799&view=auto
==============================================================================
--- struts/sandbox/trunk/struts2-javatemplates-plugin/src/test/java/org/apache/struts2/views/java/simple/ActionMessageTest.java
(added)
+++ struts/sandbox/trunk/struts2-javatemplates-plugin/src/test/java/org/apache/struts2/views/java/simple/ActionMessageTest.java
Mon Dec 15 13:01:55 2008
@@ -0,0 +1,73 @@
+package org.apache.struts2.views.java.simple;
+
+import org.apache.struts2.components.ActionError;
+import org.apache.struts2.components.UIBean;
+import org.apache.struts2.components.Anchor;
+
+import java.util.List;
+import java.util.ArrayList;
+
+public class ActionMessageTest extends AbstractTest {
+    private ActionError tag;
+    private List<String> errors;
+
+    public void testRenderActionError() {
+        tag.setCssClass("class");
+        tag.setCssStyle("style");
+
+        tag.evaluateParams();
+        map.putAll(tag.getParameters());
+        theme.renderTag(getTagName(), context);
+        String output = writer.getBuffer().toString();
+        String expected = s("<ul><li><span style='style' class='class'>this
clas is bad</span></li><li><span style='style' class='class'>baaaaad</span></li></ul>");
+        assertEquals(expected, output);
+    }
+
+    public void testRenderActionErrorWithoutCssClass() {
+        tag.setCssStyle("style");
+
+        tag.evaluateParams();
+        map.putAll(tag.getParameters());
+        theme.renderTag(getTagName(), context);
+        String output = writer.getBuffer().toString();
+        String expected = s("<ul><li><span style='style' class='actionMessage'>this
clas is bad</span></li><li><span style='style' class='actionMessage'>baaaaad</span></li></ul>");
+        assertEquals(expected, output);
+    }
+
+    public void testRenderActionErrorNoErrors() {
+        this.errors.clear();
+        tag.evaluateParams();
+        map.putAll(tag.getParameters());
+        theme.renderTag(getTagName(), context);
+        String output = writer.getBuffer().toString();
+        assertEquals("", output);
+    }
+
+    @Override
+    protected void setUp() throws Exception {
+        this.errors = new ArrayList<String>();
+        this.errors.add("this clas is bad");
+        this.errors.add("baaaaad");
+
+        //errors are needed to setup stack
+        super.setUp();
+        this.tag = new ActionError(stack, request, response);
+    }
+
+    @Override
+    protected void setUpStack() {
+        super.setUpStack();
+        expectFind("actionMessages", this.errors);
+    }
+
+    @Override
+    protected UIBean getUIBean() {
+        return tag;
+    }
+
+    @Override
+    protected String getTagName() {
+        return "actionmessage";
+    }
+}
+

Modified: struts/sandbox/trunk/struts2-javatemplates-plugin/src/test/java/org/apache/struts2/views/java/simple/AnchorTest.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-javatemplates-plugin/src/test/java/org/apache/struts2/views/java/simple/AnchorTest.java?rev=726799&r1=726798&r2=726799&view=diff
==============================================================================
--- struts/sandbox/trunk/struts2-javatemplates-plugin/src/test/java/org/apache/struts2/views/java/simple/AnchorTest.java
(original)
+++ struts/sandbox/trunk/struts2-javatemplates-plugin/src/test/java/org/apache/struts2/views/java/simple/AnchorTest.java
Mon Dec 15 13:01:55 2008
@@ -38,7 +38,7 @@
 
         tag.evaluateParams();
         map.putAll(tag.getParameters());
-        theme.renderTag("a", context);
+        theme.renderTag(getTagName(), context);
         String output = writer.getBuffer().toString();
         String expected = s("<a name='name_' id='id_' class='class' style='style' href='http://sometest.com?ab=10'
title='title' tabindex='1'></a>");
         assertEquals(expected, output);
@@ -52,7 +52,7 @@
 
     @Override
     protected UIBean getUIBean() {
-        return new Anchor(stack, request, response);
+        return tag;
     }
 
     @Override

Added: struts/sandbox/trunk/struts2-javatemplates-plugin/src/test/java/org/apache/struts2/views/java/simple/DivTest.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-javatemplates-plugin/src/test/java/org/apache/struts2/views/java/simple/DivTest.java?rev=726799&view=auto
==============================================================================
--- struts/sandbox/trunk/struts2-javatemplates-plugin/src/test/java/org/apache/struts2/views/java/simple/DivTest.java
(added)
+++ struts/sandbox/trunk/struts2-javatemplates-plugin/src/test/java/org/apache/struts2/views/java/simple/DivTest.java
Mon Dec 15 13:01:55 2008
@@ -0,0 +1,61 @@
+/*
+ * $Id$
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.struts2.views.java.simple;
+
+import org.apache.struts2.components.Anchor;
+import org.apache.struts2.components.UIBean;
+import org.apache.struts2.components.Div;
+
+public class DivTest extends AbstractCommonAttributesTest {
+    private Div tag;
+
+    public void testRenderAnchor() {
+        tag.setName("name_");
+        tag.setDisabled("true");
+        tag.setId("id_");
+        tag.setCssClass("class");
+        tag.setCssStyle("style");
+        tag.setTitle("title");
+
+        tag.evaluateParams();
+        map.putAll(tag.getParameters());
+        theme.renderTag(getTagName(), context);
+        String output = writer.getBuffer().toString();
+        String expected = s("<div name='name_' id='id_' class='class' style='style' title='title'></div>");
+        assertEquals(expected, output);
+    }
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        this.tag = new Div(stack, request, response);
+    }
+
+    @Override
+    protected UIBean getUIBean() {
+        return tag;
+    }
+
+    @Override
+    protected String getTagName() {
+        return "div";
+    }
+}

Added: struts/sandbox/trunk/struts2-javatemplates-plugin/src/test/java/org/apache/struts2/views/java/simple/FieldErrorTest.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-javatemplates-plugin/src/test/java/org/apache/struts2/views/java/simple/FieldErrorTest.java?rev=726799&view=auto
==============================================================================
--- struts/sandbox/trunk/struts2-javatemplates-plugin/src/test/java/org/apache/struts2/views/java/simple/FieldErrorTest.java
(added)
+++ struts/sandbox/trunk/struts2-javatemplates-plugin/src/test/java/org/apache/struts2/views/java/simple/FieldErrorTest.java
Mon Dec 15 13:01:55 2008
@@ -0,0 +1,122 @@
+/*
+ * $Id$
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.struts2.views.java.simple;
+
+import org.apache.struts2.components.UIBean;
+import org.apache.struts2.components.FieldError;
+
+import java.util.*;
+
+public class FieldErrorTest extends AbstractTest {
+    private FieldError tag;
+    private Map<String, List<String>> errors;
+    private List<String> fieldNames;
+
+    public void testRenderFieldError() {
+        tag.setCssClass("class");
+        tag.setCssStyle("style");
+
+        tag.evaluateParams();
+        map.putAll(tag.getParameters());
+        theme.renderTag(getTagName(), context);
+        String output = writer.getBuffer().toString();
+        String expected = s("<ul style='style' class='class'><li><span>not
good</span></li><li><span>bad</span></li><li><span>bad
to the bone</span></li></ul>");
+        assertEquals(expected, output);
+    }
+
+    public void testRenderFieldErrorWithoutCssClass() {
+        tag.setCssStyle("style");
+
+        tag.evaluateParams();
+        map.putAll(tag.getParameters());
+        theme.renderTag(getTagName(), context);
+        String output = writer.getBuffer().toString();
+        String expected = s("<ul style='style' class='errorMessage'><li><span>not
good</span></li><li><span>bad</span></li><li><span>bad
to the bone</span></li></ul>");
+        assertEquals(expected, output);
+    }
+
+    public void testRenderFieldErrorWithoutFieldName() {
+        this.fieldNames.clear();
+
+        tag.evaluateParams();
+        map.putAll(tag.getParameters());
+        theme.renderTag(getTagName(), context);
+        String output = writer.getBuffer().toString();
+        String expected = s("<ul class='errorMessage'><li><span>bad to
the bone</span></li><li><span>not good</span></li><li><span>bad</span></li></ul>");
+        assertEquals(expected, output);
+    }
+
+     public void testRenderFieldErrorWithoutOneFieldName() {
+        this.fieldNames.remove(1);
+
+        tag.evaluateParams();
+        map.putAll(tag.getParameters());
+        theme.renderTag(getTagName(), context);
+        String output = writer.getBuffer().toString();
+        String expected = s("<ul class='errorMessage'><li><span>not good</span></li><li><span>bad</span></li></ul>");
+        assertEquals(expected, output);
+    }
+
+    public void testRenderActionErrorNoErrors() {
+        this.errors.clear();
+        this.fieldNames.clear();
+
+        tag.evaluateParams();
+        map.putAll(tag.getParameters());
+        theme.renderTag(getTagName(), context);
+        String output = writer.getBuffer().toString();
+        assertEquals("", output);
+    }
+
+    @Override
+    protected void setUp() throws Exception {
+        this.errors = new HashMap<String, List<String>>(){
+            {
+                put("field1", Arrays.asList("not good", "bad"));
+                put("field2", Arrays.asList("bad to the bone"));
+            }
+        };
+        this.fieldNames = new ArrayList<String>();
+        this.fieldNames.add("field1");
+        this.fieldNames.add("field2");
+
+        //errors are needed to setup stack
+        super.setUp();
+        this.tag = new FieldError(stack, request, response);
+    }
+
+    @Override
+    protected void setUpStack() {
+        super.setUpStack();
+        expectFind("fieldErrorFieldNames", this.fieldNames);
+        expectFind("fieldErrors", this.errors);
+    }
+
+    @Override
+    protected UIBean getUIBean() {
+        return tag;
+    }
+
+    @Override
+    protected String getTagName() {
+        return "fielderror";
+    }
+}

Modified: struts/sandbox/trunk/struts2-javatemplates-plugin/src/test/java/org/apache/struts2/views/java/simple/FormTest.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-javatemplates-plugin/src/test/java/org/apache/struts2/views/java/simple/FormTest.java?rev=726799&r1=726798&r2=726799&view=diff
==============================================================================
--- struts/sandbox/trunk/struts2-javatemplates-plugin/src/test/java/org/apache/struts2/views/java/simple/FormTest.java
(original)
+++ struts/sandbox/trunk/struts2-javatemplates-plugin/src/test/java/org/apache/struts2/views/java/simple/FormTest.java
Mon Dec 15 13:01:55 2008
@@ -46,7 +46,7 @@
 
         tag.evaluateParams();
         map.putAll(tag.getParameters());
-        theme.renderTag("form", context);
+        theme.renderTag(getTagName(), context);
         String output = writer.getBuffer().toString();
         String expected = s("<form name='name_' id='id_' onsubmit='submit' onreset='reset'
target='target_' enctype='enc' class='class_' style='style_' title='title' accept-charset='charset_'
method='post'></form>");
         assertEquals(expected, output);
@@ -55,7 +55,7 @@
     public void testDefaultMethod() {
         tag.evaluateParams();
         map.putAll(tag.getParameters());
-        theme.renderTag("form", context);
+        theme.renderTag(getTagName(), context);
         String output = writer.getBuffer().toString();
         String expected = s("<form method='post'></form>");
         assertEquals(expected, output);

Modified: struts/sandbox/trunk/struts2-javatemplates-plugin/src/test/java/org/apache/struts2/views/java/simple/SelectTest.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-javatemplates-plugin/src/test/java/org/apache/struts2/views/java/simple/SelectTest.java?rev=726799&r1=726798&r2=726799&view=diff
==============================================================================
--- struts/sandbox/trunk/struts2-javatemplates-plugin/src/test/java/org/apache/struts2/views/java/simple/SelectTest.java
(original)
+++ struts/sandbox/trunk/struts2-javatemplates-plugin/src/test/java/org/apache/struts2/views/java/simple/SelectTest.java
Mon Dec 15 13:01:55 2008
@@ -43,7 +43,7 @@
 
         tag.evaluateParams();
         map.putAll(tag.getParameters());
-        theme.renderTag("select", context);
+        theme.renderTag(getTagName(), context);
         String output = writer.getBuffer().toString();
         String expected = s("<select name='name_' size='10' tabindex='1' id='id_' class='class'
style='style' title='title'></select>");
         assertEquals(expected, output);
@@ -56,7 +56,7 @@
 
         tag.evaluateParams();
         map.putAll(tag.getParameters());
-        theme.renderTag("select", context);
+        theme.renderTag(getTagName(), context);
         String output = writer.getBuffer().toString();
         String expected = s("<select name=''><option value='key0'>val</option></select>");
         assertEquals(expected, output);
@@ -69,7 +69,7 @@
 
         tag.evaluateParams();
         map.putAll(tag.getParameters());
-        theme.renderTag("select", context);
+        theme.renderTag(getTagName(), context);
         String output = writer.getBuffer().toString();
         String expected = s("<select name=''><option value='1'>val</option></select>");
         assertEquals(expected, output);
@@ -80,7 +80,7 @@
 
         tag.evaluateParams();
         map.putAll(tag.getParameters());
-        theme.renderTag("select", context);
+        theme.renderTag(getTagName(), context);
         String output = writer.getBuffer().toString();
         String expected = s("<select name=''><option value='key0'>val</option></select>");
         assertEquals(expected, output);
@@ -94,7 +94,7 @@
 
         tag.evaluateParams();
         map.putAll(tag.getParameters());
-        theme.renderTag("select", context);
+        theme.renderTag(getTagName(), context);
         String output = writer.getBuffer().toString();
         String expected = s("<select name='' value='1'><option value='1' selected='selected'>val</option></select>");
         assertEquals(expected, output);

Modified: struts/sandbox/trunk/struts2-javatemplates-plugin/src/test/java/org/apache/struts2/views/java/simple/TextFieldTest.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-javatemplates-plugin/src/test/java/org/apache/struts2/views/java/simple/TextFieldTest.java?rev=726799&r1=726798&r2=726799&view=diff
==============================================================================
--- struts/sandbox/trunk/struts2-javatemplates-plugin/src/test/java/org/apache/struts2/views/java/simple/TextFieldTest.java
(original)
+++ struts/sandbox/trunk/struts2-javatemplates-plugin/src/test/java/org/apache/struts2/views/java/simple/TextFieldTest.java
Mon Dec 15 13:01:55 2008
@@ -42,7 +42,7 @@
 
         tag.evaluateParams();
         map.putAll(tag.getParameters());
-        theme.renderTag("textfield", context);
+        theme.renderTag(getTagName(), context);
         String output = writer.getBuffer().toString();
         String expected = s("<input type='text' name='name' size='10' maxlength='11' value='val1'
tabindex='1' id='id1' class='class1' style='style1' title='title'></input>");
         assertEquals(expected, output);



Mime
View raw message