View Javadoc

1   package org.apache.maven.wagon;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
5    * agreements. See the NOTICE file distributed with this work for additional information regarding
6    * copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance with the License. You may obtain a
8    * copy of the License at
9    * 
10   * http://www.apache.org/licenses/LICENSE-2.0
11   * 
12   * Unless required by applicable law or agreed to in writing, software distributed under the License
13   * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
14   * or implied. See the License for the specific language governing permissions and limitations under
15   * the License.
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   * Base class for command executor tests.
24   *
25   * @author <a href="mailto:brett@apache.org">Brett Porter</a>
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              //expect no exception, and stderr has something.
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 }