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.ScmProviderRepositoryWithHost; 026import org.apache.maven.scm.provider.svn.SvnScmTestUtils; 027import org.codehaus.plexus.util.FileUtils; 028import org.codehaus.plexus.util.StringUtils; 029 030import java.io.File; 031 032/** 033 * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a> 034 * 035 */ 036public class CheckoutMojoTest 037 extends AbstractMojoTestCase 038{ 039 File checkoutDir; 040 041 File repository; 042 043 protected void setUp() 044 throws Exception 045 { 046 super.setUp(); 047 048 checkoutDir = getTestFile( "target/checkout" ); 049 050 repository = getTestFile( "target/repository" ); 051 052 FileUtils.forceDelete( checkoutDir ); 053 } 054 055 public void testSkipCheckoutWhenCheckoutDirectoryExistsAndSkip() 056 throws Exception 057 { 058 FileUtils.forceDelete( checkoutDir ); 059 checkoutDir.mkdirs(); 060 061 CheckoutMojo mojo = (CheckoutMojo) lookupMojo( "checkout", getTestFile( 062 "src/test/resources/mojos/checkout/checkoutWhenCheckoutDirectoryExistsAndSkip.xml" ) ); 063 064 mojo.setCheckoutDirectory( checkoutDir ); 065 066 mojo.execute(); 067 068 assertEquals( 0, checkoutDir.listFiles().length ); 069 } 070 071 public void testSkipCheckoutWithConnectionUrl() 072 throws Exception 073 { 074 if ( !ScmTestCase.isSystemCmd( SvnScmTestUtils.SVNADMIN_COMMAND_LINE ) ) 075 { 076 System.err.println( "'" + SvnScmTestUtils.SVNADMIN_COMMAND_LINE 077 + "' is not a system command. Ignored " + getName() + "." ); 078 return; 079 } 080 081 FileUtils.forceDelete( checkoutDir ); 082 083 SvnScmTestUtils.initializeRepository( repository ); 084 085 CheckoutMojo mojo = (CheckoutMojo) lookupMojo( "checkout", getTestFile( 086 "src/test/resources/mojos/checkout/checkoutWithConnectionUrl.xml" ) ); 087 mojo.setWorkingDirectory( new File( getBasedir() ) ); 088 089 String connectionUrl = mojo.getConnectionUrl(); 090 connectionUrl = StringUtils.replace( connectionUrl, "${basedir}", getBasedir() ); 091 connectionUrl = StringUtils.replace( connectionUrl, "\\", "/" ); 092 mojo.setConnectionUrl( connectionUrl ); 093 094 mojo.setCheckoutDirectory( checkoutDir ); 095 096 mojo.execute(); 097 } 098 099 public void testSkipCheckoutWithoutConnectionUrl() 100 throws Exception 101 { 102 FileUtils.forceDelete( checkoutDir ); 103 104 checkoutDir.mkdirs(); 105 CheckoutMojo mojo = (CheckoutMojo) lookupMojo( "checkout", getTestFile( 106 "src/test/resources/mojos/checkout/checkoutWithoutConnectionUrl.xml" ) ); 107 108 try 109 { 110 mojo.execute(); 111 112 fail( "mojo execution must fail." ); 113 } 114 catch ( MojoExecutionException e ) 115 { 116 assertTrue( true ); 117 } 118 } 119 120 public void testUseExport() 121 throws Exception 122 { 123 FileUtils.forceDelete( checkoutDir ); 124 125 checkoutDir.mkdirs(); 126 127 CheckoutMojo mojo = (CheckoutMojo) lookupMojo( "checkout", getTestFile( 128 "src/test/resources/mojos/checkout/checkoutUsingExport.xml" ) ); 129 130 mojo.setCheckoutDirectory( checkoutDir ); 131 132 mojo.execute(); 133 134 assertTrue( checkoutDir.listFiles().length > 0 ); 135 assertFalse( new File( checkoutDir, ".svn" ).exists() ); 136 } 137 138 public void testExcludeInclude() 139 throws Exception 140 { 141 FileUtils.forceDelete( checkoutDir ); 142 143 checkoutDir.mkdirs(); 144 145 SvnScmTestUtils.initializeRepository( repository ); 146 147 CheckoutMojo mojo = (CheckoutMojo) lookupMojo( 148 "checkout", 149 getTestFile( "src/test/resources/mojos/checkout/checkoutWithExcludesIncludes.xml" ) ); 150 151 mojo.setCheckoutDirectory( checkoutDir ); 152 153 mojo.execute(); 154 155 assertTrue( checkoutDir.listFiles().length > 0 ); 156 assertTrue( new File( checkoutDir, ".svn").exists() ); 157 assertTrue( new File( checkoutDir, "pom.xml" ).exists() ); 158 assertFalse( new File( checkoutDir, "readme.txt" ).exists() ); 159 assertFalse( new File( checkoutDir, "src/test" ).exists() ); 160 assertTrue( new File( checkoutDir, "src/main/java" ).exists() ); 161 // olamy those files not exists anymore with svn 1.7 162 //assertTrue( new File( checkoutDir, "src/main/java/.svn" ).exists() ); 163 //assertTrue( new File( checkoutDir, "src/main/.svn" ).exists() ); 164 } 165 166 public void testEncryptedPasswordFromSettings() 167 throws Exception 168 { 169 File pom = getTestFile( "src/test/resources/mojos/checkout/checkoutEncryptedPasswordFromSettings.xml" ); 170 CheckoutMojo mojo = (CheckoutMojo) lookupMojo( "checkout", pom ); 171 ScmProviderRepositoryWithHost repo = 172 (ScmProviderRepositoryWithHost) mojo.getScmRepository().getProviderRepository(); 173 174 assertEquals( "testuser", repo.getUser() ); 175 assertEquals( "testpass", repo.getPassword() ); 176 assertEquals( "testphrase", repo.getPassphrase() ); 177 } 178 179}