Search in sources :

Example 16 with Node

use of org.sonar.plugins.web.node.Node in project sonar-web by SonarSource.

the class PageLexerTest method testLexer.

@Test
public void testLexer() throws FileNotFoundException {
    String fileName = "src/test/resources/src/main/webapp/create-salesorder.xhtml";
    PageLexer lexer = new PageLexer();
    List<Node> nodeList = lexer.parse(new FileReader(fileName));
    assertTrue(nodeList.size() > 50);
    // check tagnodes
    for (Node node : nodeList) {
        if (node instanceof TagNode) {
            assertTrue(node.getCode().startsWith("<"));
            assertTrue(node.getCode().endsWith(">"));
        }
    }
    showHierarchy(nodeList);
    // check hierarchy
    for (Node node : nodeList) {
        if (node instanceof TagNode) {
            TagNode tagNode = (TagNode) node;
            if (!tagNode.isEndElement()) {
                if (tagNode.equalsElementName("define")) {
                    assertTrue("Tag should have children: " + tagNode.getCode(), tagNode.getChildren().size() > 0);
                } else if (tagNode.equalsElementName("outputText")) {
                    assertThat(tagNode.getChildren().size()).isEqualTo(0);
                }
            }
        }
    }
}
Also used : TagNode(org.sonar.plugins.web.node.TagNode) TextNode(org.sonar.plugins.web.node.TextNode) CommentNode(org.sonar.plugins.web.node.CommentNode) Node(org.sonar.plugins.web.node.Node) DirectiveNode(org.sonar.plugins.web.node.DirectiveNode) FileReader(java.io.FileReader) TagNode(org.sonar.plugins.web.node.TagNode) Test(org.junit.Test)

Example 17 with Node

use of org.sonar.plugins.web.node.Node in project sonar-web by SonarSource.

the class PageLexerTest method testNestedTagInAttribute.

@Test
public void testNestedTagInAttribute() {
    String fragment = "<td id=\"typeCellHeader\"<c:if test='${param.typeNormalOrError == \"error\"}'>" + "style=\"display:none;\"</c:if>>Type" + "</td>";
    StringReader reader = new StringReader(fragment);
    PageLexer lexer = new PageLexer();
    List<Node> nodeList = lexer.parse(reader);
    assertEquals(3, nodeList.size());
    assertTrue(nodeList.get(0) instanceof TagNode);
    assertTrue(nodeList.get(1) instanceof TextNode);
    assertTrue(nodeList.get(2) instanceof TagNode);
    TagNode tagNode = (TagNode) nodeList.get(0);
    assertEquals(4, tagNode.getAttributes().size());
    // the embedded tags are added as attributes
    assertThat(tagNode.getAttributes().get(1).getValue()).isEmpty();
    assertThat(tagNode.getAttributes().get(3).getValue()).isEmpty();
}
Also used : TagNode(org.sonar.plugins.web.node.TagNode) TextNode(org.sonar.plugins.web.node.TextNode) CommentNode(org.sonar.plugins.web.node.CommentNode) Node(org.sonar.plugins.web.node.Node) DirectiveNode(org.sonar.plugins.web.node.DirectiveNode) StringReader(java.io.StringReader) TextNode(org.sonar.plugins.web.node.TextNode) TagNode(org.sonar.plugins.web.node.TagNode) Test(org.junit.Test)

Example 18 with Node

use of org.sonar.plugins.web.node.Node in project sonar-web by SonarSource.

the class PageLexerTest method testNestedTagInValue.

