Search in sources :

Example 1 with ParamsConfig

use of com.thoughtworks.go.config.ParamsConfig in project gocd by gocd.

the class ParamsConfigTest method shouldThrowAnErrorWhenNameIsEmpty.

@Test
public void shouldThrowAnErrorWhenNameIsEmpty() {
    paramsConfig = new ParamsConfig();
    ParamConfig empty = new ParamConfig("", "value");
    paramsConfig.add(empty);
    paramsConfig.validate(context);
    assertThat(empty.errors().isEmpty(), is(false));
    assertThat(empty.errors().firstError(), contains("Parameter cannot have an empty name for pipeline 'some-pipeline'."));
}
Also used : ParamsConfig(com.thoughtworks.go.config.ParamsConfig) ParamConfig(com.thoughtworks.go.config.ParamConfig) Test(org.junit.Test)

Example 2 with ParamsConfig

use of com.thoughtworks.go.config.ParamsConfig in project gocd by gocd.

the class ParamsConfigTest method getIndex_shouldThrowExceptionIfNameNotFound.

@Test
public void getIndex_shouldThrowExceptionIfNameNotFound() {
    try {
        new ParamsConfig().getIndex(null);
        fail("should throw exception if param not found");
    } catch (IllegalArgumentException e) {
    // ok
    }
}
Also used : ParamsConfig(com.thoughtworks.go.config.ParamsConfig) Test(org.junit.Test)

Example 3 with ParamsConfig

use of com.thoughtworks.go.config.ParamsConfig in project gocd by gocd.

the class ParamsConfigTest method getIndex.

@Test
public void getIndex() {
    paramsConfig = new ParamsConfig();
    ParamConfig one = new ParamConfig("name", "value");
    paramsConfig.add(one);
    ParamConfig two = new ParamConfig("other", "other-value");
    paramsConfig.add(two);
    assertThat(paramsConfig.getIndex("other"), is(1));
    assertThat(paramsConfig.getIndex("name"), is(0));
}
Also used : ParamsConfig(com.thoughtworks.go.config.ParamsConfig) ParamConfig(com.thoughtworks.go.config.ParamConfig) Test(org.junit.Test)

Example 4 with ParamsConfig

use of com.thoughtworks.go.config.ParamsConfig in project gocd by gocd.

the class ParamsConfigTest method shouldPopulateParamFromMapIgnoringEmptyPairs.

@Test
public void shouldPopulateParamFromMapIgnoringEmptyPairs() {
    paramsConfig = new ParamsConfig();
    List<Map> paramsMap = new ArrayList<>();
    paramsMap.add(createParamMap("param-name", "param-value"));
    paramsMap.add(createParamMap("", ""));
    paramsMap.add(createParamMap("", "bar"));
    paramsConfig.setConfigAttributes(paramsMap);
    assertThat(paramsConfig.size(), is(2));
    assertThat(paramsConfig.getParamNamed("param-name").getValue(), is("param-value"));
}
Also used : ParamsConfig(com.thoughtworks.go.config.ParamsConfig) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 5 with ParamsConfig

use of com.thoughtworks.go.config.ParamsConfig in project gocd by gocd.

the class ParamsConfigTest method shouldThrowAnErrorWhenDuplicateNameIsInserted.

@Test
public void shouldThrowAnErrorWhenDuplicateNameIsInserted() {
    paramsConfig = new ParamsConfig();
    ParamConfig one = new ParamConfig("name", "value");
    paramsConfig.add(one);
    ParamConfig two = new ParamConfig("name", "other-value");
    paramsConfig.add(two);
    paramsConfig.validate(context);
    assertThat(one.errors().isEmpty(), is(false));
    assertThat(one.errors().firstError(), contains("Param name 'name' is not unique for pipeline 'some-pipeline'."));
    assertThat(two.errors().isEmpty(), is(false));
    assertThat(two.errors().firstError(), contains("Param name 'name' is not unique for pipeline 'some-pipeline'."));
}
Also used : ParamsConfig(com.thoughtworks.go.config.ParamsConfig) ParamConfig(com.thoughtworks.go.config.ParamConfig) Test(org.junit.Test)

Aggregations

ParamsConfig (com.thoughtworks.go.config.ParamsConfig)5 Test (org.junit.Test)5 ParamConfig (com.thoughtworks.go.config.ParamConfig)3 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1