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.provider.local.command.checkout;
20  
21  import java.io.File;
22  import java.io.FileReader;
23  import java.io.Reader;
24  import java.util.List;
25  
26  import org.apache.maven.scm.ScmFile;
27  import org.apache.maven.scm.command.checkout.CheckOutScmResult;
28  import org.apache.maven.scm.provider.local.metadata.LocalScmMetadata;
29  import org.apache.maven.scm.provider.local.metadata.io.xpp3.LocalScmMetadataXpp3Reader;
30  import org.apache.maven.scm.tck.command.checkout.CheckOutCommandTckTest;
31  import org.codehaus.plexus.util.FileUtils;
32  import org.codehaus.plexus.util.IOUtil;
33  import org.junit.Test;
34  
35  import static org.junit.Assert.assertEquals;
36  import static org.junit.Assert.assertTrue;
37  
38  /**
39   * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
40   *
41   */
42  public class LocalCheckOutCommandTckTest extends CheckOutCommandTckTest {
43      private String module = "check-out";
44  
45      public String getScmUrl() throws Exception {
46          return "scm:local|" + getRepositoryRoot().getAbsolutePath() + "|" + module;
47      }
48  
49      public void initRepo() throws Exception {
50          File root = new File(getRepositoryRoot() + "/" + module);
51  
52          makeFile(root, "/pom.xml");
53  
54          makeFile(root, "/readme.txt");
55  
56          makeFile(root, "/src/main/java/Application.java");
57  
58          makeFile(root, "/src/test/java/Test.java");
59  
60          makeDirectory(root, "/src/test/resources");
61      }
62  
63      /**
64       * Tests that the metadata file .maven-scm-local is written correctly
65       */
66      @Test
67      public void testMetadata() throws Exception {
68          FileUtils.deleteDirectory(getWorkingCopy());
69  
70          CheckOutScmResult result = checkOut(getWorkingCopy(), getScmRepository());
71  
72          assertResultIsSuccess(result);
73  
74          List<ScmFile> checkedOutFiles = result.getCheckedOutFiles();
75  
76          assertEquals(4, checkedOutFiles.size());
77  
78          // ----------------------------------------------------------------------
79          // Assert metadata file
80          // ----------------------------------------------------------------------
81          File metadataFile = new File(getWorkingCopy(), ".maven-scm-local");
82          assertTrue("Expected metadata file .maven-scm-local does not exist", metadataFile.exists());
83          Reader reader = new FileReader(metadataFile);
84          LocalScmMetadata metadata;
85          try {
86              metadata = new LocalScmMetadataXpp3Reader().read(reader);
87          } finally {
88              IOUtil.close(reader);
89          }
90          File root = new File(getRepositoryRoot() + "/" + module);
91          @SuppressWarnings("unchecked")
92          List<String> fileNames = FileUtils.getFileNames(root, "**", null, false);
93          assertEquals(fileNames, metadata.getRepositoryFileNames());
94      }
95  }