001package org.apache.maven.wagon.events; 002 003/* 004 * Licensed to the Apache Software Foundation (ASF) under one 005 * or more contributor license agreements. See the NOTICE file 006 * distributed with this work for additional information 007 * regarding copyright ownership. The ASF licenses this file 008 * to you under the Apache License, Version 2.0 (the 009 * "License"); you may not use this file except in compliance 010 * with the License. You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, 015 * software distributed under the License is distributed on an 016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 017 * KIND, either express or implied. See the License for the 018 * specific language governing permissions and limitations 019 * under the License. 020 */ 021 022import junit.framework.TestCase; 023 024import org.apache.maven.wagon.Wagon; 025 026import static org.easymock.EasyMock.*; 027 028/** 029 * @author <a href="michal.maczka@dimatics.com">Michal Maczka</a> 030 * 031 */ 032public class SessionEventSupportTest 033 extends TestCase 034{ 035 036 private SessionEventSupport eventSupport; 037 038 private Wagon wagon; 039 040 /** 041 * @see junit.framework.TestCase#setUp() 042 */ 043 protected void setUp() 044 throws Exception 045 { 046 super.setUp(); 047 048 eventSupport = new SessionEventSupport(); 049 050 // TODO: actually test it gets called? 051 wagon = createNiceMock( Wagon.class ); 052 } 053 054 public void testSessionListenerRegistration() 055 { 056 SessionListener mock1 = createMock( SessionListener.class ); 057 058 eventSupport.addSessionListener( mock1 ); 059 060 assertTrue( eventSupport.hasSessionListener( mock1 ) ); 061 062 SessionListener mock2 = createMock( SessionListener.class ); 063 064 assertFalse( eventSupport.hasSessionListener( mock2 ) ); 065 066 eventSupport.addSessionListener( mock2 ); 067 068 assertTrue( eventSupport.hasSessionListener( mock1 ) ); 069 070 assertTrue( eventSupport.hasSessionListener( mock2 ) ); 071 072 eventSupport.removeSessionListener( mock2 ); 073 074 assertTrue( eventSupport.hasSessionListener( mock1 ) ); 075 076 assertFalse( eventSupport.hasSessionListener( mock2 ) ); 077 078 eventSupport.removeSessionListener( mock1 ); 079 080 assertFalse( eventSupport.hasSessionListener( mock1 ) ); 081 } 082 083 public void testFireSessionDisconnected() 084 { 085 SessionListener mock1 = createMock( SessionListener.class ); 086 087 eventSupport.addSessionListener( mock1 ); 088 089 SessionListener mock2 = createMock( SessionListener.class ); 090 091 eventSupport.addSessionListener( mock2 ); 092 093 final SessionEvent event = new SessionEvent( wagon, 1 ); 094 095 mock1.sessionDisconnected( event ); 096 mock2.sessionDisconnected( event ); 097 098 replay( mock1, mock2 ); 099 100 eventSupport.fireSessionDisconnected( event ); 101 102 verify( mock1, mock2 ); 103 } 104 105 public void testFireSessionDisconneting() 106 { 107 SessionListener mock1 = createMock( SessionListener.class ); 108 109 eventSupport.addSessionListener( mock1 ); 110 111 SessionListener mock2 = createMock( SessionListener.class ); 112 113 eventSupport.addSessionListener( mock2 ); 114 115 final SessionEvent event = new SessionEvent( wagon, 1 ); 116 117 mock1.sessionDisconnecting( event ); 118 mock2.sessionDisconnecting( event ); 119 120 replay( mock1, mock2 ); 121 122 eventSupport.fireSessionDisconnecting( event ); 123 124 verify( mock1, mock2 ); 125 } 126 127 public void testFireSessionLoggedIn() 128 { 129 SessionListener mock1 = createMock( SessionListener.class ); 130 131 eventSupport.addSessionListener( mock1 ); 132 133 SessionListener mock2 = createMock( SessionListener.class ); 134 135 eventSupport.addSessionListener( mock2 ); 136 137 final SessionEvent event = new SessionEvent( wagon, 1 ); 138 139 mock1.sessionLoggedIn( event ); 140 mock2.sessionLoggedIn( event ); 141 142 replay( mock1, mock2 ); 143 144 eventSupport.fireSessionLoggedIn( event ); 145 146 verify( mock1, mock2 ); 147 } 148 149 public void testFireSessionLoggedOff() 150 { 151 SessionListener mock1 = createMock( SessionListener.class ); 152 153 eventSupport.addSessionListener( mock1 ); 154 155 SessionListener mock2 = createMock( SessionListener.class ); 156 157 eventSupport.addSessionListener( mock2 ); 158 159 final SessionEvent event = new SessionEvent( wagon, 1 ); 160 161 mock1.sessionLoggedOff( event ); 162 mock2.sessionLoggedOff( event ); 163 164 replay( mock1, mock2 ); 165 166 eventSupport.fireSessionLoggedOff( event ); 167 168 verify( mock1, mock2 ); 169 } 170 171 public void testFireSessionOpened() 172 { 173 SessionListener mock1 = createMock( SessionListener.class ); 174 175 eventSupport.addSessionListener( mock1 ); 176 177 SessionListener mock2 = createMock( SessionListener.class ); 178 179 eventSupport.addSessionListener( mock2 ); 180 181 final SessionEvent event = new SessionEvent( wagon, 1 ); 182 183 mock1.sessionOpened( event ); 184 mock2.sessionOpened( event ); 185 186 replay( mock1, mock2 ); 187 188 eventSupport.fireSessionOpened( event ); 189 190 verify( mock1, mock2 ); 191 } 192 193 public void testFireSessionOpenning() 194 { 195 SessionListener mock1 = createMock( SessionListener.class ); 196 197 eventSupport.addSessionListener( mock1 ); 198 199 SessionListener mock2 = createMock( SessionListener.class ); 200 201 eventSupport.addSessionListener( mock2 ); 202 203 final SessionEvent event = new SessionEvent( wagon, 1 ); 204 205 mock1.sessionOpening( event ); 206 mock2.sessionOpening( event ); 207 208 replay( mock1, mock2 ); 209 210 eventSupport.fireSessionOpening( event ); 211 212 verify( mock1, mock2 ); 213 } 214 215 public void testFireSessionRefused() 216 { 217 SessionListener mock1 = createMock( SessionListener.class ); 218 219 eventSupport.addSessionListener( mock1 ); 220 221 SessionListener mock2 = createMock( SessionListener.class ); 222 223 eventSupport.addSessionListener( mock2 ); 224 225 final SessionEvent event = new SessionEvent( wagon, 1 ); 226 227 mock1.sessionConnectionRefused( event ); 228 mock2.sessionConnectionRefused( event ); 229 230 replay( mock1, mock2 ); 231 232 eventSupport.fireSessionConnectionRefused( event ); 233 234 verify( mock1, mock2 ); 235 } 236 237 public void testFireDebug() 238 { 239 SessionListener mock1 = createMock( SessionListener.class ); 240 241 eventSupport.addSessionListener( mock1 ); 242 243 SessionListener mock2 = createMock( SessionListener.class ); 244 245 eventSupport.addSessionListener( mock2 ); 246 247 mock1.debug( "mm" ); 248 mock2.debug( "mm" ); 249 250 replay( mock1, mock2 ); 251 252 eventSupport.fireDebug( "mm" ); 253 254 verify( mock1, mock2 ); 255 } 256 257}