View Javadoc
1   package org.apache.maven.scm.provider.svn.svnexe.command.untag;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   * http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.apache.maven.scm.ScmTestCase;
23  import org.apache.maven.scm.provider.svn.repository.SvnScmProviderRepository;
24  import org.apache.maven.scm.repository.ScmRepository;
25  import org.codehaus.plexus.util.cli.Commandline;
26  
27  import java.io.File;
28  import org.apache.maven.scm.ScmFileSet;
29  
30  /**
31   * test the subversion untag implementation
32   *
33   */
34  public class SvnUntagCommandTest
35      extends ScmTestCase
36  {
37  
38      /**
39       * test with http repo and user
40       *
41       * @throws Exception in case of error
42       */
43      public void testUntagHttp()
44          throws Exception
45      {
46  
47          File messageFile = File.createTempFile( "maven-scm", "untag" );
48          messageFile.deleteOnExit();
49  
50          testCommandLine( "scm:svn:http://foo.com/svn/tags", new ScmFileSet( getUntagTestFile() ), "svntag", "user",
51                  messageFile, "svn --username user --no-auth-cache --non-interactive "
52                  + "--file " +  messageFile.getAbsolutePath() + " remove http://foo.com/svn/tags/svntag@" );
53      }
54  
55      /**
56       * test with ssh repo and user
57       *
58       * @throws Exception in case of error
59       */
60      public void testUntagSsh()
61          throws Exception
62      {
63  
64          File messageFile = File.createTempFile( "maven-scm", "untag" );
65          messageFile.deleteOnExit();
66  
67          testCommandLine( "scm:svn:svn+ssh://foo.com/svn/tags", new ScmFileSet( getUntagTestFile() ), "svntag", "user",
68                  messageFile, "svn --username user --no-auth-cache --non-interactive "
69                  + "--file " +  messageFile.getAbsolutePath() + " remove svn+ssh://user@foo.com/svn/tags/svntag@" );
70      }
71  
72      /**
73       * define path to local dir
74       *
75       * @return local dir
76       */
77      private File getUntagTestFile()
78      {
79          return getTestFile( "target/svn-untag-command-test" );
80      }
81  
82      /**
83       * get svn repo instance
84       *
85       * @param scmUrl     url to svn repo
86       * @return           svn repo instance
87       * @throws Exception in case of error
88       */
89      private SvnScmProviderRepository getSvnRepository( String scmUrl )
90          throws Exception
91      {
92          ScmRepository repository = getScmManager().makeScmRepository( scmUrl );
93  
94          return (SvnScmProviderRepository) repository.getProviderRepository();
95      }
96  
97      /**
98       * test routine for command line
99       *
100      * @param scmUrl      url to build repo instnace from
101      * @param scmFileSet  file set containing local base dir
102      * @param tag         tag to delete
103      * @param user        svn user for repo access
104      * @param messageFile file containing commit message
105      * @param commandline set command line to compare actual to
106      * @throws Exception  in case of error
107      */
108     private void testCommandLine( String scmUrl, ScmFileSet scmFileSet, String tag, String user, File messageFile,
109             String commandline ) throws Exception
110     {
111         SvnScmProviderRepository repo = getSvnRepository( scmUrl );
112         repo.setUser(user);
113         Commandline cl = new SvnUntagCommand().createCommandline( repo, scmFileSet, tag, messageFile );
114 
115         assertCommandLine( commandline, scmFileSet.getBasedir(), cl );
116     }
117 }