Search in sources :

Example 1 with CRMaterial

use of com.thoughtworks.go.plugin.access.configrepo.contract.material.CRMaterial in project gocd by gocd.

the class CRPipelineTest method shouldAddAnErrorForDuplicateParameterNames.

@Test
public void shouldAddAnErrorForDuplicateParameterNames() throws Exception {
    ArrayList<CRMaterial> materials = new ArrayList<>();
    materials.add(veryCustomGit);
    ArrayList<CRParameter> crParameters = new ArrayList<>();
    crParameters.add(new CRParameter("param1", "value1"));
    crParameters.add(new CRParameter("param1", "value2"));
    CRPipeline crPipeline = new CRPipeline("p1", "g1", "label", LOCK_VALUE_LOCK_ON_FAILURE, null, null, null, new ArrayList<>(), materials, null, "t1", crParameters);
    ErrorCollection errors = new ErrorCollection();
    crPipeline.getErrors(errors, "TEST");
    assertThat(errors.getErrorsAsText(), contains("Param name 'param1' is not unique."));
}
Also used : ErrorCollection(com.thoughtworks.go.plugin.access.configrepo.ErrorCollection) CRMaterial(com.thoughtworks.go.plugin.access.configrepo.contract.material.CRMaterial) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 2 with CRMaterial

use of com.thoughtworks.go.plugin.access.configrepo.contract.material.CRMaterial in project gocd by gocd.

the class CRPipelineTest method shouldAddAnErrorForDuplicateEnvironmentVariables.

@Test
public void shouldAddAnErrorForDuplicateEnvironmentVariables() throws Exception {
    ArrayList<CRMaterial> materials = new ArrayList<>();
    materials.add(veryCustomGit);
    ArrayList<CREnvironmentVariable> crEnvironmentVariables = new ArrayList<>();
    crEnvironmentVariables.add(new CREnvironmentVariable("env1", "value1"));
    crEnvironmentVariables.add(new CREnvironmentVariable("env1", "value2"));
    CRPipeline crPipeline = new CRPipeline("p1", "g1", "label", LOCK_VALUE_LOCK_ON_FAILURE, null, null, null, crEnvironmentVariables, materials, null, "t1", new ArrayList<>());
    ErrorCollection errors = new ErrorCollection();
    crPipeline.getErrors(errors, "TEST");
    assertThat(errors.getErrorsAsText(), contains("Environment variable env1 defined more than once"));
}
Also used : ErrorCollection(com.thoughtworks.go.plugin.access.configrepo.ErrorCollection) CRMaterial(com.thoughtworks.go.plugin.access.configrepo.contract.material.CRMaterial) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 3 with CRMaterial

use of com.thoughtworks.go.plugin.access.configrepo.contract.material.CRMaterial in project gocd by gocd.

the class CRPipeline method getErrors.

@Override
public void getErrors(ErrorCollection errors, String parentLocation) {
    String location = this.getLocation(parentLocation);
    errors.checkMissing(location, "name", name);
    errors.checkMissing(location, "group", group);
    errors.checkMissing(location, "materials", materials);
    validateAtLeastOneMaterial(errors, location);
    if (materials != null) {
        for (CRMaterial material : this.materials) {
            material.getErrors(errors, location);
        }
        if (materials.size() > 1) {
            validateMaterialNameUniqueness(errors, location);
            validateScmMaterials(errors, location);
        }
    }
    validateTemplateOrStages(errors, location);
    if (!hasTemplate()) {
        validateAtLeastOneStage(errors, location);
        if (stages != null) {
            for (CRStage stage : this.stages) {
                stage.getErrors(errors, location);
            }
            if (stages.size() > 1) {
                validateStageNameUniqueness(errors, location);
            }
        }
    }
    validateEnvironmentVariableUniqueness(errors, location);
    validateParamNameUniqueness(errors, location);
    validateLockBehaviorValue(errors, location);
}
Also used : CRMaterial(com.thoughtworks.go.plugin.access.configrepo.contract.material.CRMaterial)

Example 4 with CRMaterial

use of com.thoughtworks.go.plugin.access.configrepo.contract.material.CRMaterial in project gocd by gocd.

the class CRPipelineTest method shouldHandlePolymorphismWhenDeserializingJobs.

@Test
public void shouldHandlePolymorphismWhenDeserializingJobs() {
    String json = gson.toJson(pipe1);
    CRPipeline deserializedValue = gson.fromJson(json, CRPipeline.class);
    CRMaterial git = deserializedValue.getMaterialByName("gitMaterial1");
    assertThat(git instanceof CRGitMaterial, is(true));
    assertThat(((CRGitMaterial) git).getBranch(), is("feature12"));
}
Also used : CRGitMaterial(com.thoughtworks.go.plugin.access.configrepo.contract.material.CRGitMaterial) CRMaterial(com.thoughtworks.go.plugin.access.configrepo.contract.material.CRMaterial) Test(org.junit.Test)

Example 5 with CRMaterial

use of com.thoughtworks.go.plugin.access.configrepo.contract.material.CRMaterial in project gocd by gocd.

the class CRPipelineTest method shouldAddAnErrorIfNeitherTemplateOrStagesAreDefined.

@Test
public void shouldAddAnErrorIfNeitherTemplateOrStagesAreDefined() throws Exception {
    ArrayList<CRMaterial> materials = new ArrayList<>();
    materials.add(veryCustomGit);
    CRPipeline crPipeline = new CRPipeline("p1", "g1", "label", LOCK_VALUE_LOCK_ON_FAILURE, null, null, null, new ArrayList<>(), materials, new ArrayList<>(), null, new ArrayList<>());
    ErrorCollection errorCollection = new ErrorCollection();
    crPipeline.getErrors(errorCollection, "TEST");
    assertThat(errorCollection.getErrorsAsText(), contains("Pipeline has to define stages or template."));
}
Also used : ErrorCollection(com.thoughtworks.go.plugin.access.configrepo.ErrorCollection) CRMaterial(com.thoughtworks.go.plugin.access.configrepo.contract.material.CRMaterial) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

CRMaterial (com.thoughtworks.go.plugin.access.configrepo.contract.material.CRMaterial)5 Test (org.junit.Test)4 ErrorCollection (com.thoughtworks.go.plugin.access.configrepo.ErrorCollection)3 ArrayList (java.util.ArrayList)3 CRGitMaterial (com.thoughtworks.go.plugin.access.configrepo.contract.material.CRGitMaterial)1