View Javadoc

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:evenisse@apache.org">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              System.err.println( "'" + SvnScmTestUtils.SVNADMIN_COMMAND_LINE
52                  + "' is not a system command. Ignored setUp." );
53              return;
54          }
55  
56          SvnScmTestUtils.initializeRepository( repository );
57      }
58  
59      public void testChangeLog()
60          throws Exception
61      {
62          if ( !ScmTestCase.isSystemCmd( SvnScmTestUtils.SVN_COMMAND_LINE ) )
63          {
64              System.err.println( "'" + SvnScmTestUtils.SVN_COMMAND_LINE
65                  + "' is not a system command. Ignored " + getName() + "." );
66              return;
67          }
68  
69          ChangeLogMojo mojo = (ChangeLogMojo) lookupMojo( "changelog", getTestFile(
70              "src/test/resources/mojos/changelog/changelog.xml" ) );
71  
72          String connectionUrl = mojo.getConnectionUrl();
73          connectionUrl = StringUtils.replace( connectionUrl, "${basedir}", getBasedir() );
74          connectionUrl = StringUtils.replace( connectionUrl, "\\", "/" );
75          mojo.setConnectionUrl( connectionUrl );
76          mojo.setWorkingDirectory( new File( getBasedir() ) );
77          mojo.setConnectionType( "connection" );
78  
79          mojo.execute();
80      }
81  
82      public void testChangeLogWithParameters()
83          throws Exception
84      {
85          if ( !ScmTestCase.isSystemCmd( SvnScmTestUtils.SVN_COMMAND_LINE ) )
86          {
87              System.err.println( "'" + SvnScmTestUtils.SVN_COMMAND_LINE
88                  + "' is not a system command. Ignored " + getName() + "." );
89              return;
90          }
91  
92          ChangeLogMojo mojo = (ChangeLogMojo) lookupMojo( "changelog", getTestFile(
93              "src/test/resources/mojos/changelog/changelogWithParameters.xml" ) );
94  
95          String connectionUrl = mojo.getConnectionUrl();
96          connectionUrl = StringUtils.replace( connectionUrl, "${basedir}", getBasedir() );
97          connectionUrl = StringUtils.replace( connectionUrl, "\\", "/" );
98          mojo.setConnectionUrl( connectionUrl );
99          mojo.setWorkingDirectory( new File( getBasedir() ) );
100         mojo.setConnectionType( "connection" );
101 
102         mojo.execute();
103     }
104 
105     public void testChangeLogWithBadUserDateFormat()
106         throws Exception
107     {
108         ChangeLogMojo mojo = (ChangeLogMojo) lookupMojo( "changelog", getTestFile(
109             "src/test/resources/mojos/changelog/changelogWithBadUserDateFormat.xml" ) );
110 
111         String connectionUrl = mojo.getConnectionUrl();
112         connectionUrl = StringUtils.replace( connectionUrl, "${basedir}", getBasedir() );
113         connectionUrl = StringUtils.replace( connectionUrl, "\\", "/" );
114         mojo.setConnectionUrl( connectionUrl );
115         mojo.setWorkingDirectory( new File( getBasedir() ) );
116         mojo.setConnectionType( "connection" );
117 
118         try
119         {
120             mojo.execute();
121 
122             fail( "mojo execution must fail." );
123         }
124         catch ( MojoExecutionException e )
125         {
126             assertTrue( true );
127         }
128     }
129 
130     public void testChangeLogWithBadConnectionUrl()
131         throws Exception
132     {
133         ChangeLogMojo mojo = (ChangeLogMojo) lookupMojo( "changelog", getTestFile(
134             "src/test/resources/mojos/changelog/changelogWithBadConnectionUrl.xml" ) );
135 
136         String connectionUrl = mojo.getConnectionUrl();
137         connectionUrl = StringUtils.replace( connectionUrl, "${basedir}", getBasedir() );
138         connectionUrl = StringUtils.replace( connectionUrl, "\\", "/" );
139         mojo.setConnectionUrl( connectionUrl );
140         mojo.setWorkingDirectory( new File( getBasedir() ) );
141         mojo.setConnectionType( "connection" );
142 
143         try
144         {
145             mojo.execute();
146 
147             fail( "mojo execution must fail." );
148         }
149         catch ( MojoExecutionException e )
150         {
151             assertTrue( true );
152         }
153     }
154 }