Search in sources :

Example 1 with EzySimpleUser

use of com.tvd12.ezyfoxserver.client.entity.EzySimpleUser in project ezyfox-server by youngmonkeys.

the class EzySimpleServerContextTest method test.

@Test
public void test() {
    EzySimpleServerContext ctx = context;
    EzySimpleAppContext appContext = new EzySimpleAppContext();
    EzySimpleApplication app = new EzySimpleApplication();
    EzyZoneContext zoneContext = ctx.getZoneContexts().get(0);
    appContext.setParent(zoneContext);
    appContext.setApp(app);
    appContext.init();
    EzySimpleAppSetting appSetting = new EzySimpleAppSetting();
    appSetting.setName("abcxyz");
    ctx.addAppContext(appSetting, appContext);
    assert ctx.getAppContext(appSetting.getId()) != null;
    context.setProperty("test.1", "abc");
    assert context.getProperty("test.1") != null;
    assert appContext.getProperty("test.1") == null;
    appContext.setProperty("test.2", "abc");
    assert context.getProperty("test.2") == null;
    assert appContext.getProperty("test.2") != null;
    EzySimplePluginSetting pluginSetting = new EzySimplePluginSetting();
    pluginSetting.setName("plugin.1");
    EzySimplePluginContext pluginContext = new EzySimplePluginContext();
    EzySimplePlugin plugin = new EzySimplePlugin();
    pluginContext.setParent(zoneContext);
    pluginContext.setPlugin(plugin);
    pluginContext.init();
    ctx.addPluginContext(pluginSetting, pluginContext);
    assert ctx.getPluginContext(pluginSetting.getId()) != null;
    context.setProperty("test.1", "abc");
    assert context.getProperty("test.1") != null;
    assert pluginContext.getProperty("test.1") == null;
    pluginContext.setProperty("test.2", "abc");
    assert context.getProperty("test.2") == null;
    assert pluginContext.getProperty("test.2") != null;
    assert context.get(EzyBroadcastEvent.class) != null;
    context.addCommand(ExCommand.class, ExCommand::new);
    assert context.cmd(ExCommand.class) != null;
    try {
        context.cmd(Void.class);
    } catch (Exception e) {
        assert e instanceof IllegalArgumentException;
    }
    EzyServerReadyEvent serverReadyEvent = new EzySimpleServerReadyEvent();
    context.broadcast(EzyEventType.SERVER_READY, serverReadyEvent, true);
    EzySimpleServer server = (EzySimpleServer) context.getServer();
    server.setResponseApi(mock(EzyResponseApi.class));
    server.setStreamingApi(mock(EzyStreamingApi.class));
    EzyResponse response = mock(EzyResponse.class);
    EzySession recipient = spy(EzyAbstractSession.class);
    context.send(response, recipient, false);
    context.stream(new byte[0], recipient);
    context.stream(new byte[0], Lists.newArrayList(recipient));
    EzySimpleUser user = new EzySimpleUser();
    user.setName("test");
    user.addSession(recipient);
    context.send(response, user, false);
    assert context.getZoneContext(zoneContext.getZone().getSetting().getId()) != null;
    try {
        context.getZoneContext(-1);
    } catch (Exception e) {
        assert e instanceof EzyZoneNotFoundException;
    }
    try {
        context.getZoneContext("not found");
    } catch (Exception e) {
        assert e instanceof EzyZoneNotFoundException;
    }
    context.destroy();
}
Also used : EzySimpleAppSetting(com.tvd12.ezyfoxserver.setting.EzySimpleAppSetting) EzyZoneContext(com.tvd12.ezyfoxserver.context.EzyZoneContext) EzySimpleServer(com.tvd12.ezyfoxserver.EzySimpleServer) EzySimpleServerContext(com.tvd12.ezyfoxserver.context.EzySimpleServerContext) EzySimplePlugin(com.tvd12.ezyfoxserver.EzySimplePlugin) EzyStreamingApi(com.tvd12.ezyfoxserver.api.EzyStreamingApi) EzyResponse(com.tvd12.ezyfoxserver.response.EzyResponse) EzyServerReadyEvent(com.tvd12.ezyfoxserver.event.EzyServerReadyEvent) EzyResponseApi(com.tvd12.ezyfoxserver.api.EzyResponseApi) EzySession(com.tvd12.ezyfoxserver.entity.EzySession) EzyZoneNotFoundException(com.tvd12.ezyfoxserver.exception.EzyZoneNotFoundException) EzyBroadcastEvent(com.tvd12.ezyfoxserver.command.EzyBroadcastEvent) EzySimpleApplication(com.tvd12.ezyfoxserver.EzySimpleApplication) EzySimpleUser(com.tvd12.ezyfoxserver.entity.EzySimpleUser) EzyZoneNotFoundException(com.tvd12.ezyfoxserver.exception.EzyZoneNotFoundException) EzySimplePluginContext(com.tvd12.ezyfoxserver.context.EzySimplePluginContext) EzySimpleServerReadyEvent(com.tvd12.ezyfoxserver.event.EzySimpleServerReadyEvent) EzySimpleAppContext(com.tvd12.ezyfoxserver.context.EzySimpleAppContext) EzySimplePluginSetting(com.tvd12.ezyfoxserver.setting.EzySimplePluginSetting) BaseCoreTest(com.tvd12.ezyfoxserver.testing.BaseCoreTest) Test(org.testng.annotations.Test)

Example 2 with EzySimpleUser

use of com.tvd12.ezyfoxserver.client.entity.EzySimpleUser in project ezyfox-server by youngmonkeys.

