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