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.codehaus.plexus.util.FileUtils;
24  import org.junit.Before;
25  import org.junit.Test;
26  import org.junit.runner.RunWith;
27  import org.junit.runners.JUnit4;
28  
29  /**
30   * Unit Test for BootstrapMojo
31   *
32   * @author <a href="mailto:arne@degenring.com">Arne Degenring</a>
33   *
34   */
35  @RunWith(JUnit4.class)
36  public class BootstrapMojoTest extends AbstractJUnit4MojoTestCase {
37      File checkoutDir;
38  
39      File projectDir;
40  
41      File goalDir;
42  
43      BootstrapMojo bootstrapMojo;
44  
45      @Before
46      public void setUp() throws Exception {
47          super.setUp();
48  
49          checkoutDir = getTestFile("target/checkout");
50          FileUtils.forceDelete(checkoutDir);
51          checkoutDir.mkdirs();
52  
53          projectDir = getTestFile("target/checkout/my/project");
54          projectDir.mkdirs();
55  
56          goalDir = getTestFile("target/checkout/my/project/modules/1");
57          goalDir.mkdirs();
58  
59          bootstrapMojo = new BootstrapMojo();
60      }
61  
62      @Test
63      public void testDetermineWorkingDirectoryPath() throws Exception {
64          // only checkout dir
65          assertEquals(checkoutDir.getPath(), bootstrapMojo.determineWorkingDirectoryPath(checkoutDir, "", ""));
66          assertEquals(checkoutDir.getPath(), bootstrapMojo.determineWorkingDirectoryPath(checkoutDir, null, null));
67  
68          // checkout dir and goal dir
69          assertEquals(projectDir.getPath(), bootstrapMojo.determineWorkingDirectoryPath(checkoutDir, "", "my/project"));
70  
71          // checkout dir and relative path project dir
72          assertEquals(
73                  projectDir.getPath(), bootstrapMojo.determineWorkingDirectoryPath(checkoutDir, "my/project", null));
74          assertEquals(
75                  projectDir.getPath(), bootstrapMojo.determineWorkingDirectoryPath(checkoutDir, "my/project/", null));
76          assertEquals(
77                  projectDir.getPath(),
78                  bootstrapMojo.determineWorkingDirectoryPath(checkoutDir, "my" + File.separator + "project", null));
79  
80          // checkout dir, relative path project dir and goal dir have been set
81          assertEquals(
82                  goalDir.getPath(), bootstrapMojo.determineWorkingDirectoryPath(checkoutDir, "my/project", "modules/1"));
83          assertEquals(
84                  goalDir.getPath(),
85                  bootstrapMojo.determineWorkingDirectoryPath(checkoutDir, "my/project/", "modules/1/"));
86          assertEquals(
87                  goalDir.getPath(),
88                  bootstrapMojo.determineWorkingDirectoryPath(
89                          checkoutDir, "my" + File.separator + "project", "modules" + File.separator + "1"));
90      }
91  }