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  public abstract class CommandExecutorTestCase
29      extends PlexusTestCase
30  {
31      public void testErrorInCommandExecuted()
32          throws Exception
33      {
34          CommandExecutor exec = (CommandExecutor) lookup( CommandExecutor.ROLE );
35  
36          Repository repository = getTestRepository();
37  
38          AuthenticationInfo authenticationInfo = new AuthenticationInfo();
39          authenticationInfo.setUserName( System.getProperty( "user.name" ) );
40  
41          exec.connect( repository, authenticationInfo );
42  
43          try
44          {
45              exec.executeCommand( "fail" );
46              fail( "Command should have failed" );
47          }
48          catch ( CommandExecutionException e )
49          {
50              assertTrue( e.getMessage().trim().endsWith( "fail: command not found" ) );
51          }
52          finally
53          {
54              exec.disconnect();
55          }
56      }
57  
58      public void testIgnoreFailuresInCommandExecuted()
59          throws Exception
60      {
61          CommandExecutor exec = (CommandExecutor) lookup( CommandExecutor.ROLE );
62  
63          Repository repository = getTestRepository();
64  
65          AuthenticationInfo authenticationInfo = new AuthenticationInfo();
66          authenticationInfo.setUserName( System.getProperty( "user.name" ) );
67  
68          exec.connect( repository, authenticationInfo );
69  
70          try
71          {
72              Streams streams = exec.executeCommand( "fail", true );
73              
74              assertTrue( streams.getErr().length() > 0 );
75          }
76          finally
77          {
78              exec.disconnect();
79          }
80      }
81  
82      public void testExecuteSuccessfulCommand()
83          throws Exception
84      {
85          CommandExecutor exec = (CommandExecutor) lookup( CommandExecutor.ROLE );
86  
87          Repository repository = getTestRepository();
88  
89          AuthenticationInfo authenticationInfo = new AuthenticationInfo();
90          authenticationInfo.setUserName( System.getProperty( "user.name" ) );
91  
92          exec.connect( repository, authenticationInfo );
93  
94          try
95          {
96              exec.executeCommand( "ls" );
97          }
98          finally
99          {
100             exec.disconnect();
101         }
102     }
103 
104     protected abstract Repository getTestRepository();
105 }