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.list;
020
021import java.io.File;
022
023import org.apache.maven.scm.ScmFileSet;
024import org.apache.maven.scm.ScmRevision;
025import org.apache.maven.scm.ScmTestCase;
026import org.apache.maven.scm.provider.svn.repository.SvnScmProviderRepository;
027import org.apache.maven.scm.repository.ScmRepository;
028import org.codehaus.plexus.util.cli.Commandline;
029import org.junit.Test;
030
031/**
032 * @author <a href="mailto:carlos@apache.org">Carlos Sanchez</a>
033 *
034 */
035public class SvnListCommandTest extends ScmTestCase {
036    @Test
037    public void testCommandLineWithEmptyTag() throws Exception {
038        testCommandLine("scm:svn:http://foo.com/svn/trunk", true, "svn --non-interactive list --recursive");
039    }
040
041    @Test
042    public void testCommandLineWithWhitespaceTag() throws Exception {
043        testCommandLine("scm:svn:http://foo.com/svn/trunk", false, "svn --non-interactive list");
044    }
045
046    @Test
047    public void testCommandLineWithoutTag() throws Exception {
048        testCommandLine("scm:svn:http://foo.com/svn/trunk", false, "svn --non-interactive list");
049    }
050
051    @Test
052    public void testCommandLineTag() throws Exception {
053        testCommandLine(
054                "scm:svn:http://anonymous@foo.com/svn/trunk",
055                false,
056                "10",
057                "svn --username anonymous --no-auth-cache --non-interactive list -r 10");
058    }
059
060    @Test
061    public void testCommandLineWithUsernameAndTag() throws Exception {
062        testCommandLine(
063                "scm:svn:http://anonymous@foo.com/svn/trunk",
064                false,
065                "10",
066                "svn --username anonymous --no-auth-cache --non-interactive list -r 10");
067    }
068
069    // ----------------------------------------------------------------------
070    //
071    // ----------------------------------------------------------------------
072
073    private SvnScmProviderRepository getSvnRepository(String scmUrl) throws Exception {
074        ScmRepository repository = getScmManager().makeScmRepository(scmUrl);
075
076        return (SvnScmProviderRepository) repository.getProviderRepository();
077    }
078
079    private void testCommandLine(String scmUrl, boolean recursive, String commandLine) throws Exception {
080        testCommandLine(scmUrl, recursive, null, commandLine);
081    }
082
083    private void testCommandLine(String scmUrl, boolean recursive, String revision, String commandLine)
084            throws Exception {
085        ScmFileSet fileSet = new ScmFileSet(new File("."), new File("."));
086
087        Commandline cl = SvnListCommand.createCommandLine(
088                getSvnRepository(scmUrl), fileSet, recursive, new ScmRevision(revision));
089
090        assertCommandLine(
091                commandLine + " http://foo.com/svn/trunk/.@", new File(System.getProperty("java.io.tmpdir")), cl);
092    }
093}