Search in sources :

Example 1 with JavaDelegate

use of io.takari.bpm.api.JavaDelegate 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 2 with JavaDelegate

use of io.takari.bpm.api.JavaDelegate 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 3 with JavaDelegate

use of io.takari.bpm.api.JavaDelegate 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)

Example 4 with JavaDelegate

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

the class YamlParserTest method test058.

@Test
public void test058() throws Exception {
    deploy("058.yml");
    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());
    register("__withItemsUtils", new StepConverter.WithItemsUtilsTask());
    // ---
    String key = UUID.randomUUID().toString();
    start(key, "main", null);
    // ---
    ArgumentCaptor<ExecutionContext> ctxCaptor = ArgumentCaptor.forClass(ExecutionContext.class);
    verify(task, times(3)).execute(ctxCaptor.capture());
    List<ExecutionContext> retryCtx = ctxCaptor.getAllValues();
    assertEquals("test: item1", retryCtx.get(0).getVariable("msg"));
    assertEquals("retry: item1", retryCtx.get(1).getVariable("msg"));
    assertEquals("test: item2", retryCtx.get(2).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) StepConverter(com.walmartlabs.concord.project.yaml.converter.StepConverter) 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 JavaDelegate

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

the class YamlParserTest method test035.

@Test
public void test035() throws Exception {
    deploy("035.yml");
    JavaDelegate task = spy(new JavaDelegate() {

        @SuppressWarnings("rawtypes")
        @Override
        public void execute(ExecutionContext ctx) {
            Object o = ctx.getVariable("aList");
            assertTrue(o instanceof List);
            List l = (List) o;
            assertEquals(3, l.size());
            assertEquals(132, l.get(2));
        }
    });
    register("testTask", task);
    // ---
    String key = UUID.randomUUID().toString();
    start(key, "main", null);
    // ---
    verify(task, times(1)).execute(any(ExecutionContext.class));
}
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)

Aggregations

ExecutionContext (io.takari.bpm.api.ExecutionContext)7 JavaDelegate (io.takari.bpm.api.JavaDelegate)7 Test (org.junit.jupiter.api.Test)7 Mockito.anyString (org.mockito.Mockito.anyString)7 YamlTaskStepConverter (com.walmartlabs.concord.project.yaml.converter.YamlTaskStepConverter)5 BpmnError (io.takari.bpm.api.BpmnError)4 StepConverter (com.walmartlabs.concord.project.yaml.converter.StepConverter)2 ProcessDefinition (io.takari.bpm.model.ProcessDefinition)1