Search in sources :

Example 16 with EzyAppUserManager

use of com.tvd12.ezyfoxserver.wrapper.EzyAppUserManager in project ezyfox-server by youngmonkeys.

the class EzyUserRequestAppSingletonControllerTest method test.

@Test
public void test() throws Exception {
    EzyRequestHandlerImplementer.setDebug(true);
    EzyExceptionHandlerImplementer.setDebug(true);
    EzySimpleSettings settings = new EzySimpleSettings();
    EzySimpleServer server = new EzySimpleServer();
    server.setSettings(settings);
    EzySimpleServerContext serverContext = new EzySimpleServerContext();
    serverContext.setServer(server);
    serverContext.init();
    EzySimpleZoneSetting zoneSetting = new EzySimpleZoneSetting();
    EzySimpleZone zone = new EzySimpleZone();
    zone.setSetting(zoneSetting);
    EzySimpleZoneContext zoneContext = new EzySimpleZoneContext();
    zoneContext.setZone(zone);
    zoneContext.init();
    zoneContext.setParent(serverContext);
    EzySimpleAppSetting appSetting = new EzySimpleAppSetting();
    appSetting.setName("test");
    EzyAppUserManager appUserManager = EzyAppUserManagerImpl.builder().build();
    EzyEventControllersSetting eventControllersSetting = new EzySimpleEventControllersSetting();
    EzyEventControllers eventControllers = EzyEventControllersImpl.create(eventControllersSetting);
    EzySimpleApplication application = new EzySimpleApplication();
    application.setSetting(appSetting);
    application.setUserManager(appUserManager);
    application.setEventControllers(eventControllers);
    ScheduledExecutorService appScheduledExecutorService = new EzyErrorScheduledExecutorService("not implement");
    EzySimpleAppContext appContext = new EzySimpleAppContext();
    appContext.setApp(application);
    appContext.setParent(zoneContext);
    appContext.setExecutorService(appScheduledExecutorService);
    appContext.init();
    EzySimpleAppEntry entry = new EzyAppEntryEx();
    entry.config(appContext);
    entry.start();
    handleClientRequest(appContext);
    EzyBeanContext beanContext = appContext.get(EzyBeanContext.class);
    EzyRequestCommandManager requestCommandManager = beanContext.getSingleton(EzyRequestCommandManager.class);
    EzyFeatureCommandManager featureCommandManager = beanContext.getSingleton(EzyFeatureCommandManager.class);
    Asserts.assertTrue(requestCommandManager.containsCommand("v1.2.2/hello"));
    Asserts.assertTrue(requestCommandManager.containsCommand("v122/listener/hello"));
    Asserts.assertTrue(requestCommandManager.isManagementCommand("v1.2.2/hello"));
    Asserts.assertTrue(requestCommandManager.isPaymentCommand("v1.2.2/hello"));
    Asserts.assertEquals(featureCommandManager.getFeatureByCommand("v1.2.2/hello"), "hello.world");
    entry.destroy();
}
Also used : EzyErrorScheduledExecutorService(com.tvd12.ezyfox.concurrent.EzyErrorScheduledExecutorService) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) EzyErrorScheduledExecutorService(com.tvd12.ezyfox.concurrent.EzyErrorScheduledExecutorService) EzySimpleServer(com.tvd12.ezyfoxserver.EzySimpleServer) EzyBeanContext(com.tvd12.ezyfox.bean.EzyBeanContext) EzySimpleServerContext(com.tvd12.ezyfoxserver.context.EzySimpleServerContext) EzySimpleZoneContext(com.tvd12.ezyfoxserver.context.EzySimpleZoneContext) EzyFeatureCommandManager(com.tvd12.ezyfoxserver.support.manager.EzyFeatureCommandManager) EzyRequestCommandManager(com.tvd12.ezyfoxserver.support.manager.EzyRequestCommandManager) EzySimpleZone(com.tvd12.ezyfoxserver.EzySimpleZone) EzySimpleApplication(com.tvd12.ezyfoxserver.EzySimpleApplication) EzyEventControllers(com.tvd12.ezyfoxserver.wrapper.EzyEventControllers) EzyAppUserManager(com.tvd12.ezyfoxserver.wrapper.EzyAppUserManager) EzySimpleAppContext(com.tvd12.ezyfoxserver.context.EzySimpleAppContext) EzySimpleAppEntry(com.tvd12.ezyfoxserver.support.entry.EzySimpleAppEntry) Test(org.testng.annotations.Test) BaseTest(com.tvd12.test.base.BaseTest)

