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.checkout;
20  
21  import java.util.Iterator;
22  import java.util.List;
23  import java.util.Optional;
24  import java.util.SortedSet;
25  import java.util.TreeSet;
26  
27  import org.apache.maven.scm.ScmFile;
28  import org.apache.maven.scm.ScmTckTestCase;
29  import org.apache.maven.scm.command.checkout.CheckOutScmResult;
30  import org.apache.maven.scm.provider.ScmProvider;
31  import org.apache.maven.scm.repository.ScmRepository;
32  import org.apache.maven.scm.repository.UnknownRepositoryStructure;
33  import org.junit.Test;
34  
35  import static org.junit.Assert.assertTrue;
36  import static org.junit.Assert.fail;
37  import static org.junit.Assume.assumeTrue;
38  
39  /**
40   * This test tests the check out command.
41   *
42   * @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
43   */
44  public abstract class CheckOutCommandTckTest extends ScmTckTestCase {
45      @Test
46      public void testCheckOutCommandTest() throws Exception {
47          deleteDirectory(getWorkingCopy());
48  
49          CheckOutScmResult result = checkOut(getWorkingCopy(), getScmRepository());
50  
51          assertResultIsSuccess(result);
52  
53          List<ScmFile> checkedOutFiles = result.getCheckedOutFiles();
54  
55          if (checkedOutFiles.size() != 4) {
56              SortedSet<ScmFile> files = new TreeSet<>(checkedOutFiles);
57  
58              int i = 0;
59  
60              for (Iterator<ScmFile> it = files.iterator(); it.hasNext(); i++) {
61                  ScmFile scmFile = it.next();
62  
63                  System.out.println(i + ": " + scmFile);
64              }
65  
66              fail("Expected 4 files in the updated files list, was " + checkedOutFiles.size());
67          }
68      }
69  
70      @Test
71      public void testMakeProviderScmRepositoryFromCheckoutDirectory() throws Exception {
72          assumeTrue(isMakeProviderScmRepositoryFromDirectorySupportedByProvider());
73          CheckOutScmResult result = checkOut(getWorkingCopy(), getScmRepository());
74          assertResultIsSuccess(result);
75          Optional<ScmRepository> repository = getScmManager().makeProviderScmRepository(getWorkingCopy());
76          assertTrue("Could not detect SCM repository for working copy at " + getWorkingCopy(), repository.isPresent());
77      }
78  
79      private boolean isMakeProviderScmRepositoryFromDirectorySupportedByProvider() throws Exception {
80          ScmProvider provider = getScmManager().getProviderByUrl(getScmUrl());
81          try {
82              provider.makeProviderScmRepository(getWorkingCopy());
83          } catch (UnknownRepositoryStructure e) {
84              // in this case the provider does not support this operation
85              return false;
86          }
87          return true;
88      }
89  }