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