1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.scm.plugin;
20
21 import java.io.File;
22
23 import org.apache.maven.scm.PlexusJUnit4TestCase;
24 import org.apache.maven.scm.provider.svn.SvnScmTestUtils;
25 import org.codehaus.plexus.util.FileUtils;
26 import org.codehaus.plexus.util.StringUtils;
27 import org.junit.Before;
28 import org.junit.Test;
29 import org.junit.runner.RunWith;
30 import org.junit.runners.JUnit4;
31
32 import static org.apache.maven.scm.ScmTestCase.checkScmPresence;
33
34
35
36
37
38 @RunWith(JUnit4.class)
39 public class BranchMojoTest extends AbstractJUnit4MojoTestCase {
40 File checkoutDir;
41
42 File repository;
43
44 @Before
45 public void setUp() throws Exception {
46 super.setUp();
47
48 checkoutDir = getTestFile("target/checkout");
49
50 FileUtils.forceDelete(checkoutDir);
51
52 repository = getTestFile("target/repository");
53
54 FileUtils.forceDelete(repository);
55
56 checkScmPresence(SvnScmTestUtils.SVNADMIN_COMMAND_LINE);
57
58 SvnScmTestUtils.initializeRepository(repository);
59
60 checkScmPresence(SvnScmTestUtils.SVN_COMMAND_LINE);
61
62 CheckoutMojo checkoutMojo = (CheckoutMojo)
63 lookupMojo("checkout", getTestFile("src/test/resources/mojos/checkout/checkoutWithConnectionUrl.xml"));
64 checkoutMojo.setWorkingDirectory(new File(getBasedir()));
65
66 String connectionUrl = checkoutMojo.getConnectionUrl();
67 connectionUrl = StringUtils.replace(connectionUrl, "${basedir}", getBasedir());
68 connectionUrl = StringUtils.replace(connectionUrl, "\\", "/");
69 checkoutMojo.setConnectionUrl(connectionUrl);
70
71 checkoutMojo.setCheckoutDirectory(checkoutDir);
72
73 checkoutMojo.execute();
74 }
75
76 @Test
77 public void testBranch() throws Exception {
78 checkScmPresence(SvnScmTestUtils.SVNADMIN_COMMAND_LINE);
79
80 BranchMojo mojo = (BranchMojo)
81 lookupMojo("branch", PlexusJUnit4TestCase.getTestFile("src/test/resources/mojos/branch/branch.xml"));
82 mojo.setWorkingDirectory(checkoutDir);
83
84 String connectionUrl = mojo.getConnectionUrl();
85 connectionUrl = StringUtils.replace(connectionUrl, "${basedir}", PlexusJUnit4TestCase.getBasedir());
86 connectionUrl = StringUtils.replace(connectionUrl, "\\", "/");
87 mojo.setConnectionUrl(connectionUrl);
88
89 mojo.execute();
90
91 CheckoutMojo checkoutMojo = (CheckoutMojo) lookupMojo(
92 "checkout", PlexusJUnit4TestCase.getTestFile("src/test/resources/mojos/branch/checkout.xml"));
93 checkoutMojo.setWorkingDirectory(new File(PlexusJUnit4TestCase.getBasedir()));
94
95 connectionUrl = checkoutMojo.getConnectionUrl();
96 connectionUrl = StringUtils.replace(connectionUrl, "${basedir}", PlexusJUnit4TestCase.getBasedir());
97 connectionUrl = StringUtils.replace(connectionUrl, "\\", "/");
98 checkoutMojo.setConnectionUrl(connectionUrl);
99
100 File branchCheckoutDir = PlexusJUnit4TestCase.getTestFile("target/branches/mybranch");
101 if (branchCheckoutDir.exists()) {
102 FileUtils.deleteDirectory(branchCheckoutDir);
103 }
104 checkoutMojo.setCheckoutDirectory(branchCheckoutDir);
105
106 assertFalse(new File(branchCheckoutDir, "pom.xml").exists());
107 checkoutMojo.execute();
108 assertTrue(new File(branchCheckoutDir, "pom.xml").exists());
109 }
110 }