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.easymock.EasyMock;
28  
29  /**
30   * @author <a href="michal.maczka@dimatics.com">Michal Maczka</a>
31   *
32   */
33  public class SessionEventTest
34      extends TestCase
35  {
36      /*
37  	 * Class to test for void SESSIONEvent(Wagon, Repository, String, int,
38  	 * int)
39  	 */
40      public void testSessionEventProperties()
41          throws ConnectionException, AuthenticationException
42      {
43  
44          final Wagon wagon = EasyMock.createMock( Wagon.class );
45          final Repository repo = new Repository();
46  
47          wagon.connect( repo );
48  
49          final long timestamp = System.currentTimeMillis();
50          final Exception exception = new AuthenticationException( "dummy" );
51  
52          SessionEvent event = new SessionEvent( wagon, SessionEvent.SESSION_CLOSED );
53  
54          assertEquals( wagon, event.getWagon() );
55  
56          assertEquals( SessionEvent.SESSION_CLOSED, event.getEventType() );
57  
58          event = new SessionEvent( wagon, exception );
59  
60          assertEquals( wagon, event.getWagon() );
61          assertEquals( SessionEvent.SESSION_ERROR_OCCURRED, event.getEventType() );
62          assertEquals( exception, event.getException() );
63  
64          event.setException( null );
65          assertEquals( null, event.getException() );
66  
67          event.setException( exception );
68          assertEquals( exception, event.getException() );
69  
70          event.setTimestamp( timestamp );
71          assertEquals( timestamp, event.getTimestamp() );
72  
73          event.setEventType( SessionEvent.SESSION_CLOSED );
74          assertEquals( SessionEvent.SESSION_CLOSED, event.getEventType() );
75  
76          event.setEventType( SessionEvent.SESSION_DISCONNECTED );
77          assertEquals( SessionEvent.SESSION_DISCONNECTED, event.getEventType() );
78  
79          event.setEventType( SessionEvent.SESSION_DISCONNECTING );
80          assertEquals( SessionEvent.SESSION_DISCONNECTING, event.getEventType() );
81  
82          event.setEventType( SessionEvent.SESSION_ERROR_OCCURRED );
83          assertEquals( SessionEvent.SESSION_ERROR_OCCURRED, event.getEventType() );
84  
85          event.setEventType( SessionEvent.SESSION_LOGGED_IN );
86          assertEquals( SessionEvent.SESSION_LOGGED_IN, event.getEventType() );
87  
88          event.setEventType( SessionEvent.SESSION_LOGGED_OFF );
89          assertEquals( SessionEvent.SESSION_LOGGED_OFF, event.getEventType() );
90  
91          event.setEventType( SessionEvent.SESSION_OPENED );
92          assertEquals( SessionEvent.SESSION_OPENED, event.getEventType() );
93  
94          event.setEventType( SessionEvent.SESSION_OPENING );
95          assertEquals( SessionEvent.SESSION_OPENING, event.getEventType() );
96  
97          event.setEventType( SessionEvent.SESSION_CONNECTION_REFUSED );
98          assertEquals( SessionEvent.SESSION_CONNECTION_REFUSED, event.getEventType() );
99  
100         try
101         {
102             event.setEventType( -1 );
103             fail( "Exception expected" );
104         }
105         catch ( IllegalArgumentException e )
106         {
107             assertTrue( true );
108         }
109 
110     }
111 
112     public void testConstantValueConflict()
113     {
114         final int[] values = {SessionEvent.SESSION_CLOSED, SessionEvent.SESSION_DISCONNECTED,
115                               SessionEvent.SESSION_DISCONNECTING, SessionEvent.SESSION_ERROR_OCCURRED,
116                               SessionEvent.SESSION_LOGGED_IN, SessionEvent.SESSION_LOGGED_OFF,
117                               SessionEvent.SESSION_OPENED, SessionEvent.SESSION_OPENING,
118                               SessionEvent.SESSION_CONNECTION_REFUSED};
119 
120         for ( int i = 0; i < values.length; i++ )
121         {
122             for ( int j = i + 1; j < values.length; j++ )
123             {
124 
125                 final String msg = "Value confict at [i,j]=[" + i + "," + j + "]";
126                 assertTrue( msg, values[i] != values[j] );
127             }
128         }
129 
130     }
131 
132 }