View Javadoc
1   package org.apache.maven.plugin.jira;
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 java.io.File;
23  import java.io.InputStream;
24  
25  import org.apache.commons.io.FileUtils;
26  import org.apache.commons.io.IOUtils;
27  import org.apache.maven.plugin.testing.AbstractMojoTestCase;
28  
29  /**
30   * @version $Id: JiraUnicodeTestCase.java 1715100 2015-11-19 06:19:36Z krosenvold $
31   */
32  public class JiraUnicodeTestCase
33      extends AbstractMojoTestCase
34  {
35      /*
36       * Something in Doxia escapes all non-Ascii even when the charset is UTF-8. This test will fail if that ever
37       * changes.
38       */
39      private final static String TEST_TURTLES = "海龟一路下跌。";
40  
41      public void testUnicodeReport()
42          throws Exception
43      {
44  
45          File pom = new File( getBasedir(), "/src/test/unit/jira-plugin-config.xml" );
46          assertNotNull( pom );
47          assertTrue( pom.exists() );
48  
49          JiraMojo mojo = (JiraMojo) lookupMojo( "jira-report", pom );
50          InputStream testJiraXmlStream = JiraUnicodeTestCase.class.getResourceAsStream( "unicode-jira-results.xml" );
51          String jiraXml = null;
52          try {
53              jiraXml = IOUtils.toString(testJiraXmlStream, "utf-8");
54          } finally {
55              testJiraXmlStream.close();
56          }
57  
58          MockJiraDownloader mockDownloader = new MockJiraDownloader();
59          mockDownloader.setJiraXml( jiraXml );
60          mojo.setMockDownloader( mockDownloader );
61          File outputDir = new File( "target/jira-test-output" );
62          outputDir.mkdirs();
63          mojo.setReportOutputDirectory( outputDir );
64          mojo.execute();
65          String reportHtml = FileUtils.readFileToString( new File( outputDir, "jira-report.html" ), "utf-8" );
66          int turtleIndex = reportHtml.indexOf( TEST_TURTLES );
67          assertTrue( turtleIndex >= 0 );
68      }
69  
70  }