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.list;
20  
21  import java.io.File;
22  
23  import org.apache.maven.scm.ScmFileSet;
24  import org.apache.maven.scm.ScmRevision;
25  import org.apache.maven.scm.ScmTestCase;
26  import org.apache.maven.scm.provider.svn.repository.SvnScmProviderRepository;
27  import org.apache.maven.scm.repository.ScmRepository;
28  import org.codehaus.plexus.util.cli.Commandline;
29  import org.junit.Test;
30  
31  /**
32   * @author <a href="mailto:carlos@apache.org">Carlos Sanchez</a>
33   *
34   */
35  public class SvnListCommandTest extends ScmTestCase {
36      @Test
37      public void testCommandLineWithEmptyTag() throws Exception {
38          testCommandLine("scm:svn:http://foo.com/svn/trunk", true, "svn --non-interactive list --recursive");
39      }
40  
41      @Test
42      public void testCommandLineWithWhitespaceTag() throws Exception {
43          testCommandLine("scm:svn:http://foo.com/svn/trunk", false, "svn --non-interactive list");
44      }
45  
46      @Test
47      public void testCommandLineWithoutTag() throws Exception {
48          testCommandLine("scm:svn:http://foo.com/svn/trunk", false, "svn --non-interactive list");
49      }
50  
51      @Test
52      public void testCommandLineTag() throws Exception {
53          testCommandLine(
54                  "scm:svn:http://anonymous@foo.com/svn/trunk",
55                  false,
56                  "10",
57                  "svn --username anonymous --no-auth-cache --non-interactive list -r 10");
58      }
59  
60      @Test
61      public void testCommandLineWithUsernameAndTag() throws Exception {
62          testCommandLine(
63                  "scm:svn:http://anonymous@foo.com/svn/trunk",
64                  false,
65                  "10",
66                  "svn --username anonymous --no-auth-cache --non-interactive list -r 10");
67      }
68  
69      // ----------------------------------------------------------------------
70      //
71      // ----------------------------------------------------------------------
72  
73      private SvnScmProviderRepository getSvnRepository(String scmUrl) throws Exception {
74          ScmRepository repository = getScmManager().makeScmRepository(scmUrl);
75  
76          return (SvnScmProviderRepository) repository.getProviderRepository();
77      }
78  
79      private void testCommandLine(String scmUrl, boolean recursive, String commandLine) throws Exception {
80          testCommandLine(scmUrl, recursive, null, commandLine);
81      }
82  
83      private void testCommandLine(String scmUrl, boolean recursive, String revision, String commandLine)
84              throws Exception {
85          ScmFileSet fileSet = new ScmFileSet(new File("."), new File("."));
86  
87          Commandline cl = SvnListCommand.createCommandLine(
88                  getSvnRepository(scmUrl), fileSet, recursive, new ScmRevision(revision));
89  
90          assertCommandLine(
91                  commandLine + " http://foo.com/svn/trunk/.@", new File(System.getProperty("java.io.tmpdir")), cl);
92      }
93  }