Search in sources :

Example 11 with EzyApplication

use of com.tvd12.ezyfoxserver.EzyApplication 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);
}
Also used : EzySimpleAppSetting(com.tvd12.ezyfoxserver.setting.EzySimpleAppSetting) EzyApplication(com.tvd12.ezyfoxserver.EzyApplication) EzySimpleUser(com.tvd12.ezyfoxserver.entity.EzySimpleUser) EzyZoneContext(com.tvd12.ezyfoxserver.context.EzyZoneContext) EzySimpleAppUserDelegate(com.tvd12.ezyfoxserver.delegate.EzySimpleAppUserDelegate) EzyAppContext(com.tvd12.ezyfoxserver.context.EzyAppContext) BaseTest(com.tvd12.test.base.BaseTest) Test(org.testng.annotations.Test)

Example 12 with EzyApplication

use of com.tvd12.ezyfoxserver.EzyApplication 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);
}
Also used : EzySimpleAppSetting(com.tvd12.ezyfoxserver.setting.EzySimpleAppSetting) EzyApplication(com.tvd12.ezyfoxserver.EzyApplication) EzySimpleUser(com.tvd12.ezyfoxserver.entity.EzySimpleUser) EzyZoneContext(com.tvd12.ezyfoxserver.context.EzyZoneContext) EzySimpleAppUserDelegate(com.tvd12.ezyfoxserver.delegate.EzySimpleAppUserDelegate) EzyAppContext(com.tvd12.ezyfoxserver.context.EzyAppContext) BaseTest(com.tvd12.test.base.BaseTest) Test(org.testng.annotations.Test)

Example 13 with EzyApplication

use of com.tvd12.ezyfoxserver.EzyApplication 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));
}
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 14 with EzyApplication

use of com.tvd12.ezyfoxserver.EzyApplication 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 15 with EzyApplication

use of com.tvd12.ezyfoxserver.EzyApplication 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);
}
Also used : EzyApplication(com.tvd12.ezyfoxserver.EzyApplication) EzyAppUserManager(com.tvd12.ezyfoxserver.wrapper.EzyAppUserManager) EzyServerContext(com.tvd12.ezyfoxserver.context.EzyServerContext) EzySimpleExitAppRequest(com.tvd12.ezyfoxserver.request.EzySimpleExitAppRequest) EzyAppContext(com.tvd12.ezyfoxserver.context.EzyAppContext) EzyExitAppController(com.tvd12.ezyfoxserver.controller.EzyExitAppController) BaseTest(com.tvd12.test.base.BaseTest) Test(org.testng.annotations.Test)

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