use of com.amazonaws.services.cloudformation.model.Parameter in project pipeline-aws-plugin by jenkinsci.
the class ParameterParseTests method parseMap.
@Test
public void parseMap() throws IOException {
ParameterProvider parameterProvider = Mockito.mock(ParameterProvider.class);
Mockito.when(parameterProvider.getParams()).thenReturn(new HashMap<String, Object>() {
{
put("foo", "true");
put("baz", false);
put("bar", 25);
}
});
Collection<Parameter> parameters = ParameterParser.parse(new FilePath(temporaryFolder.newFolder()), parameterProvider);
Assertions.assertThat(parameters).containsExactlyInAnyOrder(new Parameter().withParameterKey("foo").withParameterValue("true"), new Parameter().withParameterKey("baz").withParameterValue("false"), new Parameter().withParameterKey("bar").withParameterValue("25"));
}
use of com.amazonaws.services.cloudformation.model.Parameter in project pipeline-aws-plugin by jenkinsci.
the class YAMLParameterFileParserTests method parseParameterCollection.
@Test
public void parseParameterCollection() throws IOException {
YAMLParameterFileParser parser = new YAMLParameterFileParser();
String json = "bar:\n - foo1\n - foo2";
Collection<Parameter> parameters = parser.parseParams(new StringInputStream(json));
Assertions.assertThat(parameters).containsExactlyInAnyOrder(new Parameter().withParameterKey("bar").withParameterValue("foo1,foo2"));
}
use of com.amazonaws.services.cloudformation.model.Parameter in project pipeline-aws-plugin by jenkinsci.
the class JSONParameterFileParser method parseParams.
@Override
public Collection<Parameter> parseParams(InputStream fileContent) throws IOException {
ObjectMapper mapper = new ObjectMapper();
JsonNode tree = mapper.readTree(fileContent);
Collection<Parameter> parameters = new ArrayList<>();
if (tree instanceof ArrayNode) {
ArrayNode jsonNodes = (ArrayNode) tree;
for (JsonNode node : jsonNodes) {
Parameter param = new Parameter();
param.withParameterKey(node.get("ParameterKey").asText());
if (node.has("ParameterValue")) {
param.withParameterValue(node.get("ParameterValue").asText());
}
if (node.has("UsePreviousValue")) {
param.withUsePreviousValue(node.get("UsePreviousValue").booleanValue());
}
parameters.add(param);
}
}
return parameters;
}
use of com.amazonaws.services.cloudformation.model.Parameter in project pipeline-aws-plugin by jenkinsci.
the class YAMLParameterFileParser method parseParams.
@Override
public Collection<Parameter> parseParams(InputStream fileContent) throws IOException {
Yaml yaml = new Yaml();
@SuppressWarnings("unchecked") Map<String, Object> parse = yaml.load(new InputStreamReader(fileContent, Charsets.UTF_8));
Collection<Parameter> parameters = new ArrayList<>();
for (Map.Entry<String, Object> entry : parse.entrySet()) {
Object value = entry.getValue();
if (value instanceof Collection) {
String val = Joiner.on(",").join((Collection) value);
parameters.add(new Parameter().withParameterKey(entry.getKey()).withParameterValue(val));
} else {
parameters.add(new Parameter().withParameterKey(entry.getKey()).withParameterValue(value.toString()));
}
}
return parameters;
}
use of com.amazonaws.services.cloudformation.model.Parameter in project pipeline-aws-plugin by jenkinsci.
the class ParameterParserTest method shouldParseYAML.
@Test
public void shouldParseYAML() throws Exception {
YAMLParameterFileParser parser = new YAMLParameterFileParser();
Collection<Parameter> parameters = parser.parseParams(this.getClass().getResourceAsStream("/params.yaml"));
Parameter[] array = parameters.toArray(new Parameter[0]);
Assert.assertEquals(2, array.length);
Parameter param1 = array[0];
Assert.assertEquals("Param1", param1.getParameterKey());
Assert.assertEquals("Value1", param1.getParameterValue());
Parameter param2 = array[1];
Assert.assertEquals("Param2", param2.getParameterKey());
Assert.assertEquals("Val2a,Val2b", param2.getParameterValue());
}
Aggregations