View Javadoc
1   package org.apache.maven.surefire.its.jiras;
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.plugins.surefire.report.ReportTestCase;
23  import org.apache.maven.plugins.surefire.report.ReportTestSuite;
24  import org.apache.maven.surefire.its.fixture.HelperAssertions;
25  import org.apache.maven.surefire.its.fixture.OutputValidator;
26  import org.apache.maven.surefire.its.fixture.SurefireJUnit4IntegrationTestCase;
27  import org.junit.Test;
28  
29  import java.util.List;
30  
31  import static org.junit.Assert.assertEquals;
32  
33  /**
34   * Test Surefire-224 (XML test reports are not well-formed when failure message contains quotes)
35   *
36   * @author <a href="mailto:dfabulich@apache.org">Dan Fabulich</a>
37   */
38  public class Surefire224WellFormedXmlFailuresIT
39      extends SurefireJUnit4IntegrationTestCase
40  {
41      @SuppressWarnings("ConstantConditions")
42      @Test
43      public void testWellFormedXmlFailures()
44      {
45          OutputValidator outputValidator = unpack( "/surefire-224-wellFormedXmlFailures" ).executeTest();
46  
47          outputValidator.assertTestSuiteResults( 4, 0, 4, 0 );
48  
49          ReportTestSuite suite = HelperAssertions.extractReports( outputValidator.getBaseDir() ).get( 0 );
50          List<org.apache.maven.plugins.surefire.report.ReportTestCase> testCases = suite.getTestCases();
51          assertEquals( "Wrong number of test case objects", 4, testCases.size() );
52          ReportTestCase testQuote = null, testLower = null, testGreater = null, testU0000 = null;
53          for ( ReportTestCase current : testCases )
54          {
55              if ( "testQuote".equals( current.getName() ) )
56              {
57                  testQuote = current;
58              }
59              else if ( "testLower".equals( current.getName() ) )
60              {
61                  testLower = current;
62              }
63              else if ( "testGreater".equals( current.getName() ) )
64              {
65                  testGreater = current;
66              }
67              else if ( "testU0000".equals( current.getName() ) )
68              {
69                  testU0000 = current;
70              }
71          }
72          assertEquals( "Wrong error message", "\"", testQuote.getFailureMessage() );
73          assertEquals( "Wrong error message", "<", testLower.getFailureMessage() );
74          assertEquals( "Wrong error message", ">", testGreater.getFailureMessage() );
75          // SUREFIRE-456 we have to doubly-escape non-visible control characters like \u0000
76          assertEquals( "Wrong error message", "&#0;", testU0000.getFailureMessage() );
77      }
78  }