001package org.apache.maven.scm.tck.command.list;
002
003/*
004 * Licensed to the Apache Software Foundation (ASF) under one
005 * or more contributor license agreements.  See the NOTICE file
006 * distributed with this work for additional information
007 * regarding copyright ownership.  The ASF licenses this file
008 * to you under the Apache License, Version 2.0 (the
009 * "License"); you may not use this file except in compliance
010 * with the License.  You may obtain a copy of the License at
011 *
012 * http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing,
015 * software distributed under the License is distributed on an
016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017 * KIND, either express or implied.  See the License for the
018 * specific language governing permissions and limitations
019 * under the License.
020 */
021
022import java.io.File;
023import java.util.List;
024
025import org.apache.maven.scm.ScmFile;
026import org.apache.maven.scm.ScmFileSet;
027import org.apache.maven.scm.ScmTckTestCase;
028import org.apache.maven.scm.ScmVersion;
029import org.apache.maven.scm.command.list.ListScmResult;
030import org.apache.maven.scm.provider.ScmProvider;
031
032/**
033 * This test tests the list command.
034 *
035 * @author <a href="mailto:carlos@apache.org">Carlos Sanchez</a>
036 *
037 */
038public abstract class ListCommandTckTest
039    extends ScmTckTestCase
040{
041    public void testListCommandTest()
042        throws Exception
043    {
044        ScmFileSet fileSet = new ScmFileSet( new File( "." ), new File( "." ) );
045
046        List<ScmFile> files = runList( fileSet, false );
047
048        assertEquals( "The result of the list command doesn't have all the files in SCM: " + files, 3, files.size() );
049    }
050
051    public void testListCommandRecursiveTest()
052        throws Exception
053    {
054        ScmFileSet fileSet = new ScmFileSet( new File( "." ), new File( "." ) );
055
056        List<ScmFile> files = runList( fileSet, true );
057
058        assertEquals( "The result of the list command doesn't have all the files in SCM: " + files, 10, files.size() );
059    }
060
061    public void testListCommandUnexistantFileTest()
062        throws Exception
063    {
064        ScmFileSet fileSet = new ScmFileSet( new File( "." ), new File( "/void" ) );
065
066        ScmProvider provider = getScmManager().getProviderByUrl( getScmUrl() );
067
068        ListScmResult result = provider.list( getScmRepository(), fileSet, false, (ScmVersion) null );
069
070        assertFalse( "Found file when shouldn't", result.isSuccess() );
071    }
072
073    private List<ScmFile> runList( ScmFileSet fileSet, boolean recursive )
074        throws Exception
075    {
076        ScmProvider provider = getScmManager().getProviderByUrl( getScmUrl() );
077
078        ListScmResult result = provider.list( getScmRepository(), fileSet, recursive, (ScmVersion) null );
079
080        assertTrue( "SCM command failed: " + result.getCommandLine() + " : " + result.getProviderMessage()
081            + ( result.getCommandOutput() == null ? "" : ": " + result.getCommandOutput() ), result.isSuccess() );
082
083        return result.getFiles();
084    }
085}