@Test public void saveSettings() throws IOException { when(authentication.getName()).thenReturn("user"); when(userStore.getUser("user")).thenReturn(user); SortedMap<String, SortedMap<String, String>> allMacroSettings = Maps.newTreeMap(); SortedMap<String, String> macroSettings = Maps.newTreeMap(); macroSettings.put("key1", "macroValue1"); allMacroSettings.put("macro1", macroSettings); macroSettings = Maps.newTreeMap(); macroSettings.put("key2", "macroValue2"); allMacroSettings.put("macro2", macroSettings); SystemSettingsForm form = new SystemSettingsForm(DOCUMENTR_HOST, SITE_NOTICE, MAIL_HOST_NAME, 123, MAIL_SENDER_EMAIL, MAIL_SENDER_NAME, MAIL_SUBJECT_PREFIX, MAIL_DEFAULT_LANGUAGE, 234, PAGE_FOOTER_HTML, UPDATE_CHECK_INTERVAL, allMacroSettings); String view = systemController.saveSettings(form, bindingResult, authentication); assertEquals("/system/edit", removeViewPrefix(view)); assertRedirect(view); Map<String, String> settings = Maps.newHashMap(); settings.put(SystemSettingsStore.DOCUMENTR_HOST, DOCUMENTR_HOST); settings.put(SystemSettingsStore.SITE_NOTICE, SITE_NOTICE); settings.put(SystemSettingsStore.MAIL_HOST_NAME, MAIL_HOST_NAME); settings.put(SystemSettingsStore.MAIL_HOST_PORT, "123"); settings.put(SystemSettingsStore.MAIL_SENDER_EMAIL, MAIL_SENDER_EMAIL); settings.put(SystemSettingsStore.MAIL_SENDER_NAME, MAIL_SENDER_NAME); settings.put(SystemSettingsStore.MAIL_SUBJECT_PREFIX, MAIL_SUBJECT_PREFIX); settings.put(SystemSettingsStore.MAIL_DEFAULT_LANGUAGE, MAIL_DEFAULT_LANGUAGE); settings.put(SystemSettingsStore.BCRYPT_ROUNDS, "234"); settings.put(SystemSettingsStore.PAGE_FOOTER_HTML, PAGE_FOOTER_HTML); settings.put(SystemSettingsStore.UPDATE_CHECK_INTERVAL, UPDATE_CHECK_INTERVAL); verify(systemSettingsStore).saveSettings(settings, user); macroSettings = Maps.newTreeMap(); macroSettings.put("key1", "macroValue1"); verify(systemSettingsStore).setMacroSetting("macro1", macroSettings, user); macroSettings = Maps.newTreeMap(); macroSettings.put("key2", "macroValue2"); verify(systemSettingsStore).setMacroSetting("macro2", macroSettings, user); }
@RequestMapping(value="/save", method=RequestMethod.POST) @PreAuthorize("hasApplicationPermission(ADMIN)") public String saveSettings(@ModelAttribute @Valid SystemSettingsForm form, BindingResult bindingResult, Authentication authentication) throws IOException { if (bindingResult.hasErrors()) { return "/system/edit"; } User user = userStore.getUser(authentication.getName()); Map<String, String> settings = Maps.newHashMap(); String documentrHost = form.getDocumentrHost(); documentrHost = StringUtils.removeEnd(documentrHost, "/"); settings.put(SystemSettingsStore.DOCUMENTR_HOST, documentrHost); settings.put(SystemSettingsStore.SITE_NOTICE, form.getSiteNotice()); settings.put(SystemSettingsStore.MAIL_HOST_NAME, form.getMailHostName()); settings.put(SystemSettingsStore.MAIL_HOST_PORT, String.valueOf(form.getMailHostPort())); settings.put(SystemSettingsStore.MAIL_SENDER_EMAIL, form.getMailSenderEmail()); settings.put(SystemSettingsStore.MAIL_SENDER_NAME, form.getMailSenderName()); settings.put(SystemSettingsStore.MAIL_SUBJECT_PREFIX, form.getMailSubjectPrefix()); settings.put(SystemSettingsStore.MAIL_DEFAULT_LANGUAGE, form.getMailDefaultLanguage()); settings.put(SystemSettingsStore.BCRYPT_ROUNDS, String.valueOf(form.getBcryptRounds())); settings.put(SystemSettingsStore.PAGE_FOOTER_HTML, form.getPageFooterHtml()); settings.put(SystemSettingsStore.UPDATE_CHECK_INTERVAL, form.getUpdateCheckInterval()); systemSettingsStore.saveSettings(settings, user); for (Map.Entry<String, SortedMap<String, String>> entry : form.getMacroSettings().entrySet()) { systemSettingsStore.setMacroSetting(entry.getKey(), entry.getValue(), user); } return "redirect:/system/edit"; }
SystemController { @RequestMapping(value="/save", method=RequestMethod.POST) @PreAuthorize("hasApplicationPermission(ADMIN)") public String saveSettings(@ModelAttribute @Valid SystemSettingsForm form, BindingResult bindingResult, Authentication authentication) throws IOException { if (bindingResult.hasErrors()) { return "/system/edit"; } User user = userStore.getUser(authentication.getName()); Map<String, String> settings = Maps.newHashMap(); String documentrHost = form.getDocumentrHost(); documentrHost = StringUtils.removeEnd(documentrHost, "/"); settings.put(SystemSettingsStore.DOCUMENTR_HOST, documentrHost); settings.put(SystemSettingsStore.SITE_NOTICE, form.getSiteNotice()); settings.put(SystemSettingsStore.MAIL_HOST_NAME, form.getMailHostName()); settings.put(SystemSettingsStore.MAIL_HOST_PORT, String.valueOf(form.getMailHostPort())); settings.put(SystemSettingsStore.MAIL_SENDER_EMAIL, form.getMailSenderEmail()); settings.put(SystemSettingsStore.MAIL_SENDER_NAME, form.getMailSenderName()); settings.put(SystemSettingsStore.MAIL_SUBJECT_PREFIX, form.getMailSubjectPrefix()); settings.put(SystemSettingsStore.MAIL_DEFAULT_LANGUAGE, form.getMailDefaultLanguage()); settings.put(SystemSettingsStore.BCRYPT_ROUNDS, String.valueOf(form.getBcryptRounds())); settings.put(SystemSettingsStore.PAGE_FOOTER_HTML, form.getPageFooterHtml()); settings.put(SystemSettingsStore.UPDATE_CHECK_INTERVAL, form.getUpdateCheckInterval()); systemSettingsStore.saveSettings(settings, user); for (Map.Entry<String, SortedMap<String, String>> entry : form.getMacroSettings().entrySet()) { systemSettingsStore.setMacroSetting(entry.getKey(), entry.getValue(), user); } return "redirect:/system/edit"; } }
SystemController { @RequestMapping(value="/save", method=RequestMethod.POST) @PreAuthorize("hasApplicationPermission(ADMIN)") public String saveSettings(@ModelAttribute @Valid SystemSettingsForm form, BindingResult bindingResult, Authentication authentication) throws IOException { if (bindingResult.hasErrors()) { return "/system/edit"; } User user = userStore.getUser(authentication.getName()); Map<String, String> settings = Maps.newHashMap(); String documentrHost = form.getDocumentrHost(); documentrHost = StringUtils.removeEnd(documentrHost, "/"); settings.put(SystemSettingsStore.DOCUMENTR_HOST, documentrHost); settings.put(SystemSettingsStore.SITE_NOTICE, form.getSiteNotice()); settings.put(SystemSettingsStore.MAIL_HOST_NAME, form.getMailHostName()); settings.put(SystemSettingsStore.MAIL_HOST_PORT, String.valueOf(form.getMailHostPort())); settings.put(SystemSettingsStore.MAIL_SENDER_EMAIL, form.getMailSenderEmail()); settings.put(SystemSettingsStore.MAIL_SENDER_NAME, form.getMailSenderName()); settings.put(SystemSettingsStore.MAIL_SUBJECT_PREFIX, form.getMailSubjectPrefix()); settings.put(SystemSettingsStore.MAIL_DEFAULT_LANGUAGE, form.getMailDefaultLanguage()); settings.put(SystemSettingsStore.BCRYPT_ROUNDS, String.valueOf(form.getBcryptRounds())); settings.put(SystemSettingsStore.PAGE_FOOTER_HTML, form.getPageFooterHtml()); settings.put(SystemSettingsStore.UPDATE_CHECK_INTERVAL, form.getUpdateCheckInterval()); systemSettingsStore.saveSettings(settings, user); for (Map.Entry<String, SortedMap<String, String>> entry : form.getMacroSettings().entrySet()) { systemSettingsStore.setMacroSetting(entry.getKey(), entry.getValue(), user); } return "redirect:/system/edit"; }  }
SystemController { @RequestMapping(value="/save", method=RequestMethod.POST) @PreAuthorize("hasApplicationPermission(ADMIN)") public String saveSettings(@ModelAttribute @Valid SystemSettingsForm form, BindingResult bindingResult, Authentication authentication) throws IOException { if (bindingResult.hasErrors()) { return "/system/edit"; } User user = userStore.getUser(authentication.getName()); Map<String, String> settings = Maps.newHashMap(); String documentrHost = form.getDocumentrHost(); documentrHost = StringUtils.removeEnd(documentrHost, "/"); settings.put(SystemSettingsStore.DOCUMENTR_HOST, documentrHost); settings.put(SystemSettingsStore.SITE_NOTICE, form.getSiteNotice()); settings.put(SystemSettingsStore.MAIL_HOST_NAME, form.getMailHostName()); settings.put(SystemSettingsStore.MAIL_HOST_PORT, String.valueOf(form.getMailHostPort())); settings.put(SystemSettingsStore.MAIL_SENDER_EMAIL, form.getMailSenderEmail()); settings.put(SystemSettingsStore.MAIL_SENDER_NAME, form.getMailSenderName()); settings.put(SystemSettingsStore.MAIL_SUBJECT_PREFIX, form.getMailSubjectPrefix()); settings.put(SystemSettingsStore.MAIL_DEFAULT_LANGUAGE, form.getMailDefaultLanguage()); settings.put(SystemSettingsStore.BCRYPT_ROUNDS, String.valueOf(form.getBcryptRounds())); settings.put(SystemSettingsStore.PAGE_FOOTER_HTML, form.getPageFooterHtml()); settings.put(SystemSettingsStore.UPDATE_CHECK_INTERVAL, form.getUpdateCheckInterval()); systemSettingsStore.saveSettings(settings, user); for (Map.Entry<String, SortedMap<String, String>> entry : form.getMacroSettings().entrySet()) { systemSettingsStore.setMacroSetting(entry.getKey(), entry.getValue(), user); } return "redirect:/system/edit"; }  @RequestMapping(value="/edit", method=RequestMethod.GET) @PreAuthorize("hasApplicationPermission(ADMIN)") String editSettings(Model model); @RequestMapping(value="/save", method=RequestMethod.POST) @PreAuthorize("hasApplicationPermission(ADMIN)") String saveSettings(@ModelAttribute @Valid SystemSettingsForm form, BindingResult bindingResult,
			Authentication authentication); @ModelAttribute SystemSettingsForm createSystemSettingsForm(
			@RequestParam(required=false) String documentrHost,
			@RequestParam(required=false) String siteNotice,
			@RequestParam(required=false) String mailHostName,
			@RequestParam(required=false) Integer mailHostPort,
			@RequestParam(required=false) String mailSenderEmail,
			@RequestParam(required=false) String mailSenderName,
			@RequestParam(required=false) String mailSubjectPrefix,
			@RequestParam(required=false) String mailDefaultLanguage,
			@RequestParam(required=false) Integer bcryptRounds,
			@RequestParam(required=false) String pageFooterHtml,
			@RequestParam(required=false) String updateCheckInterval,
			WebRequest webRequest); }
