001package org.apache.maven.scm.provider.jazz.command;
002
003import static org.junit.Assert.assertNotEquals;
004
005import org.apache.maven.scm.ScmFileSet;
006import org.apache.maven.scm.provider.jazz.JazzScmTestCase;
007import org.codehaus.plexus.util.Os;
008import org.codehaus.plexus.util.cli.Commandline;
009
010/*
011 * Licensed to the Apache Software Foundation (ASF) under one
012 * or more contributor license agreements.  See the NOTICE file
013 * distributed with this work for additional information
014 * regarding copyright ownership.  The ASF licenses this file
015 * to you under the Apache License, Version 2.0 (the
016 * "License"); you may not use this file except in compliance
017 * with the License.  You may obtain a copy of the License at
018 *
019 * http://www.apache.org/licenses/LICENSE-2.0
020 *
021 * Unless required by applicable law or agreed to in writing,
022 * software distributed under the License is distributed on an
023 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
024 * KIND, either express or implied.  See the License for the
025 * specific language governing permissions and limitations
026 * under the License.
027 */
028
029/**
030 * @author <a href="mailto:ChrisGWarp@gmail.com">Chris Graham</a>
031 */
032public class JazzScmCommandTest
033    extends JazzScmTestCase
034{
035    public void testFileList()
036    {
037        assertTrue( getScmFileSet().getFileList().size() > 0 );
038    }
039
040    public void testJazzScmCommand()
041            throws Exception
042        {
043            ScmFileSet scmFileSet = new ScmFileSet( getWorkingCopy() );
044            JazzScmCommand listCommand = new JazzScmCommand( "list", getScmProviderRepository(), scmFileSet, null );
045            String expected =
046                "scm list --repository-uri https://localhost:9443/jazz --username myUserName --password myPassword";
047
048            assertCommandLine( expected, getWorkingDirectory(), listCommand.getCommandline() );
049
050        }
051
052    public void testJazzScmCommandWithExtraArg()
053        throws Exception
054    {
055        ScmFileSet scmFileSet = new ScmFileSet( getWorkingCopy() );
056        JazzScmCommand listCommand = new JazzScmCommand( "list", getScmProviderRepository(), scmFileSet, null );
057        listCommand.addArgument( "ExtraArg" );
058        String expected =
059            "scm list --repository-uri https://localhost:9443/jazz --username myUserName --password myPassword ExtraArg";
060
061        assertCommandLine( expected, getWorkingDirectory(), listCommand.getCommandline() );
062
063    }
064
065    public void testCryptPassword()
066        throws Exception
067    {
068        JazzScmCommand listCommand = new JazzScmCommand( "list", getScmProviderRepository(), null, null );
069        // FIXME cryptPassword is broken
070        String actual = JazzScmCommand.cryptPassword( listCommand.getCommandline() );
071
072        if ( Os.isFamily( Os.FAMILY_WINDOWS ) )
073        {
074            String expected =
075                "cmd.exe /X /C \"scm list --repository-uri https://localhost:9443/jazz --username myUserName --password *****\"";
076            assertEquals( "cryptPassword failed!", expected, actual );
077        }
078        else
079        {
080            String expected =
081                "/bin/sh -c 'scm' 'list' '--repository-uri' 'https://localhost:9443/jazz' '--username' 'myUserName' '--password' '*****'";
082            assertNotEquals( "cryptPassword correct!", expected, actual );
083        }
084    }
085
086    public void testCryptPasswordWithExtraArg()
087            throws Exception
088        {
089            JazzScmCommand listCommand = new JazzScmCommand( "list", getScmProviderRepository(), null, null );
090            listCommand.addArgument( "ExtraArg" );
091            // FIXME cryptPassword is broken
092            String actual = JazzScmCommand.cryptPassword( listCommand.getCommandline() );
093
094            if ( Os.isFamily( Os.FAMILY_WINDOWS ) )
095            {
096                String expected =
097                    "cmd.exe /X /C \"scm list --repository-uri https://localhost:9443/jazz --username myUserName --password ***** ExtraArg\"";
098                assertEquals( "cryptPassword failed!", expected, actual );
099            }
100            else
101            {
102                String expected =
103                    "/bin/sh -c 'scm' 'list' '--repository-uri' 'https://localhost:9443/jazz' '--username' 'myUserName' '--password' '*****' 'ExtraArg'";
104                assertNotEquals( "cryptPassword correct!", expected, actual );
105            }
106        }
107}