View Javadoc

1   package org.apache.maven.scm.plugin;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   * http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.apache.maven.plugin.testing.AbstractMojoTestCase;
23  import org.codehaus.plexus.util.FileUtils;
24  
25  import java.io.File;
26  
27  /**
28   * Unit Test for BootstrapMojo
29   *
30   * @author <a href="mailto:arne@degenring.com">Arne Degenring</a>
31   *
32   */
33  public class BootstrapMojoTest
34      extends AbstractMojoTestCase
35  {
36      File checkoutDir;
37  
38      File projectDir;
39  
40      File goalDir;
41  
42      BootstrapMojo bootstrapMojo;
43  
44      protected void setUp()
45          throws Exception
46      {
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      public void testDetermineWorkingDirectoryPath()
63          throws Exception
64      {
65          // only checkout dir
66          assertEquals( checkoutDir.getPath(), bootstrapMojo.determineWorkingDirectoryPath( checkoutDir, "", "" ) );
67          assertEquals( checkoutDir.getPath(), bootstrapMojo.determineWorkingDirectoryPath( checkoutDir, null, null ) );
68  
69          // checkout dir and goal dir
70          assertEquals( projectDir.getPath(),
71                        bootstrapMojo.determineWorkingDirectoryPath( checkoutDir, "", "my/project" ) );
72  
73          // checkout dir and relative path project dir
74          assertEquals( projectDir.getPath(),
75                        bootstrapMojo.determineWorkingDirectoryPath( checkoutDir, "my/project", null ) );
76          assertEquals( projectDir.getPath(),
77                        bootstrapMojo.determineWorkingDirectoryPath( checkoutDir, "my/project/", null ) );
78          assertEquals( projectDir.getPath(), bootstrapMojo.determineWorkingDirectoryPath( checkoutDir, "my" + File
79              .separator + "project", null ) );
80  
81          // checkout dir, relative path project dir and goal dir have been set
82          assertEquals( goalDir.getPath(),
83                        bootstrapMojo.determineWorkingDirectoryPath( checkoutDir, "my/project", "modules/1" ) );
84          assertEquals( goalDir.getPath(),
85                        bootstrapMojo.determineWorkingDirectoryPath( checkoutDir, "my/project/", "modules/1/" ) );
86          assertEquals( goalDir.getPath(), bootstrapMojo.determineWorkingDirectoryPath( checkoutDir,
87                                                                                        "my" + File.separator + "project",
88                                                                                        "modules" + File.separator +
89                                                                                            "1" ) );
90      }
91  
92  
93  }