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