1 package org.apache.maven.wagon;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.codehaus.plexus.PlexusTestCase;
23 import org.apache.maven.wagon.repository.Repository;
24 import org.apache.maven.wagon.authentication.AuthenticationInfo;
25
26
27
28
29
30
31
32 public abstract class CommandExecutorTestCase
33 extends PlexusTestCase
34 {
35 public void testErrorInCommandExecuted()
36 throws Exception
37 {
38 CommandExecutor exec = (CommandExecutor) lookup( CommandExecutor.ROLE );
39
40 Repository repository = getTestRepository();
41
42 AuthenticationInfo authenticationInfo = new AuthenticationInfo();
43 authenticationInfo.setUserName( System.getProperty( "user.name" ) );
44
45 exec.connect( repository, authenticationInfo );
46
47 try
48 {
49 exec.executeCommand( "fail" );
50 fail( "Command should have failed" );
51 }
52 catch ( CommandExecutionException e )
53 {
54 assertTrue( e.getMessage().trim().endsWith( "fail: command not found" ) );
55 }
56 finally
57 {
58 exec.disconnect();
59 }
60 }
61
62 public void testIgnoreFailuresInCommandExecuted()
63 throws Exception
64 {
65 CommandExecutor exec = (CommandExecutor) lookup( CommandExecutor.ROLE );
66
67 Repository repository = getTestRepository();
68
69 AuthenticationInfo authenticationInfo = new AuthenticationInfo();
70 authenticationInfo.setUserName( System.getProperty( "user.name" ) );
71
72 exec.connect( repository, authenticationInfo );
73
74 try
75 {
76 Streams streams = exec.executeCommand( "fail", true );
77
78 assertTrue( streams.getErr().length() > 0 );
79 }
80 finally
81 {
82 exec.disconnect();
83 }
84 }
85
86 public void testExecuteSuccessfulCommand()
87 throws Exception
88 {
89 CommandExecutor exec = (CommandExecutor) lookup( CommandExecutor.ROLE );
90
91 Repository repository = getTestRepository();
92
93 AuthenticationInfo authenticationInfo = new AuthenticationInfo();
94 authenticationInfo.setUserName( System.getProperty( "user.name" ) );
95
96 exec.connect( repository, authenticationInfo );
97
98 try
99 {
100 exec.executeCommand( "ls" );
101 }
102 finally
103 {
104 exec.disconnect();
105 }
106 }
107
108 protected abstract Repository getTestRepository();
109 }