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
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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
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
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 }