001package 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
022import org.apache.maven.scm.ScmFile;
023import org.apache.maven.scm.ScmFileStatus;
024import org.apache.maven.scm.ScmTestCase;
025import org.apache.maven.scm.command.checkout.CheckOutScmResult;
026import org.apache.maven.scm.manager.ScmManager;
027import org.apache.maven.scm.provider.cvslib.AbstractCvsScmTest;
028import org.apache.maven.scm.provider.cvslib.CvsScmTestUtils;
029
030import java.io.File;
031import java.util.List;
032
033/**
034 * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
035 * @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
036 *
037 */
038public class CvsCheckoutCommandTest
039    extends AbstractCvsScmTest
040{
041    /** {@inheritDoc} */
042    protected String getModule()
043    {
044        return "test-repo/checkout";
045    }
046
047    /**
048     * TODO move this test to the TCK.
049     */
050    public void testCheckOutWithoutTag()
051        throws Exception
052    {
053        if ( !isSystemCmd( CvsScmTestUtils.CVS_COMMAND_LINE ) )
054        {
055            ScmTestCase.printSystemCmdUnavail( CvsScmTestUtils.CVS_COMMAND_LINE, 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            ScmTestCase.printSystemCmdUnavail( CvsScmTestUtils.CVS_COMMAND_LINE, getName() );
090            return;
091        }
092
093        ScmManager scmManager = getScmManager();
094
095        @SuppressWarnings( "deprecation" )
096        CheckOutScmResult result = scmManager.getProviderByRepository( getScmRepository() ).checkOut(
097            getScmRepository(), getScmFileSet(), "MAVEN_1_0" );
098
099        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}