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