@Test public final void testProcessFormSubmission() { try { MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletResponse response = new MockHttpServletResponse(); this.testSetAgencyUserManager(); this.testSetMessageSource(); this.testSetGroupTypesList(); TargetManager tm = new MockTargetManager(testFile); testInstance.setTargetManager(tm); try { SearchCommand aCommand = testInstance.getDefaultCommand(); aCommand.setActionCmd(SearchCommand.ACTION_DELETE); aCommand.setDeletedGroupOid(15000L); BindException aError = new BindException(aCommand, aCommand.getActionCmd()); ModelAndView mav = testInstance.processFormSubmission(request, response, aCommand, aError); fail("Insufficient Privileges to delete group"); } catch(org.webcurator.core.exceptions.WCTRuntimeException wctre) { assertTrue(wctre.getMessage().equals("You do not have the appropriate privileges to delete this group")); } this.addCurrentUserPrivilege(Privilege.MANAGE_GROUP); try { assertTrue(tm.loadGroup(15000L) != null); SearchCommand aCommand = testInstance.getDefaultCommand(); aCommand.setSelectedPageSize("10"); aCommand.setActionCmd(SearchCommand.ACTION_DELETE); aCommand.setDeletedGroupOid(15000L); BindException aError = new BindException(aCommand, aCommand.getActionCmd()); ModelAndView mav = testInstance.processFormSubmission(request, response, aCommand, aError); assertTrue(mav != null); assertFalse(tm.loadGroup(15000L) != null); } catch(org.webcurator.core.exceptions.WCTRuntimeException wctre) { fail(wctre.getMessage()); } SearchCommand aCommand = testInstance.getDefaultCommand(); aCommand.setSelectedPageSize("10"); aCommand.setActionCmd(SearchCommand.ACTION_RESET); BindException aError = new BindException(aCommand, aCommand.getActionCmd()); ModelAndView mav = testInstance.processFormSubmission(request, response, aCommand, aError); assertTrue(mav != null); SearchCommand command = (SearchCommand)mav.getModel().get("command"); assertTrue(command.getActionCmd().equals("reset")); assertTrue(command.getAgency().equals("")); assertTrue(command.getName().equals("")); assertTrue(command.getOwner().equals("")); assertTrue(command.getGroupType().equals("")); assertTrue(command.getSearchOid() == null); } catch (Exception e) { String message = e.getClass().toString() + " - " + e.getMessage(); log.debug(message); fail(message); } }
@Override protected ModelAndView processFormSubmission(HttpServletRequest request, HttpServletResponse response, Object comm, BindException errors) throws Exception { SearchCommand command = (SearchCommand) comm; if(command.isAction(SearchCommand.ACTION_DELETE)) { TargetGroup group = targetManager.loadGroup(command.getDeletedGroupOid()); if(targetManager.deleteTargetGroup(group)) { ModelAndView mav = prepareSearchView(request, response, command, errors); mav.addObject(Constants.GBL_MESSAGES, messageSource.getMessage("group.deleted.success", new Object[] { group.getName() }, Locale.getDefault())); return mav; } else { ModelAndView mav = prepareSearchView(request, response, command, errors); mav.addObject(Constants.GBL_MESSAGES, messageSource.getMessage("group.deleted.failed.instances", new Object[] { group.getName() }, Locale.getDefault())); return mav; } } else if(command.isAction(SearchCommand.ACTION_RESET)) { command.setPageNumber(0); command.setAgency(""); command.setName(""); command.setOwner(""); command.setMemberOf(""); command.setGroupType(""); command.setSearchOid(null); request.getSession().setAttribute("groupsSearchCommand", command); return prepareSearchView(request, response, command, errors); } else { request.getSession().setAttribute("groupsSearchCommand", command); return prepareSearchView(request, response, command, errors); } }
GroupSearchController extends AbstractFormController { @Override protected ModelAndView processFormSubmission(HttpServletRequest request, HttpServletResponse response, Object comm, BindException errors) throws Exception { SearchCommand command = (SearchCommand) comm; if(command.isAction(SearchCommand.ACTION_DELETE)) { TargetGroup group = targetManager.loadGroup(command.getDeletedGroupOid()); if(targetManager.deleteTargetGroup(group)) { ModelAndView mav = prepareSearchView(request, response, command, errors); mav.addObject(Constants.GBL_MESSAGES, messageSource.getMessage("group.deleted.success", new Object[] { group.getName() }, Locale.getDefault())); return mav; } else { ModelAndView mav = prepareSearchView(request, response, command, errors); mav.addObject(Constants.GBL_MESSAGES, messageSource.getMessage("group.deleted.failed.instances", new Object[] { group.getName() }, Locale.getDefault())); return mav; } } else if(command.isAction(SearchCommand.ACTION_RESET)) { command.setPageNumber(0); command.setAgency(""); command.setName(""); command.setOwner(""); command.setMemberOf(""); command.setGroupType(""); command.setSearchOid(null); request.getSession().setAttribute("groupsSearchCommand", command); return prepareSearchView(request, response, command, errors); } else { request.getSession().setAttribute("groupsSearchCommand", command); return prepareSearchView(request, response, command, errors); } } }
GroupSearchController extends AbstractFormController { @Override protected ModelAndView processFormSubmission(HttpServletRequest request, HttpServletResponse response, Object comm, BindException errors) throws Exception { SearchCommand command = (SearchCommand) comm; if(command.isAction(SearchCommand.ACTION_DELETE)) { TargetGroup group = targetManager.loadGroup(command.getDeletedGroupOid()); if(targetManager.deleteTargetGroup(group)) { ModelAndView mav = prepareSearchView(request, response, command, errors); mav.addObject(Constants.GBL_MESSAGES, messageSource.getMessage("group.deleted.success", new Object[] { group.getName() }, Locale.getDefault())); return mav; } else { ModelAndView mav = prepareSearchView(request, response, command, errors); mav.addObject(Constants.GBL_MESSAGES, messageSource.getMessage("group.deleted.failed.instances", new Object[] { group.getName() }, Locale.getDefault())); return mav; } } else if(command.isAction(SearchCommand.ACTION_RESET)) { command.setPageNumber(0); command.setAgency(""); command.setName(""); command.setOwner(""); command.setMemberOf(""); command.setGroupType(""); command.setSearchOid(null); request.getSession().setAttribute("groupsSearchCommand", command); return prepareSearchView(request, response, command, errors); } else { request.getSession().setAttribute("groupsSearchCommand", command); return prepareSearchView(request, response, command, errors); } } GroupSearchController(); }
GroupSearchController extends AbstractFormController { @Override protected ModelAndView processFormSubmission(HttpServletRequest request, HttpServletResponse response, Object comm, BindException errors) throws Exception { SearchCommand command = (SearchCommand) comm; if(command.isAction(SearchCommand.ACTION_DELETE)) { TargetGroup group = targetManager.loadGroup(command.getDeletedGroupOid()); if(targetManager.deleteTargetGroup(group)) { ModelAndView mav = prepareSearchView(request, response, command, errors); mav.addObject(Constants.GBL_MESSAGES, messageSource.getMessage("group.deleted.success", new Object[] { group.getName() }, Locale.getDefault())); return mav; } else { ModelAndView mav = prepareSearchView(request, response, command, errors); mav.addObject(Constants.GBL_MESSAGES, messageSource.getMessage("group.deleted.failed.instances", new Object[] { group.getName() }, Locale.getDefault())); return mav; } } else if(command.isAction(SearchCommand.ACTION_RESET)) { command.setPageNumber(0); command.setAgency(""); command.setName(""); command.setOwner(""); command.setMemberOf(""); command.setGroupType(""); command.setSearchOid(null); request.getSession().setAttribute("groupsSearchCommand", command); return prepareSearchView(request, response, command, errors); } else { request.getSession().setAttribute("groupsSearchCommand", command); return prepareSearchView(request, response, command, errors); } } GroupSearchController(); @Override void initBinder(HttpServletRequest request, ServletRequestDataBinder binder); SearchCommand getDefaultCommand(); @SuppressWarnings("unchecked") ModelAndView prepareSearchView(HttpServletRequest request, 
			                              HttpServletResponse response,
			                              BindException errors); @SuppressWarnings("unchecked") ModelAndView prepareSearchView(HttpServletRequest request, 
			                              HttpServletResponse response,
			                              SearchCommand command,
			                              BindException errors); void setTargetManager(TargetManager targetManager); void setAgencyUserManager(AgencyUserManager agencyUserManager); void setMessageSource(MessageSource messageSource); void setDefaultSearchOnAgencyOnly(boolean defaultSearchOnAgencyOnly); boolean getDefaultSearchOnAgencyOnly(); void setGroupTypesList(WCTTreeSet groupTypesList); void setSubGroupType(String subGroupType); void setSubGroupSeparator(String subGroupSeparator); }
