@Test public final void testProcessSave() { try { MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletResponse response = new MockHttpServletResponse(); DefaultSiteCommand comm = new DefaultSiteCommand(); comm.setEditMode(true); comm.setSiteOid(null); Tab currTab = testInstance.getTabConfig().getTabs().get(0); assertTrue(currTab != null); BindException aError = new BindException(new DefaultSiteCommand(), null); testInstance.processInitial(request, response, comm, aError); SiteEditorContext context = testInstance.getEditorContext(request); context.getSite().setTitle("Test Site"); ModelAndView mav = testInstance.processSave(currTab, request, response, comm, aError); assertTrue(mav != null); assertTrue(mav.getViewName().equals("site-search")); assertTrue(mav.getModel().get("page_message") != null); assertTrue(((String)mav.getModel().get("page_message")).startsWith("site.saved")); } catch (Exception e) { String message = e.getClass().toString() + " - " + e.getMessage(); log.debug(message); fail(message); } }
@Override protected ModelAndView processSave(Tab currentTab, HttpServletRequest req, HttpServletResponse res, Object comm, BindException errors) { log.debug("------------------------processSave-------------------------------"); checkSave(req, errors); if(errors.hasErrors()) { return getErrorsView(currentTab, req, res, comm, errors); } try { siteManager.save(getEditorContext(req).getSite()); ModelAndView mav = siteSearchController.showForm(req, res, errors); mav.addObject(Constants.GBL_MESSAGES, messageSource.getMessage("site.saved", new Object[] { getEditorContext(req).getSite().getTitle() }, Locale.getDefault())); return mav; } catch (Exception ex) { throw new WCTRuntimeException(ex.getMessage(), ex); } finally { unbindEditorContext(req); } }
SiteController extends TabbedController { @Override protected ModelAndView processSave(Tab currentTab, HttpServletRequest req, HttpServletResponse res, Object comm, BindException errors) { log.debug("------------------------processSave-------------------------------"); checkSave(req, errors); if(errors.hasErrors()) { return getErrorsView(currentTab, req, res, comm, errors); } try { siteManager.save(getEditorContext(req).getSite()); ModelAndView mav = siteSearchController.showForm(req, res, errors); mav.addObject(Constants.GBL_MESSAGES, messageSource.getMessage("site.saved", new Object[] { getEditorContext(req).getSite().getTitle() }, Locale.getDefault())); return mav; } catch (Exception ex) { throw new WCTRuntimeException(ex.getMessage(), ex); } finally { unbindEditorContext(req); } } }
SiteController extends TabbedController { @Override protected ModelAndView processSave(Tab currentTab, HttpServletRequest req, HttpServletResponse res, Object comm, BindException errors) { log.debug("------------------------processSave-------------------------------"); checkSave(req, errors); if(errors.hasErrors()) { return getErrorsView(currentTab, req, res, comm, errors); } try { siteManager.save(getEditorContext(req).getSite()); ModelAndView mav = siteSearchController.showForm(req, res, errors); mav.addObject(Constants.GBL_MESSAGES, messageSource.getMessage("site.saved", new Object[] { getEditorContext(req).getSite().getTitle() }, Locale.getDefault())); return mav; } catch (Exception ex) { throw new WCTRuntimeException(ex.getMessage(), ex); } finally { unbindEditorContext(req); } } SiteController(); }
SiteController extends TabbedController { @Override protected ModelAndView processSave(Tab currentTab, HttpServletRequest req, HttpServletResponse res, Object comm, BindException errors) { log.debug("------------------------processSave-------------------------------"); checkSave(req, errors); if(errors.hasErrors()) { return getErrorsView(currentTab, req, res, comm, errors); } try { siteManager.save(getEditorContext(req).getSite()); ModelAndView mav = siteSearchController.showForm(req, res, errors); mav.addObject(Constants.GBL_MESSAGES, messageSource.getMessage("site.saved", new Object[] { getEditorContext(req).getSite().getTitle() }, Locale.getDefault())); return mav; } catch (Exception ex) { throw new WCTRuntimeException(ex.getMessage(), ex); } finally { unbindEditorContext(req); } } SiteController(); void bindEditorContext(HttpServletRequest req, SiteEditorContext context); void unbindEditorContext(HttpServletRequest req); SiteEditorContext getEditorContext(HttpServletRequest req); void checkSave(HttpServletRequest req, BindException errors); ModelAndView getErrorsView(Tab currentTab, HttpServletRequest req, HttpServletResponse res, Object comm, BindException errors); void setSiteManager(SiteManager siteManager); void setAuthorityManager(AuthorityManager authorityManager); void setBusinessObjectFactory(BusinessObjectFactory businessObjectFactory); void setMessageSource(MessageSource messageSource); void setSiteSearchController(SiteSearchController siteSearchController); }
SiteController extends TabbedController { @Override protected ModelAndView processSave(Tab currentTab, HttpServletRequest req, HttpServletResponse res, Object comm, BindException errors) { log.debug("------------------------processSave-------------------------------"); checkSave(req, errors); if(errors.hasErrors()) { return getErrorsView(currentTab, req, res, comm, errors); } try { siteManager.save(getEditorContext(req).getSite()); ModelAndView mav = siteSearchController.showForm(req, res, errors); mav.addObject(Constants.GBL_MESSAGES, messageSource.getMessage("site.saved", new Object[] { getEditorContext(req).getSite().getTitle() }, Locale.getDefault())); return mav; } catch (Exception ex) { throw new WCTRuntimeException(ex.getMessage(), ex); } finally { unbindEditorContext(req); } } SiteController(); void bindEditorContext(HttpServletRequest req, SiteEditorContext context); void unbindEditorContext(HttpServletRequest req); SiteEditorContext getEditorContext(HttpServletRequest req); void checkSave(HttpServletRequest req, BindException errors); ModelAndView getErrorsView(Tab currentTab, HttpServletRequest req, HttpServletResponse res, Object comm, BindException errors); void setSiteManager(SiteManager siteManager); void setAuthorityManager(AuthorityManager authorityManager); void setBusinessObjectFactory(BusinessObjectFactory businessObjectFactory); void setMessageSource(MessageSource messageSource); void setSiteSearchController(SiteSearchController siteSearchController); static final String EDITOR_CONTEXT; }