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