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.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 }