public void testParse() throws Exception {
{
testReceiver recv = new testReceiver();
NodesYamlParser nodesYamlParser = new NodesYamlParser((File) null, recv);
try {
nodesYamlParser.parse();
fail("Should have thrown an Exception");
}
catch (NullPointerException ex) {
}
}
{
testReceiver recv = new testReceiver();
ByteArrayInputStream is = new ByteArrayInputStream(
"test: \n hostname: test\n".getBytes());
NodesYamlParser nodesYamlParser = new NodesYamlParser(is, recv);
nodesYamlParser.parse();
assertEquals(1, recv.nodes.size());
assertTrue(recv.nodes.containsKey("test"));
INodeEntry entry = recv.nodes.get("test");
assertNotNull(entry);
assertEquals("test", entry.getNodename());
assertEquals("test", entry.getHostname());
assertNotNull(entry.getTags());
assertEquals(0, entry.getTags().size());
assertNull(entry.getOsArch());
assertNull(entry.getOsFamily());
assertNull(entry.getOsVersion());
assertNull(entry.getOsName());
assertNotNull(entry.getAttributes());
assertNull(entry.getDescription());
assertNull(entry.getFrameworkProject());
assertNull(entry.getUsername());
}
{
//test key for map data always overrides node name
testReceiver recv = new testReceiver();
ByteArrayInputStream is = new ByteArrayInputStream(
"test: \n nodename: bill\n hostname: test\n".getBytes());
NodesYamlParser nodesYamlParser = new NodesYamlParser(is, recv);
nodesYamlParser.parse();
assertEquals(1, recv.nodes.size());
assertTrue(recv.nodes.containsKey("test"));
INodeEntry entry = recv.nodes.get("test");
assertNotNull(entry);
assertEquals("test", entry.getNodename());
assertEquals("test", entry.getHostname());
assertNotNull(entry.getTags());
assertEquals(0, entry.getTags().size());
assertNull(entry.getOsArch());
assertNull(entry.getOsFamily());
assertNull(entry.getOsVersion());
assertNull(entry.getOsName());
assertNotNull(entry.getAttributes());
assertNull(entry.getDescription());
assertNull(entry.getFrameworkProject());
assertNull(entry.getUsername());
}
{
testReceiver recv = new testReceiver();
ByteArrayInputStream is = new ByteArrayInputStream(
("test: \n"
+ " hostname: test\n"
+ " description: a description\n"
+ " tags: a, b, c\n"
+ " osArch: x86_64\n"
+ " osFamily: unix\n"
+ " osVersion: 10.6.5\n"
+ " osName: Mac OS X\n"
+ " username: a user\n"
//following should be ignored
+ " nodename: bill\n"
+ " attributes: test\n"
+ " settings: test2\n"
+ " type: blahtype\n"
+ " frameworkProject: ignored\n").getBytes());
NodesYamlParser nodesYamlParser = new NodesYamlParser(is, recv);
nodesYamlParser.parse();
assertEquals(1, recv.nodes.size());
assertTrue(recv.nodes.containsKey("test"));
INodeEntry entry = recv.nodes.get("test");
assertNotNull(entry);
assertEquals("test", entry.getNodename());
assertEquals("test", entry.getHostname());
assertNotNull(entry.getTags());
assertEquals(3,entry.getTags().size());
assertTrue(entry.getTags().contains("a"));
assertTrue(entry.getTags().contains("b"));
assertTrue(entry.getTags().contains("c"));
assertEquals("x86_64", entry.getOsArch());
assertEquals("unix", entry.getOsFamily());
assertEquals("10.6.5", entry.getOsVersion());
assertEquals("Mac OS X", entry.getOsName());
assertEquals("a description",entry.getDescription());
assertEquals("a user", entry.getUsername());
//null values should be ignored
assertNotNull(entry.getAttributes());
assertNull(entry.getFrameworkProject());
}
{
//test tags receiving Sequence data explicitly
testReceiver recv = new testReceiver();
ByteArrayInputStream is = new ByteArrayInputStream(
("test: \n"
+ " nodename: bill\n"
+ " hostname: test\n"
+ " tags: [ a, b, c ]\n"
).getBytes());
NodesYamlParser nodesYamlParser = new NodesYamlParser(is, recv);
nodesYamlParser.parse();
assertEquals(1, recv.nodes.size());
assertTrue(recv.nodes.containsKey("test"));
INodeEntry entry = recv.nodes.get("test");
assertNotNull(entry);
assertEquals("test", entry.getNodename());
assertEquals("test", entry.getHostname());
assertNotNull(entry.getTags());
assertEquals(3,entry.getTags().size());
assertTrue(entry.getTags().contains("a"));
assertTrue(entry.getTags().contains("b"));
assertTrue(entry.getTags().contains("c"));
}
{
//test flow style data
testReceiver recv = new testReceiver();
ByteArrayInputStream is = new ByteArrayInputStream(
("ubuntu: {description: \"Ubuntu server node\", hostname: \"192.168.1.101\","
+ " osFamily: \"unix\", osName: \"Linux\", username: \"demo\", tags: \"dev\"}").getBytes());
NodesYamlParser nodesYamlParser = new NodesYamlParser(is, recv);
nodesYamlParser.parse();
assertEquals(1, recv.nodes.size());
assertTrue(recv.nodes.containsKey("ubuntu"));
INodeEntry entry = recv.nodes.get("ubuntu");
assertNotNull(entry);
assertEquals("ubuntu", entry.getNodename());