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.provider.svn.svnexe.command.branch; 020 021import java.io.File; 022 023import org.apache.maven.scm.ScmBranchParameters; 024import org.apache.maven.scm.provider.svn.command.branch.SvnBranchCommandTckTest; 025import org.apache.maven.scm.provider.svn.repository.SvnScmProviderRepository; 026import org.apache.maven.scm.repository.ScmRepository; 027import org.codehaus.plexus.util.cli.Commandline; 028import org.junit.Test; 029 030import static org.apache.maven.scm.provider.svn.SvnScmTestUtils.SVN_COMMAND_LINE; 031 032/** 033 * This test tests the branch command. 034 * 035 * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a> 036 * 037 */ 038public class SvnExeBranchCommandTckTest extends SvnBranchCommandTckTest { 039 public String getScmProviderCommand() { 040 return SVN_COMMAND_LINE; 041 } 042 043 // --no-auth-cache 044 @Test 045 public void testBranchUserNameSvnHttpsRemoteBranchingWithRev() throws Exception { 046 File messageFile = File.createTempFile("maven-scm", "commit"); 047 messageFile.deleteOnExit(); 048 049 ScmBranchParameters scmBranchParameters = new ScmBranchParameters(); 050 scmBranchParameters.setRemoteBranching(true); 051 scmBranchParameters.setPinExternals(false); 052 scmBranchParameters.setScmRevision("2"); 053 054 testCommandLine( 055 "scm:svn:https://foo.com/svn/trunk", 056 "svnbranch", 057 messageFile, 058 "user", 059 "svn --username user --no-auth-cache --non-interactive copy --parents --file " 060 + messageFile.getAbsolutePath() 061 + " --encoding UTF-8 --revision 2 https://foo.com/svn/trunk@ https://foo.com/svn/branches/svnbranch@", 062 scmBranchParameters); 063 } 064 065 @Test 066 public void testBranchUserNameSvnHttpsRemoteBranchingWithRevWithPinExternals() throws Exception { 067 File messageFile = File.createTempFile("maven-scm", "commit"); 068 messageFile.deleteOnExit(); 069 070 ScmBranchParameters scmBranchParameters = new ScmBranchParameters(); 071 scmBranchParameters.setRemoteBranching(true); 072 scmBranchParameters.setPinExternals(true); 073 scmBranchParameters.setScmRevision("2"); 074 075 testCommandLine( 076 "scm:svn:https://foo.com/svn/trunk", 077 "svnbranch", 078 messageFile, 079 "user", 080 "svn --username user --no-auth-cache --non-interactive copy --parents --file " 081 + messageFile.getAbsolutePath() 082 + " --encoding UTF-8 --pin-externals --revision 2 https://foo.com/svn/trunk@ https://foo.com/svn/branches/svnbranch@", 083 scmBranchParameters); 084 } 085 086 @Test 087 public void testBranchUserNameSvnHttpsRemoteBranchingNoRev() throws Exception { 088 File messageFile = File.createTempFile("maven-scm", "commit"); 089 messageFile.deleteOnExit(); 090 091 ScmBranchParameters scmBranchParameters = new ScmBranchParameters(); 092 scmBranchParameters.setRemoteBranching(true); 093 scmBranchParameters.setPinExternals(false); 094 095 testCommandLine( 096 "scm:svn:https://foo.com/svn/trunk", 097 "svnbranch", 098 messageFile, 099 "user", 100 "svn --username user --no-auth-cache --non-interactive copy --parents --file " 101 + messageFile.getAbsolutePath() 102 + " --encoding UTF-8 https://foo.com/svn/trunk@ https://foo.com/svn/branches/svnbranch@", 103 scmBranchParameters); 104 } 105 106 @Test 107 public void testBranchUserNameSvnHttpsRemoteBranchingNoRevWithPinExternals() throws Exception { 108 File messageFile = File.createTempFile("maven-scm", "commit"); 109 messageFile.deleteOnExit(); 110 111 ScmBranchParameters scmBranchParameters = new ScmBranchParameters(); 112 scmBranchParameters.setRemoteBranching(true); 113 scmBranchParameters.setPinExternals(true); 114 115 testCommandLine( 116 "scm:svn:https://foo.com/svn/trunk", 117 "svnbranch", 118 messageFile, 119 "user", 120 "svn --username user --no-auth-cache --non-interactive copy --parents --file " 121 + messageFile.getAbsolutePath() 122 + " --encoding UTF-8 --pin-externals https://foo.com/svn/trunk@ https://foo.com/svn/branches/svnbranch@", 123 scmBranchParameters); 124 } 125 126 @Test 127 public void testBranchUserNameSvnHttps() throws Exception { 128 File messageFile = File.createTempFile("maven-scm", "commit"); 129 messageFile.deleteOnExit(); 130 131 testCommandLine( 132 "scm:svn:https://foo.com/svn/trunk", 133 "svnbranch", 134 messageFile, 135 "user", 136 "svn --username user --no-auth-cache --non-interactive copy --parents --file " 137 + messageFile.getAbsolutePath() + " --encoding UTF-8 . https://foo.com/svn/branches/svnbranch@", 138 null); 139 } 140 141 @Test 142 public void testBranchUserNameSvnSsh() throws Exception { 143 File messageFile = File.createTempFile("maven-scm", "commit"); 144 messageFile.deleteOnExit(); 145 146 testCommandLine( 147 "scm:svn:svn+ssh://foo.com/svn/trunk", 148 "svnbranch", 149 messageFile, 150 "user", 151 "svn --username user --no-auth-cache --non-interactive copy --parents --file " 152 + messageFile.getAbsolutePath() 153 + " --encoding UTF-8 . svn+ssh://user@foo.com/svn/branches/svnbranch@"); 154 } 155 156 private void testCommandLine( 157 String scmUrl, 158 String branch, 159 File messageFile, 160 String user, 161 String commandLine, 162 ScmBranchParameters scmBranchParameters) 163 throws Exception { 164 File workingDirectory = getTestFile("target/svn-update-command-test"); 165 166 ScmRepository repository = getScmManager().makeScmRepository(scmUrl); 167 168 SvnScmProviderRepository svnRepository = (SvnScmProviderRepository) repository.getProviderRepository(); 169 170 svnRepository.setUser(user); 171 172 Commandline cl = null; 173 if (scmBranchParameters == null) { 174 cl = SvnBranchCommand.createCommandLine(svnRepository, workingDirectory, branch, messageFile); 175 } else { 176 cl = SvnBranchCommand.createCommandLine( 177 svnRepository, workingDirectory, branch, messageFile, scmBranchParameters); 178 } 179 180 assertCommandLine(commandLine, workingDirectory, cl); 181 } 182 183 private void testCommandLine(String scmUrl, String branch, File messageFile, String user, String commandLine) 184 throws Exception { 185 testCommandLine(scmUrl, branch, messageFile, user, commandLine, null); 186 } 187}