Search in sources :

Example 21 with ConfigErrors

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."));
}
Also used : DependencyMaterialConfig(com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig) ConfigErrors(com.thoughtworks.go.domain.ConfigErrors) Test(org.junit.Test)

Example 22 with ConfigErrors

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;
}
Also used : EnvironmentConfig(com.thoughtworks.go.config.EnvironmentConfig) ArrayList(java.util.ArrayList) EnvironmentAgentConfig(com.thoughtworks.go.config.EnvironmentAgentConfig) ConfigErrors(com.thoughtworks.go.domain.ConfigErrors)

Example 23 with ConfigErrors

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));
                }
            }
        }
    }
}
Also used : Field(java.lang.reflect.Field) IgnoreTraversal(com.thoughtworks.go.config.IgnoreTraversal) Collection(java.util.Collection) Validatable(com.thoughtworks.go.config.Validatable) ConfigErrors(com.thoughtworks.go.domain.ConfigErrors)

Aggregations

ConfigErrors (com.thoughtworks.go.domain.ConfigErrors)23 Test (org.junit.Test)15 ArrayList (java.util.ArrayList)4 GoConfigInvalidException (com.thoughtworks.go.config.exceptions.GoConfigInvalidException)3 DependencyMaterialConfig (com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig)3 StringContains.containsString (org.hamcrest.core.StringContains.containsString)3 Cloner (com.rits.cloning.Cloner)2 IOException (java.io.IOException)2 AgentConfig (com.thoughtworks.go.config.AgentConfig)1 EnvironmentAgentConfig (com.thoughtworks.go.config.EnvironmentAgentConfig)1 EnvironmentConfig (com.thoughtworks.go.config.EnvironmentConfig)1 GoConfigDao (com.thoughtworks.go.config.GoConfigDao)1 IgnoreTraversal (com.thoughtworks.go.config.IgnoreTraversal)1 Validatable (com.thoughtworks.go.config.Validatable)1 ConfigFileHasChangedException (com.thoughtworks.go.config.exceptions.ConfigFileHasChangedException)1 ConfigMergeException (com.thoughtworks.go.config.exceptions.ConfigMergeException)1 GoConfigInvalidMergeException (com.thoughtworks.go.config.exceptions.GoConfigInvalidMergeException)1 MaterialConfigs (com.thoughtworks.go.config.materials.MaterialConfigs)1 UpdateEnvironmentsCommand (com.thoughtworks.go.config.update.UpdateEnvironmentsCommand)1 UpdateResourceCommand (com.thoughtworks.go.config.update.UpdateResourceCommand)1