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   *
32   */
33  public class MarshallerUnmarshallerTest {
34      @Test
35      public void shouldUnmarshallExistingXmlFile() throws Exception {
36          File xml = new File("target/test-classes/org/apache/maven/plugin/failsafe/failsafe-summary.xml");
37          RunResult summary = FailsafeSummaryXmlUtils.toRunResult(xml);
38  
39          assertThat(summary.getCompletedCount()).isEqualTo(7);
40  
41          assertThat(summary.getErrors()).isEqualTo(1);
42  
43          assertThat(summary.getFailures()).isEqualTo(2);
44  
45          assertThat(summary.getSkipped()).isEqualTo(3);
46  
47          assertThat(summary.getFailure())
48                  .contains("There was an error in the forked processtest "
49                          + "subsystem#no method RuntimeException Hi There!");
50  
51          assertThat(summary.getFailure())
52                  .contains("There was an error in the forked processtest "
53                          + "subsystem#no method RuntimeException Hi There! $&>>"
54                          + "\n\tat org.apache.maven.plugin.surefire.booterclient.ForkStarter"
55                          + ".awaitResultsDone(ForkStarter.java:489)");
56      }
57  
58      @Test
59      public void shouldMarshallAndUnmarshallSameXml() throws Exception {
60          RunResult expected = new RunResult(
61                  7,
62                  1,
63                  2,
64                  3,
65                  2,
66                  "There was an error in the forked processtest "
67                          + "subsystem#no method RuntimeException Hi There! $&>>"
68                          + "\n\tat org.apache.maven.plugin.surefire.booterclient.ForkStarter"
69                          + ".awaitResultsDone(ForkStarter.java:489)",
70                  true);
71  
72          File xml = SureFireFileManager.createTempFile("failsafe-summary", ".xml");
73          FailsafeSummaryXmlUtils.writeSummary(expected, xml, false);
74  
75          RunResult actual = FailsafeSummaryXmlUtils.toRunResult(xml);
76  
77          assertThat(actual.getFailures()).isEqualTo(expected.getFailures());
78  
79          assertThat(actual.isTimeout()).isEqualTo(expected.isTimeout());
80  
81          assertThat(actual.getCompletedCount()).isEqualTo(expected.getCompletedCount());
82  
83          assertThat(actual.getErrors()).isEqualTo(expected.getErrors());
84  
85          assertThat(actual.getFailures()).isEqualTo(expected.getFailures());
86  
87          assertThat(actual.getSkipped()).isEqualTo(expected.getSkipped());
88  
89          assertThat(actual.getFailure()).isEqualTo(expected.getFailure());
90      }
91  }