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