@Test public final void testProcessFormSubmission() { try { MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletResponse response = new MockHttpServletResponse(); BindException aError = new BindException(new AgencyCommand(), AgencyCommand.ACTION_EDIT); testSetAgencyUserManager(); testSetMessageSource(); AgencyCommand aCommand = new AgencyCommand(); aCommand.setActionCommand(AgencyCommand.ACTION_NEW); aCommand.setOid(new Long(2000)); ModelAndView mav = testInstance.processFormSubmission(request, response, aCommand, aError); assertTrue(mav != null); assertTrue(mav.getViewName().equals("newAgency")); List<Agency> agencies = (List<Agency>)mav.getModel().get("agencies"); assertTrue(agencies != null); assertTrue(agencies.size() > 0); aCommand = new AgencyCommand(); aCommand.setActionCommand(AgencyCommand.ACTION_VIEW); aCommand.setOid(new Long(2000)); mav = testInstance.processFormSubmission(request, response, aCommand, aError); assertTrue(mav != null); assertTrue(mav.getViewName().equals("newAgency")); agencies = (List<Agency>)mav.getModel().get("agencies"); assertTrue(agencies != null); assertTrue(agencies.size() > 0); AgencyCommand newCommand = (AgencyCommand)mav.getModel().get("command"); assertTrue(newCommand != null); assertTrue(newCommand.getViewOnlyMode()); aCommand = new AgencyCommand(); aCommand.setActionCommand(AgencyCommand.ACTION_EDIT); aCommand.setOid(new Long(2000)); mav = testInstance.processFormSubmission(request, response, aCommand, aError); assertTrue(mav != null); assertTrue(mav.getViewName().equals("newAgency")); agencies = (List<Agency>)mav.getModel().get("agencies"); assertTrue(agencies != null); assertTrue(agencies.size() > 0); newCommand = (AgencyCommand)mav.getModel().get("command"); assertTrue(newCommand != null); assertFalse(newCommand.getViewOnlyMode()); aCommand = new AgencyCommand(); aCommand.setActionCommand(AgencyCommand.ACTION_SAVE); aCommand.setName("New Test Agency"); mav = testInstance.processFormSubmission(request, response, aCommand, aError); assertTrue(mav != null); assertTrue(mav.getViewName().equals("viewAgencies")); agencies = (List<Agency>)mav.getModel().get("agencies"); assertTrue(agencies != null); assertTrue(agencies.size() > 0); } catch (Exception e) { String message = e.getClass().toString() + " - " + e.getMessage(); log.debug(message); fail(message); } }
@Override protected ModelAndView processFormSubmission(HttpServletRequest aReq, HttpServletResponse aRes, Object aCommand, BindException aError) throws Exception { ModelAndView mav = null; AgencyCommand agencyCmd = (AgencyCommand) aCommand; if (agencyCmd != null) { if (aError.hasErrors()) { mav = new ModelAndView(); mav = populateAgencyList(); mav.addObject(Constants.GBL_CMD_DATA, aError.getTarget()); mav.addObject(Constants.GBL_ERRORS, aError); mav.setViewName("newAgency"); } else if (AgencyCommand.ACTION_NEW.equals(agencyCmd.getActionCommand())) { mav = populateAgencyList(); mav.setViewName("newAgency"); } else if (AgencyCommand.ACTION_SAVE.equals(agencyCmd.getActionCommand())) { boolean update = false; Agency agency = new Agency(); if (agencyCmd.getOid() != null) { update = true; agency.setOid(agencyCmd.getOid()); } agency.setName(agencyCmd.getName()); agency.setAddress(agencyCmd.getAddress()); agency.setPhone(agencyCmd.getPhone()); agency.setFax(agencyCmd.getFax()); agency.setEmail(agencyCmd.getEmail()); agency.setAgencyURL(agencyCmd.getAgencyURL()); agency.setAgencyLogoURL(agencyCmd.getAgencyLogoURL()); agency.setShowTasks(agencyCmd.getShowTasks()); agency.setDefaultDescriptionType(agencyCmd.getDescriptionType()); agencyUserManager.updateAgency(agency, update); mav = populateAgencyList(); if (update == true) { mav.addObject(Constants.GBL_MESSAGES, messageSource.getMessage("agency.updated", new Object[] { agencyCmd.getName() }, Locale.getDefault())); } else { mav.addObject(Constants.GBL_MESSAGES, messageSource.getMessage("agency.created", new Object[] { agencyCmd.getName() }, Locale.getDefault())); } } else if (AgencyCommand.ACTION_VIEW.equals(agencyCmd.getActionCommand()) || AgencyCommand.ACTION_EDIT.equals(agencyCmd.getActionCommand())) { Agency agency = agencyUserManager.getAgencyByOid(agencyCmd.getOid()); AgencyCommand populatedCmd = new AgencyCommand(); populatedCmd.setOid(agency.getOid()); populatedCmd.setName(agency.getName()); populatedCmd.setAddress(agency.getAddress()); populatedCmd.setPhone(agency.getPhone()); populatedCmd.setFax(agency.getFax()); populatedCmd.setEmail(agency.getEmail()); populatedCmd.setAgencyURL(agency.getAgencyURL()); populatedCmd.setAgencyLogoURL(agency.getAgencyLogoURL()); populatedCmd.setShowTasks(agency.getShowTasks()); populatedCmd.setViewOnlyMode(AgencyCommand.ACTION_VIEW.equals(agencyCmd.getActionCommand())); populatedCmd.setDescriptionType(agency.getDefaultDescriptionType()); mav = new ModelAndView(); mav = populateAgencyList(); mav.addObject(Constants.GBL_CMD_DATA, populatedCmd); mav.setViewName("newAgency"); } } else { log.warn("No Action provided for AgencyController."); mav = populateAgencyList(); } mav.addObject("descriptionTypes", typeList); return mav; }
AgencyController extends AbstractFormController { @Override protected ModelAndView processFormSubmission(HttpServletRequest aReq, HttpServletResponse aRes, Object aCommand, BindException aError) throws Exception { ModelAndView mav = null; AgencyCommand agencyCmd = (AgencyCommand) aCommand; if (agencyCmd != null) { if (aError.hasErrors()) { mav = new ModelAndView(); mav = populateAgencyList(); mav.addObject(Constants.GBL_CMD_DATA, aError.getTarget()); mav.addObject(Constants.GBL_ERRORS, aError); mav.setViewName("newAgency"); } else if (AgencyCommand.ACTION_NEW.equals(agencyCmd.getActionCommand())) { mav = populateAgencyList(); mav.setViewName("newAgency"); } else if (AgencyCommand.ACTION_SAVE.equals(agencyCmd.getActionCommand())) { boolean update = false; Agency agency = new Agency(); if (agencyCmd.getOid() != null) { update = true; agency.setOid(agencyCmd.getOid()); } agency.setName(agencyCmd.getName()); agency.setAddress(agencyCmd.getAddress()); agency.setPhone(agencyCmd.getPhone()); agency.setFax(agencyCmd.getFax()); agency.setEmail(agencyCmd.getEmail()); agency.setAgencyURL(agencyCmd.getAgencyURL()); agency.setAgencyLogoURL(agencyCmd.getAgencyLogoURL()); agency.setShowTasks(agencyCmd.getShowTasks()); agency.setDefaultDescriptionType(agencyCmd.getDescriptionType()); agencyUserManager.updateAgency(agency, update); mav = populateAgencyList(); if (update == true) { mav.addObject(Constants.GBL_MESSAGES, messageSource.getMessage("agency.updated", new Object[] { agencyCmd.getName() }, Locale.getDefault())); } else { mav.addObject(Constants.GBL_MESSAGES, messageSource.getMessage("agency.created", new Object[] { agencyCmd.getName() }, Locale.getDefault())); } } else if (AgencyCommand.ACTION_VIEW.equals(agencyCmd.getActionCommand()) || AgencyCommand.ACTION_EDIT.equals(agencyCmd.getActionCommand())) { Agency agency = agencyUserManager.getAgencyByOid(agencyCmd.getOid()); AgencyCommand populatedCmd = new AgencyCommand(); populatedCmd.setOid(agency.getOid()); populatedCmd.setName(agency.getName()); populatedCmd.setAddress(agency.getAddress()); populatedCmd.setPhone(agency.getPhone()); populatedCmd.setFax(agency.getFax()); populatedCmd.setEmail(agency.getEmail()); populatedCmd.setAgencyURL(agency.getAgencyURL()); populatedCmd.setAgencyLogoURL(agency.getAgencyLogoURL()); populatedCmd.setShowTasks(agency.getShowTasks()); populatedCmd.setViewOnlyMode(AgencyCommand.ACTION_VIEW.equals(agencyCmd.getActionCommand())); populatedCmd.setDescriptionType(agency.getDefaultDescriptionType()); mav = new ModelAndView(); mav = populateAgencyList(); mav.addObject(Constants.GBL_CMD_DATA, populatedCmd); mav.setViewName("newAgency"); } } else { log.warn("No Action provided for AgencyController."); mav = populateAgencyList(); } mav.addObject("descriptionTypes", typeList); return mav; } }
AgencyController extends AbstractFormController { @Override protected ModelAndView processFormSubmission(HttpServletRequest aReq, HttpServletResponse aRes, Object aCommand, BindException aError) throws Exception { ModelAndView mav = null; AgencyCommand agencyCmd = (AgencyCommand) aCommand; if (agencyCmd != null) { if (aError.hasErrors()) { mav = new ModelAndView(); mav = populateAgencyList(); mav.addObject(Constants.GBL_CMD_DATA, aError.getTarget()); mav.addObject(Constants.GBL_ERRORS, aError); mav.setViewName("newAgency"); } else if (AgencyCommand.ACTION_NEW.equals(agencyCmd.getActionCommand())) { mav = populateAgencyList(); mav.setViewName("newAgency"); } else if (AgencyCommand.ACTION_SAVE.equals(agencyCmd.getActionCommand())) { boolean update = false; Agency agency = new Agency(); if (agencyCmd.getOid() != null) { update = true; agency.setOid(agencyCmd.getOid()); } agency.setName(agencyCmd.getName()); agency.setAddress(agencyCmd.getAddress()); agency.setPhone(agencyCmd.getPhone()); agency.setFax(agencyCmd.getFax()); agency.setEmail(agencyCmd.getEmail()); agency.setAgencyURL(agencyCmd.getAgencyURL()); agency.setAgencyLogoURL(agencyCmd.getAgencyLogoURL()); agency.setShowTasks(agencyCmd.getShowTasks()); agency.setDefaultDescriptionType(agencyCmd.getDescriptionType()); agencyUserManager.updateAgency(agency, update); mav = populateAgencyList(); if (update == true) { mav.addObject(Constants.GBL_MESSAGES, messageSource.getMessage("agency.updated", new Object[] { agencyCmd.getName() }, Locale.getDefault())); } else { mav.addObject(Constants.GBL_MESSAGES, messageSource.getMessage("agency.created", new Object[] { agencyCmd.getName() }, Locale.getDefault())); } } else if (AgencyCommand.ACTION_VIEW.equals(agencyCmd.getActionCommand()) || AgencyCommand.ACTION_EDIT.equals(agencyCmd.getActionCommand())) { Agency agency = agencyUserManager.getAgencyByOid(agencyCmd.getOid()); AgencyCommand populatedCmd = new AgencyCommand(); populatedCmd.setOid(agency.getOid()); populatedCmd.setName(agency.getName()); populatedCmd.setAddress(agency.getAddress()); populatedCmd.setPhone(agency.getPhone()); populatedCmd.setFax(agency.getFax()); populatedCmd.setEmail(agency.getEmail()); populatedCmd.setAgencyURL(agency.getAgencyURL()); populatedCmd.setAgencyLogoURL(agency.getAgencyLogoURL()); populatedCmd.setShowTasks(agency.getShowTasks()); populatedCmd.setViewOnlyMode(AgencyCommand.ACTION_VIEW.equals(agencyCmd.getActionCommand())); populatedCmd.setDescriptionType(agency.getDefaultDescriptionType()); mav = new ModelAndView(); mav = populateAgencyList(); mav.addObject(Constants.GBL_CMD_DATA, populatedCmd); mav.setViewName("newAgency"); } } else { log.warn("No Action provided for AgencyController."); mav = populateAgencyList(); } mav.addObject("descriptionTypes", typeList); return mav; } AgencyController(); }
AgencyController extends AbstractFormController { @Override protected ModelAndView processFormSubmission(HttpServletRequest aReq, HttpServletResponse aRes, Object aCommand, BindException aError) throws Exception { ModelAndView mav = null; AgencyCommand agencyCmd = (AgencyCommand) aCommand; if (agencyCmd != null) { if (aError.hasErrors()) { mav = new ModelAndView(); mav = populateAgencyList(); mav.addObject(Constants.GBL_CMD_DATA, aError.getTarget()); mav.addObject(Constants.GBL_ERRORS, aError); mav.setViewName("newAgency"); } else if (AgencyCommand.ACTION_NEW.equals(agencyCmd.getActionCommand())) { mav = populateAgencyList(); mav.setViewName("newAgency"); } else if (AgencyCommand.ACTION_SAVE.equals(agencyCmd.getActionCommand())) { boolean update = false; Agency agency = new Agency(); if (agencyCmd.getOid() != null) { update = true; agency.setOid(agencyCmd.getOid()); } agency.setName(agencyCmd.getName()); agency.setAddress(agencyCmd.getAddress()); agency.setPhone(agencyCmd.getPhone()); agency.setFax(agencyCmd.getFax()); agency.setEmail(agencyCmd.getEmail()); agency.setAgencyURL(agencyCmd.getAgencyURL()); agency.setAgencyLogoURL(agencyCmd.getAgencyLogoURL()); agency.setShowTasks(agencyCmd.getShowTasks()); agency.setDefaultDescriptionType(agencyCmd.getDescriptionType()); agencyUserManager.updateAgency(agency, update); mav = populateAgencyList(); if (update == true) { mav.addObject(Constants.GBL_MESSAGES, messageSource.getMessage("agency.updated", new Object[] { agencyCmd.getName() }, Locale.getDefault())); } else { mav.addObject(Constants.GBL_MESSAGES, messageSource.getMessage("agency.created", new Object[] { agencyCmd.getName() }, Locale.getDefault())); } } else if (AgencyCommand.ACTION_VIEW.equals(agencyCmd.getActionCommand()) || AgencyCommand.ACTION_EDIT.equals(agencyCmd.getActionCommand())) { Agency agency = agencyUserManager.getAgencyByOid(agencyCmd.getOid()); AgencyCommand populatedCmd = new AgencyCommand(); populatedCmd.setOid(agency.getOid()); populatedCmd.setName(agency.getName()); populatedCmd.setAddress(agency.getAddress()); populatedCmd.setPhone(agency.getPhone()); populatedCmd.setFax(agency.getFax()); populatedCmd.setEmail(agency.getEmail()); populatedCmd.setAgencyURL(agency.getAgencyURL()); populatedCmd.setAgencyLogoURL(agency.getAgencyLogoURL()); populatedCmd.setShowTasks(agency.getShowTasks()); populatedCmd.setViewOnlyMode(AgencyCommand.ACTION_VIEW.equals(agencyCmd.getActionCommand())); populatedCmd.setDescriptionType(agency.getDefaultDescriptionType()); mav = new ModelAndView(); mav = populateAgencyList(); mav.addObject(Constants.GBL_CMD_DATA, populatedCmd); mav.setViewName("newAgency"); } } else { log.warn("No Action provided for AgencyController."); mav = populateAgencyList(); } mav.addObject("descriptionTypes", typeList); return mav; } AgencyController(); @Override void initBinder(HttpServletRequest request, ServletRequestDataBinder binder); void setAgencyUserManager(AgencyUserManager agencyUserManager); void setMessageSource(MessageSource messageSource); void setTypeList(WCTTreeSet typeList); }
AgencyController extends AbstractFormController { @Override protected ModelAndView processFormSubmission(HttpServletRequest aReq, HttpServletResponse aRes, Object aCommand, BindException aError) throws Exception { ModelAndView mav = null; AgencyCommand agencyCmd = (AgencyCommand) aCommand; if (agencyCmd != null) { if (aError.hasErrors()) { mav = new ModelAndView(); mav = populateAgencyList(); mav.addObject(Constants.GBL_CMD_DATA, aError.getTarget()); mav.addObject(Constants.GBL_ERRORS, aError); mav.setViewName("newAgency"); } else if (AgencyCommand.ACTION_NEW.equals(agencyCmd.getActionCommand())) { mav = populateAgencyList(); mav.setViewName("newAgency"); } else if (AgencyCommand.ACTION_SAVE.equals(agencyCmd.getActionCommand())) { boolean update = false; Agency agency = new Agency(); if (agencyCmd.getOid() != null) { update = true; agency.setOid(agencyCmd.getOid()); } agency.setName(agencyCmd.getName()); agency.setAddress(agencyCmd.getAddress()); agency.setPhone(agencyCmd.getPhone()); agency.setFax(agencyCmd.getFax()); agency.setEmail(agencyCmd.getEmail()); agency.setAgencyURL(agencyCmd.getAgencyURL()); agency.setAgencyLogoURL(agencyCmd.getAgencyLogoURL()); agency.setShowTasks(agencyCmd.getShowTasks()); agency.setDefaultDescriptionType(agencyCmd.getDescriptionType()); agencyUserManager.updateAgency(agency, update); mav = populateAgencyList(); if (update == true) { mav.addObject(Constants.GBL_MESSAGES, messageSource.getMessage("agency.updated", new Object[] { agencyCmd.getName() }, Locale.getDefault())); } else { mav.addObject(Constants.GBL_MESSAGES, messageSource.getMessage("agency.created", new Object[] { agencyCmd.getName() }, Locale.getDefault())); } } else if (AgencyCommand.ACTION_VIEW.equals(agencyCmd.getActionCommand()) || AgencyCommand.ACTION_EDIT.equals(agencyCmd.getActionCommand())) { Agency agency = agencyUserManager.getAgencyByOid(agencyCmd.getOid()); AgencyCommand populatedCmd = new AgencyCommand(); populatedCmd.setOid(agency.getOid()); populatedCmd.setName(agency.getName()); populatedCmd.setAddress(agency.getAddress()); populatedCmd.setPhone(agency.getPhone()); populatedCmd.setFax(agency.getFax()); populatedCmd.setEmail(agency.getEmail()); populatedCmd.setAgencyURL(agency.getAgencyURL()); populatedCmd.setAgencyLogoURL(agency.getAgencyLogoURL()); populatedCmd.setShowTasks(agency.getShowTasks()); populatedCmd.setViewOnlyMode(AgencyCommand.ACTION_VIEW.equals(agencyCmd.getActionCommand())); populatedCmd.setDescriptionType(agency.getDefaultDescriptionType()); mav = new ModelAndView(); mav = populateAgencyList(); mav.addObject(Constants.GBL_CMD_DATA, populatedCmd); mav.setViewName("newAgency"); } } else { log.warn("No Action provided for AgencyController."); mav = populateAgencyList(); } mav.addObject("descriptionTypes", typeList); return mav; } AgencyController(); @Override void initBinder(HttpServletRequest request, ServletRequestDataBinder binder); void setAgencyUserManager(AgencyUserManager agencyUserManager); void setMessageSource(MessageSource messageSource); void setTypeList(WCTTreeSet typeList);  }