struts-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cnenn...@apache.org
Subject [04/13] struts git commit: added tests for StrutsTilesAnnotationProcessor
Date Wed, 03 Feb 2016 09:53:39 GMT
added tests for StrutsTilesAnnotationProcessor

Project: http://git-wip-us.apache.org/repos/asf/struts/repo
Commit: http://git-wip-us.apache.org/repos/asf/struts/commit/d76357fd
Tree: http://git-wip-us.apache.org/repos/asf/struts/tree/d76357fd
Diff: http://git-wip-us.apache.org/repos/asf/struts/diff/d76357fd

Branch: refs/heads/master
Commit: d76357fd829a3ea8ddca21d625c49b606cca88d5
Parents: e50c37c
Author: cnenning <cnenning@apache.org>
Authored: Mon Jan 25 11:23:10 2016 +0100
Committer: cnenning <cnenning@apache.org>
Committed: Mon Jan 25 11:23:10 2016 +0100

----------------------------------------------------------------------
 .../tiles/StrutsTilesAnnotationProcessor.java   |   7 +-
 .../TestStrutsTilesAnnotationProcessor.java     | 148 +++++++++++++++++++
 .../TilesTestActionMultipleAnnotations.java     |  12 ++
 .../tiles/TilesTestActionSingleAnnotation.java  |  49 ++++++
 ...TilesTestActionSingleAnnotationAllEmpty.java |  28 ++++
 5 files changed, 241 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/struts/blob/d76357fd/plugins/tiles/src/main/java/org/apache/struts2/tiles/StrutsTilesAnnotationProcessor.java
----------------------------------------------------------------------
diff --git a/plugins/tiles/src/main/java/org/apache/struts2/tiles/StrutsTilesAnnotationProcessor.java
b/plugins/tiles/src/main/java/org/apache/struts2/tiles/StrutsTilesAnnotationProcessor.java
index 2ae3ba4..fa5f735 100644
--- a/plugins/tiles/src/main/java/org/apache/struts2/tiles/StrutsTilesAnnotationProcessor.java
+++ b/plugins/tiles/src/main/java/org/apache/struts2/tiles/StrutsTilesAnnotationProcessor.java
@@ -66,9 +66,10 @@ public class StrutsTilesAnnotationProcessor {
                         break;
                     }
                 }
-            }
-            if (tilesDefinitions.value().length > 0) {
-                tilesDefinition = tilesDefinitions.value()[0];
+            } else {
+                if (tilesDefinitions.value().length > 0) {
+                    tilesDefinition = tilesDefinitions.value()[0];
+                }
             }
         }
 

