// Path: jsptest-generic/jsptest-common/src/main/java/net/sf/jsptest/utils/XML.java
// public class XML {
// 
//     private static final String APACHE_INDENTATION = "{http://xml.apache.org/xslt}indent-amount";
// 
//     public static String toString(Node xml) {
//         try {
//             TransformerFactory f = TransformerFactory.newInstance();
//             Transformer t = f.newTransformer();
//             t.setOutputProperty(OutputKeys.INDENT, "yes");
//             t.setOutputProperty(APACHE_INDENTATION, "2");
//             OutputStream out = new ByteArrayOutputStream();
//             t.transform(new DOMSource(xml), new StreamResult(out));
//             return out.toString();
//         } catch (TransformerException e) {
//             throw new RuntimeException(e);
//         }
//     }
// 
//     public static String textContentOf(Element element) {
//         StringBuffer textContent = new StringBuffer(100);
//         NodeList children = element.getChildNodes();
//         for (int i = 0; i < children.getLength(); i++) {
//             appendTextContentOf(children.item(i), textContent);
//         }
//         return textContent.toString();
//     }
// 
//     private static void appendTextContentOf(Node from, StringBuffer to) {
//         if (from.getNodeType() == Node.ELEMENT_NODE) {
//             to.append(textContentOf((Element) from));
//         } else if (from.getNodeType() != Node.COMMENT_NODE) {
//             to.append(from.getNodeValue().trim());
//         }
//     }
// }


import junit.framework.AssertionFailedError;
import net.sf.jsptest.utils.XML;
import org.w3c.dom.Element;

    public void testAssertingAgainstNonElementXPathFails() throws Exception {
        String xpath = "//P[@CLASS='p1']/text()";
        try {
            testcase.element(xpath);
            throw new RuntimeException("Expected assertion to fail but it didn't.");
        } catch (AssertionFailedError expected) {
        }
    }

    public void testElementShouldContain() throws Exception {
        testcase.element("//P[@CLASS='p2']").shouldContain("this is p2");
        try {
            testcase.element("//P[@CLASS='p1']").shouldContain("it doesn't contain this");
            throw new RuntimeException("Expected assertion to fail but it didn't.");
        } catch (AssertionFailedError expected) {
        }
    }

    public void testElementShouldNotContain() throws Exception {
        testcase.element("//P[@CLASS='p2']").shouldNotContain("bad things");
        try {
            testcase.element("//P[@CLASS='p2']").shouldNotContain("p2");
            throw new RuntimeException("Expected assertion to fail but it didn't.");
        } catch (AssertionFailedError expected) {
        }
    }

    public void testHasAccessToUnderlyingDomElement() throws Exception {
        Element element = testcase.element("//P[@CLASS='p2']").getElement();
        assertNotNull(element);

// Path: jsptest-generic/jsptest-common/src/main/java/net/sf/jsptest/utils/XML.java
// public class XML {
// 
//     private static final String APACHE_INDENTATION = "{http://xml.apache.org/xslt}indent-amount";
// 
//     public static String toString(Node xml) {
//         try {
//             TransformerFactory f = TransformerFactory.newInstance();
//             Transformer t = f.newTransformer();
//             t.setOutputProperty(OutputKeys.INDENT, "yes");
//             t.setOutputProperty(APACHE_INDENTATION, "2");
//             OutputStream out = new ByteArrayOutputStream();
//             t.transform(new DOMSource(xml), new StreamResult(out));
//             return out.toString();
//         } catch (TransformerException e) {
//             throw new RuntimeException(e);
//         }
//     }
// 
//     public static String textContentOf(Element element) {
//         StringBuffer textContent = new StringBuffer(100);
//         NodeList children = element.getChildNodes();
//         for (int i = 0; i < children.getLength(); i++) {
//             appendTextContentOf(children.item(i), textContent);
//         }
//         return textContent.toString();
//     }
// 
//     private static void appendTextContentOf(Node from, StringBuffer to) {
//         if (from.getNodeType() == Node.ELEMENT_NODE) {
//             to.append(textContentOf((Element) from));
//         } else if (from.getNodeType() != Node.COMMENT_NODE) {
//             to.append(from.getNodeValue().trim());
//         }
//     }
// }


// Path: jsptest-generic/jsptest-framework/src/test/java/net/sf/jsptest/TestHtmlTestCaseElementAssertions.java
import junit.framework.AssertionFailedError;
import net.sf.jsptest.utils.XML;
import org.w3c.dom.Element;

    public void testAssertingAgainstNonElementXPathFails() throws Exception {
        String xpath = "//P[@CLASS='p1']/text()";
        try {
            testcase.element(xpath);
            throw new RuntimeException("Expected assertion to fail but it didn't.");
        } catch (AssertionFailedError expected) {
        }
    }

    public void testElementShouldContain() throws Exception {
        testcase.element("//P[@CLASS='p2']").shouldContain("this is p2");
        try {
            testcase.element("//P[@CLASS='p1']").shouldContain("it doesn't contain this");
            throw new RuntimeException("Expected assertion to fail but it didn't.");
        } catch (AssertionFailedError expected) {
        }
    }

    public void testElementShouldNotContain() throws Exception {
        testcase.element("//P[@CLASS='p2']").shouldNotContain("bad things");
        try {
            testcase.element("//P[@CLASS='p2']").shouldNotContain("p2");
            throw new RuntimeException("Expected assertion to fail but it didn't.");
        } catch (AssertionFailedError expected) {
        }
    }

    public void testHasAccessToUnderlyingDomElement() throws Exception {
        Element element = testcase.element("//P[@CLASS='p2']").getElement();
        assertNotNull(element);

        assertEquals("this is p2", XML.textContentOf(element));
