Package com.dtolabs.rundeck.core.common

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


            return purgeJobsResult;
        }
    }

    public void testRun() throws Exception {
        final Framework framework = getFrameworkInstance();
        {
            //test list action
            //test null  result

            final JobsTool tool = new JobsTool(framework);
            final testCentralDispatcher1 centralDispatcher1 = new testCentralDispatcher1();
            framework.setCentralDispatcherMgr(centralDispatcher1);

            try {
                tool.run(new String[]{"list","-p","test"});
                fail("run should fail");
            } catch (JobsToolException e) {
                assertTrue(e.getMessage().startsWith("List request returned null"));
            }
        }
        {
            //test list action missing -p flag
            //test 0 items result

            final JobsTool tool = new JobsTool(framework);
            final testCentralDispatcher1 centralDispatcher1 = new testCentralDispatcher1();
            framework.setCentralDispatcherMgr(centralDispatcher1);

            final ArrayList<IStoredJob> jobs = new ArrayList<IStoredJob>();
            centralDispatcher1.listJobsResult = jobs;

            try {
                tool.run(new String[]{"list"});
                fail("run should fail");
            } catch (CLIToolOptionsException e) {
                assertTrue(e.getMessage().startsWith("list action: -p/--project option is required"));
            }
        }
        {
            //test list action
            //test 0 items result

            final JobsTool tool = new JobsTool(framework);
            final testCentralDispatcher1 centralDispatcher1 = new testCentralDispatcher1();
            framework.setCentralDispatcherMgr(centralDispatcher1);

            final ArrayList<IStoredJob> jobs = new ArrayList<IStoredJob>();
            centralDispatcher1.listJobsResult = jobs;

            tool.run(new String[]{"list", "-p", "test"});
            assertTrue("list action was not called", centralDispatcher1.listStoredJobsCalled);
            assertFalse("load action should not be called", centralDispatcher1.loadJobsCalled);
            assertNotNull(centralDispatcher1.listStoredJobsQuery);
            assertNull(centralDispatcher1.listStoredJobsOutput);
            assertEquals(JobDefinitionFileFormat.xml,centralDispatcher1.listFormat);
        }
        {
            //test list action with output file
            //test 0 items result

            final JobsTool tool = new JobsTool(framework);
            final testCentralDispatcher1 centralDispatcher1 = new testCentralDispatcher1();
            framework.setCentralDispatcherMgr(centralDispatcher1);
            File t = File.createTempFile("TestJobsTool", "xml");
            t.deleteOnExit();

            final ArrayList<IStoredJob> jobs = new ArrayList<IStoredJob>();
            centralDispatcher1.listJobsResult = jobs;

            tool.run(new String[]{"list", "-f", t.getAbsolutePath(), "-p", "test"});
            assertTrue("list action was not called", centralDispatcher1.listStoredJobsCalled);
            assertFalse("load action should not be called", centralDispatcher1.loadJobsCalled);
            assertNotNull(centralDispatcher1.listStoredJobsQuery);
            assertNotNull(centralDispatcher1.listStoredJobsOutput);
            assertEquals(JobDefinitionFileFormat.xml, centralDispatcher1.listFormat);
        }
        {
            //test list action with output file, yaml format
            //test 0 items result

            final JobsTool tool = new JobsTool(framework);
            final testCentralDispatcher1 centralDispatcher1 = new testCentralDispatcher1();
            framework.setCentralDispatcherMgr(centralDispatcher1);
            File t = File.createTempFile("TestJobsTool", "xml");
            t.deleteOnExit();

            final ArrayList<IStoredJob> jobs = new ArrayList<IStoredJob>();
            centralDispatcher1.listJobsResult = jobs;

            tool.run(new String[]{"list", "-f", t.getAbsolutePath(), "-" + JobsTool.FORMAT_OPTION,
                JobDefinitionFileFormat.yaml.getName(), "-p", "test"});
            assertTrue("list action was not called", centralDispatcher1.listStoredJobsCalled);
            assertFalse("load action should not be called", centralDispatcher1.loadJobsCalled);
            assertNotNull(centralDispatcher1.listStoredJobsQuery);
            assertNotNull(centralDispatcher1.listStoredJobsOutput);
            assertEquals(JobDefinitionFileFormat.yaml, centralDispatcher1.listFormat);
        }
        {
            //test list action with query params, -n

            final JobsTool tool = new JobsTool(framework);
            final testCentralDispatcher1 centralDispatcher1 = new testCentralDispatcher1();
            framework.setCentralDispatcherMgr(centralDispatcher1);

            final ArrayList<IStoredJob> jobs = new ArrayList<IStoredJob>();
            centralDispatcher1.listJobsResult = jobs;

            tool.run(new String[]{"list", "-" + JobsTool.NAME_OPTION, "name1", "-p", "test"});
            assertTrue("list action was not called", centralDispatcher1.listStoredJobsCalled);
            assertFalse("load action should not be called", centralDispatcher1.loadJobsCalled);
            assertNull(centralDispatcher1.listStoredJobsOutput);
            assertNotNull(centralDispatcher1.listStoredJobsQuery);
            assertEquals("name1", centralDispatcher1.listStoredJobsQuery.getNameMatch());
            assertEquals(JobDefinitionFileFormat.xml, centralDispatcher1.listFormat);
        }
        {
            //test list action with query params, --name

            final JobsTool tool = new JobsTool(framework);
            final testCentralDispatcher1 centralDispatcher1 = new testCentralDispatcher1();
            framework.setCentralDispatcherMgr(centralDispatcher1);

            final ArrayList<IStoredJob> jobs = new ArrayList<IStoredJob>();
            centralDispatcher1.listJobsResult = jobs;

            tool.run(new String[]{"list", "--" + JobsTool.NAME_OPTION_LONG, "name1", "-p", "test"});
            assertTrue("list action was not called", centralDispatcher1.listStoredJobsCalled);
            assertFalse("load action should not be called", centralDispatcher1.loadJobsCalled);
            assertNull(centralDispatcher1.listStoredJobsOutput);
            assertNotNull(centralDispatcher1.listStoredJobsQuery);
            assertEquals("name1", centralDispatcher1.listStoredJobsQuery.getNameMatch());
            assertEquals(JobDefinitionFileFormat.xml, centralDispatcher1.listFormat);
        }
        {
            //test list action with query params, -g

            final JobsTool tool = new JobsTool(framework);
            final testCentralDispatcher1 centralDispatcher1 = new testCentralDispatcher1();
            framework.setCentralDispatcherMgr(centralDispatcher1);

            final ArrayList<IStoredJob> jobs = new ArrayList<IStoredJob>();
            centralDispatcher1.listJobsResult = jobs;

            tool.run(new String[]{"list", "-" + JobsTool.GROUP_OPTION, "group1", "-p", "test"});
            assertTrue("list action was not called", centralDispatcher1.listStoredJobsCalled);
            assertFalse("load action should not be called", centralDispatcher1.loadJobsCalled);
            assertNull(centralDispatcher1.listStoredJobsOutput);
            assertNotNull(centralDispatcher1.listStoredJobsQuery);
            assertEquals("group1", centralDispatcher1.listStoredJobsQuery.getGroupMatch());
            assertEquals(JobDefinitionFileFormat.xml, centralDispatcher1.listFormat);
        }
        {
            //test list action with query params, --group

            final JobsTool tool = new JobsTool(framework);
            final testCentralDispatcher1 centralDispatcher1 = new testCentralDispatcher1();
            framework.setCentralDispatcherMgr(centralDispatcher1);

            final ArrayList<IStoredJob> jobs = new ArrayList<IStoredJob>();
            centralDispatcher1.listJobsResult = jobs;

            tool.run(new String[]{"list", "--" + JobsTool.GROUP_OPTION_LONG, "group2", "-p", "test"});
            assertTrue("list action was not called", centralDispatcher1.listStoredJobsCalled);
            assertFalse("load action should not be called", centralDispatcher1.loadJobsCalled);
            assertNull(centralDispatcher1.listStoredJobsOutput);
            assertNotNull(centralDispatcher1.listStoredJobsQuery);
            assertEquals("group2", centralDispatcher1.listStoredJobsQuery.getGroupMatch());
            assertEquals(JobDefinitionFileFormat.xml, centralDispatcher1.listFormat);
        }
        {
            //test list action with query params, -i

            final JobsTool tool = new JobsTool(framework);
            final testCentralDispatcher1 centralDispatcher1 = new testCentralDispatcher1();
            framework.setCentralDispatcherMgr(centralDispatcher1);

            final ArrayList<IStoredJob> jobs = new ArrayList<IStoredJob>();
            centralDispatcher1.listJobsResult = jobs;

            tool.run(
                new String[]{"list""-" + JobsTool.IDLIST_OPTION, "1,2", "-p", "test"});
            assertTrue("list action was not called", centralDispatcher1.listStoredJobsCalled);
            assertFalse("load action should not be called", centralDispatcher1.loadJobsCalled);
            assertNull(centralDispatcher1.listStoredJobsOutput);
            assertNotNull(centralDispatcher1.listStoredJobsQuery);
            assertEquals("1,2", centralDispatcher1.listStoredJobsQuery.getIdlist());
            assertEquals(JobDefinitionFileFormat.xml, centralDispatcher1.listFormat);
        }
        {
            //test list action with query params, --idlist

            final JobsTool tool = new JobsTool(framework);
            final testCentralDispatcher1 centralDispatcher1 = new testCentralDispatcher1();
            framework.setCentralDispatcherMgr(centralDispatcher1);

            final ArrayList<IStoredJob> jobs = new ArrayList<IStoredJob>();
            centralDispatcher1.listJobsResult = jobs;

            tool.run(
View Full Code Here


    }
    public void testJobOptionGroups() throws Exception {

        {
            //-j option but no -p option, defaulted project name
            final Framework framework = getFrameworkInstance();
            final testCentralDispatcher1 centralDispatcher1 = new testCentralDispatcher1();
            framework.setCentralDispatcherMgr(centralDispatcher1);
            centralDispatcher1.queueDispatcherJobResult = QueuedItemResultImpl.successful("test", "123", "blah",
                "blah");

            final RunTool tool = new RunTool(framework);
View Full Code Here

    }
    public void testJobOptionId() throws Exception {

        {
            //-j option but no -p option, defaulted project name
            final Framework framework = getFrameworkInstance();
            final testCentralDispatcher1 centralDispatcher1 = new testCentralDispatcher1();
            framework.setCentralDispatcherMgr(centralDispatcher1);
            centralDispatcher1.queueDispatcherJobResult = QueuedItemResultImpl.successful("test", "123", "blah",
                "blah");

            final RunTool tool = new RunTool(framework);
View Full Code Here

    }
    public void testArgs() throws Exception {

        {
            //-j option but no -p option, defaulted project name
            final Framework framework = getFrameworkInstance();
            final testCentralDispatcher1 centralDispatcher1 = new testCentralDispatcher1();
            framework.setCentralDispatcherMgr(centralDispatcher1);
            centralDispatcher1.queueDispatcherJobResult = QueuedItemResultImpl.successful("test", "123", "blah",
                "blah");

            final RunTool tool = new RunTool(framework);
View Full Code Here

            assertEquals(JobDefinitionFileFormat.xml, centralDispatcher1.listFormat);
        }
    }

    public void testLoad() throws Exception {
        final Framework framework = getFrameworkInstance();

        final JobsTool tool = new JobsTool(framework);
        final testCentralDispatcher1 centralDispatcher1 = new testCentralDispatcher1();
        framework.setCentralDispatcherMgr(centralDispatcher1);

        final ArrayList<IStoredJob> jobs = new ArrayList<IStoredJob>();
        centralDispatcher1.loadJobsResult = new ArrayList<IStoredJobLoadResult>();

        File test = File.createTempFile("blah", ".xml");
View Full Code Here

        assertEquals(StoredJobsRequestDuplicateOption.update, centralDispatcher1.loadRequest.getDuplicateOption());
        assertNotNull(centralDispatcher1.loadInput);
        assertEquals(JobDefinitionFileFormat.xml, centralDispatcher1.loadFormat);
    }
    public void testLoadWithProject() throws Exception {
        final Framework framework = getFrameworkInstance();

        final JobsTool tool = new JobsTool(framework);
        final testCentralDispatcher1 centralDispatcher1 = new testCentralDispatcher1();
        framework.setCentralDispatcherMgr(centralDispatcher1);

        final ArrayList<IStoredJob> jobs = new ArrayList<IStoredJob>();
        centralDispatcher1.loadJobsResult = new ArrayList<IStoredJobLoadResult>();

        File test = File.createTempFile("blah", ".xml");
View Full Code Here

        assertEquals(StoredJobsRequestDuplicateOption.update, centralDispatcher1.loadRequest.getDuplicateOption());
        assertNotNull(centralDispatcher1.loadInput);
        assertEquals(JobDefinitionFileFormat.xml, centralDispatcher1.loadFormat);
    }
    public void testLoadWithRemoveUUIDs() throws Exception {
        final Framework framework = getFrameworkInstance();

        final JobsTool tool = new JobsTool(framework);
        final testCentralDispatcher1 centralDispatcher1 = new testCentralDispatcher1();
        framework.setCentralDispatcherMgr(centralDispatcher1);

        final ArrayList<IStoredJob> jobs = new ArrayList<IStoredJob>();
        centralDispatcher1.loadJobsResult = new ArrayList<IStoredJobLoadResult>();

        File test = File.createTempFile("blah", ".xml");
View Full Code Here

        super(name);
    }

    public void setUp() {
        super.setUp();
        final Framework frameworkInstance = getFrameworkInstance();
        final FrameworkProject frameworkProject = frameworkInstance.getFrameworkProjectMgr().createFrameworkProject(
            PROJ_NAME);
        File resourcesfile = new File(frameworkProject.getNodesResourceFilePath());
        //copy test nodes to resources file
        try {
            FileUtils.copyFileStreams(new File("src/test/resources/com/dtolabs/rundeck/core/common/test-nodes1.xml"),
View Full Code Here

        assertEquals(StoredJobsRequestUUIDOption.remove, centralDispatcher1.loadRequest.getUUIDOption());
        assertNotNull(centralDispatcher1.loadInput);
        assertEquals(JobDefinitionFileFormat.xml, centralDispatcher1.loadFormat);
    }
    public void testLoadWithWithoutRemoveUUIDs() throws Exception {
        final Framework framework = getFrameworkInstance();

        final JobsTool tool = new JobsTool(framework);
        final testCentralDispatcher1 centralDispatcher1 = new testCentralDispatcher1();
        framework.setCentralDispatcherMgr(centralDispatcher1);

        final ArrayList<IStoredJob> jobs = new ArrayList<IStoredJob>();
        centralDispatcher1.loadJobsResult = new ArrayList<IStoredJobLoadResult>();

        File test = File.createTempFile("blah", ".xml");
View Full Code Here

        assertEquals(StoredJobsRequestUUIDOption.preserve, centralDispatcher1.loadRequest.getUUIDOption());
        assertNotNull(centralDispatcher1.loadInput);
        assertEquals(JobDefinitionFileFormat.xml, centralDispatcher1.loadFormat);
    }
    public void testPurge() throws Exception{
        final Framework framework = getFrameworkInstance();
        {
            //test purge action with query params, --idlist

            final JobsTool tool = new JobsTool(framework);
            final testCentralDispatcher1 centralDispatcher1 = new testCentralDispatcher1();
            framework.setCentralDispatcherMgr(centralDispatcher1);

            final ArrayList<IStoredJob> jobs = new ArrayList<IStoredJob>();
            jobs.add(StoredJobImpl.create("3", "test3", "blah", "blah", "blah", "test"));
            jobs.add(StoredJobImpl.create("4", "test3", "blah", "blah", "blah", "test"));
            centralDispatcher1.listJobsResult = jobs;
            final ArrayList<DeleteJobResult> results = new ArrayList<DeleteJobResult>();
            centralDispatcher1.purgeJobsResult = results;

            tool.run(
                new String[]{"purge", "--" + JobsTool.IDLIST_OPTION_LONG, "3,4", "-p", "test"});

            assertTrue("list action should be called", centralDispatcher1.listStoredJobsCalled);
            assertNull(centralDispatcher1.listStoredJobsOutput);
            assertNotNull(centralDispatcher1.listStoredJobsQuery);
            assertEquals("3,4", centralDispatcher1.listStoredJobsQuery.getIdlist());

            assertTrue("purge action should be called", centralDispatcher1.purgeStoredJobsCalled);
            assertNotNull(centralDispatcher1.purgeJobsRequest);
            assertEquals(Arrays.asList("3", "4"), centralDispatcher1.purgeJobsRequest);

            assertFalse("load action should not be called", centralDispatcher1.loadJobsCalled);
            assertNull(centralDispatcher1.loadRequest);
        }
        {
            //test purge action with query params, --idlist, no results

            final JobsTool tool = new JobsTool(framework);
            final testCentralDispatcher1 centralDispatcher1 = new testCentralDispatcher1();
            framework.setCentralDispatcherMgr(centralDispatcher1);

            final ArrayList<IStoredJob> jobs = new ArrayList<IStoredJob>();
            centralDispatcher1.listJobsResult = jobs;
            final ArrayList<DeleteJobResult> results = new ArrayList<DeleteJobResult>();
            centralDispatcher1.purgeJobsResult = results;

            tool.run(
                new String[]{"purge", "--" + JobsTool.IDLIST_OPTION_LONG, "3,4", "-p", "test"});

            assertTrue("list action should be called", centralDispatcher1.listStoredJobsCalled);
            assertNull(centralDispatcher1.listStoredJobsOutput);
            assertNotNull(centralDispatcher1.listStoredJobsQuery);
            assertEquals("3,4", centralDispatcher1.listStoredJobsQuery.getIdlist());

            assertFalse("purge action should be called", centralDispatcher1.purgeStoredJobsCalled);
            assertNull(centralDispatcher1.purgeJobsRequest);

            assertFalse("load action should not be called", centralDispatcher1.loadJobsCalled);
            assertNull(centralDispatcher1.loadRequest);
        }
        {
            //test purge: success

            final JobsTool tool = new JobsTool(framework);
            final testCentralDispatcher1 centralDispatcher1 = new testCentralDispatcher1();
            framework.setCentralDispatcherMgr(centralDispatcher1);

            final ArrayList<IStoredJob> jobs = new ArrayList<IStoredJob>();
            jobs.add(StoredJobImpl.create("3", "test3", "blah", "blah", "blah", "test"));
            jobs.add(StoredJobImpl.create("4", "test3", "blah", "blah", "blah", "test"));
            centralDispatcher1.listJobsResult = jobs;
            final ArrayList<DeleteJobResult> results = new ArrayList<DeleteJobResult>();
            results.add(DeleteJobResultImpl.createDeleteJobResultImpl(true, "success", "3", null));
            results.add(DeleteJobResultImpl.createDeleteJobResultImpl(true, "success", "4", null));
            centralDispatcher1.purgeJobsResult = results;

            tool.run(
                new String[]{"purge", "--" + JobsTool.IDLIST_OPTION_LONG, "3,4", "-p", "test"});

            assertTrue("list action should be called", centralDispatcher1.listStoredJobsCalled);
            assertNull(centralDispatcher1.listStoredJobsOutput);
            assertNotNull(centralDispatcher1.listStoredJobsQuery);
            assertEquals("3,4", centralDispatcher1.listStoredJobsQuery.getIdlist());

            assertTrue("purge action should be called", centralDispatcher1.purgeStoredJobsCalled);
            assertNotNull(centralDispatcher1.purgeJobsRequest);
            assertEquals(Arrays.asList("3", "4"), centralDispatcher1.purgeJobsRequest);

            assertFalse("load action should not be called", centralDispatcher1.loadJobsCalled);
            assertNull(centralDispatcher1.loadRequest);
        }
        {
            //test purge: failed purge causes exception

            final JobsTool tool = new JobsTool(framework);
            final testCentralDispatcher1 centralDispatcher1 = new testCentralDispatcher1();
            framework.setCentralDispatcherMgr(centralDispatcher1);

            final ArrayList<IStoredJob> jobs = new ArrayList<IStoredJob>();
            jobs.add(StoredJobImpl.create("3", "test3", "blah", "blah", "blah", "test"));
            jobs.add(StoredJobImpl.create("4", "test3", "blah", "blah", "blah", "test"));
            centralDispatcher1.listJobsResult = jobs;
View Full Code Here

TOP

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

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.