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.plugin.failsafe;
20  
21  import java.io.File;
22  
23  import org.apache.maven.plugin.failsafe.util.FailsafeSummaryXmlUtils;
24  import org.apache.maven.surefire.api.suite.RunResult;
25  import org.apache.maven.surefire.api.util.SureFireFileManager;
26  import org.junit.Test;
27  
28  import static org.assertj.core.api.Assertions.assertThat;
29  
30  /**
31   * @author <a href="mailto:tibordigana@apache.org">Tibor Digana (tibor17)</a>
32   * @since 2.20
33   */
34  @SuppressWarnings("checkstyle:magicnumber")
35  public class RunResultTest {
36  
37      @Test
38      public void testAggregatedValues() {
39          RunResult simple = getSimpleAggregate();
40  
41          assertThat(simple.getCompletedCount()).isEqualTo(20);
42  
43          assertThat(simple.getErrors()).isEqualTo(3);
44  
45          assertThat(simple.getFailures()).isEqualTo(7);
46  
47          assertThat(simple.getSkipped()).isEqualTo(4);
48  
49          assertThat(simple.getFlakes()).isEqualTo(2);
50      }
51  
52      @Test
53      public void testSerialization() throws Exception {
54          writeReadCheck(getSimpleAggregate());
55      }
56  
57      @Test
58      public void testFailures() throws Exception {
59          writeReadCheck(new RunResult(0, 1, 2, 3, "stacktraceHere", false));
60      }
61  
62      @Test
63      public void testSkipped() throws Exception {
64          writeReadCheck(new RunResult(3, 2, 1, 0, null, true));
65      }
66  
67      @Test
68      public void testAppendSerialization() throws Exception {
69          RunResult simpleAggregate = getSimpleAggregate();
70          RunResult additional = new RunResult(2, 1, 2, 2, "msg " + ((char) 0x0E01), true);
71  
72          File summary = SureFireFileManager.createTempFile("failsafe", "test");
73          FailsafeSummaryXmlUtils.writeSummary(simpleAggregate, summary, false);
74          FailsafeSummaryXmlUtils.writeSummary(additional, summary, true);
75          RunResult actual = FailsafeSummaryXmlUtils.toRunResult(summary);
76          //noinspection ResultOfMethodCallIgnored
77          summary.delete();
78  
79          RunResult expected = simpleAggregate.aggregate(additional);
80  
81          assertThat(expected.getCompletedCount()).isEqualTo(22);
82  
83          assertThat(expected.getErrors()).isEqualTo(4);
84  
85          assertThat(expected.getFailures()).isEqualTo(9);
86  
87          assertThat(expected.getSkipped()).isEqualTo(6);
88  
89          assertThat(expected.getFlakes()).isEqualTo(2);
90  
91          assertThat(expected.getFailure()).isEqualTo("msg " + ((char) 0x0E01));
92  
93          assertThat(expected.isTimeout()).isTrue();
94  
95          assertThat(actual).isEqualTo(expected);
96      }
97  
98      private void writeReadCheck(RunResult expected) throws Exception {
99          File tmp = SureFireFileManager.createTempFile("test", "xml");
100         FailsafeSummaryXmlUtils.fromRunResultToFile(expected, tmp);
101 
102         RunResult actual = FailsafeSummaryXmlUtils.toRunResult(tmp);
103         //noinspection ResultOfMethodCallIgnored
104         tmp.delete();
105 
106         assertThat(actual).isEqualTo(expected);
107     }
108 
109     private RunResult getSimpleAggregate() {
110         RunResult resultOne = new RunResult(10, 1, 3, 2, 1);
111         RunResult resultTwo = new RunResult(10, 2, 4, 2, 1);
112         return resultOne.aggregate(resultTwo);
113     }
114 }