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