GroupSearchController extends AbstractFormController { @Override protected ModelAndView processFormSubmission(HttpServletRequest request, HttpServletResponse response, Object comm, BindException errors) throws Exception { SearchCommand command = (SearchCommand) comm; if(command.isAction(SearchCommand.ACTION_DELETE)) { TargetGroup group = targetManager.loadGroup(command.getDeletedGroupOid()); if(targetManager.deleteTargetGroup(group)) { ModelAndView mav = prepareSearchView(request, response, command, errors); mav.addObject(Constants.GBL_MESSAGES, messageSource.getMessage("group.deleted.success", new Object[] { group.getName() }, Locale.getDefault())); return mav; } else { ModelAndView mav = prepareSearchView(request, response, command, errors); mav.addObject(Constants.GBL_MESSAGES, messageSource.getMessage("group.deleted.failed.instances", new Object[] { group.getName() }, Locale.getDefault())); return mav; } } else if(command.isAction(SearchCommand.ACTION_RESET)) { command.setPageNumber(0); command.setAgency(""); command.setName(""); command.setOwner(""); command.setMemberOf(""); command.setGroupType(""); command.setSearchOid(null); request.getSession().setAttribute("groupsSearchCommand", command); return prepareSearchView(request, response, command, errors); } else { request.getSession().setAttribute("groupsSearchCommand", command); return prepareSearchView(request, response, command, errors); } } GroupSearchController(); @Override void initBinder(HttpServletRequest request, ServletRequestDataBinder binder); SearchCommand getDefaultCommand(); @SuppressWarnings("unchecked") ModelAndView prepareSearchView(HttpServletRequest request, 
			                              HttpServletResponse response,
			                              BindException errors); @SuppressWarnings("unchecked") ModelAndView prepareSearchView(HttpServletRequest request, 
			                              HttpServletResponse response,
			                              SearchCommand command,
			                              BindException errors); void setTargetManager(TargetManager targetManager); void setAgencyUserManager(AgencyUserManager agencyUserManager); void setMessageSource(MessageSource messageSource); void setDefaultSearchOnAgencyOnly(boolean defaultSearchOnAgencyOnly); boolean getDefaultSearchOnAgencyOnly(); void setGroupTypesList(WCTTreeSet groupTypesList); void setSubGroupType(String subGroupType); void setSubGroupSeparator(String subGroupSeparator);  }