Search in sources :

Example 1 with ExecutionContext

use of io.takari.bpm.api.ExecutionContext in project concord by walmartlabs.

the class YamlParserTest method test033.

@SuppressWarnings("unchecked")
@Test
public void test033() throws Exception {
    String txId = UUID.randomUUID().toString();
    // ---
    deploy("033.yml");
    DockerTask task = spy(new DockerTask());
    register("docker", task);
    // ---
    String key = UUID.randomUUID().toString();
    Map<String, Object> args = new HashMap<>();
    args.put("workDir", "/tmp");
    args.put("txId", txId);
    start(key, "main", args);
    // ---
    ArgumentCaptor<ExecutionContext> captor = ArgumentCaptor.forClass(ExecutionContext.class);
    verify(task, times(1)).execute(captor.capture());
    ExecutionContext ctx = captor.getValue();
    Map<String, Object> env = (Map<String, Object>) ctx.getVariable("env");
    assertNotNull(env);
    assertEquals(2, env.size());
    assertEquals(123, env.get("x"));
    assertEquals(txId, env.get("y"));
    List<String> opts = (List<String>) ctx.getVariable("hosts");
    assertNotNull(opts);
    assertEquals(2, opts.size());
    assertEquals("foo:10.0.0.3", opts.get(0));
}
Also used : ExecutionContext(io.takari.bpm.api.ExecutionContext) Mockito.anyString(org.mockito.Mockito.anyString) Test(org.junit.jupiter.api.Test)

Example 2 with ExecutionContext

use of io.takari.bpm.api.ExecutionContext in project concord by walmartlabs.

the class YamlParserTest method test063.

@Test
public void test063() throws Exception {
    deploy("063.yml");
    JavaDelegate checkpointTask = spy(new JavaDelegate() {

        @Override
        public void execute(ExecutionContext ctx) {
            ctx.setVariable("checkpointId", "123");
        }
    });
    register("checkpoint", checkpointTask);
    // ---
    String key = UUID.randomUUID().toString();
    start(key, "main", null);
    verify(checkpointTask, times(1)).execute(any());
    verifyNoMoreInteractions(checkpointTask);
}
Also used : ExecutionContext(io.takari.bpm.api.ExecutionContext) Mockito.anyString(org.mockito.Mockito.anyString) JavaDelegate(io.takari.bpm.api.JavaDelegate) Test(org.junit.jupiter.api.Test)

Example 3 with ExecutionContext

use of io.takari.bpm.api.ExecutionContext in project concord by walmartlabs.

the class YamlParserTest method test074.

@Test
public void test074() throws Exception {
    deploy("074.yml");
    register("__withItemsUtils", new StepConverter.WithItemsUtilsTask());
    register("__retryUtils", new YamlTaskStepConverter.RetryUtilsTask());
    MyLogger task = spy(new MyLogger());
    register("log", task);
    TestErrorTask http = spy(new TestErrorTask());
    register("http", http);
    // ---
    String key = UUID.randomUUID().toString();
    start(key, "default");
    // ---
    ArgumentCaptor<ExecutionContext> captor = ArgumentCaptor.forClass(ExecutionContext.class);
    verify(http, times(12)).execute(captor.capture());
    List<String> urls = captor.getAllValues().stream().map(e -> (String) e.getVariable("url")).collect(Collectors.toList());
    assertContains("https://nonexistant.example.com/test/a", urls, 4);
    assertContains("https://nonexistant.example.com/test/b", urls, 4);
    assertContains("https://nonexistant.example.com/test/c", urls, 4);
    assertTrue(urls.isEmpty());
    verifyNoMoreInteractions(http);
}
Also used : java.util(java.util) ArgumentMatchers(org.mockito.ArgumentMatchers) StepConverter(com.walmartlabs.concord.project.yaml.converter.StepConverter) BpmnError(io.takari.bpm.api.BpmnError) Mockito.isNull(org.mockito.Mockito.isNull) Collectors(java.util.stream.Collectors) ExecutionException(io.takari.bpm.api.ExecutionException) Serializable(java.io.Serializable) Test(org.junit.jupiter.api.Test) Form(io.takari.bpm.form.Form) Mockito(org.mockito.Mockito) FormSubmitResult(io.takari.bpm.form.FormSubmitResult) ArgumentCaptor(org.mockito.ArgumentCaptor) ProcessDefinition(io.takari.bpm.model.ProcessDefinition) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) Task(com.walmartlabs.concord.sdk.Task) Assertions(org.junit.jupiter.api.Assertions) JavaDelegate(io.takari.bpm.api.JavaDelegate) Mockito.anyInt(org.mockito.Mockito.anyInt) ExecutionContext(io.takari.bpm.api.ExecutionContext) YamlTaskStepConverter(com.walmartlabs.concord.project.yaml.converter.YamlTaskStepConverter) Mockito.anyString(org.mockito.Mockito.anyString) ExecutionContext(io.takari.bpm.api.ExecutionContext) YamlTaskStepConverter(com.walmartlabs.concord.project.yaml.converter.YamlTaskStepConverter) StepConverter(com.walmartlabs.concord.project.yaml.converter.StepConverter) YamlTaskStepConverter(com.walmartlabs.concord.project.yaml.converter.YamlTaskStepConverter) Mockito.anyString(org.mockito.Mockito.anyString) Test(org.junit.jupiter.api.Test)

Example 4 with ExecutionContext

use of io.takari.bpm.api.ExecutionContext in project concord by walmartlabs.

