View Javadoc

1   package org.apache.maven.surefire.its;
2   /*
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  You may obtain a copy of the License at
10   *
11   *     http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing,
14   * software distributed under the License is distributed on an
15   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16   * KIND, either express or implied.  See the License for the
17   * specific language governing permissions and limitations
18   * under the License.
19   */
20  
21  
22  import org.apache.maven.surefire.its.misc.HelperAssertions;
23  import org.apache.maven.surefire.its.misc.ReportTestCase;
24  import org.apache.maven.surefire.its.misc.ReportTestSuite;
25  
26  import java.io.File;
27  import java.util.List;
28  
29  /**
30   * Test Surefire-224 (XML test reports are not well-formed when failure message contains quotes)
31   *
32   * @author <a href="mailto:dfabulich@apache.org">Dan Fabulich</a>
33   */
34  public class Surefire224WellFormedXmlFailuresIT
35      extends SurefireVerifierTestClass
36  {
37  
38      public Surefire224WellFormedXmlFailuresIT()
39      {
40          super( "/surefire-224-wellFormedXmlFailures" );
41      }
42  
43      public void testWellFormedXmlFailures()
44          throws Exception
45      {
46          executeTest( );
47  
48          assertTestSuiteResults( 4, 0, 4, 0 );
49  
50          ReportTestSuite suite = (ReportTestSuite) HelperAssertions.extractReports( ( new File[]{ getTestDir() } ) ).get( 0 );
51          List<ReportTestCase> testCases = suite.getTestCases();
52          assertEquals( "Wrong number of test case objects", 4, testCases.size() );
53          ReportTestCase testQuote = null, testLower = null, testGreater = null, testU0000 = null;
54          for ( ReportTestCase current : testCases )
55          {
56              if ( "testQuote".equals( current.getName() ) )
57              {
58                  testQuote = current;
59              }
60              else if ( "testLower".equals( current.getName() ) )
61              {
62                  testLower = current;
63              }
64              else if ( "testGreater".equals( current.getName() ) )
65              {
66                  testGreater = current;
67              }
68              else if ( "testU0000".equals( current.getName() ) )
69              {
70                  testU0000 = current;
71              }
72          }
73          assertEquals( "Wrong error message", "\"", testQuote.getFailure().get( "message" ) );
74          assertEquals( "Wrong error message", "<", testLower.getFailure().get( "message" ) );
75          assertEquals( "Wrong error message", ">", testGreater.getFailure().get( "message" ) );
76          // SUREFIRE-456 we have to doubly-escape non-visible control characters like \u0000
77          assertEquals( "Wrong error message", "&#0;", testU0000.getFailure().get( "message" ) );
78      }
79  }