Search in sources :

Example 1 with EzySimpleServerInitializingEvent

use of com.tvd12.ezyfoxserver.event.EzySimpleServerInitializingEvent in project ezyfox-server by youngmonkeys.

the class EzyBroadcastAppsEventImplTest method test.

@Test
public void test() {
    EzyEvent event2 = new EzySimpleServerInitializingEvent();
    EzyZoneContext zoneContext = mock(EzyZoneContext.class);
    List<EzyAppContext> appContexts = Lists.newArrayList(newAppContext("1", event2), newAppContext("2", event2), newAppContext("3", event2));
    when(zoneContext.getAppContexts()).thenReturn(appContexts);
    EzyZone zone = mock(EzyZone.class);
    EzySimpleZoneSetting zoneSetting = new EzySimpleZoneSetting();
    zoneSetting.setName("test");
    when(zone.getSetting()).thenReturn(zoneSetting);
    when(zoneContext.getZone()).thenReturn(zone);
    EzyBroadcastAppsEventImpl cmd = new EzyBroadcastAppsEventImpl(zoneContext);
    EzyEvent event = new EzySimpleServerInitializingEvent();
    cmd.fire(EzyEventType.SERVER_INITIALIZING, event, true);
    cmd.fire(EzyEventType.SERVER_INITIALIZING, event, false);
    EzySimpleUser user = new EzySimpleUser();
    user.setName("user1");
    cmd.fire(EzyEventType.SERVER_INITIALIZING, event, user, true);
    cmd.fire(EzyEventType.SERVER_INITIALIZING, event, "user1", true);
    cmd.fire(EzyEventType.SERVER_INITIALIZING, event2, true);
}
Also used : EzySimpleServerInitializingEvent(com.tvd12.ezyfoxserver.event.EzySimpleServerInitializingEvent) EzyZone(com.tvd12.ezyfoxserver.EzyZone) EzyEvent(com.tvd12.ezyfoxserver.event.EzyEvent) EzySimpleUser(com.tvd12.ezyfoxserver.entity.EzySimpleUser) EzyZoneContext(com.tvd12.ezyfoxserver.context.EzyZoneContext) EzyBroadcastAppsEventImpl(com.tvd12.ezyfoxserver.command.impl.EzyBroadcastAppsEventImpl) EzyAppContext(com.tvd12.ezyfoxserver.context.EzyAppContext) EzySimpleZoneSetting(com.tvd12.ezyfoxserver.setting.EzySimpleZoneSetting) Test(org.testng.annotations.Test) BaseTest(com.tvd12.test.base.BaseTest)

Example 2 with EzySimpleServerInitializingEvent

use of com.tvd12.ezyfoxserver.event.EzySimpleServerInitializingEvent in project ezyfox-server by youngmonkeys.

the class EzyZonesStarter method notifyServerInitializing.

protected void notifyServerInitializing(EzyZoneContext zoneContext) {
    EzyServerInitializingEvent event = new EzySimpleServerInitializingEvent();
    zoneContext.handleEvent(EzyEventType.SERVER_INITIALIZING, event);
}
Also used : EzySimpleServerInitializingEvent(com.tvd12.ezyfoxserver.event.EzySimpleServerInitializingEvent) EzyServerInitializingEvent(com.tvd12.ezyfoxserver.event.EzyServerInitializingEvent)

Example 3 with EzySimpleServerInitializingEvent

use of com.tvd12.ezyfoxserver.event.EzySimpleServerInitializingEvent in project ezyfox-server by youngmonkeys.

the class EzyBootstrap method notifyServerInitializing.

protected void notifyServerInitializing() {
    EzyServerInitializingEvent event = new EzySimpleServerInitializingEvent();
    context.handleEvent(EzyEventType.SERVER_INITIALIZING, event);
}
Also used : EzySimpleServerInitializingEvent(com.tvd12.ezyfoxserver.event.EzySimpleServerInitializingEvent) EzyServerInitializingEvent(com.tvd12.ezyfoxserver.event.EzyServerInitializingEvent)

