View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.continuum.reports.surefire;
20  
21  import org.codehaus.plexus.spring.PlexusInSpringTestCase;
22  
23  import java.io.File;
24  import java.util.List;
25  
26  /**
27   * @author <a href="mailto:olamy@apache.org">olamy</a>
28   * @version $Id: DefaultReportTestSuiteGeneratorTest.java 729433 2008-12-25 19:06:08Z olamy $
29   * @since 12 nov. 07
30   */
31  public class DefaultReportTestSuiteGeneratorTest
32      extends PlexusInSpringTestCase
33  {
34  
35      private File getReportsDirectory( String pathDir )
36      {
37          return new File( getBasedir() + File.separatorChar + "src" + File.separatorChar + "test" + File.separatorChar +
38              "resources" + File.separatorChar + pathDir );
39      }
40  
41      public void testSimpleFile()
42          throws Exception
43      {
44          File testDirectory = getReportsDirectory( "simplereport" );
45  
46          ReportTestSuiteGenerator generator =
47              (ReportTestSuiteGenerator) lookup( ReportTestSuiteGenerator.class, "default" );
48  
49          List<ReportTestSuite> reports = generator.generateReports( testDirectory );
50          assertEquals( 1, reports.size() );
51  
52          ReportTestSuite report = reports.get( 0 );
53  
54          assertEquals( "AppTest", report.getName() );
55  
56          assertEquals( 1, report.getNumberOfTests() );
57      }
58  
59      public void testContinuumCore()
60          throws Exception
61      {
62          ReportTestSuiteGenerator generator =
63              (ReportTestSuiteGenerator) lookup( ReportTestSuiteGenerator.class, "default" );
64          List<ReportTestSuite> reports = generator.generateReports( 1, 1 );
65  
66          assertEquals( 18, reports.size() );
67  
68          for ( ReportTestSuite report : reports )
69          {
70              if ( report.getName().equals( "MailContinuumNotifierTest" ) &&
71                  report.getPackageName().equals( "org.apache.maven.continuum.notification.mail" ) )
72              {
73                  assertEquals( 1, report.getNumberOfFailures() );
74                  // don't test this because can plate forme dependant
75                  //assertEquals( 11.578, report.getTimeElapsed() );
76                  assertEquals( 3, report.getNumberOfTests() );
77  
78                  for ( ReportTestCase testCase : report.getTestCases() )
79                  {
80                      if ( testCase.getName().equals( "testSuccessfulBuild" ) )
81                      {
82                          assertEquals( "junit.framework.ComparisonFailure", testCase.getFailureType() );
83                          assertEquals( "expected:&lt;...s&gt; but was:&lt;...&gt;", testCase.getFailureMessage() );
84                          assertTrue( testCase.getFailureDetails().startsWith( "junit.framework.ComparisonFailure" ) );
85                      }
86                  }
87              }
88  
89          }
90      }
91  
92      public void testgenerateReportTestResult()
93          throws Exception
94      {
95          ReportTestSuiteGenerator generator =
96              (ReportTestSuiteGenerator) lookup( ReportTestSuiteGenerator.class, "default" );
97          ReportTestResult reportTestResult = generator.generateReportTestResult( 1, 1 );
98          assertEquals( 18, reportTestResult.getSuiteResults().size() );
99          assertEquals( 1, reportTestResult.getFailureCount() );
100         assertEquals( 62, reportTestResult.getTestCount() );
101         assertEquals( 1, reportTestResult.getErrorCount() );
102     }
103 }