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.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   * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
32   * @version $Id: ChangeLogMojoTest.java 483105 2006-12-06 15:07:54Z evenisse $
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 }