Search in sources :

Example 1 with SessionManager

use of act.session.SessionManager in project actframework by actframework.

the class ActTestBase method setup.

protected void setup() throws Exception {
    initActMetricPlugin();
    mockApp = mock(App.class);
    Field f = App.class.getDeclaredField("INST");
    f.setAccessible(true);
    f.set(null, mockApp);
    mockSingletonRegistry = mock(SingletonRegistry.class);
    // when(mockApp.singletonRegistry()).thenReturn(mockSingletonRegistry);
    mockJobManager = mock(JobManager.class);
    when(mockApp.jobManager()).thenReturn(mockJobManager);
    mockEventBus = mock(EventBus.class);
    when(mockApp.eventBus()).thenReturn(mockEventBus);
    mockAppConfig = mock(AppConfig.class);
    when(mockAppConfig.possibleControllerClass(argThat(new StartsWith("testapp.controller.")))).thenReturn(true);
    mockActionContext = mock(ActionContext.class);
    when(mockActionContext.app()).thenReturn(mockApp);
    when(mockActionContext.config()).thenReturn(mockAppConfig);
    mockRouter = mock(Router.class);
    when(mockApp.config()).thenReturn(mockAppConfig);
    when(mockApp.router()).thenReturn(mockRouter);
    when(mockApp.router(Matchers.same(""))).thenReturn(mockRouter);
    when(mockApp.getInstance(any(Class.class))).thenAnswer(new Answer<Object>() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            Object[] args = invocation.getArguments();
            Class<?> cls = (Class) args[0];
            if (SessionManager.class == cls) {
                return new SessionManager(mockAppConfig);
            }
            return $.newInstance((Class) args[0]);
        }
    });
    mockReq = mock(H.Request.class);
    mockResp = mock(ActResponse.class);
    when(mockReq.method()).thenReturn(H.Method.GET);
}
Also used : App(act.app.App) AppConfig(act.conf.AppConfig) SessionManager(act.session.SessionManager) Router(act.route.Router) JobManager(act.job.JobManager) EventBus(act.event.EventBus) ActionContext(act.app.ActionContext) StartsWith(org.mockito.internal.matchers.StartsWith) Field(java.lang.reflect.Field) InvocationOnMock(org.mockito.invocation.InvocationOnMock) SingletonRegistry(act.app.SingletonRegistry)

Example 2 with SessionManager

use of act.session.SessionManager in project actframework by actframework.

the class App method initSessionManager.

private void initSessionManager() {
    sessionManager = new SessionManager(config);
    singletonRegistry.register(SessionManager.class, sessionManager);
}
Also used : SessionManager(act.session.SessionManager)

Aggregations

SessionManager (act.session.SessionManager)2 ActionContext (act.app.ActionContext)1 App (act.app.App)1 SingletonRegistry (act.app.SingletonRegistry)1 AppConfig (act.conf.AppConfig)1 EventBus (act.event.EventBus)1 JobManager (act.job.JobManager)1 Router (act.route.Router)1 Field (java.lang.reflect.Field)1 StartsWith (org.mockito.internal.matchers.StartsWith)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1