test_class.file: step-functions-plugins/step-functions-plugins-composite/step-functions-plugins-composite-handler/src/test/java/step/plugins/functions/types/composite/ArtefactFunctionHandlerTest.java
test_class.identifier: ArtefactFunctionHandlerTest
test_case.body: @Test
  	public void testError() {
  		ExecutionContext context = newExecutionContext();
  
  		Script script = new Script();
  		script.setScript("output.setError('MyError'");
  		
  		Plan compositePlan = PlanBuilder.create().startBlock(BaseArtefacts.sequence()).add(script).endBlock().build();
  		context.getPlanAccessor().save(compositePlan);
  		
  		ReportNode parentNode = new ReportNode();
  		context.getReportNodeAccessor().save(parentNode);
  		
  		ArtefactFunctionHandler handler = createArtefactFunctionHandler(context);
  		
  		Input<JsonObject> input = new Input<>();
  		Map<String, String> properties = getInputProperties(compositePlan, parentNode);
  		input.setProperties(properties);
  		Output<JsonObject> output = handler.handle(input);
  		
  		Assert.assertEquals("Error in composite keyword", output.getError().getMsg());
  		Assert.assertEquals(ErrorType.TECHNICAL, output.getError().getType());
  	}
test_case.class_method_signature: ArtefactFunctionHandlerTest.testError()
test_case.full_signature: @Test public void testError()
test_case.identifier: testError
test_case.invocations: newExecutionContext setScript build endBlock add startBlock create sequence save getPlanAccessor save getReportNodeAccessor createArtefactFunctionHandler getInputProperties setProperties handle assertEquals getMsg getError assertEquals getType getError
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testError()
focal_class.declarator: INPUT = "input"
focal_class.modifier: private static final
focal_class.original_string: private static final String INPUT = "input";
focal_class.type: String
focal_class.var_name: INPUT
focal_class.declarator: OUTPUT = "output"
focal_class.modifier: private static final
focal_class.original_string: private static final String OUTPUT = "output";
focal_class.type: String
focal_class.var_name: OUTPUT
focal_class.declarator: PLANID_KEY = "$planid"
focal_class.modifier: public static final
focal_class.original_string: public static final String PLANID_KEY = "$planid";
focal_class.type: String
focal_class.var_name: PLANID_KEY
focal_class.file: step-functions-plugins/step-functions-plugins-composite/step-functions-plugins-composite-handler/src/main/java/step/plugins/functions/types/composite/ArtefactFunctionHandler.java
focal_class.identifier: ArtefactFunctionHandler
focal_class.class_method_signature: ArtefactFunctionHandler.handle(Input<JsonObject> input)
focal_class.full_signature: @Override protected Output<JsonObject> handle(Input<JsonObject> input)
focal_class.identifier: handle
focal_class.modifiers: @Override protected
focal_class.parameters: (Input<JsonObject> input)
focal_class.return: Output<JsonObject>
focal_class.signature: Output<JsonObject> handle(Input<JsonObject> input)
focal_class.superclass: extends JsonBasedFunctionHandler
focal_method.body: @Override
  	protected Output<JsonObject> handle(Input<JsonObject> input) {
  		OutputBuilder output = new OutputBuilder();
  
  		ExecutionContext executionContext = (ExecutionContext) getTokenReservationSession().get(AbstractFunctionHandler.EXECUTION_CONTEXT_KEY);
  		
  		if(executionContext == null) {
  			output.setError("Running composite Keyword on agent not supported. Please change the keyword configuration accordingly.");
  		} else {
  			String planId = input.getProperties().get(PLANID_KEY);
  			String parentReportId = input.getProperties().get(AbstractFunctionHandler.PARENTREPORTID_KEY);
  			
  			ReportNode parentNode;
  			if(parentReportId!=null) {
  				parentNode = executionContext.getReportNodeAccessor().get(parentReportId);
  				if(parentNode == null) {
  					parentNode = executionContext.getCurrentReportNode();
  				}
  			} else {
  				parentNode = executionContext.getCurrentReportNode();
  				//throw new RuntimeException("Parent node id is null. This should never occur");
  			}
  			
  			ReportNode previousCurrentNode = executionContext.getCurrentReportNode();
  			executionContext.setCurrentReportNode(parentNode);
  			executionContext.getReportNodeCache().put(parentNode);
  			
  			AbstractArtefact artefact = executionContext.getPlanAccessor().get(planId).getRoot();
  			
  			executionContext.getVariablesManager().putVariable(parentNode, INPUT, input.getPayload());
  			executionContext.getVariablesManager().putVariable(parentNode, VariableType.IMMUTABLE, OUTPUT, output);
  			
  			try {
  				ReportNode node = executionContext.getArtefactHandlerManager().execute(artefact, parentNode);
  				if(node.getStatus()== ReportNodeStatus.TECHNICAL_ERROR || node.getStatus()== ReportNodeStatus.FAILED) {
  					Error error = new Error();
  					error.setCode(0);
  					error.setMsg("Error in composite keyword");
  					error.setRoot(false);
  					error.setType(node.getStatus().equals(ReportNodeStatus.FAILED)?ErrorType.BUSINESS:ErrorType.TECHNICAL);
  					output.setError(error);
  				}
  			} finally {
  				executionContext.getVariablesManager().removeVariable(parentNode, OUTPUT);
  				executionContext.setCurrentReportNode(previousCurrentNode);
  			}
  		}
  		
  		return output.build();
  	}
focal_method.class_method_signature: ArtefactFunctionHandler.handle(Input<JsonObject> input)
focal_method.full_signature: @Override protected Output<JsonObject> handle(Input<JsonObject> input)
focal_method.identifier: handle
focal_method.invocations: get getTokenReservationSession setError get getProperties get getProperties get getReportNodeAccessor getCurrentReportNode getCurrentReportNode getCurrentReportNode setCurrentReportNode put getReportNodeCache getRoot get getPlanAccessor putVariable getVariablesManager getPayload putVariable getVariablesManager execute getArtefactHandlerManager getStatus getStatus setCode setMsg setRoot setType equals getStatus setError removeVariable getVariablesManager setCurrentReportNode build
focal_method.modifiers: @Override protected
focal_method.parameters: (Input<JsonObject> input)
focal_method.return: Output<JsonObject>
focal_method.signature: Output<JsonObject> handle(Input<JsonObject> input)