View Javadoc
1   package org.apache.maven.scm.tck.command.list;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   * http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.io.File;
23  import java.util.List;
24  
25  import org.apache.maven.scm.ScmFile;
26  import org.apache.maven.scm.ScmFileSet;
27  import org.apache.maven.scm.ScmTckTestCase;
28  import org.apache.maven.scm.ScmVersion;
29  import org.apache.maven.scm.command.list.ListScmResult;
30  import org.apache.maven.scm.provider.ScmProvider;
31  import org.junit.Test;
32  
33  import static org.junit.Assert.assertEquals;
34  import static org.junit.Assert.assertFalse;
35  import static org.junit.Assert.assertTrue;
36  
37  /**
38   * This test tests the list command.
39   *
40   * @author <a href="mailto:carlos@apache.org">Carlos Sanchez</a>
41   *
42   */
43  public abstract class ListCommandTckTest
44      extends ScmTckTestCase
45  {
46      @Test
47      public void testListCommandTest()
48          throws Exception
49      {
50          ScmFileSet fileSet = new ScmFileSet( new File( "." ), new File( "." ) );
51  
52          List<ScmFile> files = runList( fileSet, false );
53  
54          assertEquals( "The result of the list command doesn't have all the files in SCM: " + files, 3, files.size() );
55      }
56  
57      @Test
58      public void testListCommandRecursiveTest()
59          throws Exception
60      {
61          ScmFileSet fileSet = new ScmFileSet( new File( "." ), new File( "." ) );
62  
63          List<ScmFile> files = runList( fileSet, true );
64  
65          assertEquals( "The result of the list command doesn't have all the files in SCM: " + files, 10, files.size() );
66      }
67  
68      @Test
69      public void testListCommandUnexistantFileTest()
70          throws Exception
71      {
72          ScmFileSet fileSet = new ScmFileSet( new File( "." ), new File( "/void" ) );
73  
74          ScmProvider provider = getScmManager().getProviderByUrl( getScmUrl() );
75  
76          ListScmResult result = provider.list( getScmRepository(), fileSet, false, (ScmVersion) null );
77  
78          assertFalse( "Found file when shouldn't", result.isSuccess() );
79      }
80  
81      private List<ScmFile> runList( ScmFileSet fileSet, boolean recursive )
82          throws Exception
83      {
84          ScmProvider provider = getScmManager().getProviderByUrl( getScmUrl() );
85  
86          ListScmResult result = provider.list( getScmRepository(), fileSet, recursive, (ScmVersion) null );
87  
88          assertTrue( "SCM command failed: " + result.getCommandLine() + " : " + result.getProviderMessage()
89              + ( result.getCommandOutput() == null ? "" : ": " + result.getCommandOutput() ), result.isSuccess() );
90  
91          return result.getFiles();
92      }
93  }