View Javadoc

1   package org.apache.maven.wagon.events;
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  import org.apache.maven.wagon.ConnectionException;
24  import org.apache.maven.wagon.Wagon;
25  import org.apache.maven.wagon.authentication.AuthenticationException;
26  import org.apache.maven.wagon.repository.Repository;
27  import org.apache.maven.wagon.resource.Resource;
28  import org.easymock.EasyMock;
29  
30  /**
31   * @author <a href="michal.maczka@dimatics.com">Michal Maczka</a>
32   *
33   */
34  public class TransferEventTest
35      extends TestCase
36  {
37      /*
38       * Class to test for void TransferEvent(Wagon, Repository, String, int,
39       * int)
40      */
41      public void testTransferEventProperties()
42          throws ConnectionException, AuthenticationException
43      {
44          final Wagon wagon = EasyMock.createMock( Wagon.class );
45  
46          final Repository repo = new Repository();
47  
48          wagon.connect( repo );
49  
50          final long timestamp = System.currentTimeMillis();
51  
52          final Exception exception = new AuthenticationException( "dummy" );
53  
54          Resource resource = new Resource();
55  
56          resource.setName( "mm" );
57  
58          TransferEvent event = new TransferEvent( wagon, resource, TransferEvent.TRANSFER_COMPLETED,
59                                                   TransferEvent.REQUEST_GET );
60  
61          assertEquals( wagon, event.getWagon() );
62  
63          assertEquals( "mm", event.getResource().getName() );
64  
65          assertEquals( TransferEvent.TRANSFER_COMPLETED, event.getEventType() );
66  
67          assertEquals( TransferEvent.REQUEST_GET, event.getRequestType() );
68  
69          Resource res = new Resource();
70  
71          res.setName( "mm" );
72  
73          event = new TransferEvent( wagon, res, exception, TransferEvent.REQUEST_GET );
74  
75          assertEquals( wagon, event.getWagon() );
76  
77          assertEquals( "mm", event.getResource().getName() );
78  
79          assertEquals( TransferEvent.TRANSFER_ERROR, event.getEventType() );
80  
81          assertEquals( TransferEvent.REQUEST_GET, event.getRequestType() );
82  
83          assertEquals( exception, event.getException() );
84  
85          event.setResource( null );
86  
87          assertEquals( null, event.getResource() );
88  
89          res.setName( "/foo/baa" );
90  
91          event.setResource( res );
92  
93          assertEquals( "/foo/baa", event.getResource().getName() );
94  
95          event.setTimestamp( timestamp );
96  
97          assertEquals( timestamp, event.getTimestamp() );
98  
99          event.setRequestType( TransferEvent.REQUEST_PUT );
100 
101         assertEquals( TransferEvent.REQUEST_PUT, event.getRequestType() );
102 
103         event.setRequestType( TransferEvent.REQUEST_GET );
104 
105         assertEquals( TransferEvent.REQUEST_GET, event.getRequestType() );
106 
107         try
108         {
109             event.setRequestType( -1 );
110 
111             fail( "Exception expected" );
112         }
113         catch ( IllegalArgumentException e )
114         {
115             assertTrue( true );
116         }
117 
118         event.setEventType( TransferEvent.TRANSFER_COMPLETED );
119 
120         assertEquals( TransferEvent.TRANSFER_COMPLETED, event.getEventType() );
121 
122         event.setEventType( TransferEvent.TRANSFER_ERROR );
123 
124         assertEquals( TransferEvent.TRANSFER_ERROR, event.getEventType() );
125 
126         event.setEventType( TransferEvent.TRANSFER_STARTED );
127 
128         assertEquals( TransferEvent.TRANSFER_STARTED, event.getEventType() );
129 
130         event.setEventType( TransferEvent.TRANSFER_PROGRESS );
131 
132         assertEquals( TransferEvent.TRANSFER_PROGRESS, event.getEventType() );
133 
134         try
135         {
136             event.setEventType( -1 );
137 
138             fail( "Exception expected" );
139         }
140         catch ( IllegalArgumentException e )
141         {
142             assertTrue( true );
143         }
144 
145     }
146 
147     public void testConstantValueConflict()
148     {
149         final int[] values = {TransferEvent.TRANSFER_COMPLETED, TransferEvent.TRANSFER_ERROR,
150                               TransferEvent.TRANSFER_STARTED, TransferEvent.TRANSFER_PROGRESS,
151                               TransferEvent.REQUEST_GET, TransferEvent.REQUEST_PUT};
152 
153         for ( int i = 0; i < values.length; i++ )
154         {
155             for ( int j = i + 1; j < values.length; j++ )
156             {
157 
158                 final String msg = "Value confict at [i,j]=[" + i + "," + j + "]";
159 
160                 assertTrue( msg, values[i] != values[j] );
161             }
162         }
163 
164     }
165 
166 }