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  public abstract class ListCommandTckTest extends ScmTckTestCase {
42      @Test
43      public void testListCommandTest() throws Exception {
44          ScmFileSet fileSet = new ScmFileSet(new File("."), new File("."));
45  
46          List<ScmFile> files = runList(fileSet, false);
47  
48          assertEquals("The result of the list command doesn't have all the files in SCM: " + files, 3, files.size());
49      }
50  
51      @Test
52      public void testListCommandRecursiveTest() throws Exception {
53          ScmFileSet fileSet = new ScmFileSet(new File("."), new File("."));
54  
55          List<ScmFile> files = runList(fileSet, true);
56  
57          assertEquals("The result of the list command doesn't have all the files in SCM: " + files, 10, files.size());
58      }
59  
60      @Test
61      public void testListCommandUnexistantFileTest() throws Exception {
62          ScmFileSet fileSet = new ScmFileSet(new File("."), new File("/void"));
63  
64          ScmProvider provider = getScmManager().getProviderByUrl(getScmUrl());
65  
66          ListScmResult result = provider.list(getScmRepository(), fileSet, false, (ScmVersion) null);
67  
68          assertFalse("Found file when shouldn't", result.isSuccess());
69      }
70  
71      private List<ScmFile> runList(ScmFileSet fileSet, boolean recursive) throws Exception {
72          ScmProvider provider = getScmManager().getProviderByUrl(getScmUrl());
73  
74          ListScmResult result = provider.list(getScmRepository(), fileSet, recursive, (ScmVersion) null);
75  
76          assertTrue(
77                  "SCM command failed: " + result.getCommandLine() + " : " + result.getProviderMessage()
78                          + (result.getCommandOutput() == null ? "" : ": " + result.getCommandOutput()),
79                  result.isSuccess());
80  
81          return result.getFiles();
82      }
83  }