use of com.tvd12.ezyfoxserver.context.EzyAppContext 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.context.EzyAppContext in project ezyfox-server-example by tvd12.
the class AppEntry method setupBeanContext.
@Override
protected void setupBeanContext(EzyAppContext context, EzyBeanContextBuilder builder) {
EzyAppSetting setting = context.getApp().getSetting();
String appConfigFile = getConfigFile(setting);
builder.addProperties(appConfigFile);
logger.info("hello-word app config file: {}", appConfigFile);
}
use of com.tvd12.ezyfoxserver.context.EzyAppContext in project ezyfox-server-example by tvd12.
the class AppEntry method setupBeanContext.
@Override
protected void setupBeanContext(EzyAppContext context, EzyBeanContextBuilder builder) {
EzyAppSetting setting = context.getApp().getSetting();
String appConfigFile = getConfigFile(setting);
AppConfig appConfig = readAppConfig(appConfigFile);
logger.info("hello-word app config: {}", appConfig);
}
use of com.tvd12.ezyfoxserver.context.EzyAppContext 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);
}
}
use of com.tvd12.ezyfoxserver.context.EzyAppContext in project ezyfox-server by youngmonkeys.
the class EzySimpleAppUserDelegateTest method testExceptionCase.
@Test
public void testExceptionCase() {
EzyZoneContext zoneContext = mock(EzyZoneContext.class);
EzyAppContext appContext = mock(EzyAppContext.class);
EzyApplication app = mock(EzyApplication.class);
when(appContext.getApp()).thenReturn(app);
EzySimpleAppSetting appSetting = new EzySimpleAppSetting();
when(app.getSetting()).thenReturn(appSetting);
when(appContext.getParent()).thenReturn(zoneContext);
doThrow(new IllegalStateException()).when(appContext).handleEvent(any(), any());
EzySimpleAppUserDelegate delegate = new EzySimpleAppUserDelegate();
delegate.setAppContext(appContext);
EzySimpleUser user = new EzySimpleUser();
user.setName("test");
delegate.onUserRemoved(user, EzyUserRemoveReason.EXIT_APP);
}
Aggregations