}
public void testGenerate() throws Exception {
{
ByteArrayOutputStream baos = new ByteArrayOutputStream();
NodesYamlGenerator nodesYamlGenerator = new NodesYamlGenerator(baos);
try {
nodesYamlGenerator.generate();
fail("Should have thrown an Exception");
}
catch (NodesGeneratorException ex) {
}
}
{
ByteArrayOutputStream baos = new ByteArrayOutputStream();
NodesYamlGenerator nodesYamlGenerator = new NodesYamlGenerator(baos);
final NodeEntryImpl nodeEntry = new NodeEntryImpl();
nodeEntry.setNodename("test1");
nodeEntry.setHostname("testhostname");
nodesYamlGenerator.addNode(nodeEntry);
nodesYamlGenerator.generate();
final String outputString = baos.toString();
assertNotNull(outputString);
//convert via yaml
Map parsed = parseYamlMap(outputString);
assertNotNull(parsed.get("test1"));
assertTrue(parsed.get("test1") instanceof Map);
Map node1 = (Map) parsed.get("test1");
assertEquals("testhostname", node1.get("hostname"));
assertEquals("test1", node1.get("nodename"));
assertEquals("", node1.get("tags"));
}
{
ByteArrayOutputStream baos = new ByteArrayOutputStream();
NodesYamlGenerator nodesYamlGenerator = new NodesYamlGenerator(baos);
final NodeEntryImpl nodeEntry = new NodeEntryImpl();
nodeEntry.setNodename("test1");
nodeEntry.setHostname("testhostname");
nodeEntry.setDescription("test description");
nodeEntry.setOsArch("an os arch");
nodeEntry.setOsFamily("an os fam");
nodeEntry.setOsName("an os name");
nodeEntry.setOsVersion("an os vers");
nodeEntry.setUsername("someUser");
nodeEntry.setTags(new HashSet());
nodesYamlGenerator.addNode(nodeEntry);
nodesYamlGenerator.generate();
final String outputString = baos.toString();
assertNotNull(outputString);
//convert via yaml
Map parsed = parseYamlMap(outputString);
assertNotNull(parsed.get("test1"));
assertTrue(parsed.get("test1") instanceof Map);
Map node1 = (Map) parsed.get("test1");
assertEquals("test description", node1.get("description"));
assertEquals("testhostname", node1.get("hostname"));
assertEquals("test1", node1.get("nodename"));
assertEquals("an os arch", node1.get("osArch"));
assertEquals("an os fam", node1.get("osFamily"));
assertEquals("an os name", node1.get("osName"));
assertEquals("an os vers", node1.get("osVersion"));
assertEquals("someUser", node1.get("username"));
assertEquals("", node1.get("tags"));
}
{
ByteArrayOutputStream baos = new ByteArrayOutputStream();
NodesYamlGenerator nodesYamlGenerator = new NodesYamlGenerator(baos);
final NodeEntryImpl nodeEntry = new NodeEntryImpl();
nodeEntry.setNodename("strongbad");
nodeEntry.setHostname("strongbad");
nodeEntry.setDescription("Rundeck server node");
nodeEntry.setOsArch("x86_64");
nodeEntry.setOsFamily("unix");
nodeEntry.setOsName("Mac OS X");
nodeEntry.setOsVersion("10.6.5");
nodeEntry.setUsername("alexh");
nodeEntry.setFrameworkProject("ignored");
final HashSet tags = new HashSet();
tags.add("rundeck");
tags.add("dev");
tags.add("ops");
nodeEntry.setTags(tags);
/**
* strongbad:
type: Node
description: "Rundeck server node"
hostname: "strongbad"
osArch: "x86_64"
osFamily: "unix"
osName: "Mac OS X"
osVersion: "10.6.5"
username: "alexh"
editUrl: ""
remoteUrl: ""
tags: "rundeck"
*/
nodesYamlGenerator.addNode(nodeEntry);
nodesYamlGenerator.generate();
final String outputString = baos.toString();
assertNotNull(outputString);
//convert via yaml
Map parsed = parseYamlMap(outputString);
assertNotNull(parsed.get("strongbad"));