jspwiki-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ajaqu...@apache.org
Subject svn commit: r723198 [3/3] - in /incubator/jspwiki/trunk: ./ src/com/ecyrd/jspwiki/ src/com/ecyrd/jspwiki/action/ src/com/ecyrd/jspwiki/content/ src/com/ecyrd/jspwiki/log/ src/com/ecyrd/jspwiki/plugin/ src/com/ecyrd/jspwiki/tags/ src/com/ecyrd/jspwiki/u...
Date Thu, 04 Dec 2008 03:10:39 GMT
Added: incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/ui/migrator/JspParserTest.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/ui/migrator/JspParserTest.java?rev=723198&view=auto
==============================================================================
--- incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/ui/migrator/JspParserTest.java (added)
+++ incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/ui/migrator/JspParserTest.java Wed Dec  3 19:10:36 2008
@@ -0,0 +1,779 @@
+package com.ecyrd.jspwiki.ui.migrator;
+
+import java.io.File;
+import java.util.List;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+public class JspParserTest extends TestCase
+{
+    public JspParserTest( String s )
+    {
+        super( s );
+    }
+    
+    public void testDeclaration() throws Exception
+    {
+        String s = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><html/>";
+        
+        // Parse the contents
+        JspParser parser = new JspParser();
+        JspDocument doc = parser.parse( s );
+        
+        // Verify 2 nodes total
+        List<Node> nodes = doc.getNodes();
+        assertEquals( 2, nodes.size() );
+        
+        // First node is XML declaration
+        Tag node = (Tag)nodes.get( 0 );
+        assertEquals( "xml", node.getName() );
+        assertEquals( null, node.getValue() );
+        assertEquals( NodeType.DECLARATION, node.getType() );
+        assertEquals( 2, node.getAttributes().size() );
+    }
+    
+    public void testParseDoctype() throws Exception
+    {
+        String s = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">";
+        
+        // Parse the contents
+        JspParser parser = new JspParser();
+        JspDocument doc = parser.parse( s );
+        
+        // Verify three nodes total
+        List<Node> nodes = doc.getNodes();
+        assertEquals( 1, nodes.size() );
+        Node node = nodes.get( 0 );
+        assertEquals( "(TEXT)", node.getName() );
+        assertEquals( NodeType.DOCTYPE, node.getType() );
+        assertEquals( "html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"", node.getValue() );
+        assertEquals( s, node.toString() );
+    }
+
+    public void testMeta() throws Exception
+    {
+        String s = "<META name=\"Author\" content=\"Dave Raggett\">";
+        
+        // Parse the contents
+        JspParser parser = new JspParser();
+        JspDocument doc = parser.parse( s );
+        
+        // Verify three nodes total
+        List<Node> nodes = doc.getNodes();
+        assertEquals( 1, nodes.size() );
+        Tag tag = (Tag)nodes.get( 0 );
+        assertEquals( "META", tag.getName() );
+        assertEquals( NodeType.META, tag.getType() );
+        assertEquals( 2, tag.getAttributes().size() );
+        assertEquals( "name", tag.getAttribute( "name" ).getName() );
+        assertEquals( "Author", tag.getAttribute( "name" ).getValue() );
+        assertEquals( "content", tag.getAttribute( "content" ).getName() );
+        assertEquals( "Dave Raggett", tag.getAttribute( "content" ).getValue() );
+        assertEquals( s, tag.toString() );
+    }
+    
+    public void testLink() throws Exception
+    {
+        String s = "<LINK rel=\"Start\" title=\"First\" type=\"text/html\" href=\"http://start.html\">";
+        
+        // Parse the contents
+        JspParser parser = new JspParser();
+        JspDocument doc = parser.parse( s );
+        
+        // Verify three nodes total
+        List<Node> nodes = doc.getNodes();
+        assertEquals( 1, nodes.size() );
+        Tag tag = (Tag)nodes.get( 0 );
+        assertEquals( "LINK", tag.getName() );
+        assertEquals( NodeType.LINK, tag.getType() );
+        assertEquals( 4, tag.getAttributes().size() );
+        assertEquals( "rel", tag.getAttribute( "rel" ).getName() );
+        assertEquals( "Start", tag.getAttribute( "rel" ).getValue() );
+        assertEquals( "title", tag.getAttribute( "title" ).getName() );
+        assertEquals( "First", tag.getAttribute( "title" ).getValue() );
+        assertEquals( "type", tag.getAttribute( "type" ).getName() );
+        assertEquals( "text/html", tag.getAttribute( "type" ).getValue() );
+        assertEquals( "href", tag.getAttribute( "href" ).getName() );
+        assertEquals( "http://start.html", tag.getAttribute( "href" ).getValue() );
+    }
+    
+    public void testNestedAttributes() throws Exception
+    {
+        String s = "<a <b test=\"c\">selected=\"d\"</b> >Foo</a>";
+        
+        // Parse the contents
+        JspParser parser = new JspParser();
+        JspDocument doc = parser.parse( s );
+        
+        // Verify three nodes total
+        List<Node> nodes = doc.getNodes();
+        assertEquals( 3, nodes.size() );
+        
+        // First node is a start tag
+        Node node;
+        node = nodes.get( 0 );
+        assertEquals( "a", node.getName() );
+        assertEquals( NodeType.START_TAG, node.getType() );
+        assertEquals( "<a <b test=\"c\">selected=\"d\"</b> >", node.toString() );
+        
+        // Second node is a Text node
+        node = nodes.get( 1 );
+        assertEquals( NodeType.TEXT, node.getType() );
+        assertEquals( "Foo", node.getValue() );
+        
+        // Third node is an end tag
+        node = nodes.get( 2 );
+        assertEquals( "a", node.getName() );
+        assertEquals( NodeType.END_TAG, node.getType() );
+        
+        // First and third node are children of the root
+        assertEquals( 2, doc.getRoot().getChildren().size() );
+        assertEquals( NodeType.START_TAG, doc.getRoot().getChildren().get( 0 ).getType() );
+        assertEquals( NodeType.END_TAG, doc.getRoot().getChildren().get( 1 ).getType() );
+        
+        // Test first node: should have 3 attributes (2 dynamic)
+        Tag tag = (Tag)nodes.get( 0 );
+        assertEquals( 3, tag.getAttributes().size() );
+        Attribute attribute;
+        attribute = tag.getAttributes().get( 0 );
+        assertEquals( null, attribute.getName() );
+        assertEquals( NodeType.DYNAMIC_ATTRIBUTE, attribute.getType() );
+        assertEquals( "<b test=\"c\">", attribute.getValue() );
+        assertEquals( "<b test=\"c\">", attribute.toString() );
+        attribute = tag.getAttributes().get( 1 );
+        assertEquals( "selected", attribute.getName() );
+        assertEquals( "d", attribute.getValue() );
+        assertEquals( "selected=\"d\"", attribute.toString() );
+        attribute = tag.getAttributes().get( 2 );
+        assertEquals( null, attribute.getName() );
+        assertEquals( NodeType.DYNAMIC_ATTRIBUTE, attribute.getType() );
+        assertEquals( "</b>", attribute.getValue() );
+        assertEquals( "</b>", attribute.toString() );
+    }
+
+    public void testAttributes() throws Exception
+    {
+        String s = "<a b=\"cd\"/>";
+
+        // Parse the contents
+        JspParser parser = new JspParser();
+        JspDocument doc = parser.parse( s );
+
+        // Results in one node
+        List<Node> nodes = doc.getNodes();
+        assertEquals( 1, nodes.size() );
+        Tag node;
+
+        // Verify HTML start tag
+        node = (Tag) nodes.get( 0 );
+        assertEquals( "a", node.getName() );
+        assertEquals( null, node.getValue() );
+        assertEquals( 0, node.getChildren().size() );
+        assertEquals( NodeType.EMPTY_ELEMENT_TAG, node.getType() );
+        assertEquals( "<a b=\"cd\" />", node.toString() );
+
+        // Verify attributes
+        assertEquals( 1, node.getAttributes().size() );
+        Attribute attribute = node.getAttribute( "b" );
+        assertEquals( "b", attribute.getName() );
+        assertEquals( "cd", attribute.getValue() );
+        assertEquals( 3, attribute.getStart() );
+        assertEquals( 9, attribute.getEnd() );
+    }
+
+    public void testCdata() throws Exception
+    {
+        String s = "  <![CDATA[ foo ]]>  ";
+
+        // Parse the contents
+        JspParser parser = new JspParser();
+        JspDocument doc = parser.parse( s );
+
+        // Results in 3 nodes
+        List<Node> nodes = doc.getNodes();
+        assertEquals( 3, nodes.size() );
+        Node node;
+
+        // Verify text tag (0)
+        node = nodes.get( 0 );
+        assertEquals( "(TEXT)", node.getName() );
+        assertEquals( "  ", node.getValue() );
+        assertEquals( 0, node.getChildren().size() );
+        assertEquals( NodeType.TEXT, node.getType() );
+        assertEquals( "  ", node.toString() );
+
+        // Verify CDATA tag (1)
+        node = nodes.get( 1 );
+        assertEquals( "(TEXT)", node.getName() );
+        assertEquals( " foo ", node.getValue() );
+        assertEquals( 0, node.getChildren().size() );
+        assertEquals( NodeType.CDATA, node.getType() );
+        assertEquals( "<![CDATA[ foo ]]>", node.toString() );
+        
+        // Verify text tag (2)
+        node = nodes.get( 2 );
+        assertEquals( "(TEXT)", node.getName() );
+        assertEquals( "  ", node.getValue() );
+        assertEquals( 0, node.getChildren().size() );
+        assertEquals( NodeType.TEXT, node.getType() );
+        assertEquals( "  ", node.toString() );
+    }
+    
+    public void testEmptyElementTag() throws Exception
+    {
+        String s = "<foo />";
+
+        // Parse the contents
+        JspParser parser = new JspParser();
+        JspDocument doc = parser.parse( s );
+
+        // Results in one node
+        List<Node> nodes = doc.getNodes();
+        assertEquals( 1, nodes.size() );
+        Tag node;
+
+        // Verify HTML combined tag
+        node = (Tag) nodes.get( 0 );
+        assertEquals( "foo", node.getName() );
+        assertEquals( null, node.getValue() );
+        assertEquals( 0, node.getChildren().size() );
+        assertEquals( NodeType.EMPTY_ELEMENT_TAG, node.getType() );
+        assertEquals( "<foo/>", node.toString() );
+    }
+
+    public void testParseHtmlComment() throws Exception
+    {
+        String s = "<!-- This is a comment -->";
+
+        // Parse the contents
+        JspParser parser = new JspParser();
+        JspDocument doc = parser.parse( s );
+
+        // Results in one node
+        List<Node> nodes = doc.getNodes();
+        assertEquals( 1, nodes.size() );
+        Text node;
+
+        // Verify comment
+        node = (Text) nodes.get( 0 );
+        assertEquals( "(TEXT)", node.getName() );
+        assertEquals( " This is a comment ", node.getValue() );
+        assertEquals( 0, node.getChildren().size() );
+    }
+
+    public void testParseDirective() throws Exception
+    {
+        String s = "<%@ page import=\"org.apache.log4j.*\" %>";
+
+        // Parse the contents of the file
+        JspParser parser = new JspParser();
+        JspDocument doc = parser.parse( s );
+
+        // Results in one node
+        List<Node> nodes = doc.getNodes();
+        assertEquals( 1, nodes.size() );
+        Tag node;
+        Node attribute;
+
+        // Verify directive
+        node = (Tag) nodes.get( 0 );
+        assertEquals( "page", node.getName() );
+        assertEquals( 1, node.getAttributes().size() );
+        attribute = node.getAttributes().get( 0 );
+        assertEquals( "import", attribute.getName() );
+        assertEquals( "org.apache.log4j.*", attribute.getValue() );
+        assertEquals( "<%@ page import=\"org.apache.log4j.*\" %>", node.toString());
+    }
+    
+    public void testParseDirectiveNoLeadingSpace() throws Exception
+    {
+        String s = "<%@page import=\"org.apache.log4j.*\"%>";
+
+        // Parse the contents of the file
+        JspParser parser = new JspParser();
+        JspDocument doc = parser.parse( s );
+
+        // Results in one node
+        List<Node> nodes = doc.getNodes();
+        assertEquals( 1, nodes.size() );
+        Tag node;
+        Node attribute;
+
+        // Verify directive
+        node = (Tag) nodes.get( 0 );
+        assertEquals( "page", node.getName() );
+        assertEquals( 1, node.getAttributes().size() );
+        attribute = node.getAttributes().get( 0 );
+        assertEquals( "import", attribute.getName() );
+        assertEquals( "org.apache.log4j.*", attribute.getValue() );
+        assertEquals( "<%@ page import=\"org.apache.log4j.*\" %>", node.toString());
+    }
+
+    public void testParse() throws Exception
+    {
+        File src = new File( "src/webdocs/LoginForm.jsp" );
+        String s = JspMigrator.readSource( src );
+
+        // Parse the contents of the file
+        JspParser parser = new JspParser();
+        JspDocument doc = parser.parse( s );
+
+        // Should result in 18 nodes parsed (10 tags/directives + 8
+        // text/whitespace nodes
+        Node node;
+        Node attribute;
+        List<Node> nodes = doc.getNodes();
+        assertEquals( 18, nodes.size() );
+        int i = 0;
+
+        // Test line 1 aka nodes 0+1
+        node = nodes.get( i );
+        assertEquals( 1, node.getLine() );
+        assertEquals( 1, node.getColumn() );
+        assertEquals( 0, node.getStart() );
+        assertEquals( 39, node.getEnd() );
+        assertEquals( 0, node.getChildren().size() );
+        assertEquals( NodeType.JSP_DIRECTIVE, node.getType() );
+        assertEquals( NodeType.ROOT, node.getParent().getType() );
+        assertEquals( 17, node.getSiblings().size() );
+        assertEquals( "page", node.getName() );
+        assertEquals( 1, ((Tag) node).getAttributes().size() );
+        attribute = ((Tag) node).getAttributes().get( 0 );
+        assertEquals( "import", attribute.getName() );
+        assertEquals( "org.apache.log4j.*", attribute.getValue() );
+        i++;
+        node = nodes.get( i );
+        assertEquals( 1, node.getLine() );
+        assertEquals( 40, node.getColumn() );
+        assertEquals( 39, node.getStart() );
+        assertEquals( 40, node.getEnd() );
+        assertEquals( 0, node.getChildren().size() );
+        assertEquals( NodeType.TEXT, node.getType() );
+        assertEquals( NodeType.ROOT, node.getParent().getType() );
+        assertEquals( 17, node.getSiblings().size() );
+        assertEquals( "(TEXT)", node.getName() );
+        i++;
+
+        // Test line 2 aka nodes 2+3
+        node = nodes.get( i );
+        assertEquals( 2, node.getLine() );
+        assertEquals( 1, node.getColumn() );
+        assertEquals( 40, node.getStart() );
+        assertEquals( 80, node.getEnd() );
+        assertEquals( 0, node.getChildren().size() );
+        assertEquals( NodeType.JSP_DIRECTIVE, node.getType() );
+        assertEquals( NodeType.ROOT, node.getParent().getType() );
+        assertEquals( 17, node.getSiblings().size() );
+        assertEquals( "page", node.getName() );
+        assertEquals( 1, ((Tag) node).getAttributes().size() );
+        attribute = ((Tag) node).getAttributes().get( 0 );
+        assertEquals( "import", attribute.getName() );
+        assertEquals( "com.ecyrd.jspwiki.*", attribute.getValue() );
+        i++;
+        node = nodes.get( i );
+        assertEquals( 2, node.getLine() );
+        assertEquals( 41, node.getColumn() );
+        assertEquals( 80, node.getStart() );
+        assertEquals( 81, node.getEnd() );
+        assertEquals( 0, node.getChildren().size() );
+        assertEquals( NodeType.TEXT, node.getType() );
+        assertEquals( NodeType.ROOT, node.getParent().getType() );
+        assertEquals( 17, node.getSiblings().size() );
+        assertEquals( "(TEXT)", node.getName() );
+        i++;
+
+        // Test line 3 aka nodes 4+5
+        node = nodes.get( i );
+        assertEquals( 3, node.getLine() );
+        assertEquals( 1, node.getColumn() );
+        assertEquals( 81, node.getStart() );
+        assertEquals( 128, node.getEnd() );
+        assertEquals( 0, node.getChildren().size() );
+        assertEquals( NodeType.JSP_DIRECTIVE, node.getType() );
+        assertEquals( NodeType.ROOT, node.getParent().getType() );
+        assertEquals( 17, node.getSiblings().size() );
+        assertEquals( "page", node.getName() );
+        assertEquals( 1, ((Tag) node).getAttributes().size() );
+        attribute = ((Tag) node).getAttributes().get( 0 );
+        assertEquals( "import", attribute.getName() );
+        assertEquals( "com.ecyrd.jspwiki.action.*", attribute.getValue() );
+        i++;
+        node = nodes.get( i );
+        assertEquals( 3, node.getLine() );
+        assertEquals( 48, node.getColumn() );
+        assertEquals( 128, node.getStart() );
+        assertEquals( 129, node.getEnd() );
+        assertEquals( 0, node.getChildren().size() );
+        assertEquals( NodeType.TEXT, node.getType() );
+        assertEquals( NodeType.ROOT, node.getParent().getType() );
+        assertEquals( 17, node.getSiblings().size() );
+        assertEquals( "(TEXT)", node.getName() );
+        i++;
+
+        // Test line 4 aka nodes 6+7
+        node = nodes.get( i );
+        assertEquals( 4, node.getLine() );
+        assertEquals( 1, node.getColumn() );
+        assertEquals( 129, node.getStart() );
+        assertEquals( 163, node.getEnd() );
+        assertEquals( 0, node.getChildren().size() );
+        assertEquals( NodeType.JSP_DIRECTIVE, node.getType() );
+        assertEquals( NodeType.ROOT, node.getParent().getType() );
+        assertEquals( 17, node.getSiblings().size() );
+        assertEquals( "page", node.getName() );
+        assertEquals( 1, ((Tag) node).getAttributes().size() );
+        attribute = ((Tag) node).getAttributes().get( 0 );
+        assertEquals( "errorPage", attribute.getName() );
+        assertEquals( "/Error.jsp", attribute.getValue() );
+        i++;
+        node = nodes.get( i );
+        assertEquals( 4, node.getLine() );
+        assertEquals( 35, node.getColumn() );
+        assertEquals( 163, node.getStart() );
+        assertEquals( 164, node.getEnd() );
+        assertEquals( 0, node.getChildren().size() );
+        assertEquals( NodeType.TEXT, node.getType() );
+        assertEquals( NodeType.ROOT, node.getParent().getType() );
+        assertEquals( 17, node.getSiblings().size() );
+        assertEquals( "(TEXT)", node.getName() );
+        i++;
+
+        // Test line 5 aka nodes 8+9
+        node = nodes.get( i );
+        assertEquals( 5, node.getLine() );
+        assertEquals( 1, node.getColumn() );
+        assertEquals( 164, node.getStart() );
+        assertEquals( 218, node.getEnd() );
+        assertEquals( 0, node.getChildren().size() );
+        assertEquals( NodeType.JSP_DIRECTIVE, node.getType() );
+        assertEquals( NodeType.ROOT, node.getParent().getType() );
+        assertEquals( 17, node.getSiblings().size() );
+        assertEquals( "taglib", node.getName() );
+        assertEquals( 2, ((Tag) node).getAttributes().size() );
+        attribute = ((Tag) node).getAttributes().get( 0 );
+        assertEquals( "uri", attribute.getName() );
+        assertEquals( "/WEB-INF/jspwiki.tld", attribute.getValue() );
+        attribute = ((Tag) node).getAttributes().get( 1 );
+        assertEquals( "prefix", attribute.getName() );
+        assertEquals( "wiki", attribute.getValue() );
+        i++;
+        node = nodes.get( i );
+        assertEquals( 5, node.getLine() );
+        assertEquals( 55, node.getColumn() );
+        assertEquals( 218, node.getStart() );
+        assertEquals( 219, node.getEnd() );
+        assertEquals( 0, node.getChildren().size() );
+        assertEquals( NodeType.TEXT, node.getType() );
+        assertEquals( NodeType.ROOT, node.getParent().getType() );
+        assertEquals( 17, node.getSiblings().size() );
+        assertEquals( "(TEXT)", node.getName() );
+        i++;
+
+        // Test line 6 aka nodes 10+11
+        node = nodes.get( i );
+        assertEquals( 6, node.getLine() );
+        assertEquals( 1, node.getColumn() );
+        assertEquals( 219, node.getStart() );
+        assertEquals( 276, node.getEnd() );
+        assertEquals( 0, node.getChildren().size() );
+        assertEquals( NodeType.JSP_DIRECTIVE, node.getType() );
+        assertEquals( NodeType.ROOT, node.getParent().getType() );
+        assertEquals( 17, node.getSiblings().size() );
+        assertEquals( "taglib", node.getName() );
+        assertEquals( 2, ((Tag) node).getAttributes().size() );
+        attribute = ((Tag) node).getAttributes().get( 0 );
+        assertEquals( "uri", attribute.getName() );
+        assertEquals( "/WEB-INF/stripes.tld", attribute.getValue() );
+        attribute = ((Tag) node).getAttributes().get( 1 );
+        assertEquals( "prefix", attribute.getName() );
+        assertEquals( "stripes", attribute.getValue() );
+        i++;
+        node = nodes.get( i );
+        assertEquals( 6, node.getLine() );
+        assertEquals( 58, node.getColumn() );
+        assertEquals( 276, node.getStart() );
+        assertEquals( 277, node.getEnd() );
+        assertEquals( 0, node.getChildren().size() );
+        assertEquals( NodeType.TEXT, node.getType() );
+        assertEquals( NodeType.ROOT, node.getParent().getType() );
+        assertEquals( 17, node.getSiblings().size() );
+        assertEquals( "(TEXT)", node.getName() );
+        i++;
+
+        // Test line 7 aka nodes 12+13
+        node = nodes.get( i );
+        assertEquals( 7, node.getLine() );
+        assertEquals( 1, node.getColumn() );
+        assertEquals( 277, node.getStart() );
+        assertEquals( 354, node.getEnd() );
+        assertEquals( 0, node.getChildren().size() );
+        assertEquals( NodeType.EMPTY_ELEMENT_TAG, node.getType() );
+        assertEquals( NodeType.ROOT, node.getParent().getType() );
+        assertEquals( 17, node.getSiblings().size() );
+        assertEquals( "stripes:useActionBean", node.getName() );
+
+        // AbstractNode 12 should have 1 attribute:
+        // beanclass="com.ecyrd.jspwiki.action.LoginActionBean"
+        assertEquals( 1, ((Tag) node).getAttributes().size() );
+        attribute = ((Tag) node).getAttributes().get( 0 );
+        assertEquals( "beanclass", attribute.getName() );
+        assertEquals( NodeType.ATTRIBUTE, attribute.getType() );
+        assertEquals( "com.ecyrd.jspwiki.action.LoginActionBean", attribute.getValue() );
+        assertEquals( 'c', ((Tag) node).getAttributes().get( 0 ).getValue().charAt( 0 ) );
+        i++;
+
+        // Test line 7, node 13 (line break)
+        node = nodes.get( i );
+        assertEquals( 7, node.getLine() );
+        assertEquals( 78, node.getColumn() );
+        assertEquals( 354, node.getStart() );
+        assertEquals( 355, node.getEnd() );
+        assertEquals( 0, node.getChildren().size() );
+        assertEquals( NodeType.TEXT, node.getType() );
+        assertEquals( NodeType.ROOT, node.getParent().getType() );
+        assertEquals( 17, node.getSiblings().size() );
+        assertEquals( "(TEXT)", node.getName() );
+        i++;
+
+        // Test lines 8-19 aka nodes 14+15
+        node = nodes.get( i );
+        assertEquals( 8, node.getLine() );
+        assertEquals( 1, node.getColumn() );
+        assertEquals( 355, node.getStart() );
+        assertEquals( 767, node.getEnd() );
+        assertEquals( NodeType.JSP_DECLARATION, node.getType() );
+        assertEquals( NodeType.ROOT, node.getParent().getType() );
+        assertEquals( 17, node.getSiblings().size() );
+        assertEquals( "(TEXT)", node.getName() );
+        i++;
+        node = nodes.get( i );
+        assertEquals( 19, node.getLine() );
+        assertEquals( 3, node.getColumn() );
+        assertEquals( 767, node.getStart() );
+        assertEquals( 768, node.getEnd() );
+        assertEquals( 0, node.getChildren().size() );
+        assertEquals( NodeType.TEXT, node.getType() );
+        assertEquals( NodeType.ROOT, node.getParent().getType() );
+        assertEquals( 17, node.getSiblings().size() );
+        assertEquals( "(TEXT)", node.getName() );
+        i++;
+
+        // Test line 20-33 aka node 16
+        node = nodes.get( i );
+        assertEquals( 20, node.getLine() );
+        assertEquals( 1, node.getColumn() );
+        assertEquals( 768, node.getStart() );
+        assertEquals( 1513, node.getEnd() );
+        assertEquals( 0, node.getChildren().size() );
+        assertEquals( NodeType.SCRIPTLET, node.getType() );
+        assertEquals( NodeType.ROOT, node.getParent().getType() );
+        assertEquals( 17, node.getSiblings().size() );
+        assertEquals( "(TEXT)", node.getName() );
+        i++;
+
+        // Test second tag on line 33 aka node 17
+        node = nodes.get( i );
+        assertEquals( 33, node.getLine() );
+        assertEquals( 3, node.getColumn() );
+        assertEquals( 1513, node.getStart() );
+        assertEquals( 1553, node.getEnd() );
+        assertEquals( 0, node.getChildren().size() );
+        assertEquals( NodeType.EMPTY_ELEMENT_TAG, node.getType() );
+        assertEquals( NodeType.ROOT, node.getParent().getType() );
+        assertEquals( 17, node.getSiblings().size() );
+        assertEquals( "wiki:Include", node.getName() );
+
+        // AbstractNode 17 should have 1 attribute: page="<%=contentPage%>"
+        assertEquals( 1, ((Tag) node).getAttributes().size() );
+        attribute = ((Tag) node).getAttributes().get( 0 );
+        assertEquals( "page", attribute.getName() );
+        assertEquals( NodeType.ATTRIBUTE, attribute.getType() );
+        assertEquals( "<%=contentPage%>", attribute.getValue() );
+        assertEquals( 1, attribute.getChildren().size() );
+        assertEquals( NodeType.JSP_EXPRESSION, attribute.getChildren().get( 0 ).getType() );
+        assertEquals( "contentPage", attribute.getChildren().get( 0 ).getValue() );
+        i++;
+    }
+
+    public void testParseNestedTags()
+    {
+        String s = "  <foo attribute1=\"1\">  <bar attribute2=\"2\" attribute3=\"3\"/>  </foo>  ";
+        JspDocument doc = new JspParser().parse( s );
+
+        // Total number of nodes (depth-first search) is 7
+        List<Node> nodes = doc.getNodes();
+        Node node;
+        Node attribute;
+        assertEquals( 7, nodes.size() );
+
+        // First, check the root node. Should have 4 children (2 text nodes + 2
+        // html nodes)
+        node = doc.getRoot();
+        assertEquals( 4, node.getChildren().size() );
+
+        // AbstractNode 0 is whitespace
+        node = nodes.get( 0 );
+        assertEquals( NodeType.TEXT, node.getType() );
+        assertEquals( "(TEXT)", node.getName() );
+        assertEquals( "  ", node.getValue() );
+        assertEquals( doc.getRoot(), node.getParent() );
+        assertEquals( 0, node.getStart() );
+        assertEquals( 2, node.getEnd() );
+
+        // AbstractNode 1 is <foo> with 1 attribute
+        node = nodes.get( 1 );
+        assertEquals( NodeType.START_TAG, node.getType() );
+        assertEquals( "<foo attribute1=\"1\">", node.toString() );
+        assertEquals( "foo", node.getName() );
+        assertEquals( "  <bar attribute2=\"2\" attribute3=\"3\" />  ", node.getValue() );
+        assertEquals( 2, node.getStart() );
+        assertEquals( 22, node.getEnd() );
+
+        // AbstractNode 1: attributes test
+        assertEquals( 1, ((Tag) node).getAttributes().size() );
+        attribute = ((Tag) node).getAttributes().get( 0 );
+        assertEquals( "attribute1", attribute.getName() );
+        assertEquals( "1", attribute.getValue() );
+        assertEquals( 7, attribute.getStart() );
+        assertEquals( 21, attribute.getEnd() );
+
+        // AbstractNode 1 also has 3 child elements: <bar> plus two whitespace
+        // nodes
+        assertEquals( 3, node.getChildren().size() );
+
+        // Check AbstractNode 1, child 0 -- should be whitespace
+        node = nodes.get( 1 ).getChildren().get( 0 );
+        assertEquals( NodeType.TEXT, node.getType() );
+        assertEquals( "(TEXT)", node.getName() );
+        assertEquals( "  ", node.getValue() );
+        assertEquals( nodes.get( 1 ), node.getParent() );
+        assertEquals( 22, node.getStart() );
+        assertEquals( 24, node.getEnd() );
+
+        // Check AbstractNode 1, child 1 -- should be <bar>
+        node = nodes.get( 1 ).getChildren().get( 1 );
+        assertEquals( NodeType.EMPTY_ELEMENT_TAG, node.getType() );
+        assertEquals( "<bar attribute2=\"2\" attribute3=\"3\" />", node.toString() );
+        assertEquals( "bar", node.getName() );
+        assertEquals( 0, node.getChildren().size() );
+        assertEquals( 24, node.getStart() );
+        assertEquals( 60, node.getEnd() );
+        assertEquals( 2, ((Tag) node).getAttributes().size() );
+        assertEquals( "attribute2", ((Tag) node).getAttributes().get( 0 ).getName() );
+        assertEquals( "2", ((Tag) node).getAttributes().get( 0 ).getValue() );
+        assertEquals( "attribute3", ((Tag) node).getAttributes().get( 1 ).getName() );
+        assertEquals( "3", ((Tag) node).getAttributes().get( 1 ).getValue() );
+
+        // Check AbstractNode 1, child 2 -- should be whitespace
+        node = nodes.get( 1 ).getChildren().get( 2 );
+        assertEquals( NodeType.TEXT, node.getType() );
+        assertEquals( "(TEXT)", node.getName() );
+        assertEquals( "  ", node.getValue() );
+        assertEquals( nodes.get( 1 ), node.getParent() );
+        assertEquals( 60, node.getStart() );
+        assertEquals( 62, node.getEnd() );
+
+        // AbstractNode 5 (</foo) has no attributes
+        node = nodes.get( 5 );
+        assertEquals( NodeType.END_TAG, node.getType() );
+        assertEquals( null, node.getValue() );
+        assertEquals( "foo", node.getName() );
+        assertEquals( 0, ((Tag) node).getAttributes().size() );
+        assertEquals( 0, node.getChildren().size() );
+        assertEquals( 62, node.getStart() );
+        assertEquals( 68, node.getEnd() );
+
+        // AbstractNode 6 is whitespace
+        node = nodes.get( 6 );
+        assertEquals( NodeType.TEXT, node.getType() );
+        assertEquals( "(TEXT)", node.getName() );
+        assertEquals( "  ", node.getValue() );
+        assertEquals( doc.getRoot(), node.getParent() );
+        assertEquals( 68, node.getStart() );
+        assertEquals( 70, node.getEnd() );
+
+        // The children of AbstractNode 1 == Nodes 2, 3 and 4 from
+        // doc.getNodes()
+        node = nodes.get( 1 );
+        assertEquals( nodes.get( 2 ), node.getChildren().get( 0 ) );
+        assertEquals( nodes.get( 3 ), node.getChildren().get( 1 ) );
+        assertEquals( nodes.get( 4 ), node.getChildren().get( 2 ) );
+
+    }
+
+    public void testParseNestedExpression()
+    {
+        String s = "  <wiki:Include page=\"<%=contentPage%>\" var=\'Foo\' />  ";
+        JspDocument doc = new JspParser().parse( s );
+
+        List<Node> nodes = doc.getNodes();
+        Node node;
+        assertEquals( 3, nodes.size() );
+
+        // AbstractNode 1: text node
+        node = nodes.get( 0 );
+        assertEquals( 1, node.getLine() );
+        assertEquals( 1, node.getColumn() );
+        assertEquals( 0, node.getStart() );
+        assertEquals( 2, node.getEnd() );
+        assertEquals( NodeType.TEXT, node.getType() );
+        assertEquals( "  ", node.getValue() );
+        assertEquals( "(TEXT)", node.getName() );
+        assertEquals( NodeType.ROOT, node.getParent().getType() );
+        assertEquals( 2, node.getSiblings().size() );
+        assertEquals( 0, node.getChildren().size() );
+
+        // AbstractNode 2: HTML tag with attribute containing JSP expression
+        node = nodes.get( 1 );
+        assertEquals( 1, node.getLine() );
+        assertEquals( 3, node.getColumn() );
+        assertEquals( 2, node.getStart() );
+        assertEquals( 52, node.getEnd() );
+        assertEquals( NodeType.EMPTY_ELEMENT_TAG, node.getType() );
+        assertEquals( "<wiki:Include page=\"<%=contentPage%>\" var=\'Foo\' />", node.toString() );
+        assertEquals( "wiki:Include", node.getName() );
+        assertEquals( null, node.getValue() );
+        assertEquals( NodeType.ROOT, node.getParent().getType() );
+        assertEquals( 2, node.getSiblings().size() );
+        assertEquals( 0, node.getChildren().size() );
+
+        // AbstractNode 2: test attributes
+        assertEquals( 2, ((Tag) node).getAttributes().size() );
+        Node attribute;
+        attribute = ((Tag) node).getAttributes().get( 0 );
+        assertEquals( NodeType.ATTRIBUTE, attribute.getType() );
+        assertEquals( "page", attribute.getName() );
+        assertEquals( "<%=contentPage%>", attribute.getValue() );
+        assertEquals( 1, attribute.getChildren().size() );
+        assertEquals( NodeType.JSP_EXPRESSION, attribute.getChildren().get( 0 ).getType() );
+        assertEquals( "contentPage", attribute.getChildren().get( 0 ).getValue() );
+
+        attribute = ((Tag) node).getAttributes().get( 1 );
+        assertEquals( NodeType.ATTRIBUTE, attribute.getType() );
+        assertEquals( "var", attribute.getName() );
+        assertEquals( "Foo", attribute.getValue() );
+        assertEquals( 1, attribute.getChildren().size() );
+        assertEquals( NodeType.TEXT, attribute.getChildren().get( 0 ).getType() );
+        assertEquals( "Foo", attribute.getChildren().get( 0 ).getValue() );
+
+        // AbstractNode 3: text
+        node = nodes.get( 2 );
+        assertEquals( 1, node.getLine() );
+        assertEquals( 53, node.getColumn() );
+        assertEquals( 52, node.getStart() );
+        assertEquals( 54, node.getEnd() );
+        assertEquals( NodeType.TEXT, node.getType() );
+        assertEquals( "  ", node.getValue() );
+        assertEquals( "(TEXT)", node.getName() );
+        assertEquals( NodeType.ROOT, node.getParent().getType() );
+        assertEquals( 2, node.getSiblings().size() );
+        assertEquals( 0, node.getChildren().size() );
+    }
+
+    public static Test suite()
+    {
+        return new TestSuite( JspParserTest.class );
+    }
+}

Added: incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/ui/migrator/StripesJspTransformerTest.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/ui/migrator/StripesJspTransformerTest.java?rev=723198&view=auto
==============================================================================
--- incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/ui/migrator/StripesJspTransformerTest.java (added)
+++ incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/ui/migrator/StripesJspTransformerTest.java Wed Dec  3 19:10:36 2008
@@ -0,0 +1,323 @@
+package com.ecyrd.jspwiki.ui.migrator;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+public class StripesJspTransformerTest extends TestCase
+{
+    public static Test suite()
+    {
+        return new TestSuite( StripesJspTransformerTest.class );
+    }
+
+    protected Map<String, Object> m_sharedState = new HashMap<String, Object>();
+
+    protected JspTransformer m_transformer = new StripesJspTransformer();
+
+    protected JspDocument m_doc = new JspDocument();
+
+    public StripesJspTransformerTest( String s )
+    {
+        super( s );
+    }
+
+    public void testAddStripesTaglib() throws Exception
+    {
+        String s = "<form/>";
+        JspDocument doc = new JspParser().parse( s );
+        assertEquals( 1, doc.getNodes().size() );
+        m_transformer.transform( m_sharedState, doc );
+        Node node;
+        Attribute attribute;
+
+        // Verify Stripes taglib + linebreak were added
+        assertEquals( 3, doc.getNodes().size() );
+
+        // Verify Stripes taglib
+        node = doc.getNodes().get( 0 );
+        assertEquals( NodeType.JSP_DIRECTIVE, node.getType() );
+        assertEquals( "taglib", node.getName() );
+        attribute = ((Tag) node).getAttribute( "prefix" );
+        assertEquals( "stripes", attribute.getValue() );
+        attribute = ((Tag) node).getAttribute( "uri" );
+        assertEquals( "/WEB-INF/stripes.tld", attribute.getValue() );
+
+        // Verify linebreak
+        node = doc.getNodes().get( 1 );
+        assertEquals( NodeType.TEXT, node.getType() );
+
+        // Verify old tag is still there too
+        node = doc.getNodes().get( 2 );
+        assertEquals( NodeType.EMPTY_ELEMENT_TAG, node.getType() );
+        assertEquals( "stripes:form", node.getName() );
+        assertEquals( 0, ((Tag) node).getAttributes().size() );
+    }
+
+    public void testFormEmptyElementTag() throws Exception
+    {
+        String s = "<form accept-charset=\"UTF-8\" method=\"POST\" />";
+        JspDocument doc = new JspParser().parse( s );
+        m_transformer.transform( m_sharedState, doc );
+
+        assertEquals( 3, doc.getNodes().size() ); // Added Stripes taglib + linebreak
+        Node node = doc.getNodes().get( 2 ); // First 2 are injected Stripes taglib+ llinebreak
+        assertEquals( "stripes:form", node.getName() );
+
+        assertEquals( 2, ((Tag) node).getAttributes().size() );
+        Node attribute = ((Tag) node).getAttributes().get( 0 );
+        assertEquals( "acceptcharset", attribute.getName() );
+    }
+
+    public void testFormWithParams() throws Exception
+    {
+        String s = "<form action=\"Login.jsp?tab=profile\"/>";
+        JspDocument doc = new JspParser().parse( s );
+        m_transformer.transform( m_sharedState, doc );
+
+        assertEquals( 5, doc.getNodes().size() );
+        Node node = doc.getNodes().get( 2 ); // First 2 are injected Stripes taglib+ llinebreak
+        assertEquals( "stripes:form", node.getName() );
+        assertEquals( 1, ((Tag) node).getAttributes().size() );
+        Node attribute = ((Tag) node).getAttributes().get( 0 );
+        assertEquals( "Login.jsp", attribute.getValue() );
+    }
+    
+    public void testLabel() throws Exception
+    {
+        String s = "<label for=\"assertedName\"><fmt:message key=\"prefs.assertedname\"/></label>";
+        JspDocument doc = new JspParser().parse( s );
+        m_transformer.transform( m_sharedState, doc );
+
+        // Message tag is removed; 2 more added
+        List<Node> nodes = doc.getNodes();
+        assertEquals( 3, nodes.size() );
+        
+        // First node is the Stripes taglib
+        Node node = nodes.get( 0 );
+        assertEquals( NodeType.JSP_DIRECTIVE, node.getType() );
+
+        // Second node is the injected linebreak
+        node = nodes.get( 1 );
+        assertEquals( NodeType.TEXT, node.getType() );
+        
+        // Third node is the re-structured stripes:label
+        Tag tag = (Tag)nodes.get( 2 );
+        assertEquals( NodeType.EMPTY_ELEMENT_TAG, tag.getType() );
+        assertEquals( "stripes:label", tag.getName() );
+        assertEquals( 2, tag.getAttributes().size() );
+        assertEquals( "for", tag.getAttribute( "for" ).getName() );
+        assertEquals( "assertedName", tag.getAttribute( "for" ).getValue() );
+        assertEquals( "name", tag.getAttribute( "name" ).getName() );
+        assertEquals( "prefs.assertedname", tag.getAttribute( "name" ).getValue() );
+        
+        assertEquals( "<stripes:label for=\"assertedName\" name=\"prefs.assertedname\" />", tag.toString() );
+    }
+    
+    public void testLabelConflictingName() throws Exception
+    {
+        String s = "<label for=\"assertedName\" name=\"foo\"><fmt:message key=\"prefs.assertedname\"/></label>";
+        JspDocument doc = new JspParser().parse( s );
+        m_transformer.transform( m_sharedState, doc );
+
+        // Added 2 nodes...
+        List<Node> nodes = doc.getNodes();
+        assertEquals( 5, nodes.size() );
+        
+        // First node is the Stripes taglib
+        Node node = nodes.get( 0 );
+        assertEquals( NodeType.JSP_DIRECTIVE, node.getType() );
+
+        // Second node is the injected linebreak
+        node = nodes.get( 1 );
+        assertEquals( NodeType.TEXT, node.getType() );
+        
+        // Third node is the re-structured stripes:label
+        Tag tag = (Tag)nodes.get( 2 );
+        assertEquals( NodeType.START_TAG, tag.getType() );
+        assertEquals( "stripes:label", tag.getName() );
+        assertEquals( 2, tag.getAttributes().size() );
+        assertEquals( "for", tag.getAttribute( "for" ).getName() );
+        assertEquals( "assertedName", tag.getAttribute( "for" ).getValue() );
+        assertEquals( "name", tag.getAttribute( "name" ).getName() );
+        assertEquals( "foo", tag.getAttribute( "name" ).getValue() );
+        
+        // Fourth node is the fmt:message tag, which did NOT get moved
+        tag = (Tag)nodes.get( 3 );
+        assertEquals( NodeType.EMPTY_ELEMENT_TAG, tag.getType() );
+        assertEquals( "fmt:message", tag.getName() );
+        assertEquals( 1, tag.getAttributes().size() );
+        assertEquals( "key", tag.getAttribute( "key" ).getName() );
+        assertEquals( "prefs.assertedname", tag.getAttribute( "key" ).getValue() );
+        
+        // Fifth node is the end tag
+        tag = (Tag)nodes.get( 4 );
+        assertEquals( NodeType.END_TAG, tag.getType() );
+        assertEquals( "stripes:label", tag.getName() );
+        assertEquals( 0, tag.getAttributes().size() );
+    }
+
+    public void testLabelNoFmtMessage() throws Exception
+    {
+        String s = "<label for=\"assertedName\">This is a test.</label>";
+        JspDocument doc = new JspParser().parse( s );
+        m_transformer.transform( m_sharedState, doc );
+
+        // Added 2 nodes...
+        List<Node> nodes = doc.getNodes();
+        assertEquals( 5, nodes.size() );
+        
+        // First node is the Stripes taglib
+        Node node = nodes.get( 0 );
+        assertEquals( NodeType.JSP_DIRECTIVE, node.getType() );
+
+        // Second node is the injected linebreak
+        node = nodes.get( 1 );
+        assertEquals( NodeType.TEXT, node.getType() );
+        
+        // Third node is the stripes:label start
+        Tag tag = (Tag)nodes.get( 2 );
+        assertEquals( NodeType.START_TAG, tag.getType() );
+        assertEquals( "stripes:label", tag.getName() );
+        assertEquals( 1, tag.getAttributes().size() );
+        assertEquals( "for", tag.getAttribute( "for" ).getName() );
+        assertEquals( "assertedName", tag.getAttribute( "for" ).getValue() );
+
+        // Fourth node is the label text
+        node = nodes.get( 3 );
+        assertEquals( NodeType.TEXT, node.getType() );
+        assertEquals( "This is a test.", node.getValue() );
+        
+        // Fifth node is the stripes:label end
+        tag = (Tag)nodes.get( 4 );
+        assertEquals( NodeType.END_TAG, tag.getType() );
+        assertEquals( "stripes:label", tag.getName() );
+    }
+
+    public void testNoAddStripesTaglib() throws Exception
+    {
+        String s = "<%@ taglib uri=\"/WEB-INF/stripes.tld\" prefix=\"stripes\" %>\n<foo/>";
+        JspDocument doc = new JspParser().parse( s );
+        assertEquals( 3, doc.getNodes().size() );
+        m_transformer.transform( m_sharedState, doc );
+
+        // Verify Stripes taglib was NOT added
+        assertEquals( 3, doc.getNodes().size() );
+    }
+
+    public void testPasswordTag() throws Exception
+    {
+        String s = "<input type=\"password\" size=\"24\" value=\"\" name=\"j_username\" id=\"j_username\" />";
+        JspDocument doc = new JspParser().parse( s );
+        Node node;
+
+        // Before transformation, 1 node, with 5 attributes
+        node = doc.getNodes().get( 0 );
+        assertEquals( 1, doc.getNodes().size() );
+        assertEquals( 5, ((Tag) node).getAttributes().size() );
+        m_transformer.transform( m_sharedState, doc );
+
+        // After transformation, the "type" attribute is deleted
+        assertEquals( 3, doc.getNodes().size() ); // Added Stripes taglib + linebreak
+        node = doc.getNodes().get( 2 ); // First 2 are injected Stripes taglib+llinebreak
+        assertEquals( NodeType.EMPTY_ELEMENT_TAG, node.getType() );
+        assertEquals( "stripes:password", node.getName() );
+        assertEquals( 4, ((Tag) node).getAttributes().size() );
+        assertEquals( 0, node.getChildren().size() );
+    }
+
+    public void testPasswordTagComplex() throws Exception
+    {
+        String s = "<input type=\"password\" size=\"24\" value=\"<wiki:Variable var='uid' default='' />\" name=\"j_username\" id=\"j_username\" />";
+        JspDocument doc = new JspParser().parse( s );
+        assertEquals( 1, doc.getNodes().size() );
+        m_transformer.transform( m_sharedState, doc );
+
+        // After transformation, the "type" and "value" attributes are deleted;
+        // value becomes child node
+        assertEquals( 5, doc.getNodes().size() ); // Added Stripes taglib +linebreak
+        Node node = doc.getNodes().get( 2 ); // First 2 are injected Stripes taglib+ llinebreak
+        assertEquals( NodeType.START_TAG, node.getType() );
+        assertEquals( "stripes:password", node.getName() );
+        assertEquals( 3, ((Tag) node).getAttributes().size() );
+
+        // The value attribute should show up as a child node
+        assertEquals( 1, node.getChildren().size() );
+        node = node.getChildren().get( 0 );
+        assertEquals( NodeType.EMPTY_ELEMENT_TAG, node.getType() );
+        assertEquals( "wiki:Variable", node.getName() );
+    }
+
+    public void testTextArea() throws Exception
+    {
+        String s = "<textarea id=\"members\" name=\"members\" rows=\"10\" cols=\"30\" value=\"Foo\" />";
+        JspDocument doc = new JspParser().parse( s );
+        assertEquals( 1, doc.getNodes().size() );
+        m_transformer.transform( m_sharedState, doc );
+
+        // After transformation, the tag name is renamed
+        assertEquals( 3, doc.getNodes().size() ); // Added Stripes taglib + linebreak
+        Node node = doc.getNodes().get( 2 ); // First 2 are injected Stripes taglib+ llinebreak
+        assertEquals( NodeType.EMPTY_ELEMENT_TAG, node.getType() );
+        assertEquals( "stripes:textarea", node.getName() );
+        assertEquals( 5, ((Tag) node).getAttributes().size() );
+
+        // The value attribute should have stayed as an attribute
+        Attribute attribute = ((Tag) node).getAttribute( "value" );
+        assertNotNull( attribute );
+        assertEquals( 1, attribute.getChildren().size() );
+        node = attribute.getChildren().get( 0 );
+        assertEquals( NodeType.TEXT, node.getType() );
+        assertEquals( "Foo", node.getValue() );
+    }
+
+    public void testTextAreaComplex() throws Exception
+    {
+        String s = "<textarea id=\"members\" name=\"members\" rows=\"10\" cols=\"30\" value=\"<%=foo%>\" />";
+        JspDocument doc = new JspParser().parse( s );
+        assertEquals( 1, doc.getNodes().size() );
+        m_transformer.transform( m_sharedState, doc );
+
+        // After transformation, the tag name is renamed & tag is split
+        assertEquals( 5, doc.getNodes().size() ); // Added Stripes taglib + linebreak
+        Node node = doc.getNodes().get( 2 ); // First 2 are injected Stripes taglib+ llinebreak
+        assertEquals( NodeType.START_TAG, node.getType() );
+        assertEquals( "stripes:textarea", node.getName() );
+        assertEquals( 4, ((Tag) node).getAttributes().size() ); // Value attribute vanishes...
+
+        // Verify newly created end tag
+        node = doc.getNodes().get( 4 );
+        assertEquals( NodeType.END_TAG, node.getType() );
+        assertEquals( "stripes:textarea", node.getName() );
+
+        // The value attribute should have moved to child nodes
+        node = doc.getNodes().get( 2 );
+        Attribute attribute = ((Tag) node).getAttribute( "value" );
+        assertNull( attribute );
+        
+        assertEquals( 1, node.getChildren().size() );
+        node = node.getChildren().get( 0 );
+        assertEquals( NodeType.JSP_EXPRESSION, node.getType() );
+        assertEquals( "foo", node.getValue() );
+        assertEquals( "<%=foo%>", node.toString() );
+    }
+
+    public void testTextAreaNoNameAttribute() throws Exception
+    {
+        String s = "<textarea id=\"members\" rows=\"10\" cols=\"30\" value=\"Foo\" />";
+        JspDocument doc = new JspParser().parse( s );
+        assertEquals( 1, doc.getNodes().size() );
+        m_transformer.transform( m_sharedState, doc );
+
+        // After transformation, the tag name is stays the same (no name attribute...)
+        assertEquals( 1, doc.getNodes().size() ); // NO Stripes taglib or  linebreak
+        Node node = doc.getNodes().get( 0 );
+        assertEquals( NodeType.EMPTY_ELEMENT_TAG, node.getType() );
+        assertEquals( "textarea", node.getName() );
+        assertEquals( 4, ((Tag) node).getAttributes().size() );
+    }
+}

Added: incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/ui/migrator/TagTest.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/ui/migrator/TagTest.java?rev=723198&view=auto
==============================================================================
--- incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/ui/migrator/TagTest.java (added)
+++ incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/ui/migrator/TagTest.java Wed Dec  3 19:10:36 2008
@@ -0,0 +1,85 @@
+package com.ecyrd.jspwiki.ui.migrator;
+
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+public class TagTest extends TestCase
+{
+    public void testAddChildEmptyElement()
+    {
+        JspDocument doc = new JspDocument();
+        
+        // Set up tag <foo/>
+        Tag parentTag = new Tag( doc, NodeType.EMPTY_ELEMENT_TAG );
+        parentTag.setName( "foo" );
+        doc.getRoot().addChild( parentTag );
+        assertEquals( "<foo/>", parentTag.toString() );
+        assertEquals( 1, doc.getRoot().getChildren().size() );
+        
+        // Add child tag <bar/>
+        Tag childTag = new Tag( doc, NodeType.EMPTY_ELEMENT_TAG );
+        childTag.setName( "bar" );
+        parentTag.addChild( childTag );
+        
+        // Should result in <foo><bar/></foo>
+        assertEquals( "<foo><bar/></foo>", doc.toString() );
+        assertEquals( 2, doc.getRoot().getChildren().size() );
+    }
+
+    public void testAddChild()
+    {
+        JspDocument doc = new JspDocument();
+        
+        // Set up tag <foo>
+        Tag parentTag = new Tag( doc, NodeType.START_TAG);
+        parentTag.setName( "foo" );
+        doc.getRoot().addChild( parentTag );
+        assertEquals( "<foo>", parentTag.toString() );
+        assertEquals( 1, doc.getRoot().getChildren().size() );
+        
+        // Add child tag <bar/>
+        Tag childTag = new Tag( doc, NodeType.EMPTY_ELEMENT_TAG );
+        childTag.setName( "bar" );
+        parentTag.addChild( childTag );
+        
+        // Should result in <foo><bar/> (with bar a child of foo)
+        assertEquals( "<foo><bar/>", doc.toString() );
+        assertEquals( 1, doc.getRoot().getChildren().size() );
+    }
+
+    public void testAddChildAtIndex()
+    {
+        JspDocument doc = new JspDocument();
+        
+        // Set up tag <foo>
+        Tag parentTag = new Tag( doc, NodeType.START_TAG);
+        parentTag.setName( "foo" );
+        doc.getRoot().addChild( parentTag );
+        assertEquals( "<foo>", parentTag.toString() );
+        assertEquals( 1, doc.getRoot().getChildren().size() );
+        
+        // Add child tag <bar/>
+        Tag childTag = new Tag( doc, NodeType.EMPTY_ELEMENT_TAG );
+        childTag.setName( "bar" );
+        parentTag.addChild( childTag );
+        assertEquals( 1, doc.getRoot().getChildren().size() );
+        
+        // Add a second child <golf/>  before <bar>
+        childTag = new Tag( doc, NodeType.EMPTY_ELEMENT_TAG );
+        childTag.setName( "golf" );
+        parentTag.addChild( childTag, 0 );
+        
+        // Should result in <foo><golf/><bar/> (with golf and bar children of foo)
+        assertEquals( "<foo><golf/><bar/>", doc.toString() );
+        assertEquals( 1, doc.getRoot().getChildren().size() );
+        assertEquals( 2, doc.getRoot().getChildren().get( 0 ).getChildren().size() );
+    }
+    
+    public static Test suite()
+    {
+        return new TestSuite( TagTest.class );
+    }
+
+}

Modified: incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/ui/stripes/AllTests.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/ui/stripes/AllTests.java?rev=723198&r1=723197&r2=723198&view=diff
==============================================================================
--- incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/ui/stripes/AllTests.java (original)
+++ incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/ui/stripes/AllTests.java Wed Dec  3 19:10:36 2008
@@ -8,12 +8,8 @@
 {
     public static Test suite()
     {
-        TestSuite suite = new TestSuite("JSP migration tests");
-        suite.addTest( JspParserTest.suite() );
-        suite.addTest( JspDocumentTest.suite() );
-        suite.addTest( JSPWikiJspTransformerTest.suite() );
-        suite.addTest( StripesJspTransformerTest.suite() );
-        suite.addTest( TagTest.suite() );
+        TestSuite suite = new TestSuite("Stripes UI tests");
+        suite.addTest( HandlerInfoTest.suite() );
         return suite;
     }
 

Copied: incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/ui/stripes/HandlerInfoTest.java (from r723022, incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/action/HandlerInfoTest.java)
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/ui/stripes/HandlerInfoTest.java?p2=incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/ui/stripes/HandlerInfoTest.java&p1=incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/action/HandlerInfoTest.java&r1=723022&r2=723198&rev=723198&view=diff
==============================================================================
--- incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/action/HandlerInfoTest.java (original)
+++ incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/ui/stripes/HandlerInfoTest.java Wed Dec  3 19:10:36 2008
@@ -1,4 +1,4 @@
-package com.ecyrd.jspwiki.action;
+package com.ecyrd.jspwiki.ui.stripes;
 
 import java.lang.reflect.Method;
 import java.security.Permission;
@@ -11,8 +11,10 @@
 import net.sourceforge.stripes.mock.MockRoundtrip;
 
 import com.ecyrd.jspwiki.TestEngine;
+import com.ecyrd.jspwiki.action.GroupActionBean;
 import com.ecyrd.jspwiki.auth.permissions.GroupPermission;
 import com.ecyrd.jspwiki.auth.permissions.WikiPermission;
+import com.ecyrd.jspwiki.ui.stripes.HandlerInfo;
 
 public class HandlerInfoTest extends TestCase
 {

Modified: incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/util/AllTests.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/util/AllTests.java?rev=723198&r1=723197&r2=723198&view=diff
==============================================================================
--- incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/util/AllTests.java (original)
+++ incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/util/AllTests.java Wed Dec  3 19:10:36 2008
@@ -2,7 +2,7 @@
 package com.ecyrd.jspwiki.util;
 
 
-import com.ecyrd.jspwiki.ui.stripes.JspParserTest;
+import com.ecyrd.jspwiki.ui.migrator.JspParserTest;
 
 import junit.framework.*;
 



Mime
View raw message