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 *
041 */
042public abstract class ListCommandTckTest extends ScmTckTestCase {
043    @Test
044    public void testListCommandTest() throws Exception {
045        ScmFileSet fileSet = new ScmFileSet(new File("."), new File("."));
046
047        List<ScmFile> files = runList(fileSet, false);
048
049        assertEquals("The result of the list command doesn't have all the files in SCM: " + files, 3, files.size());
050    }
051
052    @Test
053    public void testListCommandRecursiveTest() throws Exception {
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    @Test
062    public void testListCommandUnexistantFileTest() throws Exception {
063        ScmFileSet fileSet = new ScmFileSet(new File("."), new File("/void"));
064
065        ScmProvider provider = getScmManager().getProviderByUrl(getScmUrl());
066
067        ListScmResult result = provider.list(getScmRepository(), fileSet, false, (ScmVersion) null);
068
069        assertFalse("Found file when shouldn't", result.isSuccess());
070    }
071
072    private List<ScmFile> runList(ScmFileSet fileSet, boolean recursive) throws Exception {
073        ScmProvider provider = getScmManager().getProviderByUrl(getScmUrl());
074
075        ListScmResult result = provider.list(getScmRepository(), fileSet, recursive, (ScmVersion) null);
076
077        assertTrue(
078                "SCM command failed: " + result.getCommandLine() + " : " + result.getProviderMessage()
079                        + (result.getCommandOutput() == null ? "" : ": " + result.getCommandOutput()),
080                result.isSuccess());
081
082        return result.getFiles();
083    }
084}