Package org.apache.cactus.internal

Examples of org.apache.cactus.internal.WebTestResult


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

        try
        {
            // Create an instance of the test class
            TestCase testInstance = getTestClassInstance(
                getTestClassName(), getWrappedTestClassName(),
                getTestMethodName());

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

            // Call it's method corresponding to the current test case
            if (testInstance instanceof CactusTestCase)
            {
                ((CactusTestCase) testInstance).runBareServer();               
               
            }
            else
            {
                testInstance.runBare();               
            }

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


        // context scope as the HTTP request will not block in some containers.
        // However this will not happen 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 result has been committed ...
        WebTestResult result = (WebTestResult) (this.webImplicitObjects
            .getServletContext().getAttribute(TEST_RESULTS));

        // It can happen that the result has not been written in the Servlet
        // context. This could happen for example when using a load-balancer
        // which would direct the second Cactus HTTP connection to another
        // instance. In that case, we throw an error.
        if (result == null)
        {
            String message = "Error getting test result. This could happen "
                + "for example if you're using a load-balancer. Please disable "
                + "it before running Cactus tests.";

            LOGGER.error(message);
            throw new ServletException(message);
        }      

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

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

        // Use UTF-8 to transfer the result back
        webImplicitObjects.getHttpServletResponse().setContentType(
            "text/xml; charset=UTF-8");

        try
        {
            Writer writer = getResponseWriter();

            writer.write(result.toXml());
            writer.close();
        }
        catch (IOException e)
        {
            String message = "Error writing WebTestResult instance to output "
View Full Code Here

     * @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);
        }
        catch (ParsingException e)
        {
            String url = this.configuration.getRedirectorURL(theRequest);
            throw new ChainedRuntimeException("Failed to get the test "
                + "results at [" + url + "]", 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 or ComparisonFailure
            // 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.

            // Note: We have to test the exceptions by string name as the JUnit
            // AssertionFailedError class is unfortunately not serializable...

            if ((result.getExceptionClassName().equals(
                "junit.framework.AssertionFailedError"))
                || (result.getExceptionClassName().equals(
                "junit.framework.ComparisonFailure")))
            {
                throw new AssertionFailedErrorWrapper(
                    result.getExceptionMessage(),
                    result.getExceptionClassName(),
                    result.getExceptionStackTrace());
            }
            else
            {
                throw new ServletExceptionWrapper(
                    result.getExceptionMessage(),
                    result.getExceptionClassName(),
                    result.getExceptionStackTrace());
            }
        }

        return connection;
    }
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

TOP

Related Classes of org.apache.cactus.internal.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.