@Test
public void testNestedTagInValue() {
    String fragment = "<td label=\"Hello <c:if test='${param == true}'>World</c:if>\">Type</td>";
    StringReader reader = new StringReader(fragment);
    PageLexer lexer = new PageLexer();
    List<Node> nodeList = lexer.parse(reader);
    assertEquals(3, nodeList.size());
    assertTrue(nodeList.get(0) instanceof TagNode);
    assertTrue(nodeList.get(1) instanceof TextNode);
    assertTrue(nodeList.get(2) instanceof TagNode);
    TagNode tagNode = (TagNode) nodeList.get(0);
    assertEquals(1, tagNode.getAttributes().size());
}
Also used : TagNode(org.sonar.plugins.web.node.TagNode) TextNode(org.sonar.plugins.web.node.TextNode) CommentNode(org.sonar.plugins.web.node.CommentNode) Node(org.sonar.plugins.web.node.Node) DirectiveNode(org.sonar.plugins.web.node.DirectiveNode) StringReader(java.io.StringReader) TextNode(org.sonar.plugins.web.node.TextNode) TagNode(org.sonar.plugins.web.node.TagNode) Test(org.junit.Test)

Example 19 with Node

use of org.sonar.plugins.web.node.Node in project sonar-web by SonarSource.

the class PageLexerTest method escapeCharacters.

@Test
public void escapeCharacters() {
    String fragment = "<c:when test=\"${citaflagurge eq \\\"S\\\"}\">";
    StringReader reader = new StringReader(fragment);
    PageLexer lexer = new PageLexer();
    List<Node> nodeList = lexer.parse(reader);
    assertEquals(1, nodeList.size());
    TagNode tagNode = (TagNode) nodeList.get(0);
    assertEquals(1, tagNode.getAttributes().size());
}
Also used : TagNode(org.sonar.plugins.web.node.TagNode) TextNode(org.sonar.plugins.web.node.TextNode) CommentNode(org.sonar.plugins.web.node.CommentNode) Node(org.sonar.plugins.web.node.Node) DirectiveNode(org.sonar.plugins.web.node.DirectiveNode) StringReader(java.io.StringReader) TagNode(org.sonar.plugins.web.node.TagNode) Test(org.junit.Test)

Example 20 with Node

use of org.sonar.plugins.web.node.Node in project sonar-web by SonarSource.

the class PageLexerTest method testNestedComment.

@Test
public void testNestedComment() {
    String fragment = "<!-- text <!--><p>This is not part of the comment</p>";
    StringReader reader = new StringReader(fragment);
    PageLexer lexer = new PageLexer();
    List<Node> nodeList = lexer.parse(reader);
    assertEquals(4, nodeList.size());
    assertTrue(nodeList.get(0) instanceof CommentNode);
    assertTrue(nodeList.get(1) instanceof TagNode);
    assertTrue(nodeList.get(2) instanceof TextNode);
    assertTrue(nodeList.get(3) instanceof TagNode);
}
Also used : TagNode(org.sonar.plugins.web.node.TagNode) TextNode(org.sonar.plugins.web.node.TextNode) CommentNode(org.sonar.plugins.web.node.CommentNode) Node(org.sonar.plugins.web.node.Node) DirectiveNode(org.sonar.plugins.web.node.DirectiveNode) StringReader(java.io.StringReader) CommentNode(org.sonar.plugins.web.node.CommentNode) TextNode(org.sonar.plugins.web.node.TextNode) TagNode(org.sonar.plugins.web.node.TagNode) Test(org.junit.Test)

Aggregations

Node (org.sonar.plugins.web.node.Node)25 TagNode (org.sonar.plugins.web.node.TagNode)19 Test (org.junit.Test)18 TextNode (org.sonar.plugins.web.node.TextNode)17 CommentNode (org.sonar.plugins.web.node.CommentNode)15 DirectiveNode (org.sonar.plugins.web.node.DirectiveNode)15 StringReader (java.io.StringReader)10 FileReader (java.io.FileReader)7 DefaultInputFile (org.sonar.api.batch.fs.internal.DefaultInputFile)4 File (java.io.File)3 WebSourceCode (org.sonar.plugins.web.visitor.WebSourceCode)3 ArrayList (java.util.ArrayList)2 CodeReader (org.sonar.channel.CodeReader)2 Attribute (org.sonar.plugins.web.node.Attribute)2 List (java.util.List)1 InputFile (org.sonar.api.batch.fs.InputFile)1 NoSonarFilter (org.sonar.api.issue.NoSonarFilter)1 Channel (org.sonar.channel.Channel)1 PageLexer (org.sonar.plugins.web.lex.PageLexer)1