use of com.tvd12.ezyfoxserver.setting.EzySimpleAppSetting in project ezyfox-server by youngmonkeys.
the class EzyAccessAppControllerTest method accessAppFailedDueToMaxUser.
@Test
public void accessAppFailedDueToMaxUser() {
// 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().maxUsers(1).appName("test").userDelegate(userDelegate).build();
when(app.getUserManager()).thenReturn(appUserManager);
when(zoneContext.getAppContext("test")).thenReturn(appContext);
EzySimpleAccessAppRequest request1 = newRequest(1);
EzySimpleAccessAppRequest request2 = newRequest(2);
EzyAccessAppController underTest = new EzyAccessAppController();
// when
underTest.handle(serverContext, request1);
Throwable e = Asserts.assertThrows(() -> underTest.handle(serverContext, request2));
// then
Asserts.assertEqualsType(e, EzyAccessAppException.class);
Asserts.assertEqualsType(e.getCause(), EzyMaxUserException.class);
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(2)).getZoneContext(1);
verify(zoneContext, times(2)).getAppContext("test");
verify(appContext, times(2)).getApp();
verify(app, times(2)).getSetting();
verify(app, times(2)).getUserManager();
// 1 for success, 1 for failure
verify(serverContext, times(2)).send(any(EzyResponse.class), any(EzySession.class), any(boolean.class));
}
use of com.tvd12.ezyfoxserver.setting.EzySimpleAppSetting in project ezyfox-server by youngmonkeys.
the class EzyAccessAppControllerTest method accessAppFailedDueToMaxUserAfterAccess.
@Test
public void accessAppFailedDueToMaxUserAfterAccess() {
// 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 = mock(EzyAppUserManager.class);
when(appUserManager.getMaxUsers()).thenReturn(1);
when(app.getUserManager()).thenReturn(appUserManager);
when(zoneContext.getAppContext("test")).thenReturn(appContext);
EzySimpleAccessAppRequest request = newRequest(1);
EzyUser user = request.getUser();
when(appUserManager.getLock(user.getName())).thenReturn(new ReentrantLock());
doThrow(new EzyMaxUserException(1, 1)).when(appUserManager).addUser(user);
EzyAccessAppController underTest = new EzyAccessAppController();
// when
Throwable e = Asserts.assertThrows(() -> underTest.handle(serverContext, request));
// then
Asserts.assertEqualsType(e, EzyAccessAppException.class);
Asserts.assertEqualsType(e.getCause(), EzyMaxUserException.class);
verify(appUserManager, times(1)).containsUser(user);
verify(appUserManager, times(1)).getUserCount();
verify(appUserManager, times(1)).getMaxUsers();
verify(appUserManager, times(1)).getAppName();
verify(appUserManager, times(1)).getLock(user.getName());
verify(appUserManager, times(1)).removeLock(user.getName());
verify(appUserManager, times(1)).addUser(user);
verify(appContext, times(1)).handleEvent(eq(EzyEventType.USER_ACCESS_APP), any(EzySimpleUserAccessAppEvent.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();
// 1 for success, 1 for failure
verify(serverContext, times(1)).send(any(EzyResponse.class), any(EzySession.class), any(boolean.class));
}
use of com.tvd12.ezyfoxserver.setting.EzySimpleAppSetting in project ezyfox-server by youngmonkeys.
the class EzyRequestAppControllerTest method newServerContext.
@Override
protected EzyServerContext newServerContext() {
session = newSession();
session.setToken("abc");
user = new MyTestUser();
user.setName("dungtv");
user.addSession(session);
EzyAppContext appContext = mock(EzyAppContext.class);
EzySimpleApplication app = new EzySimpleApplication();
app.setSetting(new EzySimpleAppSetting());
app.setUserManager(EzyAppUserManagerImpl.builder().build());
app.getUserManager().addUser(user);
when(appContext.getApp()).thenReturn(app);
EzyServerContext serverContext = mock(EzyServerContext.class);
when(serverContext.getAppContext(1)).thenReturn(appContext);
return serverContext;
}
use of com.tvd12.ezyfoxserver.setting.EzySimpleAppSetting in project ezyfox-server by youngmonkeys.
the class EzySimpleAppSettingTest method getParentFolderWithEntries.
@Test
public void getParentFolderWithEntries() {
// given
EzySimpleAppSetting sut = new EzySimpleAppSetting();
sut.setName("test");
sut.setFolder("test");
sut.setHomePath("test-data");
sut.setConfigFile("config.properties");
// when
String configFile = sut.getConfigFile();
// then
Asserts.assertEquals("test-data/apps/entries/test/config.properties", configFile);
}
use of com.tvd12.ezyfoxserver.setting.EzySimpleAppSetting in project ezyfox-server by youngmonkeys.
the class EzySimpleAppSettingTest method getParentFolderNoEntries.
@Test
public void getParentFolderNoEntries() {
// given
EzySimpleAppSetting sut = new EzySimpleAppSetting();
sut.setName("test");
sut.setFolder("test");
sut.setHomePath("test-data1");
sut.setConfigFile("config.properties");
// when
String configFile = sut.getConfigFile();
// then
Asserts.assertEquals("test-data1/apps/test/config.properties", configFile);
}
Aggregations