View Javadoc
1   package org.apache.maven.scm.provider.jazz.command;
2   
3   import static org.junit.Assert.assertNotEquals;
4   
5   import org.apache.maven.scm.ScmFileSet;
6   import org.apache.maven.scm.provider.jazz.JazzScmTestCase;
7   import org.codehaus.plexus.util.Os;
8   import org.codehaus.plexus.util.cli.Commandline;
9   
10  /*
11   * Licensed to the Apache Software Foundation (ASF) under one
12   * or more contributor license agreements.  See the NOTICE file
13   * distributed with this work for additional information
14   * regarding copyright ownership.  The ASF licenses this file
15   * to you under the Apache License, Version 2.0 (the
16   * "License"); you may not use this file except in compliance
17   * with the License.  You may obtain a copy of the License at
18   *
19   * http://www.apache.org/licenses/LICENSE-2.0
20   *
21   * Unless required by applicable law or agreed to in writing,
22   * software distributed under the License is distributed on an
23   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
24   * KIND, either express or implied.  See the License for the
25   * specific language governing permissions and limitations
26   * under the License.
27   */
28  
29  /**
30   * @author <a href="mailto:ChrisGWarp@gmail.com">Chris Graham</a>
31   */
32  public class JazzScmCommandTest
33      extends JazzScmTestCase
34  {
35      public void testFileList()
36      {
37          assertTrue( getScmFileSet().getFileList().size() > 0 );
38      }
39  
40      public void testJazzScmCommand()
41              throws Exception
42          {
43              ScmFileSet scmFileSet = new ScmFileSet( getWorkingCopy() );
44              JazzScmCommand listCommand = new JazzScmCommand( "list", getScmProviderRepository(), scmFileSet, null );
45              String expected =
46                  "scm list --repository-uri https://localhost:9443/jazz --username myUserName --password myPassword";
47  
48              assertCommandLine( expected, getWorkingDirectory(), listCommand.getCommandline() );
49  
50          }
51  
52      public void testJazzScmCommandWithExtraArg()
53          throws Exception
54      {
55          ScmFileSet scmFileSet = new ScmFileSet( getWorkingCopy() );
56          JazzScmCommand listCommand = new JazzScmCommand( "list", getScmProviderRepository(), scmFileSet, null );
57          listCommand.addArgument( "ExtraArg" );
58          String expected =
59              "scm list --repository-uri https://localhost:9443/jazz --username myUserName --password myPassword ExtraArg";
60  
61          assertCommandLine( expected, getWorkingDirectory(), listCommand.getCommandline() );
62  
63      }
64  
65      public void testCryptPassword()
66          throws Exception
67      {
68          JazzScmCommand listCommand = new JazzScmCommand( "list", getScmProviderRepository(), null, null );
69          // FIXME cryptPassword is broken
70          String actual = JazzScmCommand.cryptPassword( listCommand.getCommandline() );
71  
72          if ( Os.isFamily( Os.FAMILY_WINDOWS ) )
73          {
74              String expected =
75                  "cmd.exe /X /C \"scm list --repository-uri https://localhost:9443/jazz --username myUserName --password *****\"";
76              assertEquals( "cryptPassword failed!", expected, actual );
77          }
78          else
79          {
80              String expected =
81                  "/bin/sh -c 'scm' 'list' '--repository-uri' 'https://localhost:9443/jazz' '--username' 'myUserName' '--password' '*****'";
82              assertNotEquals( "cryptPassword correct!", expected, actual );
83          }
84      }
85  
86      public void testCryptPasswordWithExtraArg()
87              throws Exception
88          {
89              JazzScmCommand listCommand = new JazzScmCommand( "list", getScmProviderRepository(), null, null );
90              listCommand.addArgument( "ExtraArg" );
91              // FIXME cryptPassword is broken
92              String actual = JazzScmCommand.cryptPassword( listCommand.getCommandline() );
93  
94              if ( Os.isFamily( Os.FAMILY_WINDOWS ) )
95              {
96                  String expected =
97                      "cmd.exe /X /C \"scm list --repository-uri https://localhost:9443/jazz --username myUserName --password ***** ExtraArg\"";
98                  assertEquals( "cryptPassword failed!", expected, actual );
99              }
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 }