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