1 package org.apache.maven.scm.plugin;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.maven.plugin.MojoExecutionException;
23 import org.apache.maven.plugin.testing.AbstractMojoTestCase;
24 import org.apache.maven.scm.provider.svn.SvnScmTestUtils;
25 import org.codehaus.plexus.util.FileUtils;
26 import org.codehaus.plexus.util.StringUtils;
27
28 import java.io.File;
29
30
31
32
33
34 public class ChangeLogMojoTest
35 extends AbstractMojoTestCase
36 {
37 File repository;
38
39 protected void setUp()
40 throws Exception
41 {
42 super.setUp();
43
44 repository = getTestFile( "target/repository" );
45
46 FileUtils.forceDelete( repository );
47
48 SvnScmTestUtils.initializeRepository( repository );
49 }
50
51 public void testChangeLog()
52 throws Exception
53 {
54 ChangeLogMojo mojo = (ChangeLogMojo) lookupMojo( "changelog", getTestFile(
55 "src/test/resources/mojos/changelog/changelog.xml" ) );
56
57 String connectionUrl = mojo.getConnectionUrl();
58 connectionUrl = StringUtils.replace( connectionUrl, "${basedir}", getBasedir() );
59 connectionUrl = StringUtils.replace( connectionUrl, "\\", "/" );
60 mojo.setConnectionUrl( connectionUrl );
61 mojo.setWorkingDirectory( new File( getBasedir() ) );
62 mojo.setConnectionType( "connection" );
63
64 mojo.execute();
65 }
66
67 public void testChangeLogWithParameters()
68 throws Exception
69 {
70 ChangeLogMojo mojo = (ChangeLogMojo) lookupMojo( "changelog", getTestFile(
71 "src/test/resources/mojos/changelog/changelogWithParameters.xml" ) );
72
73 String connectionUrl = mojo.getConnectionUrl();
74 connectionUrl = StringUtils.replace( connectionUrl, "${basedir}", getBasedir() );
75 connectionUrl = StringUtils.replace( connectionUrl, "\\", "/" );
76 mojo.setConnectionUrl( connectionUrl );
77 mojo.setWorkingDirectory( new File( getBasedir() ) );
78 mojo.setConnectionType( "connection" );
79
80 mojo.execute();
81 }
82
83 public void testChangeLogWithBadUserDateFormat()
84 throws Exception
85 {
86 ChangeLogMojo mojo = (ChangeLogMojo) lookupMojo( "changelog", getTestFile(
87 "src/test/resources/mojos/changelog/changelogWithBadUserDateFormat.xml" ) );
88
89 String connectionUrl = mojo.getConnectionUrl();
90 connectionUrl = StringUtils.replace( connectionUrl, "${basedir}", getBasedir() );
91 connectionUrl = StringUtils.replace( connectionUrl, "\\", "/" );
92 mojo.setConnectionUrl( connectionUrl );
93 mojo.setWorkingDirectory( new File( getBasedir() ) );
94 mojo.setConnectionType( "connection" );
95
96 try
97 {
98 mojo.execute();
99
100 fail( "mojo execution must fail." );
101 }
102 catch ( MojoExecutionException e )
103 {
104 assertTrue( true );
105 }
106 }
107
108 public void testChangeLogWithBadConnectionUrl()
109 throws Exception
110 {
111 ChangeLogMojo mojo = (ChangeLogMojo) lookupMojo( "changelog", getTestFile(
112 "src/test/resources/mojos/changelog/changelogWithBadConnectionUrl.xml" ) );
113
114 String connectionUrl = mojo.getConnectionUrl();
115 connectionUrl = StringUtils.replace( connectionUrl, "${basedir}", getBasedir() );
116 connectionUrl = StringUtils.replace( connectionUrl, "\\", "/" );
117 mojo.setConnectionUrl( connectionUrl );
118 mojo.setWorkingDirectory( new File( getBasedir() ) );
119 mojo.setConnectionType( "connection" );
120
121 try
122 {
123 mojo.execute();
124
125 fail( "mojo execution must fail." );
126 }
127 catch ( MojoExecutionException e )
128 {
129 assertTrue( true );
130 }
131 }
132 }