001package org.apache.maven.scm.plugin; 002 003/* 004 * Licensed to the Apache Software Foundation (ASF) under one 005 * or more contributor license agreements. See the NOTICE file 006 * distributed with this work for additional information 007 * regarding copyright ownership. The ASF licenses this file 008 * to you under the Apache License, Version 2.0 (the 009 * "License"); you may not use this file except in compliance 010 * with the License. You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, 015 * software distributed under the License is distributed on an 016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 017 * KIND, either express or implied. See the License for the 018 * specific language governing permissions and limitations 019 * under the License. 020 */ 021 022import org.apache.maven.plugin.MojoExecutionException; 023import org.apache.maven.plugin.testing.AbstractMojoTestCase; 024import org.apache.maven.scm.ScmTestCase; 025import org.apache.maven.scm.provider.svn.SvnScmTestUtils; 026import org.codehaus.plexus.util.FileUtils; 027import org.codehaus.plexus.util.StringUtils; 028 029import java.io.File; 030 031/** 032 * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a> 033 * 034 */ 035public class ChangeLogMojoTest 036 extends AbstractMojoTestCase 037{ 038 File repository; 039 040 protected void setUp() 041 throws Exception 042 { 043 super.setUp(); 044 045 repository = getTestFile( "target/repository" ); 046 047 FileUtils.forceDelete( repository ); 048 049 if ( !ScmTestCase.isSystemCmd( SvnScmTestUtils.SVNADMIN_COMMAND_LINE ) ) 050 { 051 System.err.println( "'" + SvnScmTestUtils.SVNADMIN_COMMAND_LINE 052 + "' is not a system command. Ignored setUp." ); 053 return; 054 } 055 056 SvnScmTestUtils.initializeRepository( repository ); 057 } 058 059 public void testChangeLog() 060 throws Exception 061 { 062 if ( !ScmTestCase.isSystemCmd( SvnScmTestUtils.SVN_COMMAND_LINE ) ) 063 { 064 System.err.println( "'" + SvnScmTestUtils.SVN_COMMAND_LINE 065 + "' is not a system command. Ignored " + getName() + "." ); 066 return; 067 } 068 069 ChangeLogMojo mojo = (ChangeLogMojo) lookupMojo( "changelog", getTestFile( 070 "src/test/resources/mojos/changelog/changelog.xml" ) ); 071 072 String connectionUrl = mojo.getConnectionUrl(); 073 connectionUrl = StringUtils.replace( connectionUrl, "${basedir}", getBasedir() ); 074 connectionUrl = StringUtils.replace( connectionUrl, "\\", "/" ); 075 mojo.setConnectionUrl( connectionUrl ); 076 mojo.setWorkingDirectory( new File( getBasedir() ) ); 077 mojo.setConnectionType( "connection" ); 078 079 mojo.execute(); 080 } 081 082 public void testChangeLogWithParameters() 083 throws Exception 084 { 085 if ( !ScmTestCase.isSystemCmd( SvnScmTestUtils.SVN_COMMAND_LINE ) ) 086 { 087 System.err.println( "'" + SvnScmTestUtils.SVN_COMMAND_LINE 088 + "' is not a system command. Ignored " + getName() + "." ); 089 return; 090 } 091 092 ChangeLogMojo mojo = (ChangeLogMojo) lookupMojo( "changelog", getTestFile( 093 "src/test/resources/mojos/changelog/changelogWithParameters.xml" ) ); 094 095 String connectionUrl = mojo.getConnectionUrl(); 096 connectionUrl = StringUtils.replace( connectionUrl, "${basedir}", getBasedir() ); 097 connectionUrl = StringUtils.replace( connectionUrl, "\\", "/" ); 098 mojo.setConnectionUrl( connectionUrl ); 099 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}