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());
assertNotNull(executionContext.getDataContext());
assertNotNull(executionContext.getDataContext().get("node"));
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<StepExecutionItem> commands = new ArrayList<StepExecutionItem>();
final StepExecutionItem 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 StepExecutionContext context =
new ExecutionContextImpl.Builder()
.frameworkProject(TEST_PROJECT)
.user("user1")
.nodeSelector(nodeset)
.executionListener(new testListener())
.framework(testFramework)
.nodes(testFramework.filterNodeSet(nodeset, TEST_PROJECT, null))
.build();
//setup testInterpreter for all command types
final NodeStepExecutionService interpreterService = NodeStepExecutionService.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 NodeStepResultImpl(null));
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 StepExecutionItem 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());
assertNotNull(executionContext.getDataContext());
assertNotNull(executionContext.getDataContext().get("node"));
assertEquals(0, executionContext.getLoglevel());
assertEquals("user1", executionContext.getUser());
assertEquals(nodeset, executionContext.getNodeSelector());
}
}