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