Example 17 with EzyAppUserManager

use of com.tvd12.ezyfoxserver.wrapper.EzyAppUserManager in project ezyfox-server by youngmonkeys.

the class EzyDefaultAppEntryTest method test.

@Test
public void test() throws Exception {
    EzySimpleSettings settings = new EzySimpleSettings();
    EzySimpleServer server = new EzySimpleServer();
    server.setSettings(settings);
    EzySimpleServerContext serverContext = new EzySimpleServerContext();
    serverContext.setServer(server);
    serverContext.init();
    EzySimpleZoneSetting zoneSetting = new EzySimpleZoneSetting();
    EzySimpleZone zone = new EzySimpleZone();
    zone.setSetting(zoneSetting);
    EzySimpleZoneContext zoneContext = new EzySimpleZoneContext();
    zoneContext.setZone(zone);
    zoneContext.init();
    zoneContext.setParent(serverContext);
    EzySimpleAppSetting appSetting = new EzySimpleAppSetting();
    appSetting.setName("test");
    appSetting.setActiveProfiles("hello,world");
    appSetting.setPackageName("x.z.y");
    EzyAppUserManager appUserManager = EzyAppUserManagerImpl.builder().build();
    EzyEventControllersSetting eventControllersSetting = new EzySimpleEventControllersSetting();
    EzyEventControllers eventControllers = EzyEventControllersImpl.create(eventControllersSetting);
    EzySimpleApplication application = new EzySimpleApplication();
    application.setSetting(appSetting);
    application.setUserManager(appUserManager);
    application.setEventControllers(eventControllers);
    ScheduledExecutorService appScheduledExecutorService = new EzyErrorScheduledExecutorService("not implement");
    EzySimpleAppContext appContext = new EzySimpleAppContext();
    appContext.setApp(application);
    appContext.setParent(zoneContext);
    appContext.setExecutorService(appScheduledExecutorService);
    appContext.init();
    EzySimpleAppEntry entry = new EzyAppEntryEx();
    entry.config(appContext);
    entry.start();
    handleClientRequest(appContext);
    entry.destroy();
}
Also used : EzyErrorScheduledExecutorService(com.tvd12.ezyfox.concurrent.EzyErrorScheduledExecutorService) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) EzyErrorScheduledExecutorService(com.tvd12.ezyfox.concurrent.EzyErrorScheduledExecutorService) EzySimpleServer(com.tvd12.ezyfoxserver.EzySimpleServer) EzySimpleServerContext(com.tvd12.ezyfoxserver.context.EzySimpleServerContext) EzySimpleZoneContext(com.tvd12.ezyfoxserver.context.EzySimpleZoneContext) EzySimpleZone(com.tvd12.ezyfoxserver.EzySimpleZone) EzySimpleApplication(com.tvd12.ezyfoxserver.EzySimpleApplication) EzyEventControllers(com.tvd12.ezyfoxserver.wrapper.EzyEventControllers) EzyAppUserManager(com.tvd12.ezyfoxserver.wrapper.EzyAppUserManager) EzySimpleAppContext(com.tvd12.ezyfoxserver.context.EzySimpleAppContext) EzySimpleAppEntry(com.tvd12.ezyfoxserver.support.entry.EzySimpleAppEntry) Test(org.testng.annotations.Test)

Example 18 with EzyAppUserManager

use of com.tvd12.ezyfoxserver.wrapper.EzyAppUserManager in project ezyfox-server by youngmonkeys.

