ReleaseUserLocksServlet extends BaseFilteredServlet { @Override protected void doGet(final HttpServletRequest request, final HttpServletResponse response) { final HttpSession session = request.getSession(); if (session != null && session.getAttribute(VFSLockServiceImpl.LOCK_SESSION_ATTRIBUTE_NAME) != null) { final Set<LockInfo> locks = (Set<LockInfo>) session.getAttribute(VFSLockServiceImpl.LOCK_SESSION_ATTRIBUTE_NAME); try { locks.forEach(lockInfo -> vfsLockService.releaseLock(lockInfo.getFile())); locks.clear(); } catch (Exception e) { logger.error("Error when releasing locks.", e); } } }    }
@Test public void releaseUserLocksWhenInvalidSessionTest() { HttpServletRequest request = mock(HttpServletRequest.class); HttpServletResponse response = mock(HttpServletResponse.class); doReturn(null).when(request).getSession(); releaseUserLocksServlet.doGet(request, response); verify(vfsLockService, never()).releaseLock(any(Path.class)); }
@Test public void releaseUserLocksWhenNoLockAttributeTest() { HttpServletRequest request = mock(HttpServletRequest.class); HttpServletResponse response = mock(HttpServletResponse.class); HttpSession session = mock(HttpSession.class); doReturn(session).when(request).getSession(); doReturn(null).when(session).getAttribute(VFSLockServiceImpl.LOCK_SESSION_ATTRIBUTE_NAME); releaseUserLocksServlet.doGet(request, response); verify(vfsLockService, never()).releaseLock(any(Path.class)); }
@Test public void releaseUserLocksSuccessTest() { HttpServletRequest request = mock(HttpServletRequest.class); HttpServletResponse response = mock(HttpServletResponse.class); HttpSession session = mock(HttpSession.class); Set<LockInfo> locks = new HashSet<>(); locks.add(mock(LockInfo.class)); doReturn(session).when(request).getSession(); doReturn(locks).when(session).getAttribute(VFSLockServiceImpl.LOCK_SESSION_ATTRIBUTE_NAME); releaseUserLocksServlet.doGet(request, response); verify(vfsLockService).releaseLock(any(Path.class)); }