use of com.thoughtworks.go.domain.ConfigErrors in project gocd by gocd.
the class ErrorCollector method collectFieldErrors.
public static void collectFieldErrors(Map<String, List<String>> errorBucket, String prefix, Object subject) {
Field[] fields = subject.getClass().getDeclaredFields();
for (Field field : fields) {
String fieldName = field.getName();
Object fieldValue = null;
try {
field.setAccessible(true);
fieldValue = field.get(subject);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
// Object fieldValue = ReflectionUtil.getField(subject, fieldName);
if (isAConstantField(field) || field.isAnnotationPresent(IgnoreTraversal.class)) {
continue;
}
if (fieldValue != null && fieldValue instanceof Collection && isConfigObject(fieldValue)) {
// collection to be walked
Collection collection = (Collection) fieldValue;
int index = 0;
for (Object collectionItem : collection) {
collectFieldErrors(errorBucket, prefix + "[" + fieldName + "][" + (index++) + "]", collectionItem);
}
} else if (isConfigObject(fieldValue)) {
// object to be walked
collectFieldErrors(errorBucket, prefix + "[" + fieldName + "]", fieldValue);
} else {
// basic field
if (subject instanceof Validatable) {
ConfigErrors configErrors = ((Validatable) subject).errors();
if (configErrors != null && configErrors.getAllOn(fieldName) != null) {
errorBucket.put(prefix + "[" + fieldName + "]", configErrors.getAllOn(fieldName));
}
}
}
}
}
use of com.thoughtworks.go.domain.ConfigErrors in project gocd by gocd.
the class CruiseConfigTestBase method shouldErrorOutWhenDependsOnItself.
@Test
public void shouldErrorOutWhenDependsOnItself() throws Exception {
CruiseConfig cruiseConfig = createCruiseConfig();
PipelineConfig pipelineConfig = goConfigMother.addPipeline(cruiseConfig, "pipeline1", "stage", "build");
goConfigMother.addStageToPipeline(cruiseConfig, "pipeline1", "ft", "build");
goConfigMother.setDependencyOn(cruiseConfig, pipelineConfig, "pipeline1", "ft");
cruiseConfig.validate(null);
ConfigErrors errors = pipelineConfig.materialConfigs().errors();
assertThat(errors.on("base"), is("Circular dependency: pipeline1 <- pipeline1"));
}
use of com.thoughtworks.go.domain.ConfigErrors in project gocd by gocd.
the class CruiseConfigTestBase method shouldBuildTheValidationContextForAnOnCancelTask.
@Test
public void shouldBuildTheValidationContextForAnOnCancelTask() {
CruiseConfig config = GoConfigMother.configWithPipelines("pipeline-1");
PipelineConfig pipelineConfig = config.pipelineConfigByName(new CaseInsensitiveString("pipeline-1"));
StageConfig stageConfig = pipelineConfig.get(0);
JobConfig jobConfig = stageConfig.getJobs().get(0);
ExecTask execTask = new ExecTask("ls", "-la", "dir");
Task mockTask = mock(Task.class);
when(mockTask.errors()).thenReturn(new ConfigErrors());
execTask.setCancelTask(mockTask);
jobConfig.addTask(execTask);
config.validateAfterPreprocess();
verify(mockTask).validate(ConfigSaveValidationContext.forChain(config, config.getGroups(), config.getGroups().findGroup("defaultGroup"), pipelineConfig, stageConfig, stageConfig.getJobs(), jobConfig, jobConfig.getTasks(), execTask, execTask.onCancelConfig()));
}
use of com.thoughtworks.go.domain.ConfigErrors in project gocd by gocd.
the class CruiseConfigTestBase method shouldNotDuplicateErrorWhenPipelineDoesnotExist.
@Test
public void shouldNotDuplicateErrorWhenPipelineDoesnotExist() throws Exception {
CruiseConfig cruiseConfig = createCruiseConfig();
PipelineConfig pipelineConfig = goConfigMother.addPipeline(cruiseConfig, "pipeline1", "stage", "build");
PipelineConfig pipelineConfig2 = goConfigMother.addPipeline(cruiseConfig, "pipeline2", "stage", "build");
goConfigMother.addStageToPipeline(cruiseConfig, "pipeline1", "ft", "build");
goConfigMother.setDependencyOn(cruiseConfig, pipelineConfig2, "pipeline1", "ft");
goConfigMother.setDependencyOn(cruiseConfig, pipelineConfig, "invalid", "invalid");
cruiseConfig.validate(null);
List<ConfigErrors> allErrors = cruiseConfig.getAllErrors();
List<String> errors = new ArrayList<>();
for (ConfigErrors allError : allErrors) {
errors.addAll(allError.getAllOn("base"));
}
assertThat(errors.size(), is(1));
assertThat(errors.get(0), is("Pipeline 'invalid' does not exist. It is used from pipeline 'pipeline1'."));
}
use of com.thoughtworks.go.domain.ConfigErrors in project gocd by gocd.
the class CruiseConfigTestBase method shouldCollectAllTheErrorsInTheChildrenHelper.
protected void shouldCollectAllTheErrorsInTheChildrenHelper(CruiseConfig config) {
SecurityAuthConfig ldapConfig = new SecurityAuthConfig("ldap", "cd.go.authorization.ldap");
ldapConfig.errors().add("uri", "invalid ldap uri");
ldapConfig.errors().add("searchBase", "invalid search base");
config.server().security().securityAuthConfigs().add(ldapConfig);
PipelineConfig pipelineConfig = config.pipelineConfigByName(new CaseInsensitiveString("pipeline-1"));
pipelineConfig.errors().add("base", "Some base errors");
P4MaterialConfig p4MaterialConfig = p4("localhost:1999", "view");
p4MaterialConfig.setConfigAttributes(Collections.singletonMap(ScmMaterialConfig.FOLDER, "p4_folder"));
pipelineConfig.addMaterialConfig(p4MaterialConfig);
p4MaterialConfig.errors().add("materialName", "material name does not follow pattern");
StageConfig stage = pipelineConfig.first();
stage.errors().add("role", "Roles must be proper");
List<ConfigErrors> allErrors = config.validateAfterPreprocess();
assertThat(allErrors.size(), is(5));
assertThat(allErrors.get(0).on("uri"), is("invalid ldap uri"));
assertThat(allErrors.get(0).on("searchBase"), is("invalid search base"));
assertThat(allErrors.get(1).on("base"), is("Some base errors"));
assertThat(allErrors.get(2).on("role"), is("Roles must be proper"));
assertThat(allErrors.get(3).on(ScmMaterialConfig.FOLDER), is("Destination directory is required when a pipeline has multiple SCM materials."));
assertThat(allErrors.get(4).on("materialName"), is("material name does not follow pattern"));
}
Aggregations