the class EzyDisconnectUserImplTest method test1.

@Test
public void test1() {
    EzySession session = newSession();
    EzySimpleUser user = newUser();
    session.setToken("abc");
    user.setName("abc");
    user.addSession(session);
}
Also used : EzySimpleUser(com.tvd12.ezyfoxserver.entity.EzySimpleUser) EzySession(com.tvd12.ezyfoxserver.entity.EzySession) BaseCoreTest(com.tvd12.ezyfoxserver.testing.BaseCoreTest) Test(org.testng.annotations.Test)

Example 3 with EzySimpleUser

use of com.tvd12.ezyfoxserver.client.entity.EzySimpleUser in project ezyfox-server by youngmonkeys.

the class EzyDisconnectUserImplTest method test.

@Test
public void test() {
    // given
    String token = RandomUtil.randomShortAlphabetString();
    EzySession session = newSession();
    session.setToken(token);
    String username = RandomUtil.randomShortAlphabetString();
    EzySimpleUser user = newUser();
    user.setName(username);
    user.addSession(session);
    // when
    EzySimpleSocketDisconnection disconnection = new EzySimpleSocketDisconnection(session, EzyDisconnectReason.ADMIN_BAN);
    // when
    Asserts.assertEquals(user.getName(), username);
    Asserts.assertEquals(user.getSession(), session);
    Asserts.assertEquals(session.getToken(), token);
    Asserts.assertEquals(disconnection.getSession(), session);
    Asserts.assertEquals(disconnection.getDisconnectReason(), EzyDisconnectReason.ADMIN_BAN);
}
Also used : EzySimpleUser(com.tvd12.ezyfoxserver.entity.EzySimpleUser) EzySimpleSocketDisconnection(com.tvd12.ezyfoxserver.socket.EzySimpleSocketDisconnection) EzySession(com.tvd12.ezyfoxserver.entity.EzySession) BaseCoreTest(com.tvd12.ezyfoxserver.testing.BaseCoreTest) Test(org.testng.annotations.Test)

Example 4 with EzySimpleUser

use of com.tvd12.ezyfoxserver.client.entity.EzySimpleUser in project ezyfox-server by youngmonkeys.

the class EzyBroadcastAppsEventImplTest method newAppContext.

private EzyAppContext newAppContext(String appName, EzyEvent event2) {
    EzyAppContext appContext = mock(EzyAppContext.class);
    EzyApplication app = mock(EzyApplication.class);
    when(appContext.getApp()).thenReturn(app);
    EzySimpleAppSetting setting = new EzySimpleAppSetting();
    setting.setName(appName);
    when(app.getSetting()).thenReturn(setting);
    EzyAppUserManager appUserManager = EzyAppUserManagerImpl.builder().appName(appName).maxUsers(99).build();
    when(app.getUserManager()).thenReturn(appUserManager);
    EzySimpleUser user = new EzySimpleUser();
    user.setName("user" + appName);
    appUserManager.addUser(user);
    doThrow(new IllegalStateException()).when(appContext).handleEvent(EzyEventType.SERVER_INITIALIZING, event2);
    return appContext;
}
Also used : EzySimpleAppSetting(com.tvd12.ezyfoxserver.setting.EzySimpleAppSetting) EzyApplication(com.tvd12.ezyfoxserver.EzyApplication) EzySimpleUser(com.tvd12.ezyfoxserver.entity.EzySimpleUser) EzyAppUserManager(com.tvd12.ezyfoxserver.wrapper.EzyAppUserManager) EzyAppContext(com.tvd12.ezyfoxserver.context.EzyAppContext)

Example 5 with EzySimpleUser

use of com.tvd12.ezyfoxserver.client.entity.EzySimpleUser 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)

Aggregations

EzySimpleUser (com.tvd12.ezyfoxserver.entity.EzySimpleUser)39 Test (org.testng.annotations.Test)29 EzyZoneContext (com.tvd12.ezyfoxserver.context.EzyZoneContext)17 EzyAbstractSession (com.tvd12.ezyfoxserver.entity.EzyAbstractSession)17 BaseTest (com.tvd12.test.base.BaseTest)13 EzyArray (com.tvd12.ezyfox.entity.EzyArray)11 EzyServerContext (com.tvd12.ezyfoxserver.context.EzyServerContext)10 EzyAppContext (com.tvd12.ezyfoxserver.context.EzyAppContext)9 EzyApplication (com.tvd12.ezyfoxserver.EzyApplication)6 EzySimpleApplication (com.tvd12.ezyfoxserver.EzySimpleApplication)6 EzySimplePlugin (com.tvd12.ezyfoxserver.EzySimplePlugin)6 EzySimpleAppSetting (com.tvd12.ezyfoxserver.setting.EzySimpleAppSetting)6 EzyZone (com.tvd12.ezyfoxserver.EzyZone)5 EzySession (com.tvd12.ezyfoxserver.entity.EzySession)5 BaseCoreTest (com.tvd12.ezyfoxserver.testing.BaseCoreTest)5 EzyAppUserManager (com.tvd12.ezyfoxserver.wrapper.EzyAppUserManager)5 EzyUser (com.tvd12.ezyfoxserver.entity.EzyUser)4 EzyPluginRequestController (com.tvd12.ezyfoxserver.plugin.EzyPluginRequestController)4 EzyZoneUserManager (com.tvd12.ezyfoxserver.wrapper.EzyZoneUserManager)4 EzyServer (com.tvd12.ezyfoxserver.EzyServer)3