Package org.apache.maven.shared.utils.xml

Examples of org.apache.maven.shared.utils.xml.Xpp3Dom


    public void testSetCompleted( WrappedReportEntry testSetReportEntry, TestSetStats testSetStats )
        throws ReporterException
    {

        Xpp3Dom testSuite = createTestSuiteElement( testSetReportEntry, testSetStats, reportNameSuffix );

        showProperties( testSuite );

        testSuite.setAttribute( "tests", String.valueOf( testSetStats.getCompletedCount() ) );

        testSuite.setAttribute( "errors", String.valueOf( testSetStats.getErrors() ) );

        testSuite.setAttribute( "skipped", String.valueOf( testSetStats.getSkipped() ) );

        testSuite.setAttribute( "failures", String.valueOf( testSetStats.getFailures() ) );

        for ( WrappedReportEntry entry : testSetStats.getReportEntries() )
        {
            if ( ReportEntryType.success.equals( entry.getReportEntryType() ) )
            {
                testSuite.addChild( createTestElement( entry, reportNameSuffix ) );
            }
            else
            {
                testSuite.addChild( getTestProblems( entry, trimStackTrace, reportNameSuffix ) );
            }

        }

        File reportFile = getReportFile( testSetReportEntry, reportsDirectory, reportNameSuffix );
View Full Code Here


        return reportFile;
    }

    private static Xpp3Dom createTestElement( WrappedReportEntry report, String reportNameSuffix )
    {
        Xpp3Dom testCase = new Xpp3Dom( "testcase" );
        testCase.setAttribute( "name", report.getReportName() );
        if ( report.getGroup() != null )
        {
            testCase.setAttribute( "group", report.getGroup() );
        }
        if ( report.getSourceName() != null )
        {
            if ( reportNameSuffix != null && reportNameSuffix.length() > 0 )
            {
                testCase.setAttribute( "classname", report.getSourceName() + "(" + reportNameSuffix + ")" );
            }
            else
            {
                testCase.setAttribute( "classname", report.getSourceName() );
            }
        }
        testCase.setAttribute( "time", report.elapsedTimeAsString() );
        return testCase;
    }
View Full Code Here

    }

    private static Xpp3Dom createTestSuiteElement( WrappedReportEntry report, TestSetStats testSetStats,
                                                   String reportNameSuffix1 )
    {
        Xpp3Dom testCase = new Xpp3Dom( "testsuite" );

        testCase.setAttribute( "name", report.getReportName( reportNameSuffix1 ) );

        if ( report.getGroup() != null )
        {
            testCase.setAttribute( "group", report.getGroup() );
        }
        testCase.setAttribute( "time", testSetStats.getElapsedForTestSet() );
        return testCase;
    }
View Full Code Here


    private Xpp3Dom getTestProblems( WrappedReportEntry report, boolean trimStackTrace, String reportNameSuffix )
    {

        Xpp3Dom testCase = createTestElement( report, reportNameSuffix );

        Xpp3Dom element = createElement( testCase, report.getReportEntryType().name() );

        String stackTrace = report.getStackTrace( trimStackTrace );

        if ( report.getMessage() != null && report.getMessage().length() > 0 )
        {
            element.setAttribute( "message", report.getMessage() );
        }

        if ( report.getStackTraceWriter() != null )
        {
            //noinspection ThrowableResultOfMethodCallIgnored
            SafeThrowable t = report.getStackTraceWriter().getThrowable();
            if ( t != null )
            {
                if ( t.getMessage() != null )
                {
                    element.setAttribute( "type", ( stackTrace.contains( ":" )
                        ? stackTrace.substring( 0, stackTrace.indexOf( ":" ) )
                        : stackTrace ) );
                }
                else
                {
                    element.setAttribute( "type", new StringTokenizer( stackTrace ).nextToken() );
                }
            }
        }

        if ( stackTrace != null )
        {
            element.setValue( stackTrace );
        }

        addOutputStreamElement( report.getStdout(), "system-out", testCase );

        addOutputStreamElement( report.getStdErr(), "system-err", testCase );
View Full Code Here

        }
    }

    private Xpp3Dom createElement( Xpp3Dom element, String name )
    {
        Xpp3Dom component = new Xpp3Dom( name );

        element.addChild( component );

        return component;
    }
