View Javadoc

1   package org.apache.maven.continuum.reports.surefire;
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 org.codehaus.plexus.spring.PlexusInSpringTestCase;
23  
24  import java.io.File;
25  import java.util.List;
26  
27  /**
28   * @author <a href="mailto:olamy@apache.org">olamy</a>
29   * @version $Id: DefaultReportTestSuiteGeneratorTest.java 1372267 2012-08-13 05:47:30Z brett $
30   * @since 12 nov. 07
31   */
32  public class DefaultReportTestSuiteGeneratorTest
33      extends PlexusInSpringTestCase
34  {
35  
36      private File getReportsDirectory( String pathDir )
37      {
38          return new File( getBasedir() + File.separatorChar + "src" + File.separatorChar + "test" + File.separatorChar +
39                               "resources" + File.separatorChar + pathDir );
40      }
41  
42      public void testSimpleFile()
43          throws Exception
44      {
45          File testDirectory = getReportsDirectory( "simplereport" );
46  
47          ReportTestSuiteGenerator generator = (ReportTestSuiteGenerator) lookup( ReportTestSuiteGenerator.class,
48                                                                                  "default" );
49  
50          List<ReportTestSuite> reports = generator.generateReports( testDirectory );
51          assertEquals( 1, reports.size() );
52  
53          ReportTestSuite report = reports.get( 0 );
54  
55          assertEquals( "AppTest", report.getName() );
56  
57          assertEquals( 1, report.getNumberOfTests() );
58      }
59  
60      public void testContinuumCore()
61          throws Exception
62      {
63          ReportTestSuiteGenerator generator = (ReportTestSuiteGenerator) lookup( ReportTestSuiteGenerator.class,
64                                                                                  "default" );
65          List<ReportTestSuite> reports = generator.generateReports( 1, 1 );
66  
67          assertEquals( 18, reports.size() );
68  
69          for ( ReportTestSuite report : reports )
70          {
71              if ( report.getName().equals( "MailContinuumNotifierTest" ) && report.getPackageName().equals(
72                  "org.apache.maven.continuum.notification.mail" ) )
73              {
74                  assertEquals( 1, report.getNumberOfFailures() );
75                  // don't test this because can plate forme dependant
76                  //assertEquals( 11.578, report.getTimeElapsed() );
77                  assertEquals( 3, report.getNumberOfTests() );
78  
79                  for ( ReportTestCase testCase : report.getTestCases() )
80                  {
81                      if ( testCase.getName().equals( "testSuccessfulBuild" ) )
82                      {
83                          assertEquals( "junit.framework.ComparisonFailure", testCase.getFailureType() );
84                          assertEquals( "expected:&lt;...s&gt; but was:&lt;...&gt;", testCase.getFailureMessage() );
85                          assertTrue( testCase.getFailureDetails().startsWith( "junit.framework.ComparisonFailure" ) );
86                      }
87                  }
88              }
89  
90          }
91      }
92  
93      public void testgenerateReportTestResult()
94          throws Exception
95      {
96          ReportTestSuiteGenerator generator = (ReportTestSuiteGenerator) lookup( ReportTestSuiteGenerator.class,
97                                                                                  "default" );
98          ReportTestResult reportTestResult = generator.generateReportTestResult( 1, 1 );
99          assertEquals( 18, reportTestResult.getSuiteResults().size() );
100         assertEquals( 1, reportTestResult.getFailureCount() );
101         assertEquals( 62, reportTestResult.getTestCount() );
102         assertEquals( 1, reportTestResult.getErrorCount() );
103     }
104 }