Package org.apache.cactus

Examples of org.apache.cactus.WebTestResult


     * @exception ParsingException if an error happens during parsing
     */
    public WebTestResult parse(String theData) throws ParsingException
    {
        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 = null;
        try {
            result = callGetResult(theRequest.getAuthentication());
        } catch (ParsingException e) {
            throw new ChainedRuntimeException("Failed to get the test "
                + "results. This is probably due to an error that happened on "
                + "the server side when trying to execute the tests. Here is "
                + "what was returned by the server : ["
                + new WebResponse(theRequest, connection).getText() + "]", e);
        }

        // 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

     *
     * @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);
        assertTrue("Should have started with [" + expectedStart + "]",
View Full Code Here

     *
     * @exception ServletException if an unexpected error occurred
     */
    public void doTest() throws ServletException
    {
        WebTestResult result = null;

        try {

            // Create an instance of the test class
            AbstractTestCase testInstance = getTestClassInstance(
                getTestClassName(), getTestMethodName());

            // Set its fields (implicit objects)
            setTestCaseFields(testInstance);

            // Call it's method corresponding to the current test case
            testInstance.runBareServerTest();

            // Return an instance of <code>WebTestResult</code> with a
            // positive result.
            result = new WebTestResult();

        } catch (Throwable e) {
            // An error occurred, return an instance of
            // <code>WebTestResult</code> with an exception.
            result = new WebTestResult(e);

        }

        LOGGER.debug("Test result : [" + 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.