View Javadoc
1   package org.apache.maven.scm.provider.cvslib.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.ScmFile;
23  import org.apache.maven.scm.ScmFileStatus;
24  import org.apache.maven.scm.ScmTestCase;
25  import org.apache.maven.scm.command.checkout.CheckOutScmResult;
26  import org.apache.maven.scm.manager.ScmManager;
27  import org.apache.maven.scm.provider.cvslib.AbstractCvsScmTest;
28  import org.apache.maven.scm.provider.cvslib.CvsScmTestUtils;
29  
30  import java.io.File;
31  import java.util.List;
32  
33  /**
34   * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
35   * @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
36   *
37   */
38  public class CvsCheckoutCommandTest
39      extends AbstractCvsScmTest
40  {
41      /** {@inheritDoc} */
42      protected String getModule()
43      {
44          return "test-repo/checkout";
45      }
46  
47      /**
48       * TODO move this test to the TCK.
49       */
50      public void testCheckOutWithoutTag()
51          throws Exception
52      {
53          if ( !isSystemCmd( CvsScmTestUtils.CVS_COMMAND_LINE ) )
54          {
55              ScmTestCase.printSystemCmdUnavail( CvsScmTestUtils.CVS_COMMAND_LINE, getName() );
56              return;
57          }
58  
59          ScmManager scmManager = getScmManager();
60  
61          CheckOutScmResult result = scmManager.checkOut( getScmRepository(), getScmFileSet() );
62  
63          if ( !result.isSuccess() )
64          {
65              fail( result.getProviderMessage() + "\n" + result.getCommandOutput() + "\n" + result.getCommandLine() );
66          }
67  
68          List<ScmFile> files = result.getCheckedOutFiles();
69  
70          assertNotNull( files );
71  
72          assertEquals( 3, files.size() );
73  
74          assertCheckedOutFile( files, 0, "/Foo.java", ScmFileStatus.UPDATED );
75  
76          assertCheckedOutFile( files, 1, "/Readme.txt", ScmFileStatus.UPDATED );
77  
78          assertCheckedOutFile( files, 2, "/src/java/org/apache/maven/MavenUtils.java", ScmFileStatus.UPDATED );
79      }
80  
81      /**
82       * TODO move this test to the TCK - checkout with "revision", then have one for tag as well.
83       */
84      public void testCheckOutWithTag()
85          throws Exception
86      {
87          if ( !isSystemCmd( CvsScmTestUtils.CVS_COMMAND_LINE ) )
88          {
89              ScmTestCase.printSystemCmdUnavail( CvsScmTestUtils.CVS_COMMAND_LINE, getName() );
90              return;
91          }
92  
93          ScmManager scmManager = getScmManager();
94  
95          @SuppressWarnings( "deprecation" )
96          CheckOutScmResult result = scmManager.getProviderByRepository( getScmRepository() ).checkOut(
97              getScmRepository(), getScmFileSet(), "MAVEN_1_0" );
98  
99          if ( !result.isSuccess() )
100         {
101             fail( result.getProviderMessage() + "\n" + result.getCommandOutput() );
102         }
103 
104         List<ScmFile> files = result.getCheckedOutFiles();
105 
106         assertNotNull( files );
107 
108         assertEquals( 1, files.size() );
109 
110         File mavenUtils =
111             assertCheckedOutFile( files, 0, "/src/java/org/apache/maven/MavenUtils.java", ScmFileStatus.UPDATED );
112 
113         assertBetween( 38403, 39511, mavenUtils.length() );
114     }
115 
116     // ----------------------------------------------------------------------
117     //
118     // ----------------------------------------------------------------------
119 
120     private File assertCheckedOutFile( List<ScmFile> files, int i, String fileName, ScmFileStatus status )
121         throws Exception
122     {
123         File file = new File( getWorkingDirectory(), fileName );
124 
125         assertTrue( file.getAbsolutePath() + " file doesn't exist.", file.exists() );
126 
127         ScmFile coFile = files.get( i );
128 
129         assertSame( status, coFile.getStatus() );
130 
131         assertPath( fileName, coFile.getPath() );
132 
133         return file;
134     }
135 }