AbstractFileServlet extends BaseFilteredServlet { protected String getSessionId(final HttpServletRequest request, final SessionProvider sessionProvider) { final HttpSession session = request.getSession(true); final String clientId = getClientId(request); final QueueSession queueSession = sessionProvider.createOrGetSession(session, clientId); return queueSession.getSessionId(); }  @Override void init(final ServletConfig config); static final String DEFAULT_CLIENT_ID; }
@Test public void testGetSessionId() throws Exception { final String clientId = "1"; final String sessionId = "2"; when(request.getSession(eq(true))).thenReturn(httpSession); when(request.getParameter(eq("clientId"))).thenReturn(clientId); when(provider.createOrGetSession(httpSession, clientId)).thenReturn(queueSession); when(queueSession.getSessionId()).thenReturn(sessionId); assertEquals(sessionId, abstractFileServlet().getSessionId(request, provider)); }
@Test public void testGetSessionIdWhenClientIdIsMissing() throws Exception { final String clientId = null; final String sessionId = "InvalidSessionId"; when(request.getSession(eq(true))).thenReturn(httpSession); when(request.getParameter(eq("clientId"))).thenReturn(clientId); when(provider.createOrGetSession(httpSession, "0")).thenReturn(queueSession); when(queueSession.getSessionId()).thenReturn(sessionId); assertEquals(sessionId, abstractFileServlet().getSessionId(request, provider)); }