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.MojoExecutionException;
024import org.apache.maven.scm.PlexusJUnit4TestCase;
025import org.apache.maven.scm.provider.svn.SvnScmTestUtils;
026import org.codehaus.plexus.util.FileUtils;
027import org.codehaus.plexus.util.StringUtils;
028import org.junit.Before;
029import org.junit.Test;
030import org.junit.runner.RunWith;
031import org.junit.runners.JUnit4;
032
033import static org.apache.maven.scm.ScmTestCase.checkScmPresence;
034
035/**
036 * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
037 *
038 */
039@RunWith(JUnit4.class)
040public class ChangeLogMojoTest extends AbstractJUnit4MojoTestCase {
041    File repository;
042
043    @Before
044    public void setUp() throws Exception {
045        super.setUp();
046
047        repository = getTestFile("target/repository");
048
049        FileUtils.forceDelete(repository);
050
051        checkScmPresence(SvnScmTestUtils.SVNADMIN_COMMAND_LINE);
052
053        SvnScmTestUtils.initializeRepository(repository);
054    }
055
056    @Test
057    public void testChangeLog() throws Exception {
058        checkScmPresence(SvnScmTestUtils.SVN_COMMAND_LINE);
059        ChangeLogMojo mojo = (ChangeLogMojo)
060                lookupMojo("changelog", getTestFile("src/test/resources/mojos/changelog/changelog.xml"));
061
062        String connectionUrl = mojo.getConnectionUrl();
063        connectionUrl = StringUtils.replace(connectionUrl, "${basedir}", PlexusJUnit4TestCase.getBasedir());
064        connectionUrl = StringUtils.replace(connectionUrl, "\\", "/");
065        mojo.setConnectionUrl(connectionUrl);
066        mojo.setWorkingDirectory(new File(PlexusJUnit4TestCase.getBasedir()));
067        mojo.setConnectionType("connection");
068
069        mojo.execute();
070    }
071
072    @Test
073    public void testChangeLogWithParameters() throws Exception {
074        checkScmPresence(SvnScmTestUtils.SVN_COMMAND_LINE);
075
076        ChangeLogMojo mojo = (ChangeLogMojo)
077                lookupMojo("changelog", getTestFile("src/test/resources/mojos/changelog/changelogWithParameters.xml"));
078
079        String connectionUrl = mojo.getConnectionUrl();
080        connectionUrl = StringUtils.replace(connectionUrl, "${basedir}", PlexusJUnit4TestCase.getBasedir());
081        connectionUrl = StringUtils.replace(connectionUrl, "\\", "/");
082        mojo.setConnectionUrl(connectionUrl);
083        mojo.setWorkingDirectory(new File(getBasedir()));
084        mojo.setConnectionType("connection");
085
086        mojo.execute();
087    }
088
089    @Test
090    public void testChangeLogWithBadUserDateFormat() throws Exception {
091        ChangeLogMojo mojo = (ChangeLogMojo) lookupMojo(
092                "changelog", getTestFile("src/test/resources/mojos/changelog/changelogWithBadUserDateFormat.xml"));
093
094        String connectionUrl = mojo.getConnectionUrl();
095        connectionUrl = StringUtils.replace(connectionUrl, "${basedir}", getBasedir());
096        connectionUrl = StringUtils.replace(connectionUrl, "\\", "/");
097        mojo.setConnectionUrl(connectionUrl);
098        mojo.setWorkingDirectory(new File(getBasedir()));
099        mojo.setConnectionType("connection");
100
101        try {
102            mojo.execute();
103
104            fail("mojo execution must fail.");
105        } catch (MojoExecutionException e) {
106            assertTrue(true);
107        }
108    }
109
110    @Test
111    public void testChangeLogWithBadConnectionUrl() throws Exception {
112        checkScmPresence(SvnScmTestUtils.SVN_COMMAND_LINE);
113
114        ChangeLogMojo mojo = (ChangeLogMojo) lookupMojo(
115                "changelog", getTestFile("src/test/resources/mojos/changelog/changelogWithBadConnectionUrl.xml"));
116
117        String connectionUrl = mojo.getConnectionUrl();
118        connectionUrl = StringUtils.replace(connectionUrl, "${basedir}", getBasedir());
119        connectionUrl = StringUtils.replace(connectionUrl, "\\", "/");
120        mojo.setConnectionUrl(connectionUrl);
121        mojo.setWorkingDirectory(new File(getBasedir()));
122        mojo.setConnectionType("connection");
123
124        try {
125            mojo.execute();
126
127            fail("mojo execution must fail.");
128        } catch (MojoExecutionException e) {
129            assertTrue(true);
130        }
131    }
132}