http://git-wip-us.apache.org/repos/asf/struts/blob/d76357fd/plugins/tiles/src/test/java/org/apache/struts2/tiles/TestStrutsTilesAnnotationProcessor.java
----------------------------------------------------------------------
diff --git a/plugins/tiles/src/test/java/org/apache/struts2/tiles/TestStrutsTilesAnnotationProcessor.java
b/plugins/tiles/src/test/java/org/apache/struts2/tiles/TestStrutsTilesAnnotationProcessor.java
new file mode 100644
index 0000000..db808cd
--- /dev/null
+++ b/plugins/tiles/src/test/java/org/apache/struts2/tiles/TestStrutsTilesAnnotationProcessor.java
@@ -0,0 +1,148 @@
+package org.apache.struts2.tiles;
+
+import java.util.List;
+import java.util.Set;
+
+import org.apache.struts2.tiles.annotation.TilesDefinition;
+import org.apache.tiles.Attribute;
+import org.apache.tiles.Definition;
+import org.apache.tiles.Expression;
+import org.junit.Test;
+
+import org.junit.Assert;
+
+public class TestStrutsTilesAnnotationProcessor {
+
+    @Test
+    public void findAnnotationSingleAction() {
+        StrutsTilesAnnotationProcessor annotationProcessor = new StrutsTilesAnnotationProcessor();
+        TilesDefinition tilesDefinition = annotationProcessor.findAnnotation(new TilesTestActionSingleAnnotation(),
null);
+        Assert.assertNotNull(tilesDefinition);
+        Assert.assertEquals("definition-name", tilesDefinition.name());
+    }
+
+    @Test
+    public void findAnnotationMultipleActionNameNull() {
+        StrutsTilesAnnotationProcessor annotationProcessor = new StrutsTilesAnnotationProcessor();
+        TilesDefinition tilesDefinition = annotationProcessor.findAnnotation(new TilesTestActionMultipleAnnotations(),
null);
+        Assert.assertNotNull(tilesDefinition);
+        Assert.assertEquals("def1", tilesDefinition.name());
+    }
+
+    @Test
+    public void findAnnotationMultipleActionNameGiven() {
+        StrutsTilesAnnotationProcessor annotationProcessor = new StrutsTilesAnnotationProcessor();
+        TilesDefinition tilesDefinition = annotationProcessor.findAnnotation(new TilesTestActionMultipleAnnotations(),
"def2");
+        Assert.assertNotNull(tilesDefinition);
+        Assert.assertEquals("def2", tilesDefinition.name());
+    }
+
+    @Test
+    public void findAnnotationMultipleActionNotFound() {
+        StrutsTilesAnnotationProcessor annotationProcessor = new StrutsTilesAnnotationProcessor();
+        TilesDefinition tilesDefinition = annotationProcessor.findAnnotation(new TilesTestActionMultipleAnnotations(),
"def3");
+        Assert.assertNull(tilesDefinition);
+    }
+
+    @Test
+    public void buildDefiniton() {
+        StrutsTilesAnnotationProcessor annotationProcessor = new StrutsTilesAnnotationProcessor();
+        TilesDefinition tilesDefinition = annotationProcessor.findAnnotation(new TilesTestActionSingleAnnotation(),
null);
+
+        Definition definition = annotationProcessor.buildTilesDefinition("tileName", tilesDefinition);
+
+        Assert.assertNotNull(definition);
+        Assert.assertEquals("tileName", definition.getName());
+        Assert.assertEquals("preparer", definition.getPreparer());
+        Assert.assertEquals("base-definition", definition.getExtends());
+        Attribute templateAttribute = definition.getTemplateAttribute();
+        Assert.assertEquals("template", templateAttribute.getValue());
+        Assert.assertEquals("type", templateAttribute.getRenderer());
+        Assert.assertEquals("role", templateAttribute.getRole());
+        Expression definitionExpressionObject = templateAttribute.getExpressionObject();
+        Assert.assertEquals("templ*", definitionExpressionObject.getExpression());
+        Assert.assertNull(definitionExpressionObject.getLanguage());
+
+        Attribute putAttribute = definition.getAttribute("put-attr");
+        Assert.assertNotNull(putAttribute);
+        Assert.assertEquals("attr-val", putAttribute.getValue());
+        Assert.assertEquals("attr-type", putAttribute.getRenderer());
+        Assert.assertEquals("attr-role", putAttribute.getRole());
+        Expression putAttrExpressionObject = putAttribute.getExpressionObject();
+        Assert.assertEquals("expr", putAttrExpressionObject.getExpression());
+        Assert.assertEquals("lang", putAttrExpressionObject.getLanguage());
+
+        Attribute listAttribute = definition.getAttribute("list-name");
+        Assert.assertEquals("list-role", listAttribute.getRole());
+        List<Attribute> listValue = getListValue(listAttribute);
+        Assert.assertEquals(2, listValue.size());
+
+        Attribute addAttribute = listValue.get(0);
+        Assert.assertEquals("list-attr-role", addAttribute.getRole());
+        Assert.assertEquals("list-attr-val", addAttribute.getValue());
+        Assert.assertEquals("list-attr-type", addAttribute.getRenderer());
+        Expression addAttrExpressionObject = addAttribute.getExpressionObject();
+        Assert.assertEquals("list-attr-expr", addAttrExpressionObject.getExpression());
+
+        Attribute addListAttribute = listValue.get(1);
+        Assert.assertEquals("list-list-attr-role", addListAttribute.getRole());
+        List<Attribute> addListValue = getListValue(addListAttribute);
+        Assert.assertEquals(1, addListValue.size());
+        Assert.assertEquals("list-list-add-attr", addListValue.get(0).getValue());
+
+        Set<String> cascadedAttributeNames = definition.getCascadedAttributeNames();
+        Assert.assertEquals(2, cascadedAttributeNames.size());
+        Assert.assertTrue(cascadedAttributeNames.contains("put-attr"));
+        Assert.assertTrue(cascadedAttributeNames.contains("list-name"));
+    }
+
+    @Test
+    public void buildDefinitonAllEmpty() {
+        StrutsTilesAnnotationProcessor annotationProcessor = new StrutsTilesAnnotationProcessor();
+        TilesDefinition tilesDefinition = annotationProcessor.findAnnotation(new TilesTestActionSingleAnnotationAllEmpty(),
null);
+
+        Definition definition = annotationProcessor.buildTilesDefinition(null, tilesDefinition);
+
+        Assert.assertNotNull(definition);
+        Assert.assertNull(definition.getName());
+        Assert.assertNull(definition.getPreparer());
+        Assert.assertNull(definition.getExtends());
+        Attribute templateAttribute = definition.getTemplateAttribute();
+        Assert.assertNull(templateAttribute.getValue());
+        //Assert.assertNull(templateAttribute.getRenderer());
+        Assert.assertNull(templateAttribute.getRole());
+        Assert.assertNull(templateAttribute.getExpressionObject());
+
+        Attribute putAttribute = definition.getAttribute("put-attr");
+        Assert.assertNotNull(putAttribute);
+        Assert.assertNull(putAttribute.getValue());
+        Assert.assertNull(putAttribute.getRenderer());
+        Assert.assertNull(putAttribute.getRole());
+        Assert.assertNull(putAttribute.getExpressionObject());
+
+        Attribute listAttribute = definition.getAttribute("list-name");
+        Assert.assertNull(listAttribute.getRole());
+        List<Attribute> listValue = getListValue(listAttribute);
+        Assert.assertEquals(2, listValue.size());
+
+        Attribute addAttribute = listValue.get(0);
+        Assert.assertNull(addAttribute.getRole());
+        Assert.assertNull(addAttribute.getValue());
+        Assert.assertNull(addAttribute.getRenderer());
+        Assert.assertNull(addAttribute.getExpressionObject());
+
+        Attribute addListAttribute = listValue.get(1);
+        Assert.assertNull(addListAttribute.getRole());
+        List<Attribute> addListValue = getListValue(addListAttribute);
+        Assert.assertEquals(1, addListValue.size());
+        Assert.assertNull(addListValue.get(0).getValue());
+
+        Set<String> cascadedAttributeNames = definition.getCascadedAttributeNames();
+        Assert.assertNull(cascadedAttributeNames);
+    }
+
+    @SuppressWarnings("unchecked")
+    protected List<Attribute> getListValue(Attribute listAttribute) {
+        return (List<Attribute>) listAttribute.getValue();
+    }
+}

