Search in sources :

Example 6 with TestBlockingSocketUserRemovalQueue

use of com.tvd12.ezyfoxserver.testing.socket.TestBlockingSocketUserRemovalQueue in project ezyfox-server by youngmonkeys.

the class EzySocketUserRemovalHandlerTest method notifyUserRemovedToPluginsExceptionCaseTest.

@Test
public void notifyUserRemovedToPluginsExceptionCaseTest() {
    TestBlockingSocketUserRemovalQueue queue = new TestBlockingSocketUserRemovalQueue();
    EzyAppContext appContext1 = mock(EzyAppContext.class);
    EzyAppUserManager userManager1 = mock(EzyAppUserManager.class);
    when(userManager1.containsUser(any(EzyUser.class))).thenReturn(true);
    EzyApplication app1 = mock(EzyApplication.class);
    when(app1.getUserManager()).thenReturn(userManager1);
    when(appContext1.getApp()).thenReturn(app1);
    doThrow(new RuntimeException()).when(appContext1).handleEvent(any(EzyConstant.class), any(EzyUserEvent.class));
    EzyAppContext appContext2 = mock(EzyAppContext.class);
    EzyAppUserManager userManager2 = mock(EzyAppUserManager.class);
    when(userManager2.containsUser(any(EzyUser.class))).thenReturn(false);
    EzyApplication app2 = mock(EzyApplication.class);
    when(app2.getUserManager()).thenReturn(userManager2);
    when(appContext2.getApp()).thenReturn(app2);
    EzyZoneContext zoneContext = mock(EzyZoneContext.class);
    when(zoneContext.getAppContexts()).thenReturn(Lists.newArrayList(appContext1, appContext2));
    EzyZone zone = mock(EzyZone.class);
    when(zoneContext.getZone()).thenReturn(zone);
    EzyZoneSetting zoneSetting = mock(EzyZoneSetting.class);
    when(zoneSetting.getName()).thenReturn("test");
    when(zone.getSetting()).thenReturn(zoneSetting);
    doThrow(new RuntimeException()).when(zoneContext).broadcastPlugins(any(EzyConstant.class), any(EzyUserEvent.class), anyBoolean());
    EzySimpleUser user = new EzySimpleUser();
    user.setName("test");
    EzySocketUserRemoval item = new EzySimpleSocketUserRemoval(zoneContext, user, EzyUserRemoveReason.EXIT_APP);
    queue.add(item);
    EzySocketUserRemovalHandler handler = new EzySocketUserRemovalHandler(queue);
    handler.handleEvent();
    handler.destroy();
}
Also used : EzyZone(com.tvd12.ezyfoxserver.EzyZone) EzyUser(com.tvd12.ezyfoxserver.entity.EzyUser) EzyZoneContext(com.tvd12.ezyfoxserver.context.EzyZoneContext) EzyZoneSetting(com.tvd12.ezyfoxserver.setting.EzyZoneSetting) EzyAppContext(com.tvd12.ezyfoxserver.context.EzyAppContext) EzyApplication(com.tvd12.ezyfoxserver.EzyApplication) EzySimpleUser(com.tvd12.ezyfoxserver.entity.EzySimpleUser) EzyAppUserManager(com.tvd12.ezyfoxserver.wrapper.EzyAppUserManager) EzyConstant(com.tvd12.ezyfox.constant.EzyConstant) EzyUserEvent(com.tvd12.ezyfoxserver.event.EzyUserEvent) Test(org.testng.annotations.Test)

Aggregations

EzyZoneContext (com.tvd12.ezyfoxserver.context.EzyZoneContext)6 EzySimpleUser (com.tvd12.ezyfoxserver.entity.EzySimpleUser)5 Test (org.testng.annotations.Test)5 EzyApplication (com.tvd12.ezyfoxserver.EzyApplication)3 EzyAppContext (com.tvd12.ezyfoxserver.context.EzyAppContext)3 EzyUser (com.tvd12.ezyfoxserver.entity.EzyUser)3 EzyAppUserManager (com.tvd12.ezyfoxserver.wrapper.EzyAppUserManager)3 EzyServerContext (com.tvd12.ezyfoxserver.context.EzyServerContext)2 EzySimpleUserDelegate (com.tvd12.ezyfoxserver.delegate.EzySimpleUserDelegate)2 TestBlockingSocketUserRemovalQueue (com.tvd12.ezyfoxserver.testing.socket.TestBlockingSocketUserRemovalQueue)2 EzyZoneUserManagerImpl (com.tvd12.ezyfoxserver.wrapper.impl.EzyZoneUserManagerImpl)2 EzyConstant (com.tvd12.ezyfox.constant.EzyConstant)1 EzyZone (com.tvd12.ezyfoxserver.EzyZone)1 EzyAbstractSession (com.tvd12.ezyfoxserver.entity.EzyAbstractSession)1 EzyUserEvent (com.tvd12.ezyfoxserver.event.EzyUserEvent)1 EzySimpleAppSetting (com.tvd12.ezyfoxserver.setting.EzySimpleAppSetting)1 EzyZoneSetting (com.tvd12.ezyfoxserver.setting.EzyZoneSetting)1