/**
 * Copyright © 2015 digitalfondue (info@digitalfondue.ch)
 *
 * Licensed 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 ch.digitalfondue.jfiveparse;

import org.junit.Assert;
import org.junit.Test;
import org.w3c.dom.Document;
import org.w3c.dom.Node;

public class W3CDomTest {

    @Test
    public void checkSimpleDomConversion() {
        Parser parser = new Parser();

        Document document = W3CDom.toW3CDocument(parser.parse("<body><p>hello world"));

        Node html = document.getFirstChild();

        Assert.assertEquals("html", html.getNodeName());
        Assert.assertEquals(1, document.getChildNodes().getLength());

        Assert.assertEquals(2, html.getChildNodes().getLength());
        Assert.assertEquals("head", html.getFirstChild().getNodeName());
        Assert.assertEquals("body", html.getLastChild().getNodeName());

        Node body = html.getLastChild();

        Assert.assertEquals(1, body.getChildNodes().getLength());

        Node p = body.getLastChild();

        Assert.assertEquals("p", p.getNodeName());

        Assert.assertEquals(1, p.getChildNodes().getLength());

        Node text = p.getLastChild();

        Assert.assertEquals(Node.TEXT_NODE, text.getNodeType());
        Assert.assertEquals("hello world", text.getTextContent());
    }
}

@@ -950,16 +950,22 @@
 %3Cbody%3E%3Cp
+ id=42
 %3Ehello w
@@ -969,24 +969,24 @@
 o world%22));%0A
-
 %0A        Nod
@@ -1551,32 +1551,120 @@
 .getNodeName());
+%0A        Assert.assertEquals(%2242%22, p.getAttributes().getNamedItem(%22id%22).getNodeValue());
 %0A%0A        Assert
@@ -1813,24 +1813,24 @@
 odeType());%0A
-
         Asse
@@ -1889,11 +1889,857 @@
 );%0A    %7D
+%0A%0A    @Test%0A    public void checkSiblingAndNested() %7B%0A        Parser parser = new Parser();%0A%0A        Document document = W3CDom.toW3CDocument(parser.parse(%22%3Cbody%3E%3Cp%3E%3Cspan%3E1%3C/span%3E%3C/p%3E%3Cp%3E%3Cspan%3E2%3C/span%3E%3C/p%3E%22));%0A%0A        Node body = document.getFirstChild().getLastChild();%0A        Assert.assertEquals(2, body.getChildNodes().getLength());%0A%0A        Node p1 = body.getFirstChild();%0A        Node p2 = p1.getNextSibling();%0A%0A        Assert.assertEquals(%22p%22, p1.getNodeName());%0A        Assert.assertEquals(%22p%22, p2.getNodeName());%0A%0A        Assert.assertEquals(%22span%22, p1.getFirstChild().getNodeName());%0A        Assert.assertEquals(%22span%22, p2.getFirstChild().getNodeName());%0A%0A        Assert.assertEquals(%221%22, p1.getFirstChild().getFirstChild().getTextContent());%0A        Assert.assertEquals(%222%22, p2.getFirstChild().getFirstChild().getTextContent());%0A%0A    %7D
 %0A%7D%0A

add more tests