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.untag; 020 021import java.io.File; 022 023import org.apache.maven.scm.ScmFileSet; 024import org.apache.maven.scm.ScmTestCase; 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 030/** 031 * test the subversion untag implementation 032 * 033 */ 034public class SvnUntagCommandTest extends ScmTestCase { 035 036 /** 037 * test with http repo and user 038 * 039 * @throws Exception in case of error 040 */ 041 @Test 042 public void testUntagHttp() throws Exception { 043 044 File messageFile = File.createTempFile("maven-scm", "untag"); 045 messageFile.deleteOnExit(); 046 047 testCommandLine( 048 "scm:svn:http://foo.com/svn/tags", 049 new ScmFileSet(getUntagTestFile()), 050 "svntag", 051 "user", 052 messageFile, 053 "svn --username user --no-auth-cache --non-interactive " + "--file " + messageFile.getAbsolutePath() 054 + " remove http://foo.com/svn/tags/svntag@"); 055 } 056 057 /** 058 * test with ssh repo and user 059 * 060 * @throws Exception in case of error 061 */ 062 @Test 063 public void testUntagSsh() throws Exception { 064 065 File messageFile = File.createTempFile("maven-scm", "untag"); 066 messageFile.deleteOnExit(); 067 068 testCommandLine( 069 "scm:svn:svn+ssh://foo.com/svn/tags", 070 new ScmFileSet(getUntagTestFile()), 071 "svntag", 072 "user", 073 messageFile, 074 "svn --username user --no-auth-cache --non-interactive " + "--file " + messageFile.getAbsolutePath() 075 + " remove svn+ssh://user@foo.com/svn/tags/svntag@"); 076 } 077 078 /** 079 * define path to local dir 080 * 081 * @return local dir 082 */ 083 private File getUntagTestFile() { 084 return getTestFile("target/svn-untag-command-test"); 085 } 086 087 /** 088 * get svn repo instance 089 * 090 * @param scmUrl url to svn repo 091 * @return svn repo instance 092 * @throws Exception in case of error 093 */ 094 private SvnScmProviderRepository getSvnRepository(String scmUrl) throws Exception { 095 ScmRepository repository = getScmManager().makeScmRepository(scmUrl); 096 097 return (SvnScmProviderRepository) repository.getProviderRepository(); 098 } 099 100 /** 101 * test routine for command line 102 * 103 * @param scmUrl url to build repo instnace from 104 * @param scmFileSet file set containing local base dir 105 * @param tag tag to delete 106 * @param user svn user for repo access 107 * @param messageFile file containing commit message 108 * @param commandline set command line to compare actual to 109 * @throws Exception in case of error 110 */ 111 private void testCommandLine( 112 String scmUrl, ScmFileSet scmFileSet, String tag, String user, File messageFile, String commandline) 113 throws Exception { 114 SvnScmProviderRepository repo = getSvnRepository(scmUrl); 115 repo.setUser(user); 116 Commandline cl = new SvnUntagCommand().createCommandline(repo, scmFileSet, tag, messageFile); 117 118 assertCommandLine(commandline, scmFileSet.getBasedir(), cl); 119 } 120}