http://git-wip-us.apache.org/repos/asf/struts/blob/d76357fd/plugins/tiles/src/test/java/org/apache/struts2/tiles/TilesTestActionMultipleAnnotations.java
----------------------------------------------------------------------
diff --git a/plugins/tiles/src/test/java/org/apache/struts2/tiles/TilesTestActionMultipleAnnotations.java
b/plugins/tiles/src/test/java/org/apache/struts2/tiles/TilesTestActionMultipleAnnotations.java
new file mode 100644
index 0000000..99a736b
--- /dev/null
+++ b/plugins/tiles/src/test/java/org/apache/struts2/tiles/TilesTestActionMultipleAnnotations.java
@@ -0,0 +1,12 @@
+package org.apache.struts2.tiles;
+
+import org.apache.struts2.tiles.annotation.TilesDefinition;
+import org.apache.struts2.tiles.annotation.TilesDefinitions;
+
+@TilesDefinitions({
+    @TilesDefinition(name="def1"),
+    @TilesDefinition(name="def2"),
+})
+public class TilesTestActionMultipleAnnotations {
+
+}

http://git-wip-us.apache.org/repos/asf/struts/blob/d76357fd/plugins/tiles/src/test/java/org/apache/struts2/tiles/TilesTestActionSingleAnnotation.java
----------------------------------------------------------------------
diff --git a/plugins/tiles/src/test/java/org/apache/struts2/tiles/TilesTestActionSingleAnnotation.java
b/plugins/tiles/src/test/java/org/apache/struts2/tiles/TilesTestActionSingleAnnotation.java
new file mode 100644
index 0000000..c7a98eb
--- /dev/null
+++ b/plugins/tiles/src/test/java/org/apache/struts2/tiles/TilesTestActionSingleAnnotation.java
@@ -0,0 +1,49 @@
+package org.apache.struts2.tiles;
+
+import org.apache.struts2.tiles.annotation.TilesAddAttribute;
+import org.apache.struts2.tiles.annotation.TilesAddListAttribute;
+import org.apache.struts2.tiles.annotation.TilesDefinition;
+import org.apache.struts2.tiles.annotation.TilesPutAttribute;
+import org.apache.struts2.tiles.annotation.TilesPutListAttribute;
+
+@TilesDefinition(
+        name = "definition-name", 
+        extend = "base-definition", 
+        preparer = "preparer", 
+        role = "role", 
+        template = "template", 
+        templateExpression = "templ*", 
+        templateType = "type",
+        putAttributes = {
+                @TilesPutAttribute(
+                        cascade = true, 
+                        expression = "lang:expr", 
+                        name = "put-attr", 
+                        role = "attr-role", 
+                        type = "attr-type", 
+                        value = "attr-val")
+        },
+        putListAttributes = {
+                @TilesPutListAttribute(
+                        cascade = true, 
+                        inherit = true, 
+                        name = "list-name", 
+                        role = "list-role",
+                        addAttributes = {
+                                @TilesAddAttribute(
+                                        expression = "list-attr-expr", 
+                                        role = "list-attr-role", 
+                                        type = "list-attr-type", 
+                                        value = "list-attr-val")
+                        },
+                        addListAttributes = {
+                                @TilesAddListAttribute(
+                                        role = "list-list-attr-role", 
+                                        addAttributes = {@TilesAddAttribute("list-list-add-attr")})
+                        }
+                )
+        }
+)
+public class TilesTestActionSingleAnnotation {
+
+}

