001package org.apache.maven.wagon; 002 003/* 004 * Licensed to the Apache Software Foundation (ASF) under one 005 * or more contributor license agreements. See the NOTICE file 006 * distributed with this work for additional information 007 * regarding copyright ownership. The ASF licenses this file 008 * to you under the Apache License, Version 2.0 (the 009 * "License"); you may not use this file except in compliance 010 * with the License. You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, 015 * software distributed under the License is distributed on an 016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 017 * KIND, either express or implied. See the License for the 018 * specific language governing permissions and limitations 019 * under the License. 020 */ 021 022import java.io.ByteArrayInputStream; 023import java.io.ByteArrayOutputStream; 024import java.io.InputStream; 025import java.io.OutputStream; 026import java.util.Collections; 027import java.util.List; 028 029import org.apache.maven.wagon.authorization.AuthorizationException; 030 031/** 032 * @author <a href="mailto:jason@maven.org">Jason van Zyl</a> 033 * 034 */ 035public class WagonMock 036 extends StreamWagon 037{ 038 private boolean errorInputStream; 039 private int timeout = 0; 040 041 public WagonMock() 042 { 043 } 044 045 public WagonMock( boolean errorInputStream ) 046 { 047 this.errorInputStream = errorInputStream; 048 } 049 050 051 public void fillInputData( InputData inputData ) 052 throws TransferFailedException 053 { 054 055 InputStream is; 056 057 if ( errorInputStream ) 058 { 059 InputStreamMock mockInputStream = new InputStreamMock(); 060 061 mockInputStream.setForcedError( true ); 062 063 is = mockInputStream; 064 065 } 066 else 067 { 068 byte[] buffer = new byte[1024 * 4 * 5]; 069 070 is = new ByteArrayInputStream( buffer ); 071 } 072 073 inputData.setInputStream( is ); 074 075 } 076 077 public void fillOutputData( OutputData outputData ) 078 throws TransferFailedException 079 { 080 081 OutputStream os; 082 083 if ( errorInputStream ) 084 { 085 OutputStreamMock mockOutputStream = new OutputStreamMock(); 086 087 mockOutputStream.setForcedError( true ); 088 089 os = mockOutputStream; 090 } 091 else 092 { 093 os = new ByteArrayOutputStream(); 094 } 095 096 outputData.setOutputStream( os ); 097 098 } 099 100 public void openConnectionInternal() 101 { 102 } 103 104 public void closeConnection() 105 { 106 } 107 108 public void setTimeout( int timeoutValue ) 109 { 110 timeout = timeoutValue; 111 } 112 113 public int getTimeout() 114 { 115 return timeout; 116 } 117 118 public List<String> getFileList( String destinationDirectory ) 119 throws TransferFailedException, AuthorizationException 120 { 121 return Collections.<String>emptyList(); 122 } 123 124 public boolean resourceExists( String resourceName ) 125 throws AuthorizationException 126 { 127 return false; 128 } 129 130}