Return-Path: X-Original-To: apmail-struts-dev-archive@www.apache.org Delivered-To: apmail-struts-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 3BD8017810 for ; Fri, 29 Jan 2016 16:56:40 +0000 (UTC) Received: (qmail 59117 invoked by uid 500); 29 Jan 2016 16:56:39 -0000 Delivered-To: apmail-struts-dev-archive@struts.apache.org Received: (qmail 59076 invoked by uid 500); 29 Jan 2016 16:56:39 -0000 Mailing-List: contact dev-help@struts.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Help: List-Post: List-Id: "Struts Developers List" Reply-To: "Struts Developers List" Delivered-To: mailing list dev@struts.apache.org Received: (qmail 59058 invoked by uid 99); 29 Jan 2016 16:56:39 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 29 Jan 2016 16:56:39 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 8A193E03BE; Fri, 29 Jan 2016 16:56:39 +0000 (UTC) From: lukaszlenart To: dev@struts.apache.org Reply-To: dev@struts.apache.org References: In-Reply-To: Subject: [GitHub] struts pull request: WW-4594: Configure TilesDefs by annotating Ac... Content-Type: text/plain Message-Id: <20160129165639.8A193E03BE@git1-us-west.apache.org> Date: Fri, 29 Jan 2016 16:56:39 +0000 (UTC) Github user lukaszlenart commented on a diff in the pull request: https://github.com/apache/struts/pull/85#discussion_r51285068 --- Diff: plugins/tiles/src/test/java/org/apache/struts2/tiles/StrutsTilesAnnotationProcessorTest.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 StrutsTilesAnnotationProcessorTest { + + @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 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 addListValue = getListValue(addListAttribute); + Assert.assertEquals(1, addListValue.size()); + Assert.assertEquals("list-list-add-attr", addListValue.get(0).getValue()); + + Set 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()); --- End diff -- If not used maybe it can be dropped? --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastructure@apache.org or file a JIRA ticket with INFRA. --- --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org For additional commands, e-mail: dev-help@struts.apache.org