1 package org.apache.maven.changelog;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 import org.apache.maven.plugin.testing.AbstractMojoTestCase;
20 import org.apache.maven.plugin.Mojo;
21 import org.apache.maven.changelog.stubs.ScmManagerStub;
22 import org.apache.maven.scm.manager.ScmManager;
23 import org.codehaus.plexus.util.FileUtils;
24
25 import java.io.File;
26
27 /**
28 * @author Edwin Punzalan
29 */
30 public class DeveloperActivityReportTest
31 extends AbstractMojoTestCase
32 {
33 private ScmManager scmManager;
34
35 public void testNoSource()
36 throws Exception
37 {
38 File pluginXmlFile = new File( getBasedir(),
39 "src/test/plugin-configs/dev-activity/no-source-plugin-config.xml" );
40
41 Mojo mojo = lookupMojo( "dev-activity", pluginXmlFile );
42
43 assertNotNull( "Mojo found.", mojo );
44
45 this.setVariableValueToObject( mojo, "manager", scmManager );
46
47 mojo.execute();
48
49 File outputDir = (File) getVariableValueFromObject( mojo, "outputDirectory" );
50
51 File outputHtml = new File( outputDir, "dev-activity.html" );
52
53 assertTrue( "Test html generated", outputHtml.exists() );
54 }
55
56 public void testMinConfig()
57 throws Exception
58 {
59 File outputXML = new File( getBasedir(), "src/test/changelog-xml/min-changelog.xml" );
60
61
62 outputXML.setLastModified( System.currentTimeMillis() );
63
64 executeMojo( "min-plugin-config.xml" );
65 }
66
67 private void executeMojo( String pluginXml )
68 throws Exception
69 {
70 File pluginXmlFile = new File( getBasedir(), "src/test/plugin-configs/dev-activity/" + pluginXml );
71
72 Mojo mojo = lookupMojo( "dev-activity", pluginXmlFile );
73
74 assertNotNull( "Mojo found.", mojo );
75
76 this.setVariableValueToObject( mojo, "manager", scmManager );
77
78 mojo.execute();
79
80 File outputXML = (File) getVariableValueFromObject( mojo, "outputXML" );
81
82 String encoding = (String) getVariableValueFromObject( mojo, "outputEncoding" );
83
84 assertTrue( "Test if changelog.xml is created", outputXML.exists() );
85
86 String changelogXml = FileUtils.fileRead( outputXML );
87
88 assertTrue( "Test for xml header", changelogXml.startsWith( "<?xml version=\"1.0\" encoding=\"" +
89 encoding + "\"?>" ) );
90
91 assertTrue( "Test for xml footer", changelogXml.endsWith( "</changelog>" ) );
92
93 File outputDir = (File) getVariableValueFromObject( mojo, "outputDirectory" );
94
95 File outputHtml = new File( outputDir, "dev-activity.html" );
96
97 assertTrue( "Test html generated", outputHtml.exists() );
98 }
99
100 protected void setUp()
101 throws Exception
102 {
103 super.setUp();
104
105 scmManager = new ScmManagerStub();
106 }
107 }