001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 */ 019package org.apache.maven.scm.plugin; 020 021import java.io.File; 022 023import org.apache.maven.plugin.MojoExecutionException; 024import org.apache.maven.scm.provider.ScmProviderRepositoryWithHost; 025import org.apache.maven.scm.provider.svn.SvnScmTestUtils; 026import org.codehaus.plexus.util.FileUtils; 027import org.codehaus.plexus.util.StringUtils; 028import org.junit.Before; 029import org.junit.Test; 030import org.junit.runner.RunWith; 031import org.junit.runners.JUnit4; 032 033import static org.apache.maven.scm.ScmTestCase.checkScmPresence; 034import static org.junit.Assert.assertNotEquals; 035 036/** 037 * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a> 038 * 039 */ 040@RunWith(JUnit4.class) 041public class CheckoutMojoTest extends AbstractJUnit4MojoTestCase { 042 File checkoutDir; 043 044 File repository; 045 046 @Before 047 public void setUp() throws Exception { 048 super.setUp(); 049 050 checkoutDir = getTestFile("target/checkout"); 051 052 repository = getTestFile("target/repository"); 053 054 FileUtils.forceDelete(checkoutDir); 055 } 056 057 @Test 058 public void testSkipCheckoutWhenCheckoutDirectoryExistsAndSkip() throws Exception { 059 FileUtils.forceDelete(checkoutDir); 060 checkoutDir.mkdirs(); 061 062 CheckoutMojo mojo = (CheckoutMojo) lookupMojo( 063 "checkout", 064 getTestFile("src/test/resources/mojos/checkout/checkoutWhenCheckoutDirectoryExistsAndSkip.xml")); 065 066 mojo.setCheckoutDirectory(checkoutDir); 067 068 mojo.execute(); 069 070 assertEquals(0, checkoutDir.listFiles().length); 071 } 072 073 @Test 074 public void testSkipCheckoutWithConnectionUrl() throws Exception { 075 checkScmPresence(SvnScmTestUtils.SVNADMIN_COMMAND_LINE); 076 077 FileUtils.forceDelete(checkoutDir); 078 079 SvnScmTestUtils.initializeRepository(repository); 080 081 checkScmPresence(SvnScmTestUtils.SVN_COMMAND_LINE); 082 083 CheckoutMojo mojo = (CheckoutMojo) 084 lookupMojo("checkout", getTestFile("src/test/resources/mojos/checkout/checkoutWithConnectionUrl.xml")); 085 mojo.setWorkingDirectory(new File(getBasedir())); 086 087 String connectionUrl = mojo.getConnectionUrl(); 088 connectionUrl = StringUtils.replace(connectionUrl, "${basedir}", getBasedir()); 089 connectionUrl = StringUtils.replace(connectionUrl, "\\", "/"); 090 mojo.setConnectionUrl(connectionUrl); 091 092 mojo.setCheckoutDirectory(checkoutDir); 093 094 mojo.execute(); 095 } 096 097 @Test 098 public void testSkipCheckoutWithoutConnectionUrl() throws Exception { 099 FileUtils.forceDelete(checkoutDir); 100 101 checkoutDir.mkdirs(); 102 CheckoutMojo mojo = (CheckoutMojo) lookupMojo( 103 "checkout", getTestFile("src/test/resources/mojos/checkout/checkoutWithoutConnectionUrl.xml")); 104 105 try { 106 mojo.execute(); 107 108 fail("mojo execution must fail."); 109 } catch (MojoExecutionException e) { 110 assertTrue(true); 111 } 112 } 113 114 @Test 115 public void testUseExport() throws Exception { 116 checkScmPresence(SvnScmTestUtils.SVN_COMMAND_LINE); 117 118 FileUtils.forceDelete(checkoutDir); 119 120 checkoutDir.mkdirs(); 121 122 CheckoutMojo mojo = (CheckoutMojo) 123 lookupMojo("checkout", getTestFile("src/test/resources/mojos/checkout/checkoutUsingExport.xml")); 124 125 mojo.setCheckoutDirectory(checkoutDir); 126 127 mojo.execute(); 128 129 assertTrue(checkoutDir.listFiles().length > 0); 130 assertFalse(new File(checkoutDir, ".svn").exists()); 131 } 132 133 @Test 134 public void testExcludeInclude() throws Exception { 135 checkScmPresence(SvnScmTestUtils.SVNADMIN_COMMAND_LINE); 136 137 FileUtils.forceDelete(checkoutDir); 138 139 checkoutDir.mkdirs(); 140 141 SvnScmTestUtils.initializeRepository(repository); 142 143 checkScmPresence(SvnScmTestUtils.SVN_COMMAND_LINE); 144 145 CheckoutMojo mojo = (CheckoutMojo) lookupMojo( 146 "checkout", getTestFile("src/test/resources/mojos/checkout/checkoutWithExcludesIncludes.xml")); 147 148 mojo.setCheckoutDirectory(checkoutDir); 149 150 mojo.execute(); 151 152 assertTrue(checkoutDir.listFiles().length > 0); 153 assertTrue(new File(checkoutDir, ".svn").exists()); 154 assertTrue(new File(checkoutDir, "pom.xml").exists()); 155 assertFalse(new File(checkoutDir, "readme.txt").exists()); 156 assertFalse(new File(checkoutDir, "src/test").exists()); 157 assertTrue(new File(checkoutDir, "src/main/java").exists()); 158 // olamy those files not exists anymore with svn 1.7 159 // assertTrue( new File( checkoutDir, "src/main/java/.svn" ).exists() ); 160 // assertTrue( new File( checkoutDir, "src/main/.svn" ).exists() ); 161 } 162 163 @Test 164 public void testEncryptedPasswordFromSettings() throws Exception { 165 File pom = getTestFile("src/test/resources/mojos/checkout/checkoutEncryptedPasswordFromSettings.xml"); 166 CheckoutMojo mojo = (CheckoutMojo) lookupMojo("checkout", pom); 167 ScmProviderRepositoryWithHost repo = 168 (ScmProviderRepositoryWithHost) mojo.getScmRepository().getProviderRepository(); 169 170 assertNotEquals( 171 "Raw encrypted Password was returned instead of the decrypted plaintext version", 172 "{Ael0S2tnXv8H3X+gHKpZAvAA25D8+gmU2w2RrGaf5v8=}", 173 repo.getPassword()); 174 175 assertNotEquals( 176 "Raw encrypted Passphrase was returned instead of the decrypted plaintext version", 177 "{7zK9P8hNVeUHbTsjiA/vnOs0zUXbND+9MBNPvdvl+x4=}", 178 repo.getPassphrase()); 179 180 assertEquals("testuser", repo.getUser()); 181 assertEquals("testpass", repo.getPassword()); 182 assertEquals("testphrase", repo.getPassphrase()); 183 } 184}