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.mkdir;
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.repository.ScmRepository;
27  import org.codehaus.plexus.util.FileUtils;
28  import org.codehaus.plexus.util.cli.Commandline;
29  import org.junit.After;
30  import org.junit.Before;
31  import org.junit.Test;
32  
33  import static org.junit.Assert.assertTrue;
34  
35  /**
36   * @author <a href="mailto:oching@apache.org">Maria Odea Ching</a>
37   *
38   */
39  public class SvnMkdirCommandTest extends ScmTestCase {
40      private File messageFile;
41  
42      String messageFileString;
43  
44      @Before
45      @Override
46      public void setUp() throws Exception {
47          super.setUp();
48  
49          messageFile = new File("mkdir-message");
50  
51          String path = messageFile.getAbsolutePath();
52          FileUtils.fileWrite(path, "create missing directory");
53  
54          if (path.indexOf(' ') >= 0) {
55              path = "\"" + path + "\"";
56          }
57          messageFileString = "--file " + path + " --encoding UTF-8";
58      }
59  
60      @After
61      @Override
62      public void tearDown() throws Exception {
63          assertTrue(messageFile.delete());
64  
65          super.tearDown();
66      }
67  
68      @Test
69      public void testCommandLineMkdirUrl() throws Exception {
70          testCommandLine(
71                  "scm:svn:http://foo.com/svn/trunk",
72                  "svn --non-interactive mkdir --parents http://foo.com/svn/trunk/missing@ " + messageFileString,
73                  false);
74      }
75  
76      @Test
77      public void testCommandLineMkdirUrlWithUsername() throws Exception {
78          testCommandLine(
79                  "scm:svn:http://anonymous@foo.com/svn/trunk",
80                  "svn --username anonymous --no-auth-cache --non-interactive mkdir --parents http://foo.com/svn/trunk/missing@ "
81                          + messageFileString,
82                  false);
83      }
84  
85      @Test
86      public void testCommandLineMkdirLocalPath() throws Exception {
87          testCommandLine("scm:svn:http://foo.com/svn/trunk", "svn --non-interactive mkdir --parents missing ", true);
88      }
89  
90      private void testCommandLine(String scmUrl, String commandLine, boolean createInLocal) throws Exception {
91          File workingDirectory = getTestFile("target/svn-mkdir-command-test");
92  
93          ScmFileSet fileSet = new ScmFileSet(workingDirectory, new File("missing"));
94  
95          ScmRepository repository = getScmManager().makeScmRepository(scmUrl);
96  
97          SvnScmProviderRepository svnRepository = (SvnScmProviderRepository) repository.getProviderRepository();
98  
99          Commandline cl = SvnMkdirCommand.createCommandLine(svnRepository, fileSet, messageFile, createInLocal);
100 
101         assertCommandLine(commandLine, workingDirectory, cl);
102     }
103 }