@Test public void shouldAddErrorsWhenValidationFails() throws IOException { when(userService.hasActiveMotechAdmin()).thenReturn(true); when(configurationService.getConfigSource()).thenReturn(ConfigSource.UI); StartupForm startupForm = startupForm(); startupForm.setLanguage(""); List<String> errors = startupController.submitForm(startupForm); assertFalse(errors.isEmpty()); }
@RequestMapping(value = "/startup", method = RequestMethod.POST) @ResponseBody public List<String> submitForm(@RequestBody StartupForm startupSettings) throws IOException { ConfigSource configSource = (configurationService.loadBootstrapConfig() != null) ? configurationService.loadBootstrapConfig().getConfigSource() : ConfigSource.UI; StartupFormValidator startupFormValidator = startupFormValidatorFactory.getStartupFormValidator(startupSettings, userService); List<String> errors = startupFormValidator.validate(startupSettings, configurationService.getConfigSource()); if (!errors.isEmpty()) { return errors; } else if (!startupManager.canLaunchBundles()) { if (ConfigSource.UI.equals(configSource)) { MotechSettings settings = startupManager.getDefaultSettings(); settings.setLanguage(startupSettings.getLanguage()); settings.setLoginModeValue(startupSettings.getLoginMode()); settings.setProviderName(startupSettings.getProviderName()); settings.setProviderUrl(startupSettings.getProviderUrl()); configurationService.savePlatformSettings(settings); if (LoginMode.REPOSITORY.equals(LoginMode.valueOf(startupSettings.getLoginMode()))) { registerMotechAdmin(startupSettings); } } else { registerMotechAdmin(startupSettings); } startupManager.startup(); } return errors; }
StartupController { @RequestMapping(value = "/startup", method = RequestMethod.POST) @ResponseBody public List<String> submitForm(@RequestBody StartupForm startupSettings) throws IOException { ConfigSource configSource = (configurationService.loadBootstrapConfig() != null) ? configurationService.loadBootstrapConfig().getConfigSource() : ConfigSource.UI; StartupFormValidator startupFormValidator = startupFormValidatorFactory.getStartupFormValidator(startupSettings, userService); List<String> errors = startupFormValidator.validate(startupSettings, configurationService.getConfigSource()); if (!errors.isEmpty()) { return errors; } else if (!startupManager.canLaunchBundles()) { if (ConfigSource.UI.equals(configSource)) { MotechSettings settings = startupManager.getDefaultSettings(); settings.setLanguage(startupSettings.getLanguage()); settings.setLoginModeValue(startupSettings.getLoginMode()); settings.setProviderName(startupSettings.getProviderName()); settings.setProviderUrl(startupSettings.getProviderUrl()); configurationService.savePlatformSettings(settings); if (LoginMode.REPOSITORY.equals(LoginMode.valueOf(startupSettings.getLoginMode()))) { registerMotechAdmin(startupSettings); } } else { registerMotechAdmin(startupSettings); } startupManager.startup(); } return errors; } }
StartupController { @RequestMapping(value = "/startup", method = RequestMethod.POST) @ResponseBody public List<String> submitForm(@RequestBody StartupForm startupSettings) throws IOException { ConfigSource configSource = (configurationService.loadBootstrapConfig() != null) ? configurationService.loadBootstrapConfig().getConfigSource() : ConfigSource.UI; StartupFormValidator startupFormValidator = startupFormValidatorFactory.getStartupFormValidator(startupSettings, userService); List<String> errors = startupFormValidator.validate(startupSettings, configurationService.getConfigSource()); if (!errors.isEmpty()) { return errors; } else if (!startupManager.canLaunchBundles()) { if (ConfigSource.UI.equals(configSource)) { MotechSettings settings = startupManager.getDefaultSettings(); settings.setLanguage(startupSettings.getLanguage()); settings.setLoginModeValue(startupSettings.getLoginMode()); settings.setProviderName(startupSettings.getProviderName()); settings.setProviderUrl(startupSettings.getProviderUrl()); configurationService.savePlatformSettings(settings); if (LoginMode.REPOSITORY.equals(LoginMode.valueOf(startupSettings.getLoginMode()))) { registerMotechAdmin(startupSettings); } } else { registerMotechAdmin(startupSettings); } startupManager.startup(); } return errors; }  }
StartupController { @RequestMapping(value = "/startup", method = RequestMethod.POST) @ResponseBody public List<String> submitForm(@RequestBody StartupForm startupSettings) throws IOException { ConfigSource configSource = (configurationService.loadBootstrapConfig() != null) ? configurationService.loadBootstrapConfig().getConfigSource() : ConfigSource.UI; StartupFormValidator startupFormValidator = startupFormValidatorFactory.getStartupFormValidator(startupSettings, userService); List<String> errors = startupFormValidator.validate(startupSettings, configurationService.getConfigSource()); if (!errors.isEmpty()) { return errors; } else if (!startupManager.canLaunchBundles()) { if (ConfigSource.UI.equals(configSource)) { MotechSettings settings = startupManager.getDefaultSettings(); settings.setLanguage(startupSettings.getLanguage()); settings.setLoginModeValue(startupSettings.getLoginMode()); settings.setProviderName(startupSettings.getProviderName()); settings.setProviderUrl(startupSettings.getProviderUrl()); configurationService.savePlatformSettings(settings); if (LoginMode.REPOSITORY.equals(LoginMode.valueOf(startupSettings.getLoginMode()))) { registerMotechAdmin(startupSettings); } } else { registerMotechAdmin(startupSettings); } startupManager.startup(); } return errors; }  @RequestMapping(value = "/startupviewdata", method = RequestMethod.GET) @ResponseBody StartupViewData getStartupViewData(final HttpServletRequest request); @RequestMapping(value = "/startup", method = RequestMethod.GET) ModelAndView startup(); @RequestMapping(value = "/startup", method = RequestMethod.POST) @ResponseBody List<String> submitForm(@RequestBody StartupForm startupSettings); void setStartupFormValidatorFactory(StartupFormValidatorFactory validatorFactory); }
StartupController { @RequestMapping(value = "/startup", method = RequestMethod.POST) @ResponseBody public List<String> submitForm(@RequestBody StartupForm startupSettings) throws IOException { ConfigSource configSource = (configurationService.loadBootstrapConfig() != null) ? configurationService.loadBootstrapConfig().getConfigSource() : ConfigSource.UI; StartupFormValidator startupFormValidator = startupFormValidatorFactory.getStartupFormValidator(startupSettings, userService); List<String> errors = startupFormValidator.validate(startupSettings, configurationService.getConfigSource()); if (!errors.isEmpty()) { return errors; } else if (!startupManager.canLaunchBundles()) { if (ConfigSource.UI.equals(configSource)) { MotechSettings settings = startupManager.getDefaultSettings(); settings.setLanguage(startupSettings.getLanguage()); settings.setLoginModeValue(startupSettings.getLoginMode()); settings.setProviderName(startupSettings.getProviderName()); settings.setProviderUrl(startupSettings.getProviderUrl()); configurationService.savePlatformSettings(settings); if (LoginMode.REPOSITORY.equals(LoginMode.valueOf(startupSettings.getLoginMode()))) { registerMotechAdmin(startupSettings); } } else { registerMotechAdmin(startupSettings); } startupManager.startup(); } return errors; }  @RequestMapping(value = "/startupviewdata", method = RequestMethod.GET) @ResponseBody StartupViewData getStartupViewData(final HttpServletRequest request); @RequestMapping(value = "/startup", method = RequestMethod.GET) ModelAndView startup(); @RequestMapping(value = "/startup", method = RequestMethod.POST) @ResponseBody List<String> submitForm(@RequestBody StartupForm startupSettings); void setStartupFormValidatorFactory(StartupFormValidatorFactory validatorFactory);  }