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.commons.lang3.StringUtils;
024import org.apache.maven.plugin.testing.AbstractMojoTestCase;
025import org.apache.maven.scm.ScmTestCase;
026import org.apache.maven.scm.provider.svn.SvnScmTestUtils;
027import org.codehaus.plexus.util.FileUtils;
028
029/**
030 * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
031 *
032 */
033public class UpdateMojoTest extends AbstractMojoTestCase {
034    File checkoutDir;
035
036    File repository;
037
038    protected void setUp() throws Exception {
039        super.setUp();
040
041        checkoutDir = getTestFile("target/checkout");
042
043        repository = getTestFile("target/repository");
044
045        FileUtils.forceDelete(checkoutDir);
046    }
047
048    public void testSkipCheckoutWithConnectionUrl() throws Exception {
049        if (!ScmTestCase.isSystemCmd(SvnScmTestUtils.SVNADMIN_COMMAND_LINE)) {
050            ScmTestCase.printSystemCmdUnavail(SvnScmTestUtils.SVNADMIN_COMMAND_LINE, getName());
051            return;
052        }
053
054        SvnScmTestUtils.initializeRepository(repository);
055
056        if (!ScmTestCase.isSystemCmd(SvnScmTestUtils.SVN_COMMAND_LINE)) {
057            ScmTestCase.printSystemCmdUnavail(SvnScmTestUtils.SVN_COMMAND_LINE, getName());
058            return;
059        }
060
061        CheckoutMojo checkoutMojo = (CheckoutMojo)
062                lookupMojo("checkout", getTestFile("src/test/resources/mojos/checkout/checkoutWithConnectionUrl.xml"));
063
064        String connectionUrl = checkoutMojo.getConnectionUrl();
065        connectionUrl = StringUtils.replace(connectionUrl, "${basedir}", getBasedir());
066        connectionUrl = StringUtils.replace(connectionUrl, "\\", "/");
067        checkoutMojo.setConnectionUrl(connectionUrl);
068
069        checkoutMojo.execute();
070
071        UpdateMojo updateMojo = (UpdateMojo)
072                lookupMojo("update", getTestFile("src/test/resources/mojos/update/updateWithConnectionUrl.xml"));
073
074        connectionUrl = updateMojo.getConnectionUrl();
075        connectionUrl = StringUtils.replace(connectionUrl, "${basedir}", getBasedir());
076        connectionUrl = StringUtils.replace(connectionUrl, "\\", "/");
077        updateMojo.setConnectionUrl(connectionUrl);
078
079        updateMojo.execute();
080    }
081}