Search in sources :

Example 1 with JsonStartupRequest

use of org.eclipse.scout.rt.ui.html.json.JsonStartupRequest in project scout.rt by eclipse.

the class JsonTestUtility method createAndInitializeUiSession.

public static IUiSession createAndInitializeUiSession() {
    String clientSessionId = "testClientSession123";
    HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
    HttpServletResponse response = Mockito.mock(HttpServletResponse.class);
    final HttpSession httpSession = Mockito.mock(HttpSession.class);
    final Object sessionMutex = new Object();
    Mockito.when(request.getLocale()).thenReturn(new Locale("de_CH"));
    Mockito.when(request.getHeader("User-Agent")).thenReturn("dummy");
    Mockito.when(request.getSession()).thenReturn(httpSession);
    Mockito.when(request.getSession(false)).thenReturn(httpSession);
    Mockito.when(httpSession.getAttribute(HttpSessionMutex.SESSION_MUTEX_ATTRIBUTE_NAME)).thenReturn(sessionMutex);
    final ISessionStore sessionStore = BEANS.get(HttpSessionHelper.class).getSessionStore(httpSession);
    Mockito.when(httpSession.getAttribute(HttpSessionHelper.SESSION_STORE_ATTRIBUTE_NAME)).thenReturn(sessionStore);
    Mockito.doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocation) {
            ((HttpSessionBindingListener) sessionStore).valueUnbound(null);
            return null;
        }
    }).when(httpSession).invalidate();
    JSONObject jsonReqObj = new JSONObject();
    jsonReqObj.put(JsonStartupRequest.PROP_CLIENT_SESSION_ID, clientSessionId);
    jsonReqObj.put("startup", true);
    JsonStartupRequest jsonStartupRequest = new JsonStartupRequest(new JsonRequest(jsonReqObj));
    IUiSession uiSession = new TestEnvironmentUiSession();
    uiSession.init(request, response, jsonStartupRequest);
    return uiSession;
}
Also used : Locale(java.util.Locale) ISessionStore(org.eclipse.scout.rt.ui.html.ISessionStore) HttpSessionHelper(org.eclipse.scout.rt.ui.html.HttpSessionHelper) HttpSession(javax.servlet.http.HttpSession) HttpServletResponse(javax.servlet.http.HttpServletResponse) JsonRequest(org.eclipse.scout.rt.ui.html.json.JsonRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) JsonStartupRequest(org.eclipse.scout.rt.ui.html.json.JsonStartupRequest) JSONObject(org.json.JSONObject) InvocationOnMock(org.mockito.invocation.InvocationOnMock) IUiSession(org.eclipse.scout.rt.ui.html.IUiSession) IJsonObject(org.eclipse.scout.rt.ui.html.json.IJsonObject) JSONObject(org.json.JSONObject)

Aggregations

Locale (java.util.Locale)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 HttpSession (javax.servlet.http.HttpSession)1 HttpSessionHelper (org.eclipse.scout.rt.ui.html.HttpSessionHelper)1 ISessionStore (org.eclipse.scout.rt.ui.html.ISessionStore)1 IUiSession (org.eclipse.scout.rt.ui.html.IUiSession)1 IJsonObject (org.eclipse.scout.rt.ui.html.json.IJsonObject)1 JsonRequest (org.eclipse.scout.rt.ui.html.json.JsonRequest)1 JsonStartupRequest (org.eclipse.scout.rt.ui.html.json.JsonStartupRequest)1 JSONObject (org.json.JSONObject)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1