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