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 746138 2009-02-20 05:02:48Z brett $
36   */
37  public abstract class AbstractConsoleDownloadMonitorTest
38      extends TestCase
39  {
40  
41      protected 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      static class TransferEventMock
96          extends TransferEvent
97      {
98  
99          public TransferEventMock()
100             throws ConnectionException, AuthenticationException
101         {
102             super( new FileWagon(), new Resource(), TransferEvent.TRANSFER_INITIATED, TransferEvent.REQUEST_GET );
103             getResource().setContentLength( 100000 );
104             getResource().setName( "foo.bar" );
105             Repository repository = new Repository();
106             getWagon().connect( repository );
107         }
108 
109         public TransferEventMock( Resource resource, int length )
110             throws ConnectionException, AuthenticationException
111         {
112             super( new FileWagon(), resource, TransferEvent.TRANSFER_INITIATED, TransferEvent.REQUEST_GET );
113             getResource().setContentLength( length );
114             Repository repository = new Repository();
115             getWagon().connect( repository );
116         }
117 
118         public TransferEventMock( Exception exception )
119             throws ConnectionException, AuthenticationException
120         {
121             super( new FileWagon(), new Resource(), exception, TransferEvent.REQUEST_GET );
122             getResource().setContentLength( 100000 );
123             getResource().setName( "foo.bar" );
124             Repository repository = new Repository();
125             getWagon().connect( repository );
126         }
127     }
128 }