Debian Codegraph @

maven-scm-plugin/src/test/java/org/apache/maven/scm/plugin/ChangeLogMojoTest.java

raw
1 package org.apache.maven.scm.plugin;
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.MojoExecutionException;
23 import org.apache.maven.plugin.testing.AbstractMojoTestCase;
24 import org.apache.maven.scm.ScmTestCase;
25 import org.apache.maven.scm.provider.svn.SvnScmTestUtils;
26 import org.codehaus.plexus.util.FileUtils;
27 import org.codehaus.plexus.util.StringUtils;
28
29 import java.io.File;
30
31 /**
32 * @author <a href="mailto:[email protected]">Emmanuel Venisse</a>
33 *
34 */
35 public class ChangeLogMojoTest
36 extends AbstractMojoTestCase
37 {
38 File repository;
39
40 protected void setUp()
41 throws Exception
42 {
43 super.setUp();
44
45 repository = getTestFile( "target/repository" );
46
47 FileUtils.forceDelete( repository );
48
49 if ( !ScmTestCase.isSystemCmd( SvnScmTestUtils.SVNADMIN_COMMAND_LINE ) )
50 {
51 ScmTestCase.printSystemCmdUnavail( SvnScmTestUtils.SVNADMIN_COMMAND_LINE, "setUp" );
52 return;
53 }
54
55 SvnScmTestUtils.initializeRepository( repository );
56 }
57
58 public void testChangeLog()
59 throws Exception
60 {
61 if ( !ScmTestCase.isSystemCmd( SvnScmTestUtils.SVN_COMMAND_LINE ) )
62 {
63 ScmTestCase.printSystemCmdUnavail( SvnScmTestUtils.SVN_COMMAND_LINE, getName() );
64 return;
65 }
66
67 ChangeLogMojo mojo = (ChangeLogMojo) lookupMojo( "changelog", getTestFile(
68 "src/test/resources/mojos/changelog/changelog.xml" ) );
69
70 String connectionUrl = mojo.getConnectionUrl();
71 connectionUrl = StringUtils.replace( connectionUrl, "${basedir}", getBasedir() );
72 connectionUrl = StringUtils.replace( connectionUrl, "\\", "/" );
73 mojo.setConnectionUrl( connectionUrl );
74 mojo.setWorkingDirectory( new File( getBasedir() ) );
75 mojo.setConnectionType( "connection" );
76
77 mojo.execute();
78 }
79
80 public void testChangeLogWithParameters()
81 throws Exception
82 {
83 if ( !ScmTestCase.isSystemCmd( SvnScmTestUtils.SVN_COMMAND_LINE ) )
84 {
85 ScmTestCase.printSystemCmdUnavail( SvnScmTestUtils.SVN_COMMAND_LINE, getName() );
86 return;
87 }
88
89 ChangeLogMojo mojo = (ChangeLogMojo) lookupMojo( "changelog", getTestFile(
90 "src/test/resources/mojos/changelog/changelogWithParameters.xml" ) );
91
92 String connectionUrl = mojo.getConnectionUrl();
93 connectionUrl = StringUtils.replace( connectionUrl, "${basedir}", getBasedir() );
94 connectionUrl = StringUtils.replace( connectionUrl, "\\", "/" );
95 mojo.setConnectionUrl( connectionUrl );
96 mojo.setWorkingDirectory( new File( getBasedir() ) );
97 mojo.setConnectionType( "connection" );
98
99 mojo.execute();
100 }
101
102 public void testChangeLogWithBadUserDateFormat()
103 throws Exception
104 {
105 ChangeLogMojo mojo = (ChangeLogMojo) lookupMojo( "changelog", getTestFile(
106 "src/test/resources/mojos/changelog/changelogWithBadUserDateFormat.xml" ) );
107
108 String connectionUrl = mojo.getConnectionUrl();
109 connectionUrl = StringUtils.replace( connectionUrl, "${basedir}", getBasedir() );
110 connectionUrl = StringUtils.replace( connectionUrl, "\\", "/" );
111 mojo.setConnectionUrl( connectionUrl );
112 mojo.setWorkingDirectory( new File( getBasedir() ) );
113 mojo.setConnectionType( "connection" );
114
115 try
116 {
117 mojo.execute();
118
119 fail( "mojo execution must fail." );
120 }
121 catch ( MojoExecutionException e )
122 {
123 assertTrue( true );
124 }
125 }
126
127 public void testChangeLogWithBadConnectionUrl()
128 throws Exception
129 {
130 ChangeLogMojo mojo = (ChangeLogMojo) lookupMojo( "changelog", getTestFile(
131 "src/test/resources/mojos/changelog/changelogWithBadConnectionUrl.xml" ) );
132
133 String connectionUrl = mojo.getConnectionUrl();
134 connectionUrl = StringUtils.replace( connectionUrl, "${basedir}", getBasedir() );
135 connectionUrl = StringUtils.replace( connectionUrl, "\\", "/" );
136 mojo.setConnectionUrl( connectionUrl );
137 mojo.setWorkingDirectory( new File( getBasedir() ) );
138 mojo.setConnectionType( "connection" );
139
140 try
141 {
142 mojo.execute();
143
144 fail( "mojo execution must fail." );
145 }
146 catch ( MojoExecutionException e )
147 {
148 assertTrue( true );
149 }
150 }
151 }