Ejemplo n.º 1
0
 @Override
 protected void tearDown() throws Exception {
   framework.stop();
   framework.waitForStop(10000);
   IO.delete(tmp);
   super.tearDown();
 }
Ejemplo n.º 2
0
  @Override
  protected void setUp() throws Exception {
    tmp = IO.getFile("generated/tmp");
    tmp.mkdirs();

    configuration = new HashMap<String, Object>();
    configuration.put(
        Constants.FRAMEWORK_STORAGE_CLEAN, Constants.FRAMEWORK_STORAGE_CLEAN_ONFIRSTINIT);
    configuration.put(Constants.FRAMEWORK_STORAGE, new File(tmp, "fwstorage").getAbsolutePath());
    configuration.put(
        Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA, "org.osgi.framework.launch;version=1.4");
    framework = new org.apache.felix.framework.FrameworkFactory().newFramework(configuration);
    framework.init();
    framework.start();
    BundleContext context = framework.getBundleContext();

    String[] bundles = {
      "../cnf/repo/osgi.cmpn/osgi.cmpn-4.3.1.jar", "testdata/slf4j-simple-1.7.12.jar",
      "testdata/slf4j-api-1.7.12.jar", "testdata/org.apache.aries.util-1.1.0.jar",
      "testdata/org.apache.aries.jmx-1.1.1.jar", "generated/biz.aQute.remote.test.jmx.jar"
    };

    for (String bundle : bundles) {
      String location = "reference:" + IO.getFile(bundle).toURI().toString();
      Bundle b = context.installBundle(location);
      if (!bundle.contains("slf4j-simple")) {
        b.start();
      }
    }

    super.setUp();
  }
Ejemplo n.º 3
0
  @Override
  protected void setUp() throws Exception {
    tmp = IO.getFile("generated/tmp");
    tmp.mkdirs();
    IO.copy(IO.getFile("testdata/ws"), tmp);
    workspace = Workspace.getWorkspace(tmp);
    workspace.refresh();

    InfoRepository repo = workspace.getPlugin(InfoRepository.class);
    t1 = create("bsn-1", new Version(1, 0, 0));
    t2 = create("bsn-2", new Version(1, 0, 0));

    repo.put(new FileInputStream(t1), null);
    repo.put(new FileInputStream(t2), null);
    t1 = repo.get("bsn-1", new Version(1, 0, 0), null);
    t2 = repo.get("bsn-2", new Version(1, 0, 0), null);
    repo.put(new FileInputStream(IO.getFile("generated/biz.aQute.remote.launcher.jar")), null);

    workspace.getPlugins().add(repo);

    File storage = IO.getFile("generated/storage-1");
    storage.mkdirs();

    configuration = new HashMap<String, Object>();
    configuration.put(
        Constants.FRAMEWORK_STORAGE_CLEAN, Constants.FRAMEWORK_STORAGE_CLEAN_ONFIRSTINIT);
    configuration.put(Constants.FRAMEWORK_STORAGE, storage.getAbsolutePath());

    configuration.put(
        Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA, "org.osgi.framework.launch;version=1.2");

    framework = new org.apache.felix.framework.FrameworkFactory().newFramework(configuration);
    framework.init();
    framework.start();
    context = framework.getBundleContext();
    location = "reference:" + IO.getFile("generated/biz.aQute.remote.agent.jar").toURI().toString();
    agent = context.installBundle(location);
    agent.start();

    thread =
        new Thread() {
          @Override
          public void run() {
            try {
              Main.main(
                  new String[] {
                    "-s", "generated/storage", "-c", "generated/cache", "-p", "1090", "-et"
                  });
            } catch (Exception e) {
              e.printStackTrace();
            }
          }
        };
    thread.setDaemon(true);
    thread.start();

    super.setUp();
  }
Ejemplo n.º 4
0
 @Override
 protected void tearDown() throws Exception {
   super.tearDown();
   framework.stop();
   IO.delete(tmp);
   Main.stop();
   IO.delete(IO.getFile("generated/cache"));
   IO.delete(IO.getFile("generated/storage"));
   framework.waitForStop(100000);
   super.tearDown();
 }
 protected void setUp() {
   super.setUp();
   testFramework = getFrameworkInstance();
   testnode = testFramework.getFrameworkNodeName();
   final FrameworkProject frameworkProject =
       testFramework.getFrameworkProjectMgr().createFrameworkProject(TEST_PROJECT);
   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"),
         resourcesfile);
   } catch (IOException e) {
     throw new RuntimeException("Caught Setup exception: " + e.getMessage(), e);
   }
 }
