1   package org.apache.maven.plugin.changelog;
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.plugin.changelog.stubs.ScmManagerStub;
23  import org.apache.maven.scm.manager.ScmManager;
24  import org.codehaus.plexus.util.FileUtils;
25  
26  import java.io.File;
27  
28  /**
29   * @author Edwin Punzalan
30   * @version $Id: DeveloperActivityReportTest.java 803814 2009-08-13 09:24:45Z vsiveton $
31   */
32  public class DeveloperActivityReportTest
33      extends AbstractChangeLogReportTest
34  {
35      private ScmManager scmManager;
36  
37      /** {@inheritDoc} */
38      protected void setUp()
39          throws Exception
40      {
41          super.setUp();
42  
43          scmManager = new ScmManagerStub();
44      }
45  
46      /** {@inheritDoc} */
47      protected void tearDown()
48          throws Exception
49      {
50          super.tearDown();
51  
52          scmManager = null;
53      }
54  
55      public void testNoSource()
56          throws Exception
57      {
58          File pluginXmlFile = new File( getBasedir(),
59                                         "src/test/plugin-configs/dev-activity/no-source-plugin-config.xml" );
60  
61          DeveloperActivityReport mojo = (DeveloperActivityReport) lookupMojo( "dev-activity", pluginXmlFile );
62  
63          assertNotNull( "Mojo found.", mojo );
64  
65          this.setVariableValueToObject( mojo, "manager", scmManager );
66  
67          mojo.execute();
68  
69          File outputDir = (File) getVariableValueFromObject( mojo, "outputDirectory" );
70  
71          File outputHtml = new File( outputDir, "dev-activity.html" );
72  
73          renderer( mojo, outputHtml );
74  
75          assertTrue( outputHtml.getAbsolutePath() + " not generated!", outputHtml.exists() );
76  
77          assertTrue( outputHtml.getAbsolutePath() + " is empty!", outputHtml.length() > 0 );
78      }
79  
80      public void testMinConfig()
81          throws Exception
82      {
83          File outputXML = new File( getBasedir(), "src/test/changelog-xml/min-changelog.xml" );
84  
85          // force reuse of existing changelog cache
86          outputXML.setLastModified( System.currentTimeMillis() );
87  
88          executeMojo( "min-plugin-config.xml" );
89      }
90  
91      private void executeMojo( String pluginXml )
92          throws Exception
93      {
94          File pluginXmlFile = new File( getBasedir(), "src/test/plugin-configs/dev-activity/" + pluginXml );
95  
96          DeveloperActivityReport mojo = (DeveloperActivityReport)lookupMojo( "dev-activity", pluginXmlFile );
97  
98          assertNotNull( "Mojo found.", mojo );
99  
100         this.setVariableValueToObject( mojo, "manager", scmManager );
101 
102         mojo.execute();
103 
104         File outputXML = (File) getVariableValueFromObject( mojo, "outputXML" );
105 
106         String encoding = (String) getVariableValueFromObject( mojo, "outputEncoding" );
107 
108         assertTrue( "Test if changelog.xml is created", outputXML.exists() );
109 
110         String changelogXml = FileUtils.fileRead( outputXML );
111 
112         assertTrue( "Test for xml header", changelogXml.startsWith( "<?xml version=\"1.0\" encoding=\"" +
113                     encoding + "\"?>" ) );
114 
115         assertTrue( "Test for xml footer", changelogXml.endsWith( "</changelog>" ) );
116 
117         File outputDir = (File) getVariableValueFromObject( mojo, "outputDirectory" );
118 
119         File outputHtml = new File( outputDir, "dev-activity.html" );
120 
121         renderer( mojo, outputHtml );
122 
123         assertTrue( outputHtml.getAbsolutePath() + " not generated!", outputHtml.exists() );
124 
125         assertTrue( outputHtml.getAbsolutePath() + " is empty!", outputHtml.length() > 0 );
126     }
127 }