1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
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 }