Ejemplo n.º 6
0
 public void testAll() throws Exception {
   assertTrue(
       Framework.executeTest("=COS(" + Math.PI + "/6)", Double.valueOf(0.8660254037844387)));
   assertTrue(Framework.executeTest("=COS(RADIANS(60))", Double.valueOf(0.5000000000000001)));
   assertTrue(Framework.executeTest("=COS(RADIANS(-30))", Double.valueOf(0.8660254037844387)));
   assertTrue(Framework.executeTest("=COS(0.785398163)", Double.valueOf(0.7071067814675859)));
   assertTrue(Framework.executeTest("=COS(\"0.0\")", Double.valueOf(1)));
   assertTrue(Framework.executeTestExpectFailure("=COS(\"abc\")"));
 }
  public void testGenericItem() {

    {
      // test jobref item
      final NodesSelector nodeset = SelectorUtils.singleNode(testFramework.getFrameworkNodeName());
      final ArrayList<ExecutionItem> commands = new ArrayList<ExecutionItem>();
      final testWorkflowCmdItem item = new testWorkflowCmdItem();
      item.type = "my-type";
      commands.add(item);
      final WorkflowImpl workflow =
          new WorkflowImpl(commands, 1, false, WorkflowStrategy.STEP_FIRST);
      final WorkflowExecutionItemImpl executionItem = new WorkflowExecutionItemImpl(workflow);
      final StepFirstWorkflowStrategy strategy = new StepFirstWorkflowStrategy(testFramework);
      final com.dtolabs.rundeck.core.execution.ExecutionContext context =
          new ExecutionContextImpl.Builder()
              .frameworkProject(TEST_PROJECT)
              .user("user1")
              .nodeSelector(nodeset)
              .executionListener(new testListener())
              .framework(testFramework)
              .build();

      // setup testInterpreter for all command types
      final CommandInterpreterService interpreterService =
          CommandInterpreterService.getInstanceForFramework(testFramework);
      testInterpreter interpreterMock = new testInterpreter();
      testInterpreter failMock = new testInterpreter();
      failMock.shouldThrowException = true;
      interpreterService.registerInstance("my-type", interpreterMock);
      interpreterService.registerInstance("exec", failMock);
      interpreterService.registerInstance("script", failMock);
      interpreterService.registerInstance(WorkflowExecutionItem.COMMAND_TYPE_NODE_FIRST, failMock);
      interpreterService.registerInstance(WorkflowExecutionItem.COMMAND_TYPE_STEP_FIRST, failMock);

      // set resturn result
      interpreterMock.resultList.add(
          new InterpreterResult() {
            public boolean isSuccess() {
              return true;
            }
          });

      final WorkflowExecutionResult result = strategy.executeWorkflow(context, executionItem);

      assertNotNull(result);
      if (!result.isSuccess() && null != result.getException()) {
        result.getException().printStackTrace(System.err);
      }
      assertNull("threw exception: " + result.getException(), result.getException());
      assertTrue(result.isSuccess());
      assertEquals(1, interpreterMock.executionItemList.size());
      final ExecutionItem executionItem1 = interpreterMock.executionItemList.get(0);
      assertTrue(
          "wrong class: " + executionItem1.getClass().getName(),
          executionItem1 instanceof testWorkflowCmdItem);
      testWorkflowCmdItem execItem = (testWorkflowCmdItem) executionItem1;
      assertNotNull(execItem.getType());
      assertEquals("my-type", execItem.getType());
      assertEquals(1, interpreterMock.executionContextList.size());
      final ExecutionContext executionContext = interpreterMock.executionContextList.get(0);
      assertEquals(TEST_PROJECT, executionContext.getFrameworkProject());
      assertNull(executionContext.getArgs());
      assertNull(executionContext.getDataContext());
      assertEquals(0, executionContext.getLoglevel());
      assertEquals("user1", executionContext.getUser());
      assertEquals(nodeset, executionContext.getNodeSelector());
    }
  }
  public void testExecuteWorkflow() throws Exception {
    {
      final FrameworkProject frameworkProject =
          testFramework.getFrameworkProjectMgr().getFrameworkProject(TEST_PROJECT);
      final INodeSet nodes = frameworkProject.getNodeSet();
      assertNotNull(nodes);
      assertEquals(2, nodes.getNodes().size());
    }

    {
      // test empty workflow
      final NodeSet nodeset = new NodeSet();
      final WorkflowImpl workflow =
          new WorkflowImpl(new ArrayList<ExecutionItem>(), 1, false, WorkflowStrategy.STEP_FIRST);
      final WorkflowExecutionItemImpl executionItem = new WorkflowExecutionItemImpl(workflow);
      final StepFirstWorkflowStrategy strategy = new StepFirstWorkflowStrategy(testFramework);
      final com.dtolabs.rundeck.core.execution.ExecutionContext context =
          new ExecutionContextImpl.Builder()
              .frameworkProject(TEST_PROJECT)
              .user("user1")
              .nodeSelector(nodeset)
              .executionListener(new testListener())
              .framework(testFramework)
              .build();

      // setup testInterpreter for all command types
      final CommandInterpreterService interpreterService =
          CommandInterpreterService.getInstanceForFramework(testFramework);
      testInterpreter interpreterMock = new testInterpreter();
      interpreterService.registerInstance("exec", interpreterMock);
      interpreterService.registerInstance("script", interpreterMock);
      interpreterService.registerInstance(
          WorkflowExecutionItem.COMMAND_TYPE_NODE_FIRST, interpreterMock);
      interpreterService.registerInstance(
          WorkflowExecutionItem.COMMAND_TYPE_STEP_FIRST, interpreterMock);
      //            interpreterService.registerInstance(JobExecutionItem.COMMAND_TYPE,
      // interpreterMock);

      final WorkflowExecutionResult result = strategy.executeWorkflow(context, executionItem);

      assertNotNull(result);
      if (!result.isSuccess() && null != result.getException()) {
        result.getException().printStackTrace(System.err);
      }
      assertNull("threw exception: " + result.getException(), result.getException());
      assertTrue(result.isSuccess());
      assertEquals(0, interpreterMock.executionItemList.size());
    }
    {
      // test undefined workflow item
      final NodeSet nodeset = new NodeSet();
      final ArrayList<ExecutionItem> commands = new ArrayList<ExecutionItem>();
      commands.add(new testWorkflowCmdItem());

      final WorkflowImpl workflow =
          new WorkflowImpl(commands, 1, false, WorkflowStrategy.STEP_FIRST);
      final WorkflowExecutionItemImpl executionItem = new WorkflowExecutionItemImpl(workflow);
      final StepFirstWorkflowStrategy strategy = new StepFirstWorkflowStrategy(testFramework);
      final com.dtolabs.rundeck.core.execution.ExecutionContext context =
          new ExecutionContextImpl.Builder()
              .frameworkProject(TEST_PROJECT)
              .user("user1")
              .nodeSelector(nodeset.nodeSelectorWithDefaultAll())
              .executionListener(new testListener())
              .framework(testFramework)
              .build();

      // setup testInterpreter for all command types
      final CommandInterpreterService interpreterService =
          CommandInterpreterService.getInstanceForFramework(testFramework);
      testInterpreter interpreterMock = new testInterpreter();
      interpreterService.registerInstance("exec", interpreterMock);
      interpreterService.registerInstance("script", interpreterMock);
      interpreterService.registerInstance(
          WorkflowExecutionItem.COMMAND_TYPE_NODE_FIRST, interpreterMock);
      interpreterService.registerInstance(
          WorkflowExecutionItem.COMMAND_TYPE_STEP_FIRST, interpreterMock);
      //            interpreterService.registerInstance(JobExecutionItem.COMMAND_TYPE,
      // interpreterMock);

      final WorkflowExecutionResult result = strategy.executeWorkflow(context, executionItem);

      assertNotNull(result);
      if (!result.isSuccess() && null != result.getException()) {
        result.getException().printStackTrace(System.err);
      }
      assertFalse(result.isSuccess());
      assertEquals(0, interpreterMock.executionItemList.size());
      assertNotNull("threw exception: " + result.getException(), result.getException());
      assertTrue(
          "threw exception: " + result.getException(),
          result.getException() instanceof WorkflowStepFailureException);
      assertEquals(
          "threw exception: " + result.getException(),
          "Step 1 of the workflow threw an exception: Failed dispatching to node test1: provider name was null for Service: CommandInterpreter",
          result.getException().getMessage());
    }

    {
      // test script exec item
      final NodesSelector nodeset = SelectorUtils.singleNode(testFramework.getFrameworkNodeName());
      final ArrayList<ExecutionItem> commands = new ArrayList<ExecutionItem>();
      final ExecutionItem testWorkflowCmdItem =
          new ScriptFileCommandBase() {
            @Override
            public String getScript() {
              return "a command";
            }
          };
      commands.add(testWorkflowCmdItem);
      final WorkflowImpl workflow =
          new WorkflowImpl(commands, 1, false, WorkflowStrategy.STEP_FIRST);
      final WorkflowExecutionItemImpl executionItem = new WorkflowExecutionItemImpl(workflow);
      final StepFirstWorkflowStrategy strategy = new StepFirstWorkflowStrategy(testFramework);
      final com.dtolabs.rundeck.core.execution.ExecutionContext context =
          new ExecutionContextImpl.Builder()
              .frameworkProject(TEST_PROJECT)
              .user("user1")
              .nodeSelector(nodeset)
              .executionListener(new testListener())
              .framework(testFramework)
              .build();

      // setup testInterpreter for all command types
      final CommandInterpreterService interpreterService =
          CommandInterpreterService.getInstanceForFramework(testFramework);
      testInterpreter interpreterMock = new testInterpreter();
      testInterpreter failMock = new testInterpreter();
      failMock.shouldThrowException = true;
      interpreterService.registerInstance("exec", failMock);
      interpreterService.registerInstance("script", interpreterMock);
      interpreterService.registerInstance(WorkflowExecutionItem.COMMAND_TYPE_NODE_FIRST, failMock);
      interpreterService.registerInstance(WorkflowExecutionItem.COMMAND_TYPE_STEP_FIRST, failMock);
      //            interpreterService.registerInstance(JobExecutionItem.COMMAND_TYPE, failMock);

      // set resturn result
      interpreterMock.resultList.add(
          new InterpreterResult() {
            public boolean isSuccess() {
              return true;
            }
          });

      final WorkflowExecutionResult result = strategy.executeWorkflow(context, executionItem);

      assertNotNull(result);
      if (!result.isSuccess() && null != result.getException()) {
        result.getException().printStackTrace(System.err);
      }
      assertNull("threw exception: " + result.getException(), result.getException());
      assertTrue(result.isSuccess());
      assertEquals(1, interpreterMock.executionItemList.size());
      final ExecutionItem executionItem1 = interpreterMock.executionItemList.get(0);
      assertTrue(
          "wrong class: " + executionItem1.getClass().getName(),
          executionItem1 instanceof ScriptFileCommandExecutionItem);
      ScriptFileCommandExecutionItem scriptItem = (ScriptFileCommandExecutionItem) executionItem1;
      assertEquals("a command", scriptItem.getScript());
      assertNull(scriptItem.getScriptAsStream());
      assertNull(scriptItem.getServerScriptFilePath());
      assertEquals(1, interpreterMock.executionContextList.size());
      final ExecutionContext executionContext = interpreterMock.executionContextList.get(0);
      assertEquals(TEST_PROJECT, executionContext.getFrameworkProject());
      assertNull(executionContext.getArgs());
      assertNull(executionContext.getDataContext());
      assertEquals(0, executionContext.getLoglevel());
      assertEquals("user1", executionContext.getUser());
      assertEquals(
          "expected " + nodeset + ", but was " + executionContext.getNodeSelector(),
          nodeset,
          executionContext.getNodeSelector());
    }
    {
      // test command exec item
      final NodesSelector nodeset = SelectorUtils.singleNode(testFramework.getFrameworkNodeName());
      final ArrayList<ExecutionItem> commands = new ArrayList<ExecutionItem>();
      final ExecutionItem testWorkflowCmdItem =
          new ExecCommandBase() {
            @Override
            public String[] getCommand() {
              return new String[] {"a", "command"};
            }
          };

      commands.add(testWorkflowCmdItem);
      final WorkflowImpl workflow =
          new WorkflowImpl(commands, 1, false, WorkflowStrategy.STEP_FIRST);
      final WorkflowExecutionItemImpl executionItem = new WorkflowExecutionItemImpl(workflow);
      final StepFirstWorkflowStrategy strategy = new StepFirstWorkflowStrategy(testFramework);
      final com.dtolabs.rundeck.core.execution.ExecutionContext context =
          new ExecutionContextImpl.Builder()
              .frameworkProject(TEST_PROJECT)
              .user("user1")
              .nodeSelector(nodeset)
              .executionListener(new testListener())
              .framework(testFramework)
              .build();

      // setup testInterpreter for all command types
      final CommandInterpreterService interpreterService =
          CommandInterpreterService.getInstanceForFramework(testFramework);
      testInterpreter interpreterMock = new testInterpreter();
      testInterpreter failMock = new testInterpreter();
      failMock.shouldThrowException = true;
      interpreterService.registerInstance("exec", interpreterMock);
      interpreterService.registerInstance("script", failMock);
      interpreterService.registerInstance(WorkflowExecutionItem.COMMAND_TYPE_NODE_FIRST, failMock);
      interpreterService.registerInstance(WorkflowExecutionItem.COMMAND_TYPE_STEP_FIRST, failMock);
      //            interpreterService.registerInstance(JobExecutionItem.COMMAND_TYPE, failMock);

      // set resturn result
      interpreterMock.resultList.add(
          new InterpreterResult() {
            public boolean isSuccess() {
              return true;
            }
          });

      final WorkflowExecutionResult result = strategy.executeWorkflow(context, executionItem);

      assertNotNull(result);
      if (!result.isSuccess() && null != result.getException()) {
        result.getException().printStackTrace(System.err);
      }
      assertNull("threw exception: " + result.getException(), result.getException());
      assertTrue(result.isSuccess());
      assertEquals(1, interpreterMock.executionItemList.size());
      final ExecutionItem executionItem1 = interpreterMock.executionItemList.get(0);
      assertTrue(
          "wrong class: " + executionItem1.getClass().getName(),
          executionItem1 instanceof ExecCommandExecutionItem);
      ExecCommandExecutionItem execItem = (ExecCommandExecutionItem) executionItem1;
      assertNotNull(execItem.getCommand());
      assertEquals(2, execItem.getCommand().length);
      assertEquals("a", execItem.getCommand()[0]);
      assertEquals("command", execItem.getCommand()[1]);
      assertEquals(1, interpreterMock.executionContextList.size());
      final ExecutionContext executionContext = interpreterMock.executionContextList.get(0);
      assertEquals(TEST_PROJECT, executionContext.getFrameworkProject());
      assertNull(executionContext.getArgs());
      assertNull(executionContext.getDataContext());
      assertEquals(0, executionContext.getLoglevel());
      assertEquals("user1", executionContext.getUser());
      assertEquals(nodeset, executionContext.getNodeSelector());
    }
    {
      // test workflow of three successful items
      final NodesSelector nodeset = SelectorUtils.singleNode(testFramework.getFrameworkNodeName());
      final ArrayList<ExecutionItem> commands = new ArrayList<ExecutionItem>();

      final ExecutionItem testWorkflowCmdItem =
          new ExecCommandBase() {
            @Override
            public String[] getCommand() {
              return new String[] {"a", "2", "command"};
            }
          };

      commands.add(testWorkflowCmdItem);

      final ExecutionItem testWorkflowCmdItemScript =
          new ScriptFileCommandBase() {
            @Override
            public String getScript() {
              return "a command";
            }

            @Override
            public String[] getArgs() {
              return new String[] {"-testargs", "1"};
            }
          };
      commands.add(testWorkflowCmdItemScript);

      final ExecutionItem testWorkflowCmdItemScript2 =
          new ScriptFileCommandBase() {
            @Override
            public String getServerScriptFilePath() {
              return "/some/file/path";
            }

            @Override
            public String[] getArgs() {
              return new String[] {"-testargs", "2"};
            }
          };
      commands.add(testWorkflowCmdItemScript2);
      final WorkflowImpl workflow =
          new WorkflowImpl(commands, 1, false, WorkflowStrategy.STEP_FIRST);
      final WorkflowExecutionItemImpl executionItem = new WorkflowExecutionItemImpl(workflow);
      final StepFirstWorkflowStrategy strategy = new StepFirstWorkflowStrategy(testFramework);
      final com.dtolabs.rundeck.core.execution.ExecutionContext context =
          new ExecutionContextImpl.Builder()
              .frameworkProject(TEST_PROJECT)
              .user("user1")
              .args(new String[] {"test", "args"})
              .nodeSelector(nodeset)
              .executionListener(new testListener())
              .framework(testFramework)
              .build();

      // setup testInterpreter for all command types
      final CommandInterpreterService interpreterService =
          CommandInterpreterService.getInstanceForFramework(testFramework);
      testInterpreter interpreterMock = new testInterpreter();
      testInterpreter failMock = new testInterpreter();
      failMock.shouldThrowException = true;
      //            interpreterService.registerInstance(JobExecutionItem.COMMAND_TYPE,
      // interpreterMock);
      interpreterService.registerInstance("exec", interpreterMock);
      interpreterService.registerInstance("script", interpreterMock);
      interpreterService.registerInstance(WorkflowExecutionItem.COMMAND_TYPE_NODE_FIRST, failMock);
      interpreterService.registerInstance(WorkflowExecutionItem.COMMAND_TYPE_STEP_FIRST, failMock);

      // set resturn results
      interpreterMock.resultList.add(new testResult(true, 0));
      interpreterMock.resultList.add(new testResult(true, 1));
      interpreterMock.resultList.add(new testResult(true, 2));

      final WorkflowExecutionResult result = strategy.executeWorkflow(context, executionItem);

      assertNotNull(result);
      if (!result.isSuccess() && null != result.getException()) {
        result.getException().printStackTrace(System.err);
      }
      assertNull("threw exception: " + result.getException(), result.getException());
      assertTrue(result.isSuccess());
      assertEquals(1, result.getResultSet().size());
      assertNotNull(result.getResultSet());
      assertNotNull(
          "missing key " + testnode + ": " + result.getResultSet().keySet(),
          result.getResultSet().get(testnode));
      final List<StatusResult> test1 = result.getResultSet().get(testnode);
      assertEquals(3, test1.size());
      for (final int i : new int[] {0, 1, 2}) {
        final StatusResult interpreterResult = test1.get(i);
        assertTrue(interpreterResult instanceof testResult);
        testResult val = (testResult) interpreterResult;
        assertTrue(val.isSuccess());
        assertEquals(i, val.flag);
      }

      assertEquals(3, interpreterMock.executionItemList.size());

      final ExecutionItem executionItem1 = interpreterMock.executionItemList.get(0);
      assertTrue(
          "wrong class: " + executionItem1.getClass().getName(),
          executionItem1 instanceof ExecCommandExecutionItem);
      ExecCommandExecutionItem execItem = (ExecCommandExecutionItem) executionItem1;
      assertNotNull(execItem.getCommand());
      assertEquals(3, execItem.getCommand().length);
      assertEquals("a", execItem.getCommand()[0]);
      assertEquals("2", execItem.getCommand()[1]);
      assertEquals("command", execItem.getCommand()[2]);

      final ExecutionItem item2 = interpreterMock.executionItemList.get(1);
      assertTrue(
          "wrong class: " + item2.getClass().getName(),
          item2 instanceof ScriptFileCommandExecutionItem);
      ScriptFileCommandExecutionItem scriptItem = (ScriptFileCommandExecutionItem) item2;
      assertEquals("a command", scriptItem.getScript());
      assertNull(scriptItem.getScriptAsStream());
      assertNull(scriptItem.getServerScriptFilePath());

      final ExecutionItem item3 = interpreterMock.executionItemList.get(2);
      assertTrue(
          "wrong class: " + item3.getClass().getName(),
          item2 instanceof ScriptFileCommandExecutionItem);
      ScriptFileCommandExecutionItem scriptItem2 = (ScriptFileCommandExecutionItem) item3;
      assertNull(scriptItem2.getScript());
      assertNull(scriptItem2.getScriptAsStream());
      assertEquals("/some/file/path", scriptItem2.getServerScriptFilePath());
      assertNotNull(scriptItem2.getArgs());
      assertEquals(2, scriptItem2.getArgs().length);
      assertEquals("-testargs", scriptItem2.getArgs()[0]);
      assertEquals("2", scriptItem2.getArgs()[1]);

      assertEquals(3, interpreterMock.executionContextList.size());

      for (final int i : new int[] {0, 1, 2}) {
        final ExecutionContext executionContext = interpreterMock.executionContextList.get(i);
        assertEquals("item " + i, TEST_PROJECT, executionContext.getFrameworkProject());
        assertNull("item " + i, executionContext.getDataContext());
        assertEquals("item " + i, 0, executionContext.getLoglevel());
        assertEquals("item " + i, "user1", executionContext.getUser());
        assertEquals("item " + i, nodeset, executionContext.getNodeSelector());
        assertNotNull("item " + i, executionContext.getArgs());
        assertEquals("item " + i, 2, executionContext.getArgs().length);
        assertEquals("item " + i, "test", executionContext.getArgs()[0]);
        assertEquals("item " + i, "args", executionContext.getArgs()[1]);
      }
    }
    {
      // test a workflow with a failing item (1), with keepgoing=false
      final NodesSelector nodeset = SelectorUtils.singleNode(testFramework.getFrameworkNodeName());
      final ArrayList<ExecutionItem> commands = new ArrayList<ExecutionItem>();

      final ExecutionItem testWorkflowCmdItem =
          new ExecCommandBase() {
            @Override
            public String[] getCommand() {
              return new String[] {"a", "2", "command"};
            }
          };

      commands.add(testWorkflowCmdItem);

      final ExecutionItem testWorkflowCmdItemScript =
          new ScriptFileCommandBase() {
            @Override
            public String getScript() {
              return "a command";
            }

            @Override
            public String[] getArgs() {
              return new String[] {"-testargs", "1"};
            }
          };
      commands.add(testWorkflowCmdItemScript);

      final ExecutionItem testWorkflowCmdItemScript2 =
          new ScriptFileCommandBase() {
            @Override
            public String getServerScriptFilePath() {
              return "/some/file/path";
            }

            @Override
            public String[] getArgs() {
              return new String[] {"-testargs", "2"};
            }
          };
      commands.add(testWorkflowCmdItemScript2);
      final WorkflowImpl workflow =
          new WorkflowImpl(commands, 1, false, WorkflowStrategy.STEP_FIRST);
      workflow.setKeepgoing(false);
      final WorkflowExecutionItemImpl executionItem = new WorkflowExecutionItemImpl(workflow);
      final StepFirstWorkflowStrategy strategy = new StepFirstWorkflowStrategy(testFramework);
      final com.dtolabs.rundeck.core.execution.ExecutionContext context =
          new ExecutionContextImpl.Builder()
              .frameworkProject(TEST_PROJECT)
              .user("user1")
              .nodeSelector(nodeset)
              .executionListener(new testListener())
              .framework(testFramework)
              .build();

      // setup testInterpreter for all command types
      final CommandInterpreterService interpreterService =
          CommandInterpreterService.getInstanceForFramework(testFramework);
      testInterpreter interpreterMock = new testInterpreter();
      testInterpreter failMock = new testInterpreter();
      failMock.shouldThrowException = true;
      //            interpreterService.registerInstance(JobExecutionItem.COMMAND_TYPE,
      // interpreterMock);
      interpreterService.registerInstance("exec", interpreterMock);
      interpreterService.registerInstance("script", interpreterMock);
      interpreterService.registerInstance(WorkflowExecutionItem.COMMAND_TYPE_NODE_FIRST, failMock);
      interpreterService.registerInstance(WorkflowExecutionItem.COMMAND_TYPE_STEP_FIRST, failMock);

      // set resturn results, fail on second item
      interpreterMock.resultList.add(new testResult(true, 0));
      interpreterMock.resultList.add(new testResult(false, 1));
      interpreterMock.resultList.add(new testResult(true, 2));

      final WorkflowExecutionResult result = strategy.executeWorkflow(context, executionItem);

      assertNotNull(result);
      if (!result.isSuccess() && null != result.getException()) {
        result.getException().printStackTrace(System.err);
      }
      assertFalse(result.isSuccess());
      assertNotNull("threw exception: " + result.getException(), result.getException());
      assertTrue(
          "threw exception: " + result.getException(),
          result.getException() instanceof WorkflowStepFailureException);
      WorkflowStepFailureException wfsfe = (WorkflowStepFailureException) result.getException();
      assertEquals(2, wfsfe.getWorkflowStep());
      assertNotNull(wfsfe.getExecutionResult());
      final ExecutionResult executionResult = wfsfe.getExecutionResult();
      assertNotNull(executionResult.getResultObject());
      assertNotNull(executionResult.getResultObject().getResults());
      assertEquals(1, executionResult.getResultObject().getResults().size());
      assertNotNull(executionResult.getResultObject().getResults().get(testnode));
      final StatusResult testnode1 = executionResult.getResultObject().getResults().get(testnode);
      assertNotNull(testnode1);
      assertTrue(testnode1 instanceof testResult);
      testResult failResult = (testResult) testnode1;
      assertEquals(1, failResult.flag);

      assertEquals(1, result.getResultSet().size());
      assertNotNull(result.getResultSet());
      assertNotNull(
          "missing key" + testnode + ": " + result.getResultSet().keySet(),
          result.getResultSet().get(testnode));
      final List<StatusResult> test1 = result.getResultSet().get(testnode);
      assertEquals(2, test1.size());
      for (final int i : new int[] {0, 1}) {
        final StatusResult interpreterResult = test1.get(i);
        assertTrue(interpreterResult instanceof testResult);
        testResult val = (testResult) interpreterResult;
        assertEquals(i, val.flag);
        if (0 == i) {
          assertTrue(val.isSuccess());
        } else {
          assertFalse(val.isSuccess());
        }
      }

      assertEquals(2, interpreterMock.executionItemList.size());

      final ExecutionItem executionItem1 = interpreterMock.executionItemList.get(0);
      assertTrue(
          "wrong class: " + executionItem1.getClass().getName(),
          executionItem1 instanceof ExecCommandExecutionItem);
      ExecCommandExecutionItem execItem = (ExecCommandExecutionItem) executionItem1;
      assertNotNull(execItem.getCommand());
      assertEquals(3, execItem.getCommand().length);
      assertEquals("a", execItem.getCommand()[0]);
      assertEquals("2", execItem.getCommand()[1]);
      assertEquals("command", execItem.getCommand()[2]);

      final ExecutionItem item2 = interpreterMock.executionItemList.get(1);
      assertTrue(
          "wrong class: " + item2.getClass().getName(),
          item2 instanceof ScriptFileCommandExecutionItem);
      ScriptFileCommandExecutionItem scriptItem = (ScriptFileCommandExecutionItem) item2;
      assertEquals("a command", scriptItem.getScript());
      assertNull(scriptItem.getScriptAsStream());
      assertNull(scriptItem.getServerScriptFilePath());
      assertNotNull(scriptItem.getArgs());
      assertEquals(2, scriptItem.getArgs().length);
      assertEquals("-testargs", scriptItem.getArgs()[0]);
      assertEquals("1", scriptItem.getArgs()[1]);

      assertEquals(2, interpreterMock.executionContextList.size());

      for (final int i : new int[] {0, 1}) {
        final ExecutionContext executionContext = interpreterMock.executionContextList.get(i);
        assertEquals(TEST_PROJECT, executionContext.getFrameworkProject());
        assertNull(executionContext.getDataContext());
        assertEquals(0, executionContext.getLoglevel());
        assertEquals("user1", executionContext.getUser());
        assertEquals(nodeset, executionContext.getNodeSelector());
        assertNull(executionContext.getArgs());
      }
    }
  }