View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.plugins.changes.jira;
20  
21  import java.io.File;
22  import java.util.Collections;
23  import java.util.List;
24  
25  import org.apache.commons.io.FileUtils;
26  import org.apache.maven.execution.MavenSession;
27  import org.apache.maven.model.Plugin;
28  import org.apache.maven.plugin.MojoExecution;
29  import org.apache.maven.plugin.testing.AbstractMojoTestCase;
30  import org.apache.maven.plugins.changes.issues.Issue;
31  import org.apache.maven.project.MavenProject;
32  import org.eclipse.aether.DefaultRepositorySystemSession;
33  import org.eclipse.aether.RepositorySystem;
34  import org.eclipse.aether.repository.LocalRepository;
35  import org.eclipse.aether.repository.RemoteRepository;
36  
37  import static org.mockito.Mockito.mock;
38  import static org.mockito.Mockito.when;
39  
40  /**
41   * @version $Id$
42   */
43  public class JiraUnicodeTestCase extends AbstractMojoTestCase {
44      /*
45       * Something in Doxia escapes all non-Ascii even when the charset is UTF-8. This test will fail if that ever
46       * changes.
47       */
48      private static final String TEST_TURTLES = "海龟一路下跌。";
49  
50      public void testUnicodeReport() throws Exception {
51  
52          File pom = new File(getBasedir(), "/src/test/unit/jira-plugin-config.xml");
53          assertNotNull(pom);
54          assertTrue(pom.exists());
55  
56          JiraChangesReport mojo = lookupMojo("jira-changes", pom);
57          MavenProject project = new JiraUnicodeTestProjectStub();
58          MavenSession session = newMavenSession(project);
59  
60          RepositorySystem repositorySystem = lookup(RepositorySystem.class);
61  
62          DefaultRepositorySystemSession repositorySystemSession =
63                  (DefaultRepositorySystemSession) session.getRepositorySession();
64          repositorySystemSession.setLocalRepositoryManager(repositorySystem.newLocalRepositoryManager(
65                  repositorySystemSession, new LocalRepository(System.getProperty("localRepository"))));
66  
67          // Test need to download a maven-fluido-skin if not present in local repo
68          List<RemoteRepository> remoteRepositories = repositorySystem.newResolutionRepositories(
69                  repositorySystemSession,
70                  Collections.singletonList(
71                          new RemoteRepository.Builder("central", "default", "https://repo.maven.apache.org/maven2")
72                                  .build()));
73  
74          setVariableValueToObject(mojo, "project", project);
75          setVariableValueToObject(mojo, "reactorProjects", Collections.singletonList(project));
76          setVariableValueToObject(mojo, "repoSession", repositorySystemSession);
77          setVariableValueToObject(mojo, "remoteProjectRepositories", remoteRepositories);
78  
79          setVariableValueToObject(mojo, "siteDirectory", new File("non-existing"));
80          setVariableValueToObject(mojo, "mavenSession", session);
81          setVariableValueToObject(mojo, "mojoExecution", new MojoExecution(new Plugin(), "jira-changes", "default"));
82  
83          RestJiraDownloader mock = mock(RestJiraDownloader.class);
84          Issue issue = new Issue();
85          issue.setKey("PCSUNIT-2");
86          issue.setLink("http://pcsjira.slg.gr/browse/PCSUNIT-2");
87          issue.setSummary("海龟一路下跌。 Απεικόνιση σε EXCEL των data των φορμών. Περίπτωση με πολλά blocks");
88          issue.setStatus("Closed");
89          issue.setResolution("Fixed");
90          issue.setAssignee("Nikolaos Stais");
91          when(mock.getIssueList()).thenReturn(Collections.singletonList(issue));
92  
93          mojo.setMockDownloader(mock);
94          File outputDir = new File("target/jira-test-output");
95          outputDir.mkdirs();
96          mojo.setReportOutputDirectory(outputDir);
97          mojo.execute();
98          String reportHtml = FileUtils.readFileToString(new File(outputDir, "jira-changes.html"), "utf-8");
99          int turtleIndex = reportHtml.indexOf(TEST_TURTLES);
100         assertTrue(turtleIndex >= 0);
101     }
102 }