Package org.apache.cactus

Examples of org.apache.cactus.WebTestResult


        // However this will not happend because on the client side, once the
        // first request is done to execute the test, all the result is read
        // by the AutoReadHttpURLConnection class, thus ensuring that the
        // request is fully finished and the resukt has been committed ...

        WebTestResult result =
            (WebTestResult) (this.webImplicitObjects.getServletContext().
            getAttribute(TEST_RESULTS));

        LOGGER.debug("Test Result = [" + result + "]");

        // Write back the results to the outgoing stream as an XML string.
        try {

            Writer writer = getResponseWriter();
            writer.write(result.toXml());
            writer.close();

        } catch (IOException e) {
            String message = "Error writing WebTestResult instance to output "
                + "stream";
View Full Code Here


     *
     * @exception ParsingException if error
     */
    public void testParseNoException() throws ParsingException
    {
        WebTestResult initialResult = new WebTestResult();
        WebTestResultParser parser = new WebTestResultParser();
        WebTestResult result = parser.parse(initialResult.toXml());

        assertNotNull(result);
        assertTrue(!result.hasException());
        assertNull(result.getExceptionClassName());
        assertNull(result.getExceptionMessage());
        assertNull(result.getExceptionStackTrace());
    }
View Full Code Here

     * @exception ParsingException if error
     */
    public void testParseWithException() throws ParsingException
    {
        Exception e = new Exception("test exception");
        WebTestResult initialResult = new WebTestResult(e);
        WebTestResultParser parser = new WebTestResultParser();
        WebTestResult result = parser.parse(initialResult.toXml());

        assertNotNull(result);
        assertTrue("There is no exception in the test result !",
            result.hasException());
        assertEquals("java.lang.Exception", result.getExceptionClassName());
        assertEquals("test exception", result.getExceptionMessage());
        assertTrue("Should not be empty",
            result.getExceptionStackTrace().length() > 0);
    }
View Full Code Here

     *
     * @exception ParsingException if error
     */
    public void testReadRootElementEmpty() throws ParsingException
    {
        WebTestResult initialResult = new WebTestResult();
        WebTestResultParser parser = new WebTestResultParser();

        String buffer = parser.readRootElement(initialResult.toXml());

        assertEquals("", buffer);
    }
View Full Code Here

            + "java.lang.Exception\"><message><![CDATA[test exception]]>"
            + "</message><stacktrace><![CDATA[";
        String expectedEnd = "]]></stacktrace></exception>";

        Exception e = new Exception("test exception");
        WebTestResult initialResult = new WebTestResult(e);
        WebTestResultParser parser = new WebTestResultParser();

        String buffer = parser.readRootElement(initialResult.toXml());

        assertTrue("Should have started with [" + expectedStart + "]",
            buffer.startsWith(expectedStart));
        assertTrue("Should have ended with [" + expectedEnd + "]",
            buffer.endsWith(expectedEnd));
View Full Code Here

        String expectedStart = "<message><![CDATA[test exception]]>"
            + "</message><stacktrace><![CDATA[";
        String expectedEnd = "]]></stacktrace>";

        Exception e = new Exception("test exception");
        WebTestResult initialResult = new WebTestResult(e);
        WebTestResultParser parser = new WebTestResultParser();
        String buffer = parser.readRootElement(initialResult.toXml());

        buffer = parser.readExceptionClassname(buffer);
        assertEquals("java.lang.Exception", parser.exceptionClassname);
        assertTrue("Should have started with [" + expectedStart + "]",
            buffer.startsWith(expectedStart));
View Full Code Here

    {
        String expectedStart = "<stacktrace><![CDATA[";
        String expectedEnd = "]]></stacktrace>";

        Exception e = new Exception("test exception");
        WebTestResult initialResult = new WebTestResult(e);
        WebTestResultParser parser = new WebTestResultParser();
        String buffer = parser.readRootElement(initialResult.toXml());

        buffer = parser.readExceptionClassname(buffer);

        buffer = parser.readExceptionMessage(buffer);
        assertEquals("test exception", parser.exceptionMessage);
View Full Code Here

     *         string
     */
    public WebTestResult parse(String theData)
    {
        String buffer;
        WebTestResult result;

        buffer = readRootElement(theData);

        if (buffer.length() == 0) {
            result = new WebTestResult();
        } else {
            buffer = readExceptionClassname(buffer);
            buffer = readExceptionMessage(buffer);
            buffer = readExceptionStacktrace(buffer);
            result = new WebTestResult(this.exceptionClassname,
                this.exceptionMessage, this.exceptionStacktrace);
        }

        return result;
    }
View Full Code Here

        // Open the first connection to the redirector to execute the test on
        // the server side
        HttpURLConnection connection = callRunTest(theRequest);

        // Open the second connection to get the test results
        WebTestResult result = callGetResult(theRequest.getAuthentication());

        // Check if the returned result object returned contains an error or
        // not. If yes, we need to raise an exception so that the JUnit
        // framework can catch it

        if (result.hasException()) {

            // Wrap the exception message and stack trace into a fake
            // exception class with overloaded <code>printStackTrace()</code>
            // methods so that when JUnit calls this method it will print the
            // stack trace that was set on the server side.

            // If the error was an AssertionFailedError then we use an instance
            // of AssertionFailedErrorWrapper (so that JUnit recognize it is
            // an AssertionFailedError exception and print it differently in
            // it's runner console). Otherwise we use an instance of
            // ServletExceptionWrapper.

            if (result.getExceptionClassName().
                equals("junit.framework.AssertionFailedError")) {

                throw new AssertionFailedErrorWrapper(
                    result.getExceptionMessage(),
                    result.getExceptionClassName(),
                    result.getExceptionStackTrace());

            } else {

                throw new ServletExceptionWrapper(
                    result.getExceptionMessage(),
                    result.getExceptionClassName(),
                    result.getExceptionStackTrace());

            }

        }
View Full Code Here

        HttpURLConnection resultConnection = helper.connect(resultsRequest);

        // Read the test result
        WebTestResultParser parser = new WebTestResultParser();
        WebTestResult result = parser.parse(
            IoUtil.getText(resultConnection.getInputStream()));

        return result;
    }
View Full Code Here

TOP

Related Classes of org.apache.cactus.WebTestResult

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.