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.codehaus.plexus.util.FileUtils;
024import org.junit.Before;
025import org.junit.Test;
026import org.junit.runner.RunWith;
027import org.junit.runners.JUnit4;
028
029/**
030 * Unit Test for BootstrapMojo
031 *
032 * @author <a href="mailto:arne@degenring.com">Arne Degenring</a>
033 *
034 */
035@RunWith(JUnit4.class)
036public class BootstrapMojoTest extends AbstractJUnit4MojoTestCase {
037    File checkoutDir;
038
039    File projectDir;
040
041    File goalDir;
042
043    BootstrapMojo bootstrapMojo;
044
045    @Before
046    public void setUp() throws Exception {
047        super.setUp();
048
049        checkoutDir = getTestFile("target/checkout");
050        FileUtils.forceDelete(checkoutDir);
051        checkoutDir.mkdirs();
052
053        projectDir = getTestFile("target/checkout/my/project");
054        projectDir.mkdirs();
055
056        goalDir = getTestFile("target/checkout/my/project/modules/1");
057        goalDir.mkdirs();
058
059        bootstrapMojo = new BootstrapMojo();
060    }
061
062    @Test
063    public void testDetermineWorkingDirectoryPath() throws Exception {
064        // only checkout dir
065        assertEquals(checkoutDir.getPath(), bootstrapMojo.determineWorkingDirectoryPath(checkoutDir, "", ""));
066        assertEquals(checkoutDir.getPath(), bootstrapMojo.determineWorkingDirectoryPath(checkoutDir, null, null));
067
068        // checkout dir and goal dir
069        assertEquals(projectDir.getPath(), bootstrapMojo.determineWorkingDirectoryPath(checkoutDir, "", "my/project"));
070
071        // checkout dir and relative path project dir
072        assertEquals(
073                projectDir.getPath(), bootstrapMojo.determineWorkingDirectoryPath(checkoutDir, "my/project", null));
074        assertEquals(
075                projectDir.getPath(), bootstrapMojo.determineWorkingDirectoryPath(checkoutDir, "my/project/", null));
076        assertEquals(
077                projectDir.getPath(),
078                bootstrapMojo.determineWorkingDirectoryPath(checkoutDir, "my" + File.separator + "project", null));
079
080        // checkout dir, relative path project dir and goal dir have been set
081        assertEquals(
082                goalDir.getPath(), bootstrapMojo.determineWorkingDirectoryPath(checkoutDir, "my/project", "modules/1"));
083        assertEquals(
084                goalDir.getPath(),
085                bootstrapMojo.determineWorkingDirectoryPath(checkoutDir, "my/project/", "modules/1/"));
086        assertEquals(
087                goalDir.getPath(),
088                bootstrapMojo.determineWorkingDirectoryPath(
089                        checkoutDir, "my" + File.separator + "project", "modules" + File.separator + "1"));
090    }
091}