Search in sources :

Example 6 with EzyApplication

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

the class EzySimpleAppEntryTest method scanPackages.

@Test
public void scanPackages() {
    // given
    EzyAppContext appContext = mock(EzyAppContext.class);
    ScheduledExecutorService executorService = mock(ScheduledExecutorService.class);
    EzyZoneContext zoneContext = mock(EzyZoneContext.class);
    EzyServerContext serverContext = mock(EzyServerContext.class);
    EzyApplication application = mock(EzyApplication.class);
    EzyAppUserManager appUserManager = mock(EzyAppUserManager.class);
    EzyAppSetup appSetup = mock(EzyAppSetup.class);
    EzyAppSetting appSetting = mock(EzyAppSetting.class);
    when(application.getSetting()).thenReturn(appSetting);
    InternalAppEntry sut = new InternalAppEntry();
    // when
    when(appContext.get(ScheduledExecutorService.class)).thenReturn(executorService);
    when(appContext.getParent()).thenReturn(zoneContext);
    when(zoneContext.getParent()).thenReturn(serverContext);
    when(appContext.getApp()).thenReturn(application);
    when(application.getUserManager()).thenReturn(appUserManager);
    when(appContext.get(EzyAppSetup.class)).thenReturn(appSetup);
    sut.config(appContext);
    // then
    EzyBeanContext beanContext = sut.beanContext;
    MongoConfig mongoConfig = (MongoConfig) beanContext.getBean(MongoConfig.class);
    Set<String> expectedPackages = Sets.newHashSet(EzySupportConstants.DEFAULT_PACKAGE_TO_SCAN, "com.tvd12.ezyfoxserver.support.v120.test.entry");
    Asserts.assertEquals(expectedPackages, mongoConfig.packagesToScan);
    Singleton singleton = (Singleton) beanContext.getBean(Singleton.class);
    Asserts.assertNotNull(singleton);
}
Also used : ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) EzyAppSetup(com.tvd12.ezyfoxserver.command.EzyAppSetup) EzyZoneContext(com.tvd12.ezyfoxserver.context.EzyZoneContext) EzyBeanContext(com.tvd12.ezyfox.bean.EzyBeanContext) EzyServerContext(com.tvd12.ezyfoxserver.context.EzyServerContext) EzyAppContext(com.tvd12.ezyfoxserver.context.EzyAppContext) EzyAppSetting(com.tvd12.ezyfoxserver.setting.EzyAppSetting) EzyApplication(com.tvd12.ezyfoxserver.EzyApplication) EzyAppUserManager(com.tvd12.ezyfoxserver.wrapper.EzyAppUserManager) EzySingleton(com.tvd12.ezyfox.bean.annotation.EzySingleton) Test(org.testng.annotations.Test)

Example 7 with EzyApplication

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

the class EzySocketUserRemovalHandlerTest method test.

@Test
public void test() {
    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);
    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));
    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 : EzyUser(com.tvd12.ezyfoxserver.entity.EzyUser) EzyApplication(com.tvd12.ezyfoxserver.EzyApplication) EzySimpleUser(com.tvd12.ezyfoxserver.entity.EzySimpleUser) EzyZoneContext(com.tvd12.ezyfoxserver.context.EzyZoneContext) EzyAppUserManager(com.tvd12.ezyfoxserver.wrapper.EzyAppUserManager) EzyAppContext(com.tvd12.ezyfoxserver.context.EzyAppContext) Test(org.testng.annotations.Test)

Example 8 with EzyApplication

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

the class EzySocketUserRemovalHandlerTest method removeUserFromAppExceptionCaseTest.

