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);
}
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();
}
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();
}
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();
}
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);
}
}
Aggregations