// Path: jsptest-generic/jsptest-framework/src/main/java/net/sf/jsptest/assertion/ExpectedAssertionFailure.java
// public abstract class ExpectedAssertionFailure {
// 
//     private HtmlTestCase testcase;
// 
//     /**
//      * Override this method to perform a test that should fail with an exception.
//      */
//     protected abstract void run() throws Exception;
// 
//     /**
//      * @param testcase
//      *            The <tt>HtmlTestCase</tt> that serves as the context for this operation.
//      */
//     public ExpectedAssertionFailure(HtmlTestCase testcase) throws Exception {
//         this(testcase, "Operation should've failed but it didn't.");
//     }
// 
//     /**
//      * @param testcase
//      *            The <tt>HtmlTestCase</tt> that serves as the context for this operation.
//      * @param message
//      *            The message to display if the specified operation doesn't throw an
//      *            AssertionFailedError.
//      */
//     public ExpectedAssertionFailure(HtmlTestCase testcase, String message) throws Exception {
//         this.testcase = testcase;
//         verify(message);
//     }
// 
//     /**
//      * Gives access to a <tt>PageAssertion</tt> object, enabling page-oriented (HTML) assertions.
//      */
//     protected PageAssertion page() {
//         return testcase.page();
//     }
// 
//     /**
//      * Gives access to an <tt>OutputAssertion</tt> object, enabling raw output-oriented
//      * assertions.
//      */
//     protected OutputAssertion output() {
//         return testcase.output();
//     }
// 
//     /**
//      * Gives access to an <tt>ElementAssertion</tt> object for the HTML element identified by the
//      * given XPath expression.
//      * 
//      * @param xpath
//      * @return
//      */
//     protected ElementAssertion element(String xpath) {
//         return testcase.element(xpath);
//     }
// 
//     private void verify(String message) {
//         try {
//             run();
//             throw new NoExceptionWasThrown();
//         } catch (AssertionFailedError expected) {
//             // everything went according to the plan!
//         } catch (NoExceptionWasThrown e) {
//             throw new AssertionFailedError(message);
//         } catch (Throwable e) {
//             throw new IncorrectExceptionError("A non-assertion exception was thrown: "
//                     + e.getClass().getName(), e);
//         }
//     }
// 
//     /**
//      * Thrown from an assertion method indicating that the wrong kind of exception was thrown by the
//      * code under test.
//      * 
//      * @author Lasse Koskela
//      */
//     public static class IncorrectExceptionError extends RuntimeException {
// 
//         public IncorrectExceptionError(String message, Throwable e) {
//             super(message, e);
//         }
//     }
// 
//     /**
//      * Thrown from an assertion method indicating that no exception was thrown by the code under
//      * test against the expectations. This class is only used internally and is never passed to
//      * client code (test written by a JspTest user).
//      * 
//      * @author Lasse Koskela
//      */
//     private static class NoExceptionWasThrown extends Exception {
//     }
// }


import net.sf.jsptest.assertion.ExpectedAssertionFailure;

/*
 * Copyright 2007 Lasse Koskela.
 * 
 * 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 net.sf.jsptest;


/**
 * @author Lasse Koskela
 */
public class TestHtmlTestCaseLinkAssertions extends AbstractHtmlTestCaseTestCase {

    private static final String LINK_HREF = "http://target.com/page.html";
    private static final String LINK_ID = "linkId";
    private static final String LINK_NAME = "linkName";
    private static final String LINK_TEXT = "linkText";
    private static final String LINK_CLASS = ".linkClass";
    private static final String IMAGE_ID = "imageId";
    private static final String IMAGE_NAME = "imageName";
    private static final String IMAGE_TITLE = "imageTitle";
    private static final String IMAGE_FILENAME = "filename.jpg";
    private static final String IMAGE_SRC = "./images/" + IMAGE_FILENAME;

    protected void appendOutput(StringBuffer h) {
        h.append("<html><head>");
        h.append("<title>PageTitle</title>");
        h.append("</head><body>");
        h.append("<a href='" + LINK_HREF + "'>Link with href</a>");
        h.append("<a id='" + LINK_ID + "'>Link with ID</a>");
        h.append("<a name='" + LINK_NAME + "'>Link with name</a>");
        h.append("<a class='" + LINK_CLASS + "'>Link with class</a>");
        h.append("<a href='foo'>" + LINK_TEXT + "</a>");
        h.append("<a name='foo'><img id='" + IMAGE_ID + "' name='" + IMAGE_NAME + "' src='"
                + IMAGE_SRC + "' title='" + IMAGE_TITLE + "'/></a>");
        h.append("</body></html>");
    }