the class EzySimpleAppEntryTest method test.

@SuppressWarnings({ "rawtypes" })
@Test
public void test() throws Exception {
    EzySimpleSettings settings = new EzySimpleSettings();
    EzySimpleServer server = new EzySimpleServer();
    server.setSettings(settings);
    EzySimpleServerContext serverContext = new EzySimpleServerContext();
    serverContext.setServer(server);
    serverContext.init();
    EzySimpleZoneSetting zoneSetting = new EzySimpleZoneSetting();
    EzySimpleZone zone = new EzySimpleZone();
    zone.setSetting(zoneSetting);
    EzySimpleZoneContext zoneContext = new EzySimpleZoneContext();
    zoneContext.setZone(zone);
    zoneContext.init();
    zoneContext.setParent(serverContext);
    EzySimpleAppSetting appSetting = new EzySimpleAppSetting();
    appSetting.setName("test");
    EzyAppUserManager appUserManager = EzyAppUserManagerImpl.builder().build();
    EzyEventControllersSetting eventControllersSetting = new EzySimpleEventControllersSetting();
    EzyEventControllers eventControllers = EzyEventControllersImpl.create(eventControllersSetting);
    EzySimpleApplication application = new EzySimpleApplication();
    application.setSetting(appSetting);
    application.setUserManager(appUserManager);
    application.setEventControllers(eventControllers);
    ScheduledExecutorService appScheduledExecutorService = new EzyErrorScheduledExecutorService("not implement");
    EzySimpleAppContext appContext = new EzySimpleAppContext();
    appContext.setApp(application);
    appContext.setParent(zoneContext);
    appContext.setExecutorService(appScheduledExecutorService);
    appContext.init();
    EzySimpleAppEntry entry = new EzyAppEntryEx();
    entry.config(appContext);
    entry.start();
    handleClientRequest(appContext);
    List<EzyEventController> serverReadyHandlers = appContext.getApp().getEventControllers().getControllers(EzyEventType.SERVER_READY);
    Assert.assertEquals(serverReadyHandlers.size(), 2);
    Assert.assertEquals(serverReadyHandlers.get(0).getClass(), ServerReadyEventHandler2.class);
    Assert.assertEquals(serverReadyHandlers.get(1).getClass(), ServerReadyEventHandler.class);
    List<EzyEventController> loginEventHandlers = appContext.getApp().getEventControllers().getControllers(EzyEventType.USER_LOGIN);
    Assert.assertEquals(loginEventHandlers.size(), 1);
    Assert.assertEquals(loginEventHandlers.get(0).getClass(), AppUserLoginRequestController.class);
    entry.destroy();
}
Also used : EzyErrorScheduledExecutorService(com.tvd12.ezyfox.concurrent.EzyErrorScheduledExecutorService) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) EzyErrorScheduledExecutorService(com.tvd12.ezyfox.concurrent.EzyErrorScheduledExecutorService) EzySimpleServer(com.tvd12.ezyfoxserver.EzySimpleServer) EzySimpleServerContext(com.tvd12.ezyfoxserver.context.EzySimpleServerContext) EzySimpleZoneContext(com.tvd12.ezyfoxserver.context.EzySimpleZoneContext) EzySimpleZone(com.tvd12.ezyfoxserver.EzySimpleZone) EzySimpleApplication(com.tvd12.ezyfoxserver.EzySimpleApplication) EzyEventControllers(com.tvd12.ezyfoxserver.wrapper.EzyEventControllers) EzyAppUserManager(com.tvd12.ezyfoxserver.wrapper.EzyAppUserManager) EzySimpleAppContext(com.tvd12.ezyfoxserver.context.EzySimpleAppContext) EzyEventController(com.tvd12.ezyfoxserver.controller.EzyEventController) EzySimpleAppEntry(com.tvd12.ezyfoxserver.support.entry.EzySimpleAppEntry) Test(org.testng.annotations.Test)

Example 19 with EzyAppUserManager

