Search in sources :

Example 1 with Task

use of com.walmartlabs.concord.sdk.Task 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 2 with Task

use of com.walmartlabs.concord.sdk.Task in project concord-plugins by walmartlabs.

the class S3TaskTest method test.

@Test
@SuppressWarnings("unchecked")
public void test() throws Exception {
    String data = "Hello!";
    Path p = Files.createTempFile("test", ".txt");
    Files.write(p, data.getBytes());
    Map<String, Object> auth = new HashMap<>();
    auth.put("accessKey", System.getenv("AWS_ACCESS_KEY"));
    auth.put("secretKey", System.getenv("AWS_SECRET_KEY"));
    Map<String, Object> args = new HashMap<>();
    args.put(com.walmartlabs.concord.sdk.Constants.Context.WORK_DIR_KEY, p.getParent().toAbsolutePath().toString());
    args.put(ACTION_KEY, TaskParams.Action.PUTOBJECT.name());
    args.put(PutObjectParams.BUCKET_NAME_KEY, "ibodrov-test");
    args.put(PutObjectParams.OBJECT_KEY, "xyz");
    args.put(PutObjectParams.SRC_KEY, p.getFileName().toString());
    args.put(PutObjectParams.ENDPOINT_KEY, System.getenv("AWS_ENDPOINT"));
    args.put(PutObjectParams.REGION_KEY, System.getenv("AWS_REGION"));
    args.put(PutObjectParams.PATH_STYLE_ACCESS_KEY, true);
    args.put(PutObjectParams.AUTH_KEY, Collections.singletonMap("basic", auth));
    MockContext ctx = new MockContext(args);
    Task t = new S3Task();
    t.execute(ctx);
    Map<String, Object> r = (Map<String, Object>) ctx.getVariable(Constants.RESULT_KEY);
    assertTrue((Boolean) r.get("ok"));
    // ---
    args.put(Constants.ACTION_KEY, TaskParams.Action.GETOBJECT.name());
    ctx = new MockContext(args);
    t.execute(ctx);
    r = (Map<String, Object>) ctx.getVariable(Constants.RESULT_KEY);
    assertTrue((Boolean) r.get("ok"));
    String storedObject = (String) r.get("path");
    String s = new String(Files.readAllBytes(p.getParent().resolve(storedObject)));
    assertEquals(data, s);
}
Also used : Path(java.nio.file.Path) Task(com.walmartlabs.concord.sdk.Task) MockContext(com.walmartlabs.concord.sdk.MockContext) HashMap(java.util.HashMap) Map(java.util.Map) HashMap(java.util.HashMap) Test(org.junit.Test)

Aggregations

Task (com.walmartlabs.concord.sdk.Task)2 StepConverter (com.walmartlabs.concord.project.yaml.converter.StepConverter)1 YamlTaskStepConverter (com.walmartlabs.concord.project.yaml.converter.YamlTaskStepConverter)1 MockContext (com.walmartlabs.concord.sdk.MockContext)1 BpmnError (io.takari.bpm.api.BpmnError)1 ExecutionContext (io.takari.bpm.api.ExecutionContext)1 ExecutionException (io.takari.bpm.api.ExecutionException)1 JavaDelegate (io.takari.bpm.api.JavaDelegate)1 Form (io.takari.bpm.form.Form)1 FormSubmitResult (io.takari.bpm.form.FormSubmitResult)1 ProcessDefinition (io.takari.bpm.model.ProcessDefinition)1 Serializable (java.io.Serializable)1 Path (java.nio.file.Path)1 java.util (java.util)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)1 Collectors (java.util.stream.Collectors)1 Test (org.junit.Test)1 Assertions (org.junit.jupiter.api.Assertions)1