001/*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *   http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing,
013 * software distributed under the License is distributed on an
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 * KIND, either express or implied.  See the License for the
016 * specific language governing permissions and limitations
017 * under the License.
018 */
019package org.apache.maven.scm.plugin;
020
021import java.io.File;
022
023import org.apache.maven.plugin.testing.AbstractMojoTestCase;
024import org.codehaus.plexus.util.FileUtils;
025
026/**
027 * Unit Test for BootstrapMojo
028 *
029 * @author <a href="mailto:arne@degenring.com">Arne Degenring</a>
030 *
031 */
032public class BootstrapMojoTest extends AbstractMojoTestCase {
033    File checkoutDir;
034
035    File projectDir;
036
037    File goalDir;
038
039    BootstrapMojo bootstrapMojo;
040
041    protected void setUp() throws Exception {
042        super.setUp();
043
044        checkoutDir = getTestFile("target/checkout");
045        FileUtils.forceDelete(checkoutDir);
046        checkoutDir.mkdirs();
047
048        projectDir = getTestFile("target/checkout/my/project");
049        projectDir.mkdirs();
050
051        goalDir = getTestFile("target/checkout/my/project/modules/1");
052        goalDir.mkdirs();
053
054        bootstrapMojo = new BootstrapMojo();
055    }
056
057    public void testDetermineWorkingDirectoryPath() throws Exception {
058        // only checkout dir
059        assertEquals(checkoutDir.getPath(), bootstrapMojo.determineWorkingDirectoryPath(checkoutDir, "", ""));
060        assertEquals(checkoutDir.getPath(), bootstrapMojo.determineWorkingDirectoryPath(checkoutDir, null, null));
061
062        // checkout dir and goal dir
063        assertEquals(projectDir.getPath(), bootstrapMojo.determineWorkingDirectoryPath(checkoutDir, "", "my/project"));
064
065        // checkout dir and relative path project dir
066        assertEquals(
067                projectDir.getPath(), bootstrapMojo.determineWorkingDirectoryPath(checkoutDir, "my/project", null));
068        assertEquals(
069                projectDir.getPath(), bootstrapMojo.determineWorkingDirectoryPath(checkoutDir, "my/project/", null));
070        assertEquals(
071                projectDir.getPath(),
072                bootstrapMojo.determineWorkingDirectoryPath(checkoutDir, "my" + File.separator + "project", null));
073
074        // checkout dir, relative path project dir and goal dir have been set
075        assertEquals(
076                goalDir.getPath(), bootstrapMojo.determineWorkingDirectoryPath(checkoutDir, "my/project", "modules/1"));
077        assertEquals(
078                goalDir.getPath(),
079                bootstrapMojo.determineWorkingDirectoryPath(checkoutDir, "my/project/", "modules/1/"));
080        assertEquals(
081                goalDir.getPath(),
082                bootstrapMojo.determineWorkingDirectoryPath(
083                        checkoutDir, "my" + File.separator + "project", "modules" + File.separator + "1"));
084    }
085}