use of com.tvd12.ezyfoxserver.wrapper.EzyAppUserManager in project ezyfox-server by youngmonkeys.

the class EzyAppResponseImplTest method test.

@SuppressWarnings("rawtypes")
@Test
public void test() throws Exception {
    EzyAppContext context = mock(EzyAppContext.class);
    EzyApplication application = mock(EzyApplication.class);
    EzyAppUserManager userManager = EzyAppUserManagerImpl.builder().build();
    when(context.getApp()).thenReturn(application);
    when(application.getUserManager()).thenReturn(userManager);
    EzyAppResponse response = new EzyAppResponseImpl(context);
    Field recipients = EzyAbstractResponse.class.getDeclaredField("recipients");
    Field exclusiveRecipients = EzyAbstractResponse.class.getDeclaredField("exclusiveRecipients");
    recipients.setAccessible(true);
    exclusiveRecipients.setAccessible(true);
    assert ((Collection) recipients.get(response)).size() == 0;
    assert ((Collection) exclusiveRecipients.get(response)).size() == 0;
    EzyUser user1 = newUser("user1");
    response.user(user1);
    assert ((Collection) recipients.get(response)).size() == 2;
    assert ((Collection) exclusiveRecipients.get(response)).size() == 0;
    EzyUser user2 = newUser("user2");
    response.user(user2);
    response.user(user2, true);
    assert ((Collection) recipients.get(response)).size() == 4;
    assert ((Collection) exclusiveRecipients.get(response)).size() == 2;
    EzyUser user3 = newUser("user3");
    EzyUser user4 = newUser("user4");
    response.users(user3, user4);
    response.users(new EzyUser[] { user3, null }, true);
    assert ((Collection) recipients.get(response)).size() == 8;
    assert ((Collection) exclusiveRecipients.get(response)).size() == 4;
    EzyUser user5 = newUser("user5");
    EzyUser user6 = newUser("user6");
    response.users(Lists.newArrayList(user5, user6));
    response.users(Lists.newArrayList(user5, null), true);
    assert ((Collection) recipients.get(response)).size() == 12;
    assert ((Collection) exclusiveRecipients.get(response)).size() == 6;
    EzyUser user7 = newUser("user7");
    EzyUser user8 = newUser("user8");
    userManager.addUser(user7);
    userManager.addUser(user8);
    response.username("user7");
    response.username("user7", true);
    assert ((Collection) recipients.get(response)).size() == 14;
    assert ((Collection) exclusiveRecipients.get(response)).size() == 8;
    EzyUser user9 = newUser("user9");
    EzyUser user10 = newUser("user10");
    EzyUser user11 = newUser("user11");
    userManager.addUser(user9);
    userManager.addUser(user10);
    userManager.addUser(user11);
    response.usernames("user9", "user10");
    response.usernames(new String[] { "user11" }, true);
    assert ((Collection) recipients.get(response)).size() == 18;
    assert ((Collection) exclusiveRecipients.get(response)).size() == 10;
    EzyUser user12 = newUser("user12");
    EzyUser user13 = newUser("user13");
    EzyUser user14 = newUser("user14");
    userManager.addUser(user12);
    userManager.addUser(user13);
    userManager.addUser(user14);
    response.usernames(Lists.newArrayList("user12", "user13"));
    response.usernames(Lists.newArrayList("user14"), true);
    assert ((Collection) recipients.get(response)).size() == 22;
    assert ((Collection) exclusiveRecipients.get(response)).size() == 12;
    EzySession session1 = new ExSession();
    response.session(session1);
    assert ((Collection) recipients.get(response)).size() == 23;
    assert ((Collection) exclusiveRecipients.get(response)).size() == 12;
    EzySession session2 = new ExSession();
    EzySession session3 = new ExSession();
    response.sessions(session2, session3);
    response.sessions(new EzySession[] { session3 }, true);
    assert ((Collection) recipients.get(response)).size() == 25;
    assert ((Collection) exclusiveRecipients.get(response)).size() == 13;
    EzySession session4 = new ExSession();
    EzySession session5 = new ExSession();
    response.sessions(Lists.newArrayList(session4, session5));
    response.sessions(Lists.newArrayList(session4, session5), true);
    assert ((Collection) recipients.get(response)).size() == 27;
    assert ((Collection) exclusiveRecipients.get(response)).size() == 15;
}
Also used : EzyApplication(com.tvd12.ezyfoxserver.EzyApplication) Field(java.lang.reflect.Field) EzyUser(com.tvd12.ezyfoxserver.entity.EzyUser) EzyAppUserManager(com.tvd12.ezyfoxserver.wrapper.EzyAppUserManager) EzyAppContext(com.tvd12.ezyfoxserver.context.EzyAppContext) EzyAppResponseImpl(com.tvd12.ezyfoxserver.command.impl.EzyAppResponseImpl) EzyAppResponse(com.tvd12.ezyfoxserver.command.EzyAppResponse) EzySession(com.tvd12.ezyfoxserver.entity.EzySession) Test(org.testng.annotations.Test) BaseTest(com.tvd12.test.base.BaseTest)