SystemController { @RequestMapping(value="/save", method=RequestMethod.POST) @PreAuthorize("hasApplicationPermission(ADMIN)") public String saveSettings(@ModelAttribute @Valid SystemSettingsForm form, BindingResult bindingResult, Authentication authentication) throws IOException { if (bindingResult.hasErrors()) { return "/system/edit"; } User user = userStore.getUser(authentication.getName()); Map<String, String> settings = Maps.newHashMap(); String documentrHost = form.getDocumentrHost(); documentrHost = StringUtils.removeEnd(documentrHost, "/"); settings.put(SystemSettingsStore.DOCUMENTR_HOST, documentrHost); settings.put(SystemSettingsStore.SITE_NOTICE, form.getSiteNotice()); settings.put(SystemSettingsStore.MAIL_HOST_NAME, form.getMailHostName()); settings.put(SystemSettingsStore.MAIL_HOST_PORT, String.valueOf(form.getMailHostPort())); settings.put(SystemSettingsStore.MAIL_SENDER_EMAIL, form.getMailSenderEmail()); settings.put(SystemSettingsStore.MAIL_SENDER_NAME, form.getMailSenderName()); settings.put(SystemSettingsStore.MAIL_SUBJECT_PREFIX, form.getMailSubjectPrefix()); settings.put(SystemSettingsStore.MAIL_DEFAULT_LANGUAGE, form.getMailDefaultLanguage()); settings.put(SystemSettingsStore.BCRYPT_ROUNDS, String.valueOf(form.getBcryptRounds())); settings.put(SystemSettingsStore.PAGE_FOOTER_HTML, form.getPageFooterHtml()); settings.put(SystemSettingsStore.UPDATE_CHECK_INTERVAL, form.getUpdateCheckInterval()); systemSettingsStore.saveSettings(settings, user); for (Map.Entry<String, SortedMap<String, String>> entry : form.getMacroSettings().entrySet()) { systemSettingsStore.setMacroSetting(entry.getKey(), entry.getValue(), user); } return "redirect:/system/edit"; }  @RequestMapping(value="/edit", method=RequestMethod.GET) @PreAuthorize("hasApplicationPermission(ADMIN)") String editSettings(Model model); @RequestMapping(value="/save", method=RequestMethod.POST) @PreAuthorize("hasApplicationPermission(ADMIN)") String saveSettings(@ModelAttribute @Valid SystemSettingsForm form, BindingResult bindingResult,
			Authentication authentication); @ModelAttribute SystemSettingsForm createSystemSettingsForm(
			@RequestParam(required=false) String documentrHost,
			@RequestParam(required=false) String siteNotice,
			@RequestParam(required=false) String mailHostName,
			@RequestParam(required=false) Integer mailHostPort,
			@RequestParam(required=false) String mailSenderEmail,
			@RequestParam(required=false) String mailSenderName,
			@RequestParam(required=false) String mailSubjectPrefix,
			@RequestParam(required=false) String mailDefaultLanguage,
			@RequestParam(required=false) Integer bcryptRounds,
			@RequestParam(required=false) String pageFooterHtml,
			@RequestParam(required=false) String updateCheckInterval,
			WebRequest webRequest);  }