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.checkout;
20  
21  import java.io.File;
22  
23  import org.apache.maven.scm.ScmRevision;
24  import org.apache.maven.scm.ScmTestCase;
25  import org.apache.maven.scm.manager.ScmManager;
26  import org.apache.maven.scm.provider.svn.repository.SvnScmProviderRepository;
27  import org.apache.maven.scm.repository.ScmRepository;
28  import org.codehaus.plexus.util.FileUtils;
29  import org.codehaus.plexus.util.cli.Commandline;
30  import org.junit.Before;
31  import org.junit.Test;
32  
33  /**
34   * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
35   *
36   */
37  public class SvnCheckOutCommandTest extends ScmTestCase {
38      private File workingDirectory;
39  
40      private boolean recursive;
41  
42      // ----------------------------------------------------------------------
43      //
44      // ----------------------------------------------------------------------
45  
46      @Before
47      @Override
48      public void setUp() throws Exception {
49          super.setUp();
50  
51          recursive = true;
52          workingDirectory = getTestFile("target/svn-checkout-command-test");
53          if (workingDirectory != null && workingDirectory.isDirectory()) {
54              FileUtils.deleteDirectory(workingDirectory);
55          }
56      }
57  
58      // ----------------------------------------------------------------------
59      //
60      // ----------------------------------------------------------------------
61  
62      @Test
63      public void testCommandLineWithoutRevision() throws Exception {
64          testCommandLine(
65                  getScmManager(),
66                  "scm:svn:http://foo.com/svn/trunk",
67                  null,
68                  "svn --non-interactive checkout http://foo.com/svn/trunk@ " + workingDirectory.getAbsolutePath());
69      }
70  
71      @Test
72      public void testCommandLineWithEmptyRevision() throws Exception {
73          testCommandLine(
74                  getScmManager(),
75                  "scm:svn:http://foo.com/svn/trunk",
76                  "",
77                  "svn --non-interactive checkout http://foo.com/svn/trunk@ " + workingDirectory.getAbsolutePath());
78      }
79  
80      @Test
81      public void testCommandLineWithRevision() throws Exception {
82          testCommandLine(
83                  getScmManager(),
84                  "scm:svn:http://foo.com/svn/trunk",
85                  "10",
86                  "svn --non-interactive checkout -r 10 http://foo.com/svn/trunk@ " + workingDirectory.getAbsolutePath());
87      }
88  
89      @Test
90      public void testRecursiveCheckOutCommandLine() throws Exception {
91          recursive = false;
92          testCommandLine(
93                  getScmManager(),
94                  "scm:svn:http://foo.com/svn/trunk",
95                  "10",
96                  "svn --non-interactive checkout -N -r 10 http://foo.com/svn/trunk@ "
97                          + workingDirectory.getAbsolutePath());
98      }
99  
100     // ----------------------------------------------------------------------
101     //
102     // ----------------------------------------------------------------------
103 
104     private void testCommandLine(ScmManager scmManager, String scmUrl, String revision, String commandLine)
105             throws Exception {
106         ScmRepository repository = scmManager.makeScmRepository(scmUrl);
107 
108         SvnScmProviderRepository svnRepository = (SvnScmProviderRepository) repository.getProviderRepository();
109 
110         Commandline cl = SvnCheckOutCommand.createCommandLine(
111                 svnRepository, workingDirectory, new ScmRevision(revision), svnRepository.getUrl(), recursive);
112 
113         assertCommandLine(commandLine, workingDirectory.getParentFile(), cl);
114     }
115 }