public Map<String, Map<String, String>> getConfigAsMap() { Map<String, Map<String, String>> configMap = new HashMap<>(); for (ConfigurationProperty property : configuration) { Map<String, String> mapValue = new HashMap<>(); mapValue.put(VALUE_KEY, property.getValue()); if (!property.errors().isEmpty()) { mapValue.put(ERRORS_KEY, StringUtils.join(property.errors().getAll(), ", ")); } configMap.put(property.getConfigKeyName(), mapValue); } return configMap; }
private void validateCommand() { if (StringUtils.isBlank(command)) { errors.add(COMMAND, "Command cannot be empty"); } }
@Test public void shouldAddAll() { ConfigErrors configErrors = new ConfigErrors(); configErrors.add("err1", "foo"); configErrors.add("err1", "baz"); configErrors.add("err2", "bar"); ConfigErrors other = new ConfigErrors(); other.add("baz", "one"); other.addAll(configErrors); assertThat(other.getAll(), hasItems("baz", "foo", "baz", "bar")); }
public ConfigErrors getAllErrors() { ConfigErrors configErrors = new ConfigErrors(); configErrors.addAll(errors); for (ConfigRepoConfig repoConfig : this) { configErrors.addAll(repoConfig.errors()); } return configErrors; }
private ConfigErrors error(String fieldName) { ConfigErrors errors1 = new ConfigErrors(); errors1.add(fieldName, "error on " + fieldName); return errors1; } }
@Test public void shouldValidateTheJobName() { assertThat(createJobAndValidate(".name").errors().isEmpty(), is(true)); ConfigErrors configErrors = createJobAndValidate("name pavan").errors(); assertThat(configErrors.isEmpty(), is(false)); assertThat(configErrors.on(JobConfig.NAME), is("Invalid job name 'name pavan'. This must be alphanumeric and may contain underscores and periods. The maximum allowed length is 255 characters.")); } @Test
@Test public void shouldValidateName() throws Exception { SCM scm = new SCM(); scm.setName("some name"); scm.validate(new ConfigSaveValidationContext(null)); assertThat(scm.errors().isEmpty(), is(false)); assertThat(scm.errors().getAllOn(SCM.NAME).get(0), is("Invalid SCM name 'some name'. This must be alphanumeric and can contain underscores and periods (however, it cannot start with a period). The maximum allowed length is 255 characters.")); }
@Test public void shouldAddErrorWhenAssociatedSCMPluginIsMissing() throws Exception { PipelineConfigSaveValidationContext configSaveValidationContext = mock(PipelineConfigSaveValidationContext.class); when(configSaveValidationContext.findScmById(anyString())).thenReturn(mock(SCM.class)); SCM scmConfig = mock(SCM.class); when(scmConfig.doesPluginExist()).thenReturn(false); PluggableSCMMaterialConfig pluggableSCMMaterialConfig = new PluggableSCMMaterialConfig(null, scmConfig, "usr/home", null); pluggableSCMMaterialConfig.setScmId("scm-id"); pluggableSCMMaterialConfig.validateTree(configSaveValidationContext); assertThat(pluggableSCMMaterialConfig.errors().getAll().size(), is(1)); assertThat(pluggableSCMMaterialConfig.errors().on(PluggableSCMMaterialConfig.SCM_ID), is("Could not find plugin for scm-id: [scm-id].")); }
public boolean validateTree(PipelineConfigSaveValidationContext validationContext) { if (isEmpty()) { errors().add("materials", "A pipeline must have at least one material"); } validate(validationContext); boolean isValid = errors().isEmpty(); for (MaterialConfig materialConfig : this) { isValid = materialConfig.validateTree(validationContext) && isValid; } return isValid; }
@Test public void validateTree_configRepoShouldBeInvalidIfMaterialConfigHasErrors() { CruiseConfig cruiseConfig = new BasicCruiseConfig(); MaterialConfig materialConfig = mock(MaterialConfig.class); when(materialConfig.errors()).thenReturn(new ConfigErrors()); ConfigRepoConfig configRepoConfig = new ConfigRepoConfig(materialConfig, "plug", "id"); cruiseConfig.setConfigRepos(new ConfigReposConfig(configRepoConfig)); ConfigSaveValidationContext validationContext = ConfigSaveValidationContext.forChain(cruiseConfig); assertFalse(configRepoConfig.validateTree(validationContext)); assertTrue(configRepoConfig.errors().isEmpty()); assertFalse(configRepoConfig.getMaterialConfig().errors().isEmpty()); }
@Test public void shouldGetAll() { ConfigErrors configErrors = new ConfigErrors(); configErrors.add("err1", "foo"); configErrors.add("err1", "baz"); configErrors.add("err2", "bar"); assertThat(configErrors.getAll(), hasItems("foo", "baz", "bar")); }
@Test public void shouldNotAddSameErrorAgain() { ConfigErrors configErrors = new ConfigErrors(); configErrors.add("field", "error"); configErrors.add("field", "error"); assertThat(configErrors.getAllOn("field"), is(asList("error"))); } }
public static AgentInstance createFromConfig(AgentConfig agentInConfig, SystemEnvironment systemEnvironment, AgentStatusChangeListener agentStatusChangeListener) { AgentType type = agentInConfig.isFromLocalHost() ? AgentType.LOCAL : AgentType.REMOTE; AgentInstance result = new AgentInstance(agentInConfig, type, systemEnvironment, agentStatusChangeListener); result.agentConfigStatus = agentInConfig.isDisabled() ? AgentConfigStatus.Disabled : AgentConfigStatus.Enabled; result.errors.addAll(agentInConfig.errors()); for (ResourceConfig resourceConfig : agentInConfig.getResourceConfigs()) { result.errors.addAll(resourceConfig.errors()); } return result; }
@Test public void shouldValidateThatNameIsMandatory() { ArtifactPropertyConfig generator = new ArtifactPropertyConfig(null, "props.xml", "//some_xpath"); generator.validateTree(null); assertThat(generator.errors().on(ArtifactPropertyConfig.NAME), containsString("Invalid property name 'null'.")); }
public void validate(CruiseConfig cruiseConfig) { List<ConfigErrors> errors = validateConfig(cruiseConfig); List<String> errorMessages = new ArrayList<>(); for (ConfigErrors error : errors) { errorMessages.addAll(error.getAll()); } if (!errors.isEmpty()) throw new RuntimeException(StringUtils.join(errorMessages, ", ")); }
private void initErrors() { if (configErrors == null) { configErrors = new ConfigErrors(); } }