package com.netflix.conductor.contribs.script;

import com.netflix.conductor.common.metadata.tasks.Task;
import com.netflix.conductor.common.run.Workflow;
import com.netflix.conductor.contribs.lambda.Lambda;
import com.netflix.conductor.core.execution.WorkflowExecutor;
import org.junit.Test;

import java.util.HashMap;
import java.util.Map;

import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;

public class LambdaTest {

    private Workflow workflow = new Workflow();
    private WorkflowExecutor executor = mock(WorkflowExecutor.class);


    @Test
    public void start() throws Exception {
        Lambda lambda = new Lambda();

        Map inputObj = new HashMap();
        inputObj.put("a",1);

        /**
         * test for scriptExpression == null
         */
        Task task = new Task();
        task.getInputData().put("input", inputObj);
        lambda.start(workflow, task, executor);
        assertEquals(Task.Status.FAILED, task.getStatus());

        /**
         * test for normal
         */
        task = new Task();
        task.getInputData().put("input", inputObj);
        task.getInputData().put("scriptExpression", "if ($.input.a==1){return {a:true}}else{return {a:false} } ");
        lambda.start(workflow, task, executor);
        assertEquals(Task.Status.COMPLETED, task.getStatus());

        /**
         * test for scriptExpression ScriptException
         */
        task = new Task();
        task.getInputData().put("input", inputObj);
        task.getInputData().put("scriptExpression", "if ($.a.size==1){return 1}else{return 0 } ");
        lambda.start(workflow, task, executor);
        assertEquals(Task.Status.FAILED, task.getStatus());
    }

}
@@ -1203,16 +1203,9 @@
 urn 
-%7Ba:true%7D
+1
 %7Dels
@@ -1217,17 +1217,9 @@
 urn 
-%7Ba:false%7D
+0
  %7D %22
@@ -1323,32 +1323,101 @@
 sk.getStatus());
+%0A        assertEquals(task.getOutputData().toString(), %22%7Bresult=1%7D%22);
 %0A%0A        /**%0A  

Update LambdaTest.java