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.tck.command.list;
020
021import java.io.File;
022import java.util.List;
023
024import org.apache.maven.scm.ScmFile;
025import org.apache.maven.scm.ScmFileSet;
026import org.apache.maven.scm.ScmTckTestCase;
027import org.apache.maven.scm.ScmVersion;
028import org.apache.maven.scm.command.list.ListScmResult;
029import org.apache.maven.scm.provider.ScmProvider;
030import org.junit.Test;
031
032import static org.junit.Assert.assertEquals;
033import static org.junit.Assert.assertFalse;
034import static org.junit.Assert.assertTrue;
035
036/**
037 * This test tests the list command.
038 *
039 * @author <a href="mailto:carlos@apache.org">Carlos Sanchez</a>
040 */
041public abstract class ListCommandTckTest extends ScmTckTestCase {
042    @Test
043    public void testListCommandTest() throws Exception {
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    @Test
052    public void testListCommandRecursiveTest() throws Exception {
053        ScmFileSet fileSet = new ScmFileSet(new File("."), new File("."));
054
055        List<ScmFile> files = runList(fileSet, true);
056
057        assertEquals("The result of the list command doesn't have all the files in SCM: " + files, 10, files.size());
058    }
059
060    @Test
061    public void testListCommandUnexistantFileTest() throws Exception {
062        ScmFileSet fileSet = new ScmFileSet(new File("."), new File("/void"));
063
064        ScmProvider provider = getScmManager().getProviderByUrl(getScmUrl());
065
066        ListScmResult result = provider.list(getScmRepository(), fileSet, false, (ScmVersion) null);
067
068        assertFalse("Found file when shouldn't", result.isSuccess());
069    }
070
071    private List<ScmFile> runList(ScmFileSet fileSet, boolean recursive) throws Exception {
072        ScmProvider provider = getScmManager().getProviderByUrl(getScmUrl());
073
074        ListScmResult result = provider.list(getScmRepository(), fileSet, recursive, (ScmVersion) null);
075
076        assertTrue(
077                "SCM command failed: " + result.getCommandLine() + " : " + result.getProviderMessage()
078                        + (result.getCommandOutput() == null ? "" : ": " + result.getCommandOutput()),
079                result.isSuccess());
080
081        return result.getFiles();
082    }
083}