View Javadoc

1   package org.apache.maven.surefire.its.jiras;
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.FileNotFoundException;
23  import org.apache.maven.shared.utils.xml.Xpp3Dom;
24  import org.apache.maven.shared.utils.xml.Xpp3DomBuilder;
25  import org.apache.maven.surefire.its.fixture.OutputValidator;
26  import org.apache.maven.surefire.its.fixture.SurefireJUnit4IntegrationTestCase;
27  
28  import org.junit.Assert;
29  import org.junit.Test;
30  
31  public class Surefire943ReportContentIT
32      extends SurefireJUnit4IntegrationTestCase
33  {
34  
35      @Test
36      public void test_noParallel()
37          throws Exception
38      {
39          doTest( "none" );
40      }
41  
42      @Test
43      public void test_parallelBoth()
44          throws Exception
45      {
46          doTest( "both" );
47      }
48  
49      private void doTest( String parallelMode )
50          throws Exception
51      {
52          OutputValidator validator = unpack( "surefire-943-report-content" )
53                  .maven()
54                  .sysProp( "parallel", parallelMode )
55                  .sysProp( "threadCount", 4 )
56                  .withFailure()
57                  .executeTest();
58  
59          validator.assertTestSuiteResults( 9, 0, 3, 3 );
60  
61          validate( validator, "org.sample.module.My1Test", 1 );
62          validate( validator, "org.sample.module.My2Test", 1 );
63          validate( validator, "org.sample.module.My3Test", 0 );
64          validateSkipped( validator, "org.sample.module.My4Test" );
65      }
66  
67      private void validateSkipped( OutputValidator validator, String className )
68          throws FileNotFoundException
69      {
70          Xpp3Dom[] children = readTests( validator, className );
71  
72          Assert.assertEquals( 1, children.length );
73  
74          Xpp3Dom child = children[0];
75  
76          Assert.assertEquals( className, child.getAttribute( "classname" ) );
77          Assert.assertEquals( className, child.getAttribute( "name" ) );
78  
79          Assert.assertEquals( "Expected skipped tag for ignored method for " + className, 1,
80                               child.getChildren( "skipped" ).length );
81  
82          Assert.assertTrue( "time for ignored test is expected to be zero",
83                             Double.compare( Double.parseDouble( child.getAttribute( "time" ) ), 0.0d ) == 0 );
84      }
85  
86      private void validate( OutputValidator validator, String className, int ignored )
87          throws FileNotFoundException
88      {
89          Xpp3Dom[] children = readTests( validator, className );
90  
91          Assert.assertEquals( 2 + ignored, children.length );
92  
93          for ( Xpp3Dom child : children )
94          {
95              Assert.assertEquals( className, child.getAttribute( "classname" ) );
96  
97              if ( "alwaysSuccessful".equals( child.getAttribute( "name" ) ) )
98              {
99                  Assert.assertEquals( "Expected no failures for method alwaysSuccessful for " + className, 0,
100                                      child.getChildCount() );
101 
102                 Assert.assertTrue( "time for successful test is expected to be positive",
103                                    Double.compare( Double.parseDouble( child.getAttribute( "time" ) ), 0.0d ) > 0 );
104             }
105             else if ( child.getAttribute( "name" ).contains( "Ignored" ) )
106             {
107                 Assert.assertEquals( "Expected skipped-tag for ignored method for " + className, 1,
108                                      child.getChildren( "skipped" ).length );
109 
110                 Assert.assertTrue( "time for ignored test is expected to be zero",
111                                    Double.compare( Double.parseDouble( child.getAttribute( "time" ) ), 0.0d ) == 0 );
112 
113             }
114             else
115             {
116                 Assert.assertEquals( "Expected methods \"alwaysSuccessful\", \"*Ignored\" and \"fails\" in "
117                     + className, "fails", child.getAttribute( "name" ) );
118                 Assert.assertEquals( "Expected failure description for method \"fails\" in " + className, 1,
119                                      child.getChildren( "failure" ).length );
120                 Assert.assertTrue( "time for failed test is expected to be positive",
121                                    Double.compare( Double.parseDouble( child.getAttribute( "time" ) ), 0.0d ) > 0 );
122             }
123         }
124     }
125 
126     private Xpp3Dom[] readTests( OutputValidator validator, String className )
127         throws FileNotFoundException
128     {
129         Xpp3Dom testResult =
130             Xpp3DomBuilder.build( validator.getSurefireReportsXmlFile( "TEST-" + className + ".xml" ).getFileInputStream(),
131                                   "UTF-8" );
132         Xpp3Dom[] children = testResult.getChildren( "testcase" );
133         return children;
134     }
135 
136 }