    public void testShouldHaveLinkWithText() throws Exception {
        testcase.page().shouldHaveLink().withText(LINK_TEXT);

// Path: jsptest-generic/jsptest-framework/src/main/java/net/sf/jsptest/assertion/ExpectedAssertionFailure.java
// public abstract class ExpectedAssertionFailure {
// 
//     private HtmlTestCase testcase;
// 
//     /**
//      * Override this method to perform a test that should fail with an exception.
//      */
//     protected abstract void run() throws Exception;
// 
//     /**
//      * @param testcase
//      *            The <tt>HtmlTestCase</tt> that serves as the context for this operation.
//      */
//     public ExpectedAssertionFailure(HtmlTestCase testcase) throws Exception {
//         this(testcase, "Operation should've failed but it didn't.");
//     }
// 
//     /**
//      * @param testcase
//      *            The <tt>HtmlTestCase</tt> that serves as the context for this operation.
//      * @param message
//      *            The message to display if the specified operation doesn't throw an
//      *            AssertionFailedError.
//      */
//     public ExpectedAssertionFailure(HtmlTestCase testcase, String message) throws Exception {
//         this.testcase = testcase;
//         verify(message);
//     }
// 
//     /**
//      * Gives access to a <tt>PageAssertion</tt> object, enabling page-oriented (HTML) assertions.
//      */
//     protected PageAssertion page() {
//         return testcase.page();
//     }
// 
//     /**
//      * Gives access to an <tt>OutputAssertion</tt> object, enabling raw output-oriented
//      * assertions.
//      */
//     protected OutputAssertion output() {
//         return testcase.output();
//     }
// 
//     /**
//      * Gives access to an <tt>ElementAssertion</tt> object for the HTML element identified by the
//      * given XPath expression.
//      * 
//      * @param xpath
//      * @return
//      */
//     protected ElementAssertion element(String xpath) {
//         return testcase.element(xpath);
//     }
// 
//     private void verify(String message) {
//         try {
//             run();
//             throw new NoExceptionWasThrown();
//         } catch (AssertionFailedError expected) {
//             // everything went according to the plan!
//         } catch (NoExceptionWasThrown e) {
//             throw new AssertionFailedError(message);
//         } catch (Throwable e) {
//             throw new IncorrectExceptionError("A non-assertion exception was thrown: "
//                     + e.getClass().getName(), e);
//         }
//     }
// 
//     /**
//      * Thrown from an assertion method indicating that the wrong kind of exception was thrown by the
//      * code under test.
//      * 
//      * @author Lasse Koskela
//      */
//     public static class IncorrectExceptionError extends RuntimeException {
// 
//         public IncorrectExceptionError(String message, Throwable e) {
//             super(message, e);
//         }
//     }
// 
//     /**
//      * Thrown from an assertion method indicating that no exception was thrown by the code under
//      * test against the expectations. This class is only used internally and is never passed to
//      * client code (test written by a JspTest user).
//      * 
//      * @author Lasse Koskela
//      */
//     private static class NoExceptionWasThrown extends Exception {
//     }
// }


// Path: jsptest-generic/jsptest-framework/src/test/java/net/sf/jsptest/TestHtmlTestCaseLinkAssertions.java
import net.sf.jsptest.assertion.ExpectedAssertionFailure;

/*
 * Copyright 2007 Lasse Koskela.
 * 
 * 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 net.sf.jsptest;


/**
 * @author Lasse Koskela
 */
public class TestHtmlTestCaseLinkAssertions extends AbstractHtmlTestCaseTestCase {

    private static final String LINK_HREF = "http://target.com/page.html";
    private static final String LINK_ID = "linkId";
    private static final String LINK_NAME = "linkName";
    private static final String LINK_TEXT = "linkText";
    private static final String LINK_CLASS = ".linkClass";
    private static final String IMAGE_ID = "imageId";
    private static final String IMAGE_NAME = "imageName";
    private static final String IMAGE_TITLE = "imageTitle";
    private static final String IMAGE_FILENAME = "filename.jpg";
    private static final String IMAGE_SRC = "./images/" + IMAGE_FILENAME;

    protected void appendOutput(StringBuffer h) {
        h.append("<html><head>");
        h.append("<title>PageTitle</title>");
        h.append("</head><body>");
        h.append("<a href='" + LINK_HREF + "'>Link with href</a>");
        h.append("<a id='" + LINK_ID + "'>Link with ID</a>");
        h.append("<a name='" + LINK_NAME + "'>Link with name</a>");
        h.append("<a class='" + LINK_CLASS + "'>Link with class</a>");
        h.append("<a href='foo'>" + LINK_TEXT + "</a>");
        h.append("<a name='foo'><img id='" + IMAGE_ID + "' name='" + IMAGE_NAME + "' src='"
                + IMAGE_SRC + "' title='" + IMAGE_TITLE + "'/></a>");
        h.append("</body></html>");
    }

    public void testShouldHaveLinkWithText() throws Exception {
        testcase.page().shouldHaveLink().withText(LINK_TEXT);

        new ExpectedAssertionFailure(testcase) {
