View Javadoc
1   package org.apache.maven.plugin.failsafe;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *     http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
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  }