View Javadoc
1   package org.apache.maven.plugin.failsafe;
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.apache.maven.plugin.failsafe.util.FailsafeSummaryXmlUtils;
23  import org.apache.maven.surefire.suite.RunResult;
24  import org.junit.Test;
25  
26  import java.io.File;
27  import java.nio.charset.Charset;
28  
29  import static org.fest.assertions.Assertions.assertThat;
30  
31  /**
32   * @author <a href="mailto:tibordigana@apache.org">Tibor Digana (tibor17)</a>
33   * @since 2.20
34   */
35  public class RunResultTest
36  {
37  
38      @Test
39      public void testAggregatedValues()
40      {
41          RunResult simple = getSimpleAggregate();
42  
43          assertThat( simple.getCompletedCount() )
44                  .isEqualTo( 20 );
45  
46          assertThat( simple.getErrors() )
47                  .isEqualTo( 3 );
48  
49          assertThat( simple.getFailures() )
50                  .isEqualTo( 7 );
51  
52          assertThat( simple.getSkipped() )
53                  .isEqualTo( 4 );
54  
55          assertThat( simple.getFlakes() )
56                  .isEqualTo( 2 );
57      }
58  
59      @Test
60      public void testSerialization()
61              throws Exception
62      {
63          writeReadCheck( getSimpleAggregate() );
64      }
65  
66      @Test
67      public void testFailures()
68              throws Exception
69      {
70          writeReadCheck( new RunResult( 0, 1, 2, 3, "stacktraceHere", false ) );
71      }
72  
73      @Test
74      public void testSkipped()
75              throws Exception
76      {
77          writeReadCheck( new RunResult( 3, 2, 1, 0, null, true ) );
78      }
79  
80      @Test
81      public void testAppendSerialization()
82              throws Exception
83      {
84          RunResult simpleAggregate = getSimpleAggregate();
85          RunResult additional = new RunResult( 2, 1, 2, 2, "msg " + ( (char) 0x0E01 ), true );
86  
87          File summary = File.createTempFile( "failsafe", "test" );
88          FailsafeSummaryXmlUtils.writeSummary( simpleAggregate, summary, false );
89          FailsafeSummaryXmlUtils.writeSummary( additional, summary, true );
90          RunResult actual = FailsafeSummaryXmlUtils.toRunResult( summary );
91          //noinspection ResultOfMethodCallIgnored
92          summary.delete();
93  
94          RunResult expected = simpleAggregate.aggregate( additional );
95  
96          assertThat( expected.getCompletedCount() )
97                  .isEqualTo( 22 );
98  
99          assertThat( expected.getErrors() )
100                 .isEqualTo( 4 );
101 
102         assertThat( expected.getFailures() )
103                 .isEqualTo( 9 );
104 
105         assertThat( expected.getSkipped() )
106                 .isEqualTo( 6 );
107 
108         assertThat( expected.getFlakes() )
109                 .isEqualTo( 2 );
110 
111         assertThat( expected.getFailure() )
112                 .isEqualTo( "msg " + ( (char) 0x0E01 ) );
113 
114         assertThat( expected.isTimeout() )
115                 .isTrue();
116 
117         assertThat( actual )
118                 .isEqualTo( expected );
119     }
120 
121     @Test
122     public void shouldAcceptAliasCharset()
123     {
124         Charset charset1 = IntegrationTestMojo.toCharset( "UTF8" );
125         assertThat( charset1.name() ).isEqualTo( "UTF-8" );
126 
127         Charset charset2 = IntegrationTestMojo.toCharset( "utf8" );
128         assertThat( charset2.name() ).isEqualTo( "UTF-8" );
129     }
130 
131     private void writeReadCheck( RunResult expected )
132             throws Exception
133     {
134         File tmp = File.createTempFile( "test", "xml" );
135         FailsafeSummaryXmlUtils.fromRunResultToFile( expected, tmp );
136 
137         RunResult actual = FailsafeSummaryXmlUtils.toRunResult( tmp );
138         //noinspection ResultOfMethodCallIgnored
139         tmp.delete();
140 
141         assertThat( actual )
142                 .isEqualTo( expected );
143     }
144 
145     private RunResult getSimpleAggregate()
146     {
147         RunResult resultOne = new RunResult( 10, 1, 3, 2, 1 );
148         RunResult resultTwo = new RunResult( 10, 2, 4, 2, 1 );
149         return resultOne.aggregate( resultTwo );
150     }
151 }