View Full Code Here

     *
     * @param testSuite The test suite to report to
     */
    private void showProperties( Xpp3Dom testSuite )
    {
        Xpp3Dom properties = createElement( testSuite, "properties" );

        Properties systemProperties = System.getProperties();

        if ( systemProperties != null )
        {
            Enumeration<?> propertyKeys = systemProperties.propertyNames();

            while ( propertyKeys.hasMoreElements() )
            {
                String key = (String) propertyKeys.nextElement();

                String value = systemProperties.getProperty( key );

                if ( value == null )
                {
                    value = "null";
                }

                Xpp3Dom property = createElement( properties, "property" );

                property.setAttribute( "name", key );

                property.setAttribute( "value", value );

            }
        }
    }
View Full Code Here

    {
        Xpp3Dom[] children = readTests( validator, className );

        Assert.assertEquals( 1, children.length );

        Xpp3Dom child = children[0];

        Assert.assertEquals( className, child.getAttribute( "classname" ) );
        Assert.assertEquals( className, child.getAttribute( "name" ) );

        Assert.assertEquals( "Expected skipped tag for ignored method for " + className, 1,
                             child.getChildren( "skipped" ).length );

        Assert.assertTrue( "time for ignored test is expected to be zero",
                           Double.compare( Double.parseDouble( child.getAttribute( "time" ) ), 0.0d ) == 0 );
    }
View Full Code Here

    }

    private Xpp3Dom[] readTests( OutputValidator validator, String className )
        throws FileNotFoundException
    {
        Xpp3Dom testResult =
            Xpp3DomBuilder.build( validator.getSurefireReportsXmlFile( "TEST-" + className + ".xml" ).getFileInputStream(),
                                  "UTF-8" );
        Xpp3Dom[] children = testResult.getChildren( "testcase" );
        return children;
    }
View Full Code Here

    private void assertTestCount( TestFile reportFile, int tests )
        throws FileNotFoundException
    {
        assertTrue( reportFile.exists() );

        Xpp3Dom testResult = Xpp3DomBuilder.build( reportFile.getFileInputStream(), "UTF-8" );
        Xpp3Dom[] children = testResult.getChildren( "testcase" );
        assertEquals( tests, children.length );
    }
View Full Code Here

        StatelessXmlReporter reporter = new StatelessXmlReporter( new File( "." ), null, false );
        reporter.testSetCompleted( testSetReportEntry, stats );

        FileInputStream fileInputStream = new FileInputStream( expectedReportFile );

        Xpp3Dom testSuite = Xpp3DomBuilder.build( new InputStreamReader( fileInputStream, "UTF-8") );
        assertEquals( "testsuite", testSuite.getName() );
        Xpp3Dom properties = testSuite.getChild( "properties" );
        assertEquals( System.getProperties().size(), properties.getChildCount() );
        Xpp3Dom child = properties.getChild( 1 );
        assertFalse( StringUtils.isEmpty( child.getAttribute( "value" ) ) );
        assertFalse( StringUtils.isEmpty( child.getAttribute( "name" ) ) );

        Xpp3Dom[] testcase = testSuite.getChildren( "testcase" );
        Xpp3Dom tca = testcase[0];
        assertEquals( testName, tca.getAttribute( "name" ) ); // Hopefully same order on jdk5
        assertEquals( "0.012", tca.getAttribute( "time" ) );
        assertEquals( this.getClass().getName(), tca.getAttribute( "classname" ) );

        Xpp3Dom tcb = testcase[1];
        assertEquals( testName2, tcb.getAttribute( "name" ) );
        assertEquals( "0.013", tcb.getAttribute( "time" ) );
        assertEquals( Inner.class.getName(), tcb.getAttribute( "classname" ) );
        Xpp3Dom errorNode = tcb.getChild( "error" );
        assertNotNull( errorNode );
        assertEquals( "A fud msg", errorNode.getAttribute( "message" ) );
        assertEquals( "fail at foo", errorNode.getAttribute( "type" ) );
        assertEquals( "std-o\u00DCt<null>!", tcb.getChild( "system-out" ).getValue() );
        assertEquals( "std-\u0115rr?&-&amp;&#163;", tcb.getChild( "system-err" ).getValue() );

        expectedReportFile.delete();
    }
View Full Code Here

TOP

Related Classes of org.apache.maven.shared.utils.xml.Xpp3Dom

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.