001package org.apache.maven.scm.provider.perforce.command.login;
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.ScmFileSet;
023import org.apache.maven.scm.ScmTestCase;
024import org.apache.maven.scm.log.DefaultLog;
025import org.apache.maven.scm.log.ScmLogger;
026import org.apache.maven.scm.provider.perforce.repository.PerforceScmProviderRepository;
027import org.apache.maven.scm.repository.ScmRepository;
028import org.codehaus.plexus.util.cli.Commandline;
029
030import java.io.File;
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 *
036 */
037public class PerforceLoginCommandTest
038    extends ScmTestCase
039{
040    private static final File workingDirectory = getTestFile( "target/perforce-login-command-test" );
041
042    private static final String cmdPrefix = "p4 -d " + workingDirectory.getAbsolutePath();
043
044    public void testGetCommandLine()
045        throws Exception
046    {
047        testCommandLine( cmdPrefix + " login" );
048    }
049
050    /**
051     * This test requires P4 installed
052     * 
053     * @throws Exception
054     */
055    public void disabledTestLoginWithoutPassword()
056        throws Exception
057    {
058        ScmRepository repository = getScmManager().makeScmRepository( "scm:perforce://depot/projects/pathname" );
059        PerforceScmProviderRepository scmRepository =
060            (PerforceScmProviderRepository) repository.getProviderRepository();
061        ScmFileSet fileSet = new ScmFileSet( new File( "." ) );
062
063        PerforceLoginCommand command = new PerforceLoginCommand();
064        ScmLogger logger = new DefaultLog();
065        command.setLogger( logger );
066
067        command.executeLoginCommand( scmRepository, fileSet, null );
068    }
069
070    // ----------------------------------------------------------------------
071    //
072    // ----------------------------------------------------------------------
073
074    private void testCommandLine( String commandLine )
075        throws Exception
076    {
077        ScmRepository repository = getScmManager().makeScmRepository( "scm:perforce://depot/projects/pathname" );
078        PerforceScmProviderRepository scmRepository = (PerforceScmProviderRepository) repository
079            .getProviderRepository();
080        //CommandParameters params = new CommandParameters();
081        Commandline cl = PerforceLoginCommand.createCommandLine( scmRepository, workingDirectory );
082
083        assertCommandLine( commandLine, null, cl );
084    }
085}