1 package org.apache.maven.plugin.failsafe;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.maven.plugin.failsafe.util.FailsafeSummaryXmlUtils;
23 import org.apache.maven.surefire.api.suite.RunResult;
24 import org.junit.Test;
25
26 import java.io.File;
27
28 import static org.fest.assertions.Assertions.assertThat;
29
30
31
32
33 public class MarshallerUnmarshallerTest
34 {
35 @Test
36 public void shouldUnmarshallExistingXmlFile() throws Exception
37 {
38 File xml = new File( "target/test-classes/org/apache/maven/plugin/failsafe/failsafe-summary.xml" );
39 RunResult summary = FailsafeSummaryXmlUtils.toRunResult( xml );
40
41 assertThat( summary.getCompletedCount() )
42 .isEqualTo( 7 );
43
44 assertThat( summary.getErrors() )
45 .isEqualTo( 1 );
46
47 assertThat( summary.getFailures() )
48 .isEqualTo( 2 );
49
50 assertThat( summary.getSkipped() )
51 .isEqualTo( 3 );
52
53 assertThat( summary.getFailure() )
54 .contains( "There was an error in the forked processtest "
55 + "subsystem#no method RuntimeException Hi There!"
56 );
57
58 assertThat( summary.getFailure() )
59 .contains( "There was an error in the forked processtest "
60 + "subsystem#no method RuntimeException Hi There! $&>>"
61 + "\n\tat org.apache.maven.plugin.surefire.booterclient.ForkStarter"
62 + ".awaitResultsDone(ForkStarter.java:489)"
63 );
64 }
65
66 @Test
67 public void shouldMarshallAndUnmarshallSameXml() throws Exception
68 {
69 RunResult expected =
70 new RunResult( 7, 1, 2, 3, 2,
71 "There was an error in the forked processtest "
72 + "subsystem#no method RuntimeException Hi There! $&>>"
73 + "\n\tat org.apache.maven.plugin.surefire.booterclient.ForkStarter"
74 + ".awaitResultsDone(ForkStarter.java:489)", true );
75
76 File xml = File.createTempFile( "failsafe-summary", ".xml" );
77 FailsafeSummaryXmlUtils.writeSummary( expected, xml, false );
78
79 RunResult actual = FailsafeSummaryXmlUtils.toRunResult( xml );
80
81 assertThat( actual.getFailures() )
82 .isEqualTo( expected.getFailures() );
83
84 assertThat( actual.isTimeout() )
85 .isEqualTo( expected.isTimeout() );
86
87 assertThat( actual.getCompletedCount() )
88 .isEqualTo( expected.getCompletedCount() );
89
90 assertThat( actual.getErrors() )
91 .isEqualTo( expected.getErrors() );
92
93 assertThat( actual.getFailures() )
94 .isEqualTo( expected.getFailures() );
95
96 assertThat( actual.getSkipped() )
97 .isEqualTo( expected.getSkipped() );
98
99 assertThat( actual.getFailure() )
100 .isEqualTo( expected.getFailure() );
101 }
102 }