SitePermissionController extends AbstractCommandController { @Override protected ModelAndView handle(HttpServletRequest req, HttpServletResponse resp, Object comm, BindException errors) throws Exception { SitePermissionCommand command = (SitePermissionCommand) comm; if(command.isAction(SitePermissionCommand.ACTION_CANCEL)) { return handleCancel(req, resp, command, errors); } else if(command.isAction(SitePermissionCommand.ACTION_SAVE)) { return handleSave(req, resp, command, errors); } else if(command.isAction(SitePermissionCommand.ACTION_ADD_NOTE) || command.isAction(SitePermissionCommand.ACTION_MODIFY_NOTE) || command.isAction(SitePermissionCommand.ACTION_DELETE_NOTE)) { return handleAnnotation(req, resp, command, errors); } else if(command.isAction(SitePermissionCommand.ACTION_ADD_EXCLUSION)) { return handleAddExclusion(req, resp, command, errors); } else if(command.isAction(SitePermissionCommand.ACTION_DELETE_EXCLUSION)) { return handleDeleteExclusion(req, resp, command, errors); } else { throw new WCTRuntimeException("Unknown ActionCmd"); } } SitePermissionController(); SiteEditorContext getEditorContext(HttpServletRequest req); @Override void initBinder(HttpServletRequest request, ServletRequestDataBinder binder); void setBusinessObjectFactory(BusinessObjectFactory businessObjectFactory); void setSiteController(SiteController siteController); void setAccessStatusList(List<String> accessStatusList);  }
@Test public final void testHandle() { try { HttpServletRequest aReq = new MockHttpServletRequest(); SiteManager siteManager = new MockSiteManagerImpl(testFile); Site site = siteManager.getSite(9000L, true); SiteEditorContext ctx = new SiteEditorContext(site); HttpServletResponse aResp = new MockHttpServletResponse(); SitePermissionCommand aCmd = new SitePermissionCommand(); aCmd.setActionCmd(SitePermissionCommand.ACTION_ADD_NOTE); aCmd.setNote("A note"); Iterator<Permission> it = site.getPermissions().iterator(); assertTrue(it.hasNext()); Permission p = it.next(); List<Annotation> list = createAnnotationList(); assertFalse(checkSortedList(list)); p.setAnnotations(list); ctx.putObject(p); aCmd.setIdentity(p.getIdentity()); aReq.getSession().setAttribute(SiteController.EDITOR_CONTEXT, ctx); BindException aErrors = new BindException(aCmd, aCmd.getActionCmd()); int numAnnotations = p.getAnnotations().size(); ModelAndView mav = testInstance.handle(aReq, aResp, aCmd, aErrors); assertTrue(mav != null); assertTrue(mav.getViewName().equals("site-permissions")); assertTrue(((Permission)mav.getModel().get("permission")).equals(p)); int listSize = p.getAnnotations().size(); assertTrue(listSize > 0); int noteIndex = 0; assertTrue(p.getAnnotations().size() == (numAnnotations+1)); assertTrue(p.getAnnotations().get(noteIndex).getNote().equals("A note")); assertTrue(checkSortedList(p.getAnnotations())); aCmd.setActionCmd(SitePermissionCommand.ACTION_MODIFY_NOTE); aCmd.setNote("A new note"); aCmd.setNoteIndex(noteIndex); aErrors = new BindException(aCmd, aCmd.getActionCmd()); mav = testInstance.handle(aReq, aResp, aCmd, aErrors); assertTrue(mav != null); assertTrue(mav.getViewName().equals("site-permissions")); assertTrue(((Permission)mav.getModel().get("permission")).equals(p)); listSize = p.getAnnotations().size(); assertTrue(listSize > 0); int newNoteIndex = 0; assertTrue(newNoteIndex == noteIndex); assertTrue(p.getAnnotations().size() == (numAnnotations+1)); assertFalse(p.getAnnotations().get(noteIndex).getNote().equals("A note")); assertTrue(p.getAnnotations().get(noteIndex).getNote().equals("A new note")); assertTrue(checkSortedList(p.getAnnotations())); aCmd.setActionCmd(SitePermissionCommand.ACTION_DELETE_NOTE); aCmd.setNoteIndex(noteIndex); aErrors = new BindException(aCmd, aCmd.getActionCmd()); mav = testInstance.handle(aReq, aResp, aCmd, aErrors); assertTrue(mav != null); assertTrue(mav.getViewName().equals("site-permissions")); assertTrue(((Permission)mav.getModel().get("permission")).equals(p)); int newListSize = p.getAnnotations().size(); assertTrue(newListSize == (listSize-1)); assertTrue(p.getAnnotations().size() == numAnnotations); assertTrue(checkSortedList(p.getAnnotations())); } catch(Exception e) { fail(e.getClass().getName()+" - "+e.getMessage()); } }