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.checkin;
20  
21  import java.io.File;
22  
23  import org.apache.maven.scm.ScmFileSet;
24  import org.apache.maven.scm.ScmTestCase;
25  import org.apache.maven.scm.provider.svn.repository.SvnScmProviderRepository;
26  import org.apache.maven.scm.provider.svn.util.SvnUtil;
27  import org.apache.maven.scm.repository.ScmRepository;
28  import org.codehaus.plexus.util.cli.Commandline;
29  import org.junit.Before;
30  import org.junit.Test;
31  
32  /**
33   * @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
34   *
35   */
36  public class SvnCheckInCommandTest extends ScmTestCase {
37      private File messageFile;
38  
39      private String messageFileString;
40  
41      @Before
42      @Override
43      public void setUp() throws Exception {
44          super.setUp();
45  
46          messageFile = new File("commit-message");
47  
48          String path = messageFile.getAbsolutePath();
49          if (path.indexOf(' ') >= 0) {
50              path = "\"" + path + "\"";
51          }
52          messageFileString = "--file " + path + " --encoding UTF-8";
53      }
54  
55      @Test
56      public void testCommandLineWithEmptyTag() throws Exception {
57          testCommandLine("scm:svn:http://foo.com/svn/trunk", "svn --non-interactive commit " + messageFileString);
58      }
59  
60      @Test
61      public void testCommandLineWithoutTag() throws Exception {
62          testCommandLine("scm:svn:http://foo.com/svn/trunk", "svn --non-interactive commit " + messageFileString);
63      }
64  
65      @Test
66      public void testCommandLineTag() throws Exception {
67          testCommandLine(
68                  "scm:svn:http://anonymous@foo.com/svn/trunk",
69                  "svn --username anonymous --no-auth-cache --non-interactive commit " + messageFileString);
70      }
71  
72      @Test
73      public void testCommandLineWithUsernameAndTag() throws Exception {
74          testCommandLine(
75                  "scm:svn:http://anonymous@foo.com/svn/trunk",
76                  "svn --username anonymous --no-auth-cache --non-interactive commit " + messageFileString);
77      }
78  
79      @Test
80      public void testCommandLineWithUsernameWithoutNonInteractive() throws Exception {
81          try {
82              SvnUtil.setSettingsDirectory(getTestFile("src/test/resources/svn/checkin/macos"));
83              testCommandLine(
84                      "scm:svn:http://anonymous@foo.com/svn/trunk",
85                      "svn --username anonymous --no-auth-cache commit " + messageFileString);
86          } finally {
87  
88              SvnUtil.setSettingsDirectory(SvnUtil.DEFAULT_SETTINGS_DIRECTORY);
89          }
90      }
91  
92      // ----------------------------------------------------------------------
93      //
94      // ----------------------------------------------------------------------
95  
96      private void testCommandLine(String scmUrl, String commandLine) throws Exception {
97          File workingDirectory = getTestFile("target/svn-checkin-command-test");
98  
99          ScmRepository repository = getScmManager().makeScmRepository(scmUrl);
100 
101         SvnScmProviderRepository svnRepository = (SvnScmProviderRepository) repository.getProviderRepository();
102 
103         Commandline cl =
104                 SvnCheckInCommand.createCommandLine(svnRepository, new ScmFileSet(workingDirectory), messageFile);
105 
106         assertCommandLine(commandLine, workingDirectory, cl);
107     }
108 }