Package com.dtolabs.rundeck.core.common

Examples of com.dtolabs.rundeck.core.common.NodesYamlParser



    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());
View Full Code Here


                 + "  hostname: test\n"
                 + "  tags: [ a, b, c ]\n"
                 + "  my-attribute: some value\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());
View Full Code Here

                 + "  osName: Mac OS X\n"
                 + "  username: a user\n"
                 + "  editUrl: http://a.com/url\n"
                 + "  remoteUrl: http://b.com/aurl\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());
View Full Code Here

            //no hostname value
            testReceiver recv = new testReceiver();
            ByteArrayInputStream is = new ByteArrayInputStream(
                "- \n  hostname: bill\n  blah: test\n".getBytes());

            NodesYamlParser nodesYamlParser = new NodesYamlParser(is, recv);
            try {
                nodesYamlParser.parse();
                fail("parsing should fail");
            } catch (NodeFileParserException e) {
                assertTrue(e.getCause() instanceof IllegalArgumentException);
                assertEquals("Required property 'nodename' was not specified", e.getCause().getMessage());
            }

        }
        {
            //no hostname value
            testReceiver recv = new testReceiver();
            ByteArrayInputStream is = new ByteArrayInputStream(
                "test: \n  nodename: bill\n  blah: test\n".getBytes());

            NodesYamlParser nodesYamlParser = new NodesYamlParser(is, recv);
            try {
                nodesYamlParser.parse();
                fail("parsing should fail");
            } catch (NodeFileParserException e) {
                assertTrue(e.getCause() instanceof IllegalArgumentException);
                assertEquals("Required property 'hostname' was not specified", e.getCause().getMessage());
            }

        }
        {
            //unexpected data type for string field
            testReceiver recv = new testReceiver();
            ByteArrayInputStream is = new ByteArrayInputStream(
                ("test: \n"
                 + "  nodename: bill\n"
                 + "  hostname: test\n"
                 + "  username: {test:value, a:b}\n").getBytes());

            NodesYamlParser nodesYamlParser = new NodesYamlParser(is, recv);
            try {
                nodesYamlParser.parse();
                fail("parsing should fail: " + recv.nodes);
            } catch (NodeFileParserException e) {
                assertTrue(e.getCause() instanceof YAMLException);
            }

        }
        {
            //don't allow arbitrary java class
            testReceiver recv = new testReceiver();
            ByteArrayInputStream is = new ByteArrayInputStream(
                ("test: \n"
                 + "  nodename: bill\n"
                 + "  hostname: test\n"
                 + "  username: !!java.io.File [woops.txt]\n").getBytes());

            NodesYamlParser nodesYamlParser = new NodesYamlParser(is, recv);
            try {
                nodesYamlParser.parse();
                fail("parsing should fail: " + recv.nodes);
            } catch (NodeFileParserException e) {
                assertTrue(e.getCause() instanceof YAMLException);
            }
View Full Code Here

    }

    public INodeSet parseDocument(final File file) throws ResourceFormatParserException {
        final NodeSetImpl nodes = new NodeSetImpl();
        try {
            new NodesYamlParser(file, nodes).parse();
        } catch (NodeFileParserException e) {
            throw new ResourceFormatParserException(e);
        }
        return nodes;
    }
View Full Code Here

    }

    public INodeSet parseDocument(final InputStream input) throws ResourceFormatParserException {
        final NodeSetImpl nodes = new NodeSetImpl();
        try {
            new NodesYamlParser(input, nodes).parse();
        } catch (NodeFileParserException e) {
            throw new ResourceFormatParserException(e);
        }
        return nodes;
    }
View Full Code Here

TOP

Related Classes of com.dtolabs.rundeck.core.common.NodesYamlParser

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.