View Javadoc

1   package org.apache.maven.surefire.report;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *     http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.io.File;
23  import org.codehaus.plexus.util.xml.Xpp3Dom;
24  
25  import junit.framework.AssertionFailedError;
26  import junit.framework.TestCase;
27  
28  public class XMLReporterTest
29      extends TestCase
30  {
31  
32      private XMLReporter reporter;
33  
34      private ReportEntry reportEntry;
35  
36      private String message;
37  
38      protected void setUp()
39          throws Exception
40      {
41          super.setUp();
42          reporter = new XMLReporter( true, new File( "." ));
43          message = "junit.framework.AssertionFailedError";
44          reportEntry = new SimpleReportEntry( this.getClass().getName(), "XMLReporterTest",
45                                               new PojoStackTraceWriter( "", "", new AssertionFailedError() ) );
46      }
47  
48      /*
49       * Test method for 'org.codehaus.surefire.report.XMLReporter.testError(ReportEntry, String, String)'
50       */
51      public void testTestError()
52      {
53          reporter.testError( reportEntry, "", "" );
54          assertResult( reporter, message );
55      }
56  
57      /*
58       * Test method for 'org.codehaus.surefire.report.XMLReporter.testFailed(ReportEntry, String, String)'
59       */
60      public void testTestFailed()
61      {
62          reporter.testError( reportEntry, "", "" );
63          assertResult( reporter, message );
64      }
65  
66      private void assertResult( XMLReporter reporter, String message )
67      {
68          Xpp3Dom result = (Xpp3Dom) reporter.getResults().next();
69          Xpp3Dom child = result.getChild( "error" );
70          assertEquals( message, child.getAttribute( "type" ) );
71      }
72  
73      /*
74       * Test method for 'org.codehaus.surefire.report.XMLReporter.testSetCompleted(ReportEntry report)'
75       */
76      public void testFileNameWithoutSuffix()
77      {
78          File reportDir = new File( "." );
79          String testName = "org.apache.maven.surefire.report.XMLReporterTest";
80          reportEntry = new SimpleReportEntry( this.getClass().getName(), testName );
81          reporter = new XMLReporter( true, reportDir, null );
82          reporter.testSetCompleted( reportEntry );
83  
84          File expectedReportFile = new File( reportDir, "TEST-" + testName + ".xml" );
85          assertTrue("Report file (" + expectedReportFile.getAbsolutePath() + ") doesn't exist",  expectedReportFile.exists() );
86          expectedReportFile.delete();
87      }
88  
89      /*
90       * Test method for 'org.codehaus.surefire.report.XMLReporter.testSetCompleted(ReportEntry report)'
91       */
92      public void testFileNameWithSuffix()
93      {
94          File reportDir = new File( "." );
95          String testName = "org.apache.maven.surefire.report.XMLReporterTest";
96          String suffixText = "sampleSuffixText";
97          reportEntry = new SimpleReportEntry( this.getClass().getName(), testName );
98          reporter = new XMLReporter( true, reportDir, suffixText );
99          reporter.testSetCompleted( reportEntry );
100 
101         File expectedReportFile = new File( reportDir, "TEST-" + testName + "-" + suffixText + ".xml" );
102         assertTrue("Report file (" + expectedReportFile.getAbsolutePath() + ") doesn't exist",  expectedReportFile.exists() );
103         expectedReportFile.delete();
104     }
105 
106 }