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.provider.svn.svnexe.command.checkin;
020
021import java.io.File;
022
023import org.apache.maven.scm.ScmFileSet;
024import org.apache.maven.scm.ScmTestCase;
025import org.apache.maven.scm.provider.svn.repository.SvnScmProviderRepository;
026import org.apache.maven.scm.provider.svn.util.SvnUtil;
027import org.apache.maven.scm.repository.ScmRepository;
028import org.codehaus.plexus.util.cli.Commandline;
029import org.junit.Before;
030import org.junit.Test;
031
032/**
033 * @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
034 *
035 */
036public class SvnCheckInCommandTest extends ScmTestCase {
037    private File messageFile;
038
039    private String messageFileString;
040
041    @Before
042    @Override
043    public void setUp() throws Exception {
044        super.setUp();
045
046        messageFile = new File("commit-message");
047
048        String path = messageFile.getAbsolutePath();
049        if (path.indexOf(' ') >= 0) {
050            path = "\"" + path + "\"";
051        }
052        messageFileString = "--file " + path + " --encoding UTF-8";
053    }
054
055    @Test
056    public void testCommandLineWithEmptyTag() throws Exception {
057        testCommandLine("scm:svn:http://foo.com/svn/trunk", "svn --non-interactive commit " + messageFileString);
058    }
059
060    @Test
061    public void testCommandLineWithoutTag() throws Exception {
062        testCommandLine("scm:svn:http://foo.com/svn/trunk", "svn --non-interactive commit " + messageFileString);
063    }
064
065    @Test
066    public void testCommandLineTag() throws Exception {
067        testCommandLine(
068                "scm:svn:http://anonymous@foo.com/svn/trunk",
069                "svn --username anonymous --no-auth-cache --non-interactive commit " + messageFileString);
070    }
071
072    @Test
073    public void testCommandLineWithUsernameAndTag() throws Exception {
074        testCommandLine(
075                "scm:svn:http://anonymous@foo.com/svn/trunk",
076                "svn --username anonymous --no-auth-cache --non-interactive commit " + messageFileString);
077    }
078
079    @Test
080    public void testCommandLineWithUsernameWithoutNonInteractive() throws Exception {
081        try {
082            SvnUtil.setSettingsDirectory(getTestFile("src/test/resources/svn/checkin/macos"));
083            testCommandLine(
084                    "scm:svn:http://anonymous@foo.com/svn/trunk",
085                    "svn --username anonymous --no-auth-cache commit " + messageFileString);
086        } finally {
087
088            SvnUtil.setSettingsDirectory(SvnUtil.DEFAULT_SETTINGS_DIRECTORY);
089        }
090    }
091
092    // ----------------------------------------------------------------------
093    //
094    // ----------------------------------------------------------------------
095
096    private void testCommandLine(String scmUrl, String commandLine) throws Exception {
097        File workingDirectory = getTestFile("target/svn-checkin-command-test");
098
099        ScmRepository repository = getScmManager().makeScmRepository(scmUrl);
100
101        SvnScmProviderRepository svnRepository = (SvnScmProviderRepository) repository.getProviderRepository();
102
103        Commandline cl =
104                SvnCheckInCommand.createCommandLine(svnRepository, new ScmFileSet(workingDirectory), messageFile);
105
106        assertCommandLine(commandLine, workingDirectory, cl);
107    }
108}