Example 4 with EzySimpleServerInitializingEvent

use of com.tvd12.ezyfoxserver.event.EzySimpleServerInitializingEvent in project ezyfox-server by youngmonkeys.

the class EzyBroadcastEventImplTest method test.

@Test
public void test() {
    EzyServerContext serverContext = mock(EzyServerContext.class);
    EzyZoneContext zoneContext1 = mock(EzyZoneContext.class);
    EzyZoneContext zoneContext2 = mock(EzyZoneContext.class);
    doThrow(new IllegalStateException()).when(zoneContext2).handleEvent(any(), any());
    when(serverContext.getZoneContexts()).thenReturn(Lists.newArrayList(zoneContext1, zoneContext2));
    EzyBroadcastEventImpl cmd = new EzyBroadcastEventImpl(serverContext);
    EzyServerInitializingEvent event = new EzySimpleServerInitializingEvent();
    cmd.fire(EzyEventType.SERVER_INITIALIZING, event, true);
    try {
        cmd.fire(EzyEventType.SERVER_INITIALIZING, event, false);
    } catch (Exception e) {
        assert e instanceof IllegalStateException;
    }
}
Also used : EzySimpleServerInitializingEvent(com.tvd12.ezyfoxserver.event.EzySimpleServerInitializingEvent) EzyZoneContext(com.tvd12.ezyfoxserver.context.EzyZoneContext) EzyServerContext(com.tvd12.ezyfoxserver.context.EzyServerContext) EzyServerInitializingEvent(com.tvd12.ezyfoxserver.event.EzyServerInitializingEvent) EzyBroadcastEventImpl(com.tvd12.ezyfoxserver.command.impl.EzyBroadcastEventImpl) BaseTest(com.tvd12.test.base.BaseTest) Test(org.testng.annotations.Test)

Example 5 with EzySimpleServerInitializingEvent

use of com.tvd12.ezyfoxserver.event.EzySimpleServerInitializingEvent in project ezyfox-server by youngmonkeys.

the class EzySimpleZoneContextTest method normalCaseTest.

@SuppressWarnings("unchecked")
@Test
public void normalCaseTest() {
    EzyServerContext parent = mock(EzyServerContext.class);
    EzySimpleZoneSetting zoneSetting = new EzySimpleZoneSetting();
    zoneSetting.setName("test");
    EzySimpleZone zone = new EzySimpleZone();
    zone.setUserManager(mock(EzyZoneUserManager.class));
    zone.setSetting(zoneSetting);
    EzySimpleZoneContext context = new EzySimpleZoneContext();
    context.setZone(zone);
    context.setParent(parent);
    context.init();
    assert context.get(EzyBroadcastEvent.class) != null;
    Asserts.assertNull(context.get(Void.class));
    context.addCommand(ExCommand.class, ExCommand::new);
    assert context.cmd(ExCommand.class) != null;
    Asserts.assertNull(context.cmd(Void.class));
    context.broadcast(EzyEventType.SERVER_INITIALIZING, new EzySimpleServerInitializingEvent(), true);
    context.broadcastApps(EzyEventType.SERVER_READY, new EzySimpleServerReadyEvent(), true);
    EzySimpleUser user = new EzySimpleUser();
    user.setName("dungtv");
    EzyUserAccessAppEvent accessAppEvent = new EzySimpleUserAccessAppEvent(user);
    context.broadcastApps(EzyEventType.USER_ACCESS_APP, accessAppEvent, "dungtv", true);
    context.broadcastApps(EzyEventType.USER_ACCESS_APP, accessAppEvent, user, true);
    context.broadcastApps(EzyEventType.USER_ACCESS_APP, accessAppEvent, EzyPredicates.ALWAYS_TRUE, true);
    // noinspection EqualsWithItself
    assert context.equals(context);
    EzyZoneContext zoneContext2 = mock(EzyZoneContext.class);
    EzySimpleZone zone2 = new EzySimpleZone();
    when(zoneContext2.getZone()).thenReturn(zone2);
    assert !zoneContext2.equals(context);
    System.out.println(context.hashCode() + ", " + context.hashCode());
    assert context.hashCode() == context.hashCode();
    EzyResponse response = mock(EzyResponse.class);
    EzySession recipient = spy(EzyAbstractSession.class);
    context.send(response, recipient, false);
    context.send(response, Lists.newArrayList(recipient), false);
    context.stream(new byte[0], recipient);
    context.stream(new byte[0], Lists.newArrayList(recipient));
    context.destroy();
}
Also used : EzySimpleServerInitializingEvent(com.tvd12.ezyfoxserver.event.EzySimpleServerInitializingEvent) EzyZoneContext(com.tvd12.ezyfoxserver.context.EzyZoneContext) EzyServerContext(com.tvd12.ezyfoxserver.context.EzyServerContext) EzySimpleZoneContext(com.tvd12.ezyfoxserver.context.EzySimpleZoneContext) EzyResponse(com.tvd12.ezyfoxserver.response.EzyResponse) EzySession(com.tvd12.ezyfoxserver.entity.EzySession) EzyZoneUserManager(com.tvd12.ezyfoxserver.wrapper.EzyZoneUserManager) EzyBroadcastEvent(com.tvd12.ezyfoxserver.command.EzyBroadcastEvent) EzySimpleZone(com.tvd12.ezyfoxserver.EzySimpleZone) EzySimpleUser(com.tvd12.ezyfoxserver.entity.EzySimpleUser) EzySimpleServerReadyEvent(com.tvd12.ezyfoxserver.event.EzySimpleServerReadyEvent) EzySimpleZoneSetting(com.tvd12.ezyfoxserver.setting.EzySimpleZoneSetting) EzyUserAccessAppEvent(com.tvd12.ezyfoxserver.event.EzyUserAccessAppEvent) EzySimpleUserAccessAppEvent(com.tvd12.ezyfoxserver.event.EzySimpleUserAccessAppEvent) Test(org.testng.annotations.Test) BaseTest(com.tvd12.test.base.BaseTest)

