use of com.tvd12.ezyfoxserver.context.EzyAppContext in project ezyfox-server by youngmonkeys.
the class EzySimpleAppUserDelegateTest method test.
@Test
public void test() {
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);
EzySimpleAppUserDelegate delegate = new EzySimpleAppUserDelegate();
delegate.setAppContext(appContext);
EzySimpleUser user = new EzySimpleUser();
user.setName("test");
delegate.onUserRemoved(user, EzyUserRemoveReason.EXIT_APP);
}
use of com.tvd12.ezyfoxserver.context.EzyAppContext in project ezyfox-server by youngmonkeys.
the class EzyAccessAppControllerTest method accessAppSuccessfullyBut2Times.
@Test
public void accessAppSuccessfullyBut2Times() {
// given
EzyServerContext serverContext = mock(EzyServerContext.class);
EzyZoneContext zoneContext = mock(EzyZoneContext.class);
when(serverContext.getZoneContext(1)).thenReturn(zoneContext);
EzyAppContext appContext = mock(EzyAppContext.class);
EzyApplication app = mock(EzyApplication.class);
EzySimpleAppSetting appSetting = new EzySimpleAppSetting();
appSetting.setName("test");
when(app.getSetting()).thenReturn(appSetting);
when(appContext.getApp()).thenReturn(app);
EzySimpleAppUserDelegate userDelegate = new EzySimpleAppUserDelegate();
userDelegate.setAppContext(appContext);
EzyAppUserManager appUserManager = EzyAppUserManagerImpl.builder().appName("test").userDelegate(userDelegate).build();
when(app.getUserManager()).thenReturn(appUserManager);
when(zoneContext.getAppContext("test")).thenReturn(appContext);
EzySimpleAccessAppRequest request = newRequest(1);
EzyAccessAppController underTest = new EzyAccessAppController();
// when
underTest.handle(serverContext, request);
underTest.handle(serverContext, request);
// then
verify(appContext, times(2)).handleEvent(eq(EzyEventType.USER_ACCESS_APP), any(EzySimpleUserAccessAppEvent.class));
verify(appContext, times(1)).handleEvent(eq(EzyEventType.USER_ACCESSED_APP), any(EzySimpleUserAccessedAppEvent.class));
verify(serverContext, times(2)).getZoneContext(1);
verify(zoneContext, times(2)).getAppContext("test");
verify(appContext, times(2)).getApp();
verify(app, times(2)).getSetting();
verify(app, times(2)).getUserManager();
verify(serverContext, times(2)).send(any(EzyResponse.class), any(EzySession.class), any(boolean.class));
}
use of com.tvd12.ezyfoxserver.context.EzyAppContext in project ezyfox-server by youngmonkeys.
the class EzyAccessAppControllerTest method accessAppSuccessfully.
@Test
public void accessAppSuccessfully() {
// given
EzyServerContext serverContext = mock(EzyServerContext.class);
EzyZoneContext zoneContext = mock(EzyZoneContext.class);
when(serverContext.getZoneContext(1)).thenReturn(zoneContext);
EzyAppContext appContext = mock(EzyAppContext.class);
EzyApplication app = mock(EzyApplication.class);
EzySimpleAppSetting appSetting = new EzySimpleAppSetting();
appSetting.setName("test");
when(app.getSetting()).thenReturn(appSetting);
when(appContext.getApp()).thenReturn(app);
EzySimpleAppUserDelegate userDelegate = new EzySimpleAppUserDelegate();
userDelegate.setAppContext(appContext);
EzyAppUserManager appUserManager = EzyAppUserManagerImpl.builder().appName("test").userDelegate(userDelegate).build();
when(app.getUserManager()).thenReturn(appUserManager);
when(zoneContext.getAppContext("test")).thenReturn(appContext);
EzySimpleAccessAppRequest request = newRequest(1);
EzyAccessAppController underTest = new EzyAccessAppController();
// when
underTest.handle(serverContext, request);
// then
verify(appContext, times(1)).handleEvent(eq(EzyEventType.USER_ACCESS_APP), any(EzySimpleUserAccessAppEvent.class));
verify(appContext, times(1)).handleEvent(eq(EzyEventType.USER_ACCESSED_APP), any(EzySimpleUserAccessedAppEvent.class));
verify(serverContext, times(1)).getZoneContext(1);
verify(zoneContext, times(1)).getAppContext("test");
verify(appContext, times(1)).getApp();
verify(app, times(1)).getSetting();
verify(app, times(1)).getUserManager();
verify(serverContext, times(1)).send(any(EzyResponse.class), any(EzySession.class), any(boolean.class));
}
use of com.tvd12.ezyfoxserver.context.EzyAppContext in project ezyfox-server by youngmonkeys.
the class EzyExitAppControllerTest method test.
@Test
public void test() {
EzyExitAppController controller = new EzyExitAppController();
EzyServerContext serverContext = mock(EzyServerContext.class);
EzyAppContext appContext = mock(EzyAppContext.class);
EzyApplication app = mock(EzyApplication.class);
when(appContext.getApp()).thenReturn(app);
EzyAppUserManager userManager = mock(EzyAppUserManager.class);
when(app.getUserManager()).thenReturn(userManager);
when(serverContext.getAppContext(1)).thenReturn(appContext);
EzySimpleExitAppRequest request = new EzySimpleExitAppRequest();
request.deserializeParams(EzyEntityFactory.newArrayBuilder().append(1).build());
controller.handle(serverContext, request);
}
use of com.tvd12.ezyfoxserver.context.EzyAppContext in project ezyfox-server by youngmonkeys.
the class EzySimpleServerContextBuilder method newAppContext.
protected EzyAppContext newAppContext(EzyZoneContext parent, EzyAppSetting setting) {
EzySimpleAppUserDelegate userDelegate = new EzySimpleAppUserDelegate();
EzyAppUserManager appUserManager = newAppUserManager(setting, userDelegate);
EzyEventControllers eventControllers = newEventControllers();
EzySimpleApplication app = new EzySimpleApplication();
app.setSetting(setting);
app.setUserManager(appUserManager);
app.setEventControllers(eventControllers);
ScheduledExecutorService appExecutorService = newAppExecutorService(setting);
EzySimpleAppContext appContext = new EzySimpleAppContext();
userDelegate.setAppContext(appContext);
appContext.setApp(app);
appContext.setParent(parent);
appContext.setExecutorService(appExecutorService);
appContext.init();
return appContext;
}
Aggregations