001    package org.apache.maven.scm.provider.cvslib.command.checkout;
002    
003    /*
004     * Licensed to the Apache Software Foundation (ASF) under one
005     * or more contributor license agreements.  See the NOTICE file
006     * distributed with this work for additional information
007     * regarding copyright ownership.  The ASF licenses this file
008     * to you under the Apache License, Version 2.0 (the
009     * "License"); you may not use this file except in compliance
010     * with the License.  You may obtain a copy of the License at
011     *
012     * http://www.apache.org/licenses/LICENSE-2.0
013     *
014     * Unless required by applicable law or agreed to in writing,
015     * software distributed under the License is distributed on an
016     * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017     * KIND, either express or implied.  See the License for the
018     * specific language governing permissions and limitations
019     * under the License.
020     */
021    
022    import org.apache.maven.scm.ScmFile;
023    import org.apache.maven.scm.ScmFileStatus;
024    import org.apache.maven.scm.command.checkout.CheckOutScmResult;
025    import org.apache.maven.scm.manager.ScmManager;
026    import org.apache.maven.scm.provider.cvslib.AbstractCvsScmTest;
027    import org.apache.maven.scm.provider.cvslib.CvsScmTestUtils;
028    
029    import java.io.File;
030    import java.util.List;
031    
032    /**
033     * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
034     * @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
035     * @version $Id: CvsCheckoutCommandTest.java 1057015 2011-01-09 20:10:42Z olamy $
036     */
037    public class CvsCheckoutCommandTest
038        extends AbstractCvsScmTest
039    {
040        /** {@inheritDoc} */
041        protected String getModule()
042        {
043            return "test-repo/checkout";
044        }
045    
046        /**
047         * @todo move this test to the TCK.
048         */
049        public void testCheckOutWithoutTag()
050            throws Exception
051        {
052            if ( !isSystemCmd( CvsScmTestUtils.CVS_COMMAND_LINE ) )
053            {
054                System.err.println( "'" + CvsScmTestUtils.CVS_COMMAND_LINE + "' is not a system command. Ignored "
055                    + getName() + "." );
056                return;
057            }
058    
059            ScmManager scmManager = getScmManager();
060    
061            CheckOutScmResult result = scmManager.checkOut( getScmRepository(), getScmFileSet() );
062    
063            if ( !result.isSuccess() )
064            {
065                fail( result.getProviderMessage() + "\n" + result.getCommandOutput() + "\n" + result.getCommandLine() );
066            }
067    
068            List<ScmFile> files = result.getCheckedOutFiles();
069    
070            assertNotNull( files );
071    
072            assertEquals( 3, files.size() );
073    
074            assertCheckedOutFile( files, 0, "/Foo.java", ScmFileStatus.UPDATED );
075    
076            assertCheckedOutFile( files, 1, "/Readme.txt", ScmFileStatus.UPDATED );
077    
078            assertCheckedOutFile( files, 2, "/src/java/org/apache/maven/MavenUtils.java", ScmFileStatus.UPDATED );
079        }
080    
081        /**
082         * @todo move this test to the TCK - checkout with "revision", then have one for tag as well.
083         */
084        public void testCheckOutWithTag()
085            throws Exception
086        {
087            if ( !isSystemCmd( CvsScmTestUtils.CVS_COMMAND_LINE ) )
088            {
089                System.err.println( "'" + CvsScmTestUtils.CVS_COMMAND_LINE + "' is not a system command. Ignored "
090                    + getName() + "." );
091                return;
092            }
093    
094            ScmManager scmManager = getScmManager();
095    
096            @SuppressWarnings( "deprecation" )
097            CheckOutScmResult result = scmManager.getProviderByRepository( getScmRepository() ).checkOut(
098                getScmRepository(), getScmFileSet(), "MAVEN_1_0" );
099    
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    }