1   package org.apache.maven.scm.provider.svn.svnexe.command.branch;
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.ScmBranchParameters;
23  import org.apache.maven.scm.provider.svn.command.branch.SvnBranchCommandTckTest;
24  import org.apache.maven.scm.provider.svn.repository.SvnScmProviderRepository;
25  import org.apache.maven.scm.repository.ScmRepository;
26  import org.codehaus.plexus.util.cli.Commandline;
27  
28  import java.io.File;
29  
30  /**
31   * This test tests the branch command.
32   *
33   * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
34   * @version $Id: SvnExeBranchCommandTckTest.java 965290 2010-07-18 21:09:51Z olamy $
35   */
36  public class SvnExeBranchCommandTckTest
37      extends SvnBranchCommandTckTest
38  {
39      //--no-auth-cache
40      public void testBranchUserNameSvnHttpsRemoteBranchingWithRev()
41          throws Exception
42      {
43          File messageFile = File.createTempFile( "maven-scm", "commit" );
44          messageFile.deleteOnExit();
45  
46          ScmBranchParameters scmBranchParameters = new ScmBranchParameters();
47          scmBranchParameters.setRemoteBranching( true );
48          scmBranchParameters.setScmRevision( "2" );
49  
50          testCommandLine( "scm:svn:https://foo.com/svn/trunk", "svnbranch", messageFile, "user",
51                           "svn --username user --no-auth-cache --non-interactive copy --file " + messageFile.getAbsolutePath()
52                               + " --revision 2 https://foo.com/svn/trunk https://foo.com/svn/branches/svnbranch",
53                           scmBranchParameters );
54      }
55  
56      public void testBranchUserNameSvnHttpsRemoteBranchingNoRev()
57          throws Exception
58      {
59          File messageFile = File.createTempFile( "maven-scm", "commit" );
60          messageFile.deleteOnExit();
61  
62          ScmBranchParameters scmBranchParameters = new ScmBranchParameters();
63          scmBranchParameters.setRemoteBranching( true );
64  
65          testCommandLine( "scm:svn:https://foo.com/svn/trunk", "svnbranch", messageFile, "user",
66                           "svn --username user --no-auth-cache --non-interactive copy --file " + messageFile.getAbsolutePath()
67                               + " https://foo.com/svn/trunk https://foo.com/svn/branches/svnbranch", scmBranchParameters );
68      }
69  
70      public void testBranchUserNameSvnHttps()
71          throws Exception
72      {
73          File messageFile = File.createTempFile( "maven-scm", "commit" );
74          messageFile.deleteOnExit();
75  
76          testCommandLine( "scm:svn:https://foo.com/svn/trunk", "svnbranch", messageFile, "user",
77                           "svn --username user --no-auth-cache --non-interactive copy --file " + messageFile.getAbsolutePath()
78                               + " . https://foo.com/svn/branches/svnbranch", null );
79      }
80  
81      public void testBranchUserNameSvnSsh()
82          throws Exception
83      {
84          File messageFile = File.createTempFile( "maven-scm", "commit" );
85          messageFile.deleteOnExit();
86  
87          testCommandLine( "scm:svn:svn+ssh://foo.com/svn/trunk", "svnbranch", messageFile, "user",
88                           "svn --username user --no-auth-cache --non-interactive copy --file " + messageFile.getAbsolutePath()
89                               + " . svn+ssh://user@foo.com/svn/branches/svnbranch" );
90      }
91  
92      private void testCommandLine( String scmUrl, String branch, File messageFile, String user, String commandLine,
93                                    ScmBranchParameters scmBranchParameters )
94          throws Exception
95      {
96          File workingDirectory = getTestFile( "target/svn-update-command-test" );
97  
98          ScmRepository repository = getScmManager().makeScmRepository( scmUrl );
99  
100         SvnScmProviderRepository svnRepository = (SvnScmProviderRepository) repository.getProviderRepository();
101 
102         svnRepository.setUser( user );
103 
104         Commandline cl = null;
105         if ( scmBranchParameters == null )
106         {
107             cl = SvnBranchCommand.createCommandLine( svnRepository, workingDirectory, branch, messageFile );
108         }
109         else
110         {
111             cl = SvnBranchCommand.createCommandLine( svnRepository, workingDirectory, branch, messageFile,
112                                                      scmBranchParameters );
113         }
114 
115         assertCommandLine( commandLine, workingDirectory, cl );
116     }
117 
118     private void testCommandLine( String scmUrl, String branch, File messageFile, String user, String commandLine )
119         throws Exception
120     {
121         testCommandLine( scmUrl, branch, messageFile, user, commandLine, null );
122     }
123 }