SystemController { @RequestMapping(value="/edit", method=RequestMethod.GET) @PreAuthorize("hasApplicationPermission(ADMIN)") public String editSettings(Model model) { Map<String, String> settings = systemSettingsStore.getSettings(); SortedMap<String, SortedMap<String, String>> allMacroSettings = getMacroSettingsFromSystemSettings(); SystemSettingsForm form = new SystemSettingsForm( settings.get(SystemSettingsStore.DOCUMENTR_HOST), settings.get(SystemSettingsStore.SITE_NOTICE), settings.get(SystemSettingsStore.MAIL_HOST_NAME), Integer.parseInt(settings.get(SystemSettingsStore.MAIL_HOST_PORT)), settings.get(SystemSettingsStore.MAIL_SENDER_EMAIL), settings.get(SystemSettingsStore.MAIL_SENDER_NAME), settings.get(SystemSettingsStore.MAIL_SUBJECT_PREFIX), settings.get(SystemSettingsStore.MAIL_DEFAULT_LANGUAGE), Integer.parseInt(settings.get(SystemSettingsStore.BCRYPT_ROUNDS)), settings.get(SystemSettingsStore.PAGE_FOOTER_HTML), settings.get(SystemSettingsStore.UPDATE_CHECK_INTERVAL), allMacroSettings); model.addAttribute("systemSettingsForm", form); return "/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);  }
@Test public void editSettings() { when(macroDescriptor1.getMacroName()).thenReturn("macro1"); when(setting1.value()).thenReturn("key1"); when(macroDescriptor1.getSettings()).thenReturn(Sets.newHashSet(setting1)); when(macroDescriptor2.getMacroName()).thenReturn("macro2"); when(setting2.value()).thenReturn("key2"); when(macroDescriptor2.getSettings()).thenReturn(Sets.newHashSet(setting2)); when(macroFactory.getDescriptors()).thenReturn(Sets.newHashSet(macroDescriptor1, macroDescriptor2)); when(systemSettingsStore.getMacroSetting("macro1", "key1")).thenReturn("macroValue1"); when(systemSettingsStore.getMacroSetting("macro2", "key2")).thenReturn("macroValue2"); 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); when(systemSettingsStore.getSettings()).thenReturn(settings); String view = systemController.editSettings(model); assertEquals("/system/edit", view); ArgumentCaptor<SystemSettingsForm> captor = ArgumentCaptor.forClass(SystemSettingsForm.class); verify(model).addAttribute(eq("systemSettingsForm"), captor.capture()); SystemSettingsForm form = captor.getValue(); assertEquals(DOCUMENTR_HOST, form.getDocumentrHost()); assertEquals(SITE_NOTICE, form.getSiteNotice()); assertEquals(MAIL_HOST_NAME, form.getMailHostName()); assertEquals(123, 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(234, 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")); }