@Test
public void removeUserFromAppExceptionCaseTest() {
    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 IllegalArgumentException()).when(userManager1).removeUser(any(), any());
    EzySimpleAppSetting appSetting1 = new EzySimpleAppSetting();
    appSetting1.setName("app1");
    when(app1.getSetting()).thenReturn(appSetting1);
    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));
    EzySimpleUser user = new EzySimpleUser();
    user.setName("test");
    EzySocketUserRemoval item = new EzySimpleSocketUserRemoval(zoneContext, user, EzyUserRemoveReason.EXIT_APP);
    queue.add(item);
    EzySocketUserRemovalQueue userRemovalQueue = new EzyBlockingSocketUserRemovalQueue();
    new EzySocketUserRemovalHandler(userRemovalQueue);
    EzySocketUserRemovalHandler handler = new EzySocketUserRemovalHandler(queue);
    handler.handleEvent();
    handler.destroy();
}
Also used : EzySimpleAppSetting(com.tvd12.ezyfoxserver.setting.EzySimpleAppSetting) EzyUser(com.tvd12.ezyfoxserver.entity.EzyUser) EzyZoneContext(com.tvd12.ezyfoxserver.context.EzyZoneContext) EzyAppContext(com.tvd12.ezyfoxserver.context.EzyAppContext) EzyApplication(com.tvd12.ezyfoxserver.EzyApplication) EzySimpleUser(com.tvd12.ezyfoxserver.entity.EzySimpleUser) EzyAppUserManager(com.tvd12.ezyfoxserver.wrapper.EzyAppUserManager) Test(org.testng.annotations.Test)

Example 9 with EzyApplication

use of com.tvd12.ezyfoxserver.EzyApplication in project ezyfox-server-example by tvd12.

the class UdpBroadcastMessageHandler method execute.

@Override
protected void execute() throws EzyBadRequestException {
    EzyApplication app = appContext.getApp();
    EzyAppUserManager userManager = app.getUserManager();
    responseFactory.newObjectResponse().udpTransport().command(UDP_BROADCAST_MESSAGE).param("message", message).users(userManager.getUserList()).execute();
}
Also used : EzyApplication(com.tvd12.ezyfoxserver.EzyApplication) EzyAppUserManager(com.tvd12.ezyfoxserver.wrapper.EzyAppUserManager)

Example 10 with EzyApplication

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

the class EzyAppsStarter method startApp.

protected void startApp(String appName) {
    try {
        logger.debug("app: {} loading...", appName);
        EzyAppContext context = zoneContext.getAppContext(appName);
        EzyApplication application = context.getApp();
        EzyAppEntry entry = startApp(appName, newAppEntryLoader(appName));
        ((EzyEntryAware) application).setEntry(entry);
        logger.debug("app: {} loaded", appName);
    } catch (Exception e) {
        logger.error("can not start app: {}", appName, e);
    }
}
Also used : EzyAppEntry(com.tvd12.ezyfoxserver.ext.EzyAppEntry) EzyAppContext(com.tvd12.ezyfoxserver.context.EzyAppContext) EzyEntryAware(com.tvd12.ezyfoxserver.ext.EzyEntryAware)

Aggregations

EzyApplication (com.tvd12.ezyfoxserver.EzyApplication)23 EzyAppContext (com.tvd12.ezyfoxserver.context.EzyAppContext)21 EzyAppUserManager (com.tvd12.ezyfoxserver.wrapper.EzyAppUserManager)19 Test (org.testng.annotations.Test)15 EzyZoneContext (com.tvd12.ezyfoxserver.context.EzyZoneContext)12 BaseTest (com.tvd12.test.base.BaseTest)10 EzyUser (com.tvd12.ezyfoxserver.entity.EzyUser)9 EzySimpleAppSetting (com.tvd12.ezyfoxserver.setting.EzySimpleAppSetting)9 EzySession (com.tvd12.ezyfoxserver.entity.EzySession)8 EzyServerContext (com.tvd12.ezyfoxserver.context.EzyServerContext)7 EzySimpleAppUserDelegate (com.tvd12.ezyfoxserver.delegate.EzySimpleAppUserDelegate)6 EzySimpleUser (com.tvd12.ezyfoxserver.entity.EzySimpleUser)6 EzySimpleUserAccessAppEvent (com.tvd12.ezyfoxserver.event.EzySimpleUserAccessAppEvent)5 EzyResponse (com.tvd12.ezyfoxserver.response.EzyResponse)5 EzyAppResponseImpl (com.tvd12.ezyfoxserver.command.impl.EzyAppResponseImpl)4 EzyAccessAppController (com.tvd12.ezyfoxserver.controller.EzyAccessAppController)4 EzySimpleUserAccessedAppEvent (com.tvd12.ezyfoxserver.event.EzySimpleUserAccessedAppEvent)4 EzySimpleAccessAppRequest (com.tvd12.ezyfoxserver.request.EzySimpleAccessAppRequest)4 EzyAppResponse (com.tvd12.ezyfoxserver.command.EzyAppResponse)2 EzyAppSetting (com.tvd12.ezyfoxserver.setting.EzyAppSetting)2