http://git-wip-us.apache.org/repos/asf/struts/blob/d76357fd/plugins/tiles/src/test/java/org/apache/struts2/tiles/TilesTestActionSingleAnnotationAllEmpty.java
----------------------------------------------------------------------
diff --git a/plugins/tiles/src/test/java/org/apache/struts2/tiles/TilesTestActionSingleAnnotationAllEmpty.java
b/plugins/tiles/src/test/java/org/apache/struts2/tiles/TilesTestActionSingleAnnotationAllEmpty.java
new file mode 100644
index 0000000..4a9aff9
--- /dev/null
+++ b/plugins/tiles/src/test/java/org/apache/struts2/tiles/TilesTestActionSingleAnnotationAllEmpty.java
@@ -0,0 +1,28 @@
+package org.apache.struts2.tiles;
+
+import org.apache.struts2.tiles.annotation.TilesAddAttribute;
+import org.apache.struts2.tiles.annotation.TilesAddListAttribute;
+import org.apache.struts2.tiles.annotation.TilesDefinition;
+import org.apache.struts2.tiles.annotation.TilesPutAttribute;
+import org.apache.struts2.tiles.annotation.TilesPutListAttribute;
+
+@TilesDefinition(
+        putAttributes = {
+                @TilesPutAttribute(name = "put-attr")
+        },
+        putListAttributes = {
+                @TilesPutListAttribute(
+                        name = "list-name",
+                        addAttributes = {
+                                @TilesAddAttribute()
+                        },
+                        addListAttributes = {
+                                @TilesAddListAttribute(
+                                        addAttributes = {@TilesAddAttribute()})
+                        }
+                )
+        }
+)
+public class TilesTestActionSingleAnnotationAllEmpty {
+
+}


Mime
View raw message