use of com.thoughtworks.go.domain.ConfigErrors in project gocd by gocd.
the class MaterialConfigsTest method shouldNotAllowMultipleDependenciesForTheSamePipelines.
@Test
public void shouldNotAllowMultipleDependenciesForTheSamePipelines() throws Exception {
CruiseConfig config = GoConfigMother.configWithPipelines("pipeline1", "pipeline2", "pipeline3", "go");
DependencyMaterialConfig dependencyMaterial = new DependencyMaterialConfig(new CaseInsensitiveString("pipeline2"), new CaseInsensitiveString("stage"));
DependencyMaterialConfig duplicateDependencyMaterial = new DependencyMaterialConfig(new CaseInsensitiveString("pipeline2"), new CaseInsensitiveString("stage"));
MaterialConfigs materialConfigs = new MaterialConfigs(dependencyMaterial, duplicateDependencyMaterial);
ValidationContext validationContext = ConfigSaveValidationContext.forChain(config);
materialConfigs.validate(validationContext);
ConfigErrors errors = duplicateDependencyMaterial.errors();
assertThat(errors.isEmpty(), is(false));
assertThat(errors.on("pipelineStageName"), is("A pipeline can depend on each upstream pipeline only once. Remove one of the occurrences of 'pipeline2' from the current pipeline dependencies."));
}
use of com.thoughtworks.go.domain.ConfigErrors in project gocd by gocd.
the class EnvironmentAgentValidator method validateConfig.
public List<ConfigErrors> validateConfig(CruiseConfig cruiseConfig) {
List<ConfigErrors> errors = new ArrayList<>();
Set<String> uuids = cruiseConfig.agents().acceptedUuids();
if (!cruiseConfig.getEnvironments().validateContainOnlyUuids(uuids)) {
for (EnvironmentConfig environmentConfig : cruiseConfig.getEnvironments()) {
for (EnvironmentAgentConfig environmentAgentConfig : environmentConfig.getAgents()) {
if (!environmentAgentConfig.errors().isEmpty()) {
errors.add(environmentAgentConfig.errors());
}
}
}
}
return errors;
}
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));
}
}
}
}
}
Aggregations