1   package org.apache.maven.cli;
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 junit.framework.TestCase;
23  
24  import org.apache.maven.wagon.ConnectionException;
25  import org.apache.maven.wagon.authentication.AuthenticationException;
26  import org.apache.maven.wagon.events.TransferEvent;
27  import org.apache.maven.wagon.providers.file.FileWagon;
28  import org.apache.maven.wagon.repository.Repository;
29  import org.apache.maven.wagon.resource.Resource;
30  
31  /**
32   * Test for {@link AbstractConsoleDownloadMonitor}
33   * 
34   * @author <a href="mailto:carlos@apache.org">Carlos Sanchez</a>
35   * @version $Id: AbstractConsoleDownloadMonitorTest.java 640549 2008-03-24 20:05:11Z bentmann $
36   */
37  public abstract class AbstractConsoleDownloadMonitorTest
38      extends TestCase
39  {
40  
41      private AbstractConsoleDownloadMonitor monitor;
42  
43      public AbstractConsoleDownloadMonitorTest()
44      {
45          super();
46      }
47  
48      public void setMonitor( AbstractConsoleDownloadMonitor monitor )
49      {
50          this.monitor = monitor;
51      }
52  
53      public AbstractConsoleDownloadMonitor getMonitor()
54      {
55          return monitor;
56      }
57  
58      public void testTransferInitiated()
59          throws Exception
60      {
61          monitor.transferInitiated( new TransferEventMock() );
62      }
63  
64      public void testTransferStarted()
65          throws Exception
66      {
67          monitor.transferStarted( new TransferEventMock() );
68      }
69  
70      public void testTransferProgress()
71          throws Exception
72      {
73          byte[] buffer = new byte[1000];
74          monitor.transferProgress( new TransferEventMock(), buffer, 1000 );
75      }
76  
77      public void testTransferCompleted()
78          throws Exception
79      {
80          monitor.transferCompleted( new TransferEventMock() );
81      }
82  
83      public void testTransferError()
84          throws Exception
85      {
86          monitor.transferError( new TransferEventMock( new RuntimeException() ) );
87      }
88  
89      public void testDebug()
90          throws Exception
91      {
92          monitor.debug( "msg" );
93      }
94  
95      private class TransferEventMock
96          extends TransferEvent
97      {
98          public TransferEventMock()
99              throws ConnectionException, AuthenticationException
100         {
101             super( new FileWagon(), new Resource(), TransferEvent.TRANSFER_INITIATED, TransferEvent.REQUEST_GET );
102             getResource().setContentLength( 100000 );
103             Repository repository = new Repository();
104             getWagon().connect( repository );
105         }
106 
107         public TransferEventMock( Exception exception )
108             throws ConnectionException, AuthenticationException
109         {
110             super( new FileWagon(), new Resource(), exception, TransferEvent.REQUEST_GET );
111             getResource().setContentLength( 100000 );
112             Repository repository = new Repository();
113             getWagon().connect( repository );
114         }
115     }
116 }