View Javadoc

1   package org.apache.maven.wagon;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.io.ByteArrayInputStream;
23  import java.io.ByteArrayOutputStream;
24  import java.io.InputStream;
25  import java.io.OutputStream;
26  import java.util.Collections;
27  import java.util.List;
28  
29  import org.apache.maven.wagon.authorization.AuthorizationException;
30  
31  /**
32   * @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
33   *
34   */
35  public class WagonMock
36      extends StreamWagon
37  {
38      private boolean errorInputStream;
39      private int timeout = 0;
40  
41      public WagonMock()
42      {
43      }
44  
45      public WagonMock( boolean errorInputStream )
46      {
47          this.errorInputStream = errorInputStream;
48      }
49  
50  
51      public void fillInputData( InputData inputData )
52          throws TransferFailedException
53      {
54  
55          InputStream is;
56  
57          if ( errorInputStream )
58          {
59              InputStreamMock mockInputStream = new InputStreamMock();
60  
61              mockInputStream.setForcedError( true );
62  
63              is = mockInputStream;
64  
65          }
66          else
67          {
68              byte[] buffer = new byte[1024 * 4 * 5];
69  
70              is = new ByteArrayInputStream( buffer );
71          }
72  
73          inputData.setInputStream( is );
74  
75      }
76  
77      public void fillOutputData( OutputData outputData )
78          throws TransferFailedException
79      {
80  
81          OutputStream os;
82  
83          if ( errorInputStream )
84          {
85              OutputStreamMock mockOutputStream = new OutputStreamMock();
86  
87              mockOutputStream.setForcedError( true );
88  
89              os = mockOutputStream;
90          }
91          else
92          {
93              os = new ByteArrayOutputStream();
94          }
95  
96          outputData.setOutputStream( os );
97  
98      }
99  
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 }