001package org.apache.maven.wagon; 002 003/* 004 * Licensed to the Apache Software Foundation (ASF) under one or more contributor license 005 * agreements. See the NOTICE file distributed with this work for additional information regarding 006 * copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance with the License. You may obtain a 008 * copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software distributed under the License 013 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 014 * or implied. See the License for the specific language governing permissions and limitations under 015 * the License. 016 */ 017 018import org.codehaus.plexus.PlexusTestCase; 019import org.apache.maven.wagon.repository.Repository; 020import org.apache.maven.wagon.authentication.AuthenticationInfo; 021 022/** 023 * Base class for command executor tests. 024 * 025 * @author <a href="mailto:brett@apache.org">Brett Porter</a> 026 * 027 */ 028public abstract class CommandExecutorTestCase 029 extends PlexusTestCase 030{ 031 public void testErrorInCommandExecuted() 032 throws Exception 033 { 034 CommandExecutor exec = (CommandExecutor) lookup( CommandExecutor.ROLE ); 035 036 Repository repository = getTestRepository(); 037 038 AuthenticationInfo authenticationInfo = new AuthenticationInfo(); 039 authenticationInfo.setUserName( System.getProperty( "user.name" ) ); 040 041 exec.connect( repository, authenticationInfo ); 042 043 try 044 { 045 exec.executeCommand( "fail" ); 046 fail( "Command should have failed" ); 047 } 048 catch ( CommandExecutionException e ) 049 { 050 assertTrue( e.getMessage().trim().endsWith( "fail: command not found" ) ); 051 } 052 finally 053 { 054 exec.disconnect(); 055 } 056 } 057 058 public void testIgnoreFailuresInCommandExecuted() 059 throws Exception 060 { 061 CommandExecutor exec = (CommandExecutor) lookup( CommandExecutor.ROLE ); 062 063 Repository repository = getTestRepository(); 064 065 AuthenticationInfo authenticationInfo = new AuthenticationInfo(); 066 authenticationInfo.setUserName( System.getProperty( "user.name" ) ); 067 068 exec.connect( repository, authenticationInfo ); 069 070 try 071 { 072 Streams streams = exec.executeCommand( "fail", true ); 073 //expect no exception, and stderr has something. 074 assertTrue( streams.getErr().length() > 0 ); 075 } 076 finally 077 { 078 exec.disconnect(); 079 } 080 } 081 082 public void testExecuteSuccessfulCommand() 083 throws Exception 084 { 085 CommandExecutor exec = (CommandExecutor) lookup( CommandExecutor.ROLE ); 086 087 Repository repository = getTestRepository(); 088 089 AuthenticationInfo authenticationInfo = new AuthenticationInfo(); 090 authenticationInfo.setUserName( System.getProperty( "user.name" ) ); 091 092 exec.connect( repository, authenticationInfo ); 093 094 try 095 { 096 exec.executeCommand( "ls" ); 097 } 098 finally 099 { 100 exec.disconnect(); 101 } 102 } 103 104 protected abstract Repository getTestRepository(); 105}