the class YamlParserTest method test068.

@Test
public void test068() throws Exception {
    deploy("068.yml");
    MyLogger logBean = spy(new MyLogger());
    register("log", logBean);
    JavaDelegate task = mock(JavaDelegate.class);
    doThrow(new BpmnError("first error")).doNothing().when(task).execute(any());
    register("testErrorTask", task);
    JavaDelegate task2 = mock(JavaDelegate.class);
    doThrow(new BpmnError("first error")).doNothing().when(task2).execute(any());
    register("testErrorTask2", task2);
    register("__retryUtils", new YamlTaskStepConverter.RetryUtilsTask());
    // ---
    String key = UUID.randomUUID().toString();
    start(key, "main", null);
    // ---
    ArgumentCaptor<ExecutionContext> ctxCaptor = ArgumentCaptor.forClass(ExecutionContext.class);
    verify(task, times(2)).execute(ctxCaptor.capture());
    List<ExecutionContext> retryCtx = ctxCaptor.getAllValues();
    assertEquals("test", retryCtx.get(0).getVariable("msg"));
    assertEquals("retry", retryCtx.get(1).getVariable("msg"));
    verifyNoMoreInteractions(task);
    // ---
    ArgumentCaptor<ExecutionContext> ctxCaptor2 = ArgumentCaptor.forClass(ExecutionContext.class);
    verify(task2, times(2)).execute(ctxCaptor2.capture());
    List<ExecutionContext> retryCtx2 = ctxCaptor2.getAllValues();
    assertEquals("test2", retryCtx2.get(0).getVariable("msg"));
    assertEquals("retry2", retryCtx2.get(1).getVariable("msg"));
    verifyNoMoreInteractions(task2);
}
Also used : ExecutionContext(io.takari.bpm.api.ExecutionContext) YamlTaskStepConverter(com.walmartlabs.concord.project.yaml.converter.YamlTaskStepConverter) Mockito.anyString(org.mockito.Mockito.anyString) JavaDelegate(io.takari.bpm.api.JavaDelegate) BpmnError(io.takari.bpm.api.BpmnError) Test(org.junit.jupiter.api.Test)

Example 5 with ExecutionContext

use of io.takari.bpm.api.ExecutionContext in project concord by walmartlabs.

the class YamlParserTest method test077.

@Test
public void test077() throws Exception {
    deploy("077.yml");
    ProcessDefinition pd = getDefinition("main");
    TestBean testBean = spy(new TestBean());
    register("testBean", testBean);
    JavaDelegate task = mock(JavaDelegate.class);
    doThrow(new BpmnError("first error")).doNothing().when(task).execute(any());
    register("testErrorTask", task);
    register("__retryUtils", new YamlTaskStepConverter.RetryUtilsTask());
    // ---
    String key = UUID.randomUUID().toString();
    start(key, "main", null);
    // ---
    ArgumentCaptor<ExecutionContext> ctxCaptor = ArgumentCaptor.forClass(ExecutionContext.class);
    verify(task, times(2)).execute(ctxCaptor.capture());
    List<ExecutionContext> retryCtx = ctxCaptor.getAllValues();
    assertEquals("test", retryCtx.get(0).getVariable("msg"));
    assertEquals("retry", retryCtx.get(1).getVariable("msg"));
    verify(testBean, times(1)).toString(eq("end"));
    verifyNoMoreInteractions(testBean);
    verifyNoMoreInteractions(task);
}
Also used : ExecutionContext(io.takari.bpm.api.ExecutionContext) YamlTaskStepConverter(com.walmartlabs.concord.project.yaml.converter.YamlTaskStepConverter) ProcessDefinition(io.takari.bpm.model.ProcessDefinition) Mockito.anyString(org.mockito.Mockito.anyString) JavaDelegate(io.takari.bpm.api.JavaDelegate) BpmnError(io.takari.bpm.api.BpmnError) Test(org.junit.jupiter.api.Test)

Aggregations

ExecutionContext (io.takari.bpm.api.ExecutionContext)12 Test (org.junit.jupiter.api.Test)9 Mockito.anyString (org.mockito.Mockito.anyString)9 JavaDelegate (io.takari.bpm.api.JavaDelegate)8 YamlTaskStepConverter (com.walmartlabs.concord.project.yaml.converter.YamlTaskStepConverter)6 BpmnError (io.takari.bpm.api.BpmnError)5 StepConverter (com.walmartlabs.concord.project.yaml.converter.StepConverter)3 ProcessDefinition (io.takari.bpm.model.ProcessDefinition)2 VariablesSnapshotListener (com.walmartlabs.concord.runner.VariablesSnapshotListener)1 InjectVariableELResolver (com.walmartlabs.concord.runner.engine.el.InjectVariableELResolver)1 TaskResolver (com.walmartlabs.concord.runner.engine.el.TaskResolver)1 Task (com.walmartlabs.concord.sdk.Task)1 Configuration (io.takari.bpm.Configuration)1 EngineBuilder (io.takari.bpm.EngineBuilder)1 Engine (io.takari.bpm.api.Engine)1 ExecutionException (io.takari.bpm.api.ExecutionException)1 DefaultExecutionContextFactory (io.takari.bpm.context.DefaultExecutionContextFactory)1 DefaultExpressionManager (io.takari.bpm.el.DefaultExpressionManager)1 ExecutionContextVariableResolver (io.takari.bpm.el.ExecutionContextVariableResolver)1 ExpressionManager (io.takari.bpm.el.ExpressionManager)1