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.update;
20  
21  import java.io.File;
22  
23  import org.apache.maven.scm.ScmBranch;
24  import org.apache.maven.scm.ScmRevision;
25  import org.apache.maven.scm.ScmTag;
26  import org.apache.maven.scm.ScmTestCase;
27  import org.apache.maven.scm.ScmVersion;
28  import org.apache.maven.scm.provider.svn.repository.SvnScmProviderRepository;
29  import org.apache.maven.scm.provider.svn.util.SvnUtil;
30  import org.apache.maven.scm.repository.ScmRepository;
31  import org.codehaus.plexus.util.Os;
32  import org.codehaus.plexus.util.cli.Commandline;
33  import org.junit.Test;
34  
35  import static org.junit.Assert.assertTrue;
36  
37  /**
38   * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
39   *
40   */
41  public class SvnUpdateCommandTest extends ScmTestCase {
42      @Test
43      public void testCommandLineWithEmptyTag() throws Exception {
44          testCommandLine(
45                  "scm:svn:http://foo.com/svn/trunk",
46                  new ScmTag(""),
47                  "svn --non-interactive update " + getUpdateTestFile().getAbsolutePath() + "@");
48      }
49  
50      @Test
51      public void testCommandLineWithEmptyBranch() throws Exception {
52          testCommandLine(
53                  "scm:svn:http://foo.com/svn/trunk",
54                  new ScmBranch(""),
55                  "svn --non-interactive update " + getUpdateTestFile().getAbsolutePath() + "@");
56      }
57  
58      @Test
59      public void testCommandLineWithEmptyVersion() throws Exception {
60          testCommandLine(
61                  "scm:svn:http://foo.com/svn/trunk",
62                  new ScmRevision(""),
63                  "svn --non-interactive update " + getUpdateTestFile().getAbsolutePath() + "@");
64      }
65  
66      @Test
67      public void testCommandLineWithWhitespaceTag() throws Exception {
68          testCommandLine(
69                  "scm:svn:http://foo.com/svn/trunk",
70                  new ScmTag("  "),
71                  "svn --non-interactive update " + getUpdateTestFile().getAbsolutePath() + "@");
72      }
73  
74      @Test
75      public void testCommandLineWithWhitespaceBranch() throws Exception {
76          testCommandLine(
77                  "scm:svn:http://foo.com/svn/trunk",
78                  new ScmBranch("  "),
79                  "svn --non-interactive update " + getUpdateTestFile().getAbsolutePath() + "@");
80      }
81  
82      @Test
83      public void testCommandLineWithWhitespaceRevision() throws Exception {
84          testCommandLine(
85                  "scm:svn:http://foo.com/svn/trunk",
86                  new ScmRevision("  "),
87                  "svn --non-interactive update " + getUpdateTestFile().getAbsolutePath() + "@");
88      }
89  
90      @Test
91      public void testCommandLineWithoutTag() throws Exception {
92          testCommandLine(
93                  "scm:svn:http://foo.com/svn/trunk",
94                  null,
95                  "svn --non-interactive update " + getUpdateTestFile().getAbsolutePath() + "@");
96      }
97  
98      @Test
99      public void testCommandLineTag() throws Exception {
100         testCommandLine(
101                 "scm:svn:http://anonymous@foo.com/svn/trunk",
102                 new ScmRevision("10"),
103                 "svn --username anonymous --no-auth-cache --non-interactive update -r 10 "
104                         + getUpdateTestFile().getAbsolutePath() + "@");
105     }
106 
107     @Test
108     public void testCommandLineWithUsernameAndTag() throws Exception {
109         testCommandLine(
110                 "scm:svn:http://anonymous@foo.com/svn/trunk",
111                 new ScmRevision("10"),
112                 "svn --username anonymous --no-auth-cache --non-interactive update -r 10 "
113                         + getUpdateTestFile().getAbsolutePath() + "@");
114     }
115 
116     @Test
117     public void testCommandLineWithCygwinProperty() throws Exception {
118         if (Os.isFamily(Os.FAMILY_WINDOWS)) {
119             SvnUtil.setSettingsDirectory(getTestFile("src/test/resources/svn/update/cygwin"));
120             try {
121                 assertTrue(SvnUtil.getSettings().isUseCygwinPath());
122                 testCommandLine(
123                         "scm:svn:http://foo.com/svn/trunk",
124                         null,
125                         "svn --non-interactive update /mnt/c/my_working_directory@",
126                         new File("c:\\my_working_directory"));
127             } finally {
128                 SvnUtil.setSettingsDirectory(SvnUtil.DEFAULT_SETTINGS_DIRECTORY);
129             }
130         }
131     }
132 
133     @Test
134     public void testCommandLineWithRelativeURLTag() throws Exception {
135         testCommandLine(
136                 "scm:svn:http://foo.com/svn/trunk",
137                 new ScmBranch("branches/my-test-branch"),
138                 "svn --non-interactive switch http://foo.com/svn/branches/my-test-branch@ "
139                         + getUpdateTestFile().getAbsolutePath() + "@");
140     }
141 
142     @Test
143     public void testCommandLineWithAbsoluteURLTag() throws Exception {
144         testCommandLine(
145                 "scm:svn:http://foo.com/svn/trunk",
146                 new ScmBranch("http://foo.com/svn/branches/my-test-branch"),
147                 "svn --non-interactive switch http://foo.com/svn/branches/my-test-branch@ "
148                         + getUpdateTestFile().getAbsolutePath() + "@");
149     }
150 
151     @Test
152     public void testCommandLineWithNonDeterminantBase() throws Exception {
153         testCommandLine(
154                 "scm:svn:http://foo.com/svn/some-project",
155                 new ScmBranch("branches/my-test-branch"),
156                 "svn --non-interactive switch http://foo.com/svn/some-project/branches/my-test-branch@ "
157                         + getUpdateTestFile().getAbsolutePath() + "@");
158     }
159 
160     @Test
161     public void testCommandLineWithNonDeterminantBaseTrailingSlash() throws Exception {
162         testCommandLine(
163                 "scm:svn:http://foo.com/svn/some-project/",
164                 new ScmBranch("branches/my-test-branch"),
165                 "svn --non-interactive switch http://foo.com/svn/some-project/branches/my-test-branch@ "
166                         + getUpdateTestFile().getAbsolutePath() + "@");
167     }
168 
169     @Test
170     public void testCommandLineWithBranchSameAsBase() throws Exception {
171         testCommandLine(
172                 "scm:svn:http://foo.com/svn/tags/my-tag",
173                 new ScmTag("tags/my-tag"),
174                 "svn --non-interactive switch http://foo.com/svn/tags/my-tag@ "
175                         + getUpdateTestFile().getAbsolutePath() + "@");
176     }
177 
178     // ----------------------------------------------------------------------
179     //
180     // ----------------------------------------------------------------------
181 
182     private File getUpdateTestFile() {
183         return getTestFile("target/svn-update-command-test");
184     }
185 
186     private SvnScmProviderRepository getSvnRepository(String scmUrl) throws Exception {
187         ScmRepository repository = getScmManager().makeScmRepository(scmUrl);
188 
189         return (SvnScmProviderRepository) repository.getProviderRepository();
190     }
191 
192     private void testCommandLine(String scmUrl, ScmVersion version, String commandLine) throws Exception {
193         File workingDirectory = getUpdateTestFile();
194 
195         testCommandLine(scmUrl, version, commandLine, workingDirectory);
196     }
197 
198     private void testCommandLine(String scmUrl, ScmVersion version, String commandLine, File workingDirectory)
199             throws Exception {
200         Commandline cl = SvnUpdateCommand.createCommandLine(getSvnRepository(scmUrl), workingDirectory, version);
201 
202         assertCommandLine(commandLine, workingDirectory, cl);
203     }
204 }