1 package org.apache.maven.plugin.changelog;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.File;
23
24 import org.apache.maven.plugin.changelog.stubs.ScmManagerStub;
25 import org.apache.maven.scm.manager.ScmManager;
26 import org.codehaus.plexus.util.FileUtils;
27
28
29
30
31
32 public class FileActivityReportTest
33 extends AbstractChangeLogReportTest
34 {
35 private ScmManager scmManager;
36
37
38 protected void setUp()
39 throws Exception
40 {
41 super.setUp();
42
43 scmManager = new ScmManagerStub();
44 }
45
46
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 =
59 new File( getBasedir(), "src/test/plugin-configs/file-activity/no-source-plugin-config.xml" );
60
61 FileActivityReport mojo = (FileActivityReport) lookupMojo( "file-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, "file-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
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/file-activity/" + pluginXml );
95
96 FileActivityReport mojo = (FileActivityReport) lookupMojo( "file-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=\"" + encoding
113 + "\"?>" ) );
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, "file-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 }