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   *
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.
37       * This test will fail if that ever 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 = IOUtils.toString( testJiraXmlStream, "utf-8" );
52          MockJiraDownloader mockDownloader = new MockJiraDownloader();
53          mockDownloader.setJiraXml( jiraXml );
54          mojo.setMockDownloader( mockDownloader );
55          File outputDir = new File ( "target/jira-test-output" );
56          outputDir.mkdirs();
57          mojo.setReportOutputDirectory( outputDir );
58          mojo.execute();
59          String reportHtml = FileUtils.readFileToString( new File( outputDir, "jira-report.html" ),
60                                                          "utf-8" ); 
61          int turtleIndex = reportHtml.indexOf( TEST_TURTLES );
62          assertTrue ( turtleIndex >= 0 );
63      }
64  
65  }