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.command.checkout.CheckOutScmResult;
25  import org.apache.maven.scm.manager.ScmManager;
26  import org.apache.maven.scm.provider.cvslib.AbstractCvsScmTest;
27  import org.apache.maven.scm.provider.cvslib.CvsScmTestUtils;
28  
29  import java.io.File;
30  import java.util.List;
31  
32  /**
33   * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
34   * @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
35   *
36   */
37  public class CvsCheckoutCommandTest
38      extends AbstractCvsScmTest
39  {
40      /** {@inheritDoc} */
41      protected String getModule()
42      {
43          return "test-repo/checkout";
44      }
45  
46      /**
47       * @todo move this test to the TCK.
48       */
49      public void testCheckOutWithoutTag()
50          throws Exception
51      {
52          if ( !isSystemCmd( CvsScmTestUtils.CVS_COMMAND_LINE ) )
53          {
54              System.err.println( "'" + CvsScmTestUtils.CVS_COMMAND_LINE + "' is not a system command. Ignored "
55                  + 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              System.err.println( "'" + CvsScmTestUtils.CVS_COMMAND_LINE + "' is not a system command. Ignored "
90                  + getName() + "." );
91              return;
92          }
93  
94          ScmManager scmManager = getScmManager();
95  
96          @SuppressWarnings( "deprecation" )
97          CheckOutScmResult result = scmManager.getProviderByRepository( getScmRepository() ).checkOut(
98              getScmRepository(), getScmFileSet(), "MAVEN_1_0" );
99  
100         if ( !result.isSuccess() )
101         {
102             fail( result.getProviderMessage() + "\n" + result.getCommandOutput() );
103         }
104 
105         List<ScmFile> files = result.getCheckedOutFiles();
106 
107         assertNotNull( files );
108 
109         assertEquals( 1, files.size() );
110 
111         File mavenUtils =
112             assertCheckedOutFile( files, 0, "/src/java/org/apache/maven/MavenUtils.java", ScmFileStatus.UPDATED );
113 
114         assertBetween( 38403, 39511, mavenUtils.length() );
115     }
116 
117     // ----------------------------------------------------------------------
118     //
119     // ----------------------------------------------------------------------
120 
121     private File assertCheckedOutFile( List<ScmFile> files, int i, String fileName, ScmFileStatus status )
122         throws Exception
123     {
124         File file = new File( getWorkingDirectory(), fileName );
125 
126         assertTrue( file.getAbsolutePath() + " file doesn't exist.", file.exists() );
127 
128         ScmFile coFile = files.get( i );
129 
130         assertSame( status, coFile.getStatus() );
131 
132         assertPath( fileName, coFile.getPath() );
133 
134         return file;
135     }
136 }