Search in sources :

Example 1 with BpmnError

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

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

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

the class ProcessErrorProcessor method getError.

private static Throwable getError(Throwable t) {
    t = unroll(t);
    if (t instanceof BpmnError) {
        BpmnError error = (BpmnError) t;
        if (!DEFAULT_ERROR_REF.equals(error.getErrorRef())) {
            return error;
        }
        Throwable cause = error.getCause();
        if (cause == null) {
            return error;
        }
    }
    if (t instanceof ELException && t.getCause() != null) {
        return t.getCause();
    }
    return t;
}
Also used : ELException(javax.el.ELException) BpmnError(io.takari.bpm.api.BpmnError)

Example 4 with BpmnError

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

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

the class YamlParserTest method test048.

@Test
public void test048() throws Exception {
    deploy("048.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());
    // ---
    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"));
    Map<String, String> expectedVars0 = new HashMap<>();
    expectedVars0.put("a", "a-value-original");
    expectedVars0.put("b", "b-value-original");
    Map<String, String> expectedVars1 = new HashMap<>();
    expectedVars1.put("a", "a-value-original");
    expectedVars1.put("b", "b-value-retry");
    assertEquals(expectedVars0, retryCtx.get(0).getVariable("nested"));
    assertEquals(expectedVars1, retryCtx.get(1).getVariable("nested"));
    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) 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

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