@Test public void createSystemSettingsForm() { Map<String, String[]> params = Maps.newHashMap(); params.put("macro.macro1.key1", new String[] { "macroValue1" }); params.put("macro.macro2.key2", new String[] { "macroValue2" }); when(webRequest.getParameterMap()).thenReturn(params); SystemSettingsForm form = systemController.createSystemSettingsForm(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, webRequest); assertEquals(DOCUMENTR_HOST, form.getDocumentrHost()); assertEquals(SITE_NOTICE, form.getSiteNotice()); assertEquals(MAIL_HOST_NAME, form.getMailHostName()); assertEquals(MAIL_HOST_PORT, form.getMailHostPort()); assertEquals(MAIL_SENDER_EMAIL, form.getMailSenderEmail()); assertEquals(MAIL_SENDER_NAME, form.getMailSenderName()); assertEquals(MAIL_SUBJECT_PREFIX, form.getMailSubjectPrefix()); assertEquals(MAIL_DEFAULT_LANGUAGE, form.getMailDefaultLanguage()); assertEquals(BCRYPT_ROUNDS, form.getBcryptRounds()); assertEquals(PAGE_FOOTER_HTML, form.getPageFooterHtml()); assertEquals(UPDATE_CHECK_INTERVAL, form.getUpdateCheckInterval()); assertEquals("macroValue1", form.getMacroSettings().get("macro1").get("key1")); assertEquals("macroValue2", form.getMacroSettings().get("macro2").get("key2")); }
@ModelAttribute public 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) { SortedMap<String, SortedMap<String, String>> allMacroSettings = getMacroSettingsFromRequest(webRequest); return new SystemSettingsForm( Strings.emptyToNull(documentrHost), Strings.emptyToNull(siteNotice), Strings.emptyToNull(mailHostName), (mailHostPort != null) ? mailHostPort : Integer.MIN_VALUE, Strings.emptyToNull(mailSenderEmail), Strings.emptyToNull(mailSenderName), Strings.emptyToNull(mailSubjectPrefix), Strings.emptyToNull(mailDefaultLanguage), (bcryptRounds != null) ? bcryptRounds : Integer.MIN_VALUE, Strings.emptyToNull(pageFooterHtml), Strings.emptyToNull(updateCheckInterval), allMacroSettings); }
SystemController { @ModelAttribute public 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) { SortedMap<String, SortedMap<String, String>> allMacroSettings = getMacroSettingsFromRequest(webRequest); return new SystemSettingsForm( Strings.emptyToNull(documentrHost), Strings.emptyToNull(siteNotice), Strings.emptyToNull(mailHostName), (mailHostPort != null) ? mailHostPort : Integer.MIN_VALUE, Strings.emptyToNull(mailSenderEmail), Strings.emptyToNull(mailSenderName), Strings.emptyToNull(mailSubjectPrefix), Strings.emptyToNull(mailDefaultLanguage), (bcryptRounds != null) ? bcryptRounds : Integer.MIN_VALUE, Strings.emptyToNull(pageFooterHtml), Strings.emptyToNull(updateCheckInterval), allMacroSettings); } }
SystemController { @ModelAttribute public 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) { SortedMap<String, SortedMap<String, String>> allMacroSettings = getMacroSettingsFromRequest(webRequest); return new SystemSettingsForm( Strings.emptyToNull(documentrHost), Strings.emptyToNull(siteNotice), Strings.emptyToNull(mailHostName), (mailHostPort != null) ? mailHostPort : Integer.MIN_VALUE, Strings.emptyToNull(mailSenderEmail), Strings.emptyToNull(mailSenderName), Strings.emptyToNull(mailSubjectPrefix), Strings.emptyToNull(mailDefaultLanguage), (bcryptRounds != null) ? bcryptRounds : Integer.MIN_VALUE, Strings.emptyToNull(pageFooterHtml), Strings.emptyToNull(updateCheckInterval), allMacroSettings); }  }
SystemController { @ModelAttribute public 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) { SortedMap<String, SortedMap<String, String>> allMacroSettings = getMacroSettingsFromRequest(webRequest); return new SystemSettingsForm( Strings.emptyToNull(documentrHost), Strings.emptyToNull(siteNotice), Strings.emptyToNull(mailHostName), (mailHostPort != null) ? mailHostPort : Integer.MIN_VALUE, Strings.emptyToNull(mailSenderEmail), Strings.emptyToNull(mailSenderName), Strings.emptyToNull(mailSubjectPrefix), Strings.emptyToNull(mailDefaultLanguage), (bcryptRounds != null) ? bcryptRounds : Integer.MIN_VALUE, Strings.emptyToNull(pageFooterHtml), Strings.emptyToNull(updateCheckInterval), allMacroSettings); }  @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 { @ModelAttribute public 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) { SortedMap<String, SortedMap<String, String>> allMacroSettings = getMacroSettingsFromRequest(webRequest); return new SystemSettingsForm( Strings.emptyToNull(documentrHost), Strings.emptyToNull(siteNotice), Strings.emptyToNull(mailHostName), (mailHostPort != null) ? mailHostPort : Integer.MIN_VALUE, Strings.emptyToNull(mailSenderEmail), Strings.emptyToNull(mailSenderName), Strings.emptyToNull(mailSubjectPrefix), Strings.emptyToNull(mailDefaultLanguage), (bcryptRounds != null) ? bcryptRounds : Integer.MIN_VALUE, Strings.emptyToNull(pageFooterHtml), Strings.emptyToNull(updateCheckInterval), allMacroSettings); }  @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);  }