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