Example 20 with EzyAppUserManager

use of com.tvd12.ezyfoxserver.wrapper.EzyAppUserManager in project ezyfox-server by youngmonkeys.

the class EzyAppResponseImplTest method newResponse.

private EzyAppResponse newResponse() {
    EzyAppContext context = mock(EzyAppContext.class);
    EzyApplication application = mock(EzyApplication.class);
    EzyAppUserManager userManager = EzyAppUserManagerImpl.builder().build();
    when(context.getApp()).thenReturn(application);
    when(application.getUserManager()).thenReturn(userManager);
    return new EzyAppResponseImpl(context);
}
Also used : EzyApplication(com.tvd12.ezyfoxserver.EzyApplication) EzyAppUserManager(com.tvd12.ezyfoxserver.wrapper.EzyAppUserManager) EzyAppContext(com.tvd12.ezyfoxserver.context.EzyAppContext) EzyAppResponseImpl(com.tvd12.ezyfoxserver.command.impl.EzyAppResponseImpl)

Aggregations

EzyAppUserManager (com.tvd12.ezyfoxserver.wrapper.EzyAppUserManager)26 EzyApplication (com.tvd12.ezyfoxserver.EzyApplication)19 Test (org.testng.annotations.Test)18 EzyAppContext (com.tvd12.ezyfoxserver.context.EzyAppContext)16 EzyZoneContext (com.tvd12.ezyfoxserver.context.EzyZoneContext)9 BaseTest (com.tvd12.test.base.BaseTest)9 EzyUser (com.tvd12.ezyfoxserver.entity.EzyUser)8 EzySession (com.tvd12.ezyfoxserver.entity.EzySession)7 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)7 EzyServerContext (com.tvd12.ezyfoxserver.context.EzyServerContext)6 EzySimpleAppSetting (com.tvd12.ezyfoxserver.setting.EzySimpleAppSetting)6 EzyEventControllers (com.tvd12.ezyfoxserver.wrapper.EzyEventControllers)6 EzyErrorScheduledExecutorService (com.tvd12.ezyfox.concurrent.EzyErrorScheduledExecutorService)5 EzySimpleApplication (com.tvd12.ezyfoxserver.EzySimpleApplication)5 EzySimpleServer (com.tvd12.ezyfoxserver.EzySimpleServer)5 EzySimpleZone (com.tvd12.ezyfoxserver.EzySimpleZone)5 EzySimpleAppContext (com.tvd12.ezyfoxserver.context.EzySimpleAppContext)5 EzySimpleServerContext (com.tvd12.ezyfoxserver.context.EzySimpleServerContext)5 EzySimpleZoneContext (com.tvd12.ezyfoxserver.context.EzySimpleZoneContext)5 EzySimpleAppUserDelegate (com.tvd12.ezyfoxserver.delegate.EzySimpleAppUserDelegate)5