Search in sources :

Example 6 with EzySimpleAppUserDelegate

use of com.tvd12.ezyfoxserver.delegate.EzySimpleAppUserDelegate 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));
}
Also used : EzySimpleAppSetting(com.tvd12.ezyfoxserver.setting.EzySimpleAppSetting) EzyZoneContext(com.tvd12.ezyfoxserver.context.EzyZoneContext) EzyServerContext(com.tvd12.ezyfoxserver.context.EzyServerContext) EzySimpleAppUserDelegate(com.tvd12.ezyfoxserver.delegate.EzySimpleAppUserDelegate) EzyAppContext(com.tvd12.ezyfoxserver.context.EzyAppContext) EzySimpleUserAccessedAppEvent(com.tvd12.ezyfoxserver.event.EzySimpleUserAccessedAppEvent) EzyResponse(com.tvd12.ezyfoxserver.response.EzyResponse) EzySession(com.tvd12.ezyfoxserver.entity.EzySession) EzyApplication(com.tvd12.ezyfoxserver.EzyApplication) EzyAccessAppController(com.tvd12.ezyfoxserver.controller.EzyAccessAppController) EzyAppUserManager(com.tvd12.ezyfoxserver.wrapper.EzyAppUserManager) EzySimpleAccessAppRequest(com.tvd12.ezyfoxserver.request.EzySimpleAccessAppRequest) EzySimpleUserAccessAppEvent(com.tvd12.ezyfoxserver.event.EzySimpleUserAccessAppEvent) Test(org.testng.annotations.Test) BaseTest(com.tvd12.test.base.BaseTest)

Example 7 with EzySimpleAppUserDelegate

use of com.tvd12.ezyfoxserver.delegate.EzySimpleAppUserDelegate 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;
}
Also used : EzyEventControllers(com.tvd12.ezyfoxserver.wrapper.EzyEventControllers) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) EzyAppUserManager(com.tvd12.ezyfoxserver.wrapper.EzyAppUserManager) EzySimpleAppUserDelegate(com.tvd12.ezyfoxserver.delegate.EzySimpleAppUserDelegate)

Aggregations

EzySimpleAppUserDelegate (com.tvd12.ezyfoxserver.delegate.EzySimpleAppUserDelegate)7 EzyApplication (com.tvd12.ezyfoxserver.EzyApplication)6 EzyAppContext (com.tvd12.ezyfoxserver.context.EzyAppContext)6 EzyZoneContext (com.tvd12.ezyfoxserver.context.EzyZoneContext)6 EzySimpleAppSetting (com.tvd12.ezyfoxserver.setting.EzySimpleAppSetting)6 BaseTest (com.tvd12.test.base.BaseTest)6 Test (org.testng.annotations.Test)6 EzyAppUserManager (com.tvd12.ezyfoxserver.wrapper.EzyAppUserManager)5 EzyServerContext (com.tvd12.ezyfoxserver.context.EzyServerContext)4 EzyAccessAppController (com.tvd12.ezyfoxserver.controller.EzyAccessAppController)4 EzySession (com.tvd12.ezyfoxserver.entity.EzySession)4 EzySimpleUserAccessAppEvent (com.tvd12.ezyfoxserver.event.EzySimpleUserAccessAppEvent)4 EzySimpleAccessAppRequest (com.tvd12.ezyfoxserver.request.EzySimpleAccessAppRequest)4 EzyResponse (com.tvd12.ezyfoxserver.response.EzyResponse)4 EzySimpleUserAccessedAppEvent (com.tvd12.ezyfoxserver.event.EzySimpleUserAccessedAppEvent)3 EzySimpleUser (com.tvd12.ezyfoxserver.entity.EzySimpleUser)2 EzyUser (com.tvd12.ezyfoxserver.entity.EzyUser)1 EzyMaxUserException (com.tvd12.ezyfoxserver.exception.EzyMaxUserException)1 EzyEventControllers (com.tvd12.ezyfoxserver.wrapper.EzyEventControllers)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1