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.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   * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
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 }