Search in sources :

Example 11 with ErrorCollection

use of com.thoughtworks.go.plugin.access.configrepo.ErrorCollection in project gocd by gocd.

the class CRArtifactTest method shouldDeserializeFromAPILikeObject.

@Test
public void shouldDeserializeFromAPILikeObject() {
    String json = "{\n" + "      \"source\": \"test\",\n" + "      \"destination\": \"res1\",\n" + "      \"type\": \"test\"\n" + "    }";
    CRArtifact deserializedValue = gson.fromJson(json, CRArtifact.class);
    assertThat(deserializedValue.getSource(), is("test"));
    assertThat(deserializedValue.getDestination(), is("res1"));
    assertThat(deserializedValue.getType(), is(CRArtifactType.test));
    ErrorCollection errors = deserializedValue.getErrors();
    assertTrue(errors.isEmpty());
}
Also used : ErrorCollection(com.thoughtworks.go.plugin.access.configrepo.ErrorCollection) Test(org.junit.Test)

Example 12 with ErrorCollection

use of com.thoughtworks.go.plugin.access.configrepo.ErrorCollection in project gocd by gocd.

the class CRBaseTest method shouldGetErrorsWhenDeserializedFromEmptyBlock.

@Test
public void shouldGetErrorsWhenDeserializedFromEmptyBlock() {
    String json = "{}";
    Class<? extends CRBase> typeOfT = null;
    for (T example : getGoodExamples().values()) {
        typeOfT = example.getClass();
        break;
    }
    T deserializedValue = (T) gson.fromJson(json, typeOfT);
    ErrorCollection errorCollection = new ErrorCollection();
    deserializedValue.getErrors(errorCollection, "GetErrorsWhenDeserializedFromEmptyBlockTest");
}
Also used : ErrorCollection(com.thoughtworks.go.plugin.access.configrepo.ErrorCollection) Test(org.junit.Test)

Example 13 with ErrorCollection

use of com.thoughtworks.go.plugin.access.configrepo.ErrorCollection in project gocd by gocd.

the class CRBaseTest method shouldErrorWhenBadExample.

@Test
public void shouldErrorWhenBadExample() {
    Map<String, T> examples = getBadExamples();
    for (Map.Entry<String, T> example : examples.entrySet()) {
        ErrorCollection errorCollection = new ErrorCollection();
        example.getValue().getErrors(errorCollection, "ErrorWhenBadExampleTest");
        assertThat(String.format("Example %s - invalid value should return errors", example.getKey()), errorCollection.isEmpty(), is(false));
    }
}
Also used : ErrorCollection(com.thoughtworks.go.plugin.access.configrepo.ErrorCollection) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 14 with ErrorCollection

use of com.thoughtworks.go.plugin.access.configrepo.ErrorCollection in project gocd by gocd.

the class CRPipelineTest method shouldAppendPrettyLocationInErrors_WhenPipelineHasExplicitLocationField.

@Test
public void shouldAppendPrettyLocationInErrors_WhenPipelineHasExplicitLocationField() {
    CRPipeline p = new CRPipeline();
    p.setName("pipe4");
    p.addMaterial(veryCustomGit);
    // plugin may voluntarily set this
    p.setLocation("pipe4.json");
    ErrorCollection errors = new ErrorCollection();
    p.getErrors(errors, "TEST");
    String fullError = errors.getErrorsAsText();
    assertThat(fullError, contains("pipe4.json; Pipeline pipe4"));
    assertThat(fullError, contains("Missing field 'group'"));
    assertThat(fullError, contains("Pipeline has no stages"));
}
Also used : ErrorCollection(com.thoughtworks.go.plugin.access.configrepo.ErrorCollection) Test(org.junit.Test)

Example 15 with ErrorCollection

use of com.thoughtworks.go.plugin.access.configrepo.ErrorCollection in project gocd by gocd.

the class CRPipelineTest method shouldCheckMissingDestinationDirectoryWhenManySCMs.

@Test
public void shouldCheckMissingDestinationDirectoryWhenManySCMs() {
    CRPipeline p = new CRPipeline();
    p.setName("pipe4");
    CRGitMaterial simpleGit1 = new CRGitMaterial();
    simpleGit1.setUrl("url1");
    CRGitMaterial simpleGit2 = new CRGitMaterial();
    simpleGit2.setUrl("url2");
    p.addMaterial(simpleGit1);
    p.addMaterial(simpleGit2);
    ErrorCollection errors = new ErrorCollection();
    p.getErrors(errors, "TEST");
    String fullError = errors.getErrorsAsText();
    assertThat(fullError, contains("Pipeline pipe4; Git material"));
    assertThat(fullError, contains("Material must have destination directory when there are many SCM materials"));
}
Also used : ErrorCollection(com.thoughtworks.go.plugin.access.configrepo.ErrorCollection) CRGitMaterial(com.thoughtworks.go.plugin.access.configrepo.contract.material.CRGitMaterial) Test(org.junit.Test)

Aggregations

ErrorCollection (com.thoughtworks.go.plugin.access.configrepo.ErrorCollection)18 Test (org.junit.Test)17 CRGitMaterial (com.thoughtworks.go.plugin.access.configrepo.contract.material.CRGitMaterial)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 CRBaseTest (com.thoughtworks.go.plugin.access.configrepo.contract.CRBaseTest)1 CRTimer (com.thoughtworks.go.plugin.access.configrepo.contract.CRTimer)1