1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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 }