Aggregations

EzySimpleServerInitializingEvent (com.tvd12.ezyfoxserver.event.EzySimpleServerInitializingEvent)5 EzyZoneContext (com.tvd12.ezyfoxserver.context.EzyZoneContext)3 EzyServerInitializingEvent (com.tvd12.ezyfoxserver.event.EzyServerInitializingEvent)3 BaseTest (com.tvd12.test.base.BaseTest)3 Test (org.testng.annotations.Test)3 EzyServerContext (com.tvd12.ezyfoxserver.context.EzyServerContext)2 EzySimpleUser (com.tvd12.ezyfoxserver.entity.EzySimpleUser)2 EzySimpleZoneSetting (com.tvd12.ezyfoxserver.setting.EzySimpleZoneSetting)2 EzySimpleZone (com.tvd12.ezyfoxserver.EzySimpleZone)1 EzyZone (com.tvd12.ezyfoxserver.EzyZone)1 EzyBroadcastEvent (com.tvd12.ezyfoxserver.command.EzyBroadcastEvent)1 EzyBroadcastAppsEventImpl (com.tvd12.ezyfoxserver.command.impl.EzyBroadcastAppsEventImpl)1 EzyBroadcastEventImpl (com.tvd12.ezyfoxserver.command.impl.EzyBroadcastEventImpl)1 EzyAppContext (com.tvd12.ezyfoxserver.context.EzyAppContext)1 EzySimpleZoneContext (com.tvd12.ezyfoxserver.context.EzySimpleZoneContext)1 EzySession (com.tvd12.ezyfoxserver.entity.EzySession)1 EzyEvent (com.tvd12.ezyfoxserver.event.EzyEvent)1 EzySimpleServerReadyEvent (com.tvd12.ezyfoxserver.event.EzySimpleServerReadyEvent)1 EzySimpleUserAccessAppEvent (com.tvd12.ezyfoxserver.event.EzySimpleUserAccessAppEvent)1 EzyUserAccessAppEvent (com.tvd12.ezyfoxserver.event.EzyUserAccessAppEvent)1