Search in sources :

Example 1 with ProcessApi

use of com.walmartlabs.concord.client.ProcessApi in project concord by walmartlabs.

the class FormIT method testSubmitInInvalidProcessState.

@Test
public void testSubmitInInvalidProcessState() throws Exception {
    Payload payload = new Payload().archive(resource("form"));
    // ---
    ConcordProcess proc = concord.processes().start(payload);
    expectStatus(proc, ProcessEntry.StatusEnum.SUSPENDED);
    // ---
    List<FormListEntry> forms = proc.forms();
    assertEquals(1, forms.size());
    // change process status to emulate resuming from another form
    ProcessApi api = new ProcessApi(concord.apiClient());
    api.updateStatus(proc.instanceId(), UUID.randomUUID().toString(), ProcessEntry.StatusEnum.RESUMING.getValue());
    // form data
    String firstName = "john_" + randomString();
    String lastName = "smith_" + randomString();
    int age = ThreadLocalRandom.current().nextInt(100);
    Map<String, Object> data = new HashMap<>();
    data.put("lastName", lastName);
    data.put("firstName", firstName);
    data.put("age", age);
    try {
        proc.submitForm(forms.get(0).getName(), data);
        fail("exception expected");
    } catch (Exception e) {
    // ignore
    }
    // change process status back to emulate another form submitted
    api.updateStatus(proc.instanceId(), UUID.randomUUID().toString(), ProcessEntry.StatusEnum.SUSPENDED.getValue());
    forms = proc.forms();
    assertEquals(1, forms.size());
    FormListEntry myForm = forms.get(0);
    assertFalse(myForm.isCustom());
    String formName = myForm.getName();
    assertEquals("myForm", formName);
    FormSubmitResponse fsr = proc.submitForm(formName, data);
    assertTrue(fsr.isOk());
    assertTrue(fsr.getErrors() == null || fsr.getErrors().isEmpty());
    expectStatus(proc, ProcessEntry.StatusEnum.FINISHED);
    // ---
    proc.assertLog(".*firstName=" + firstName + ".*");
    proc.assertLog(".*lastName=" + lastName + ".*");
    proc.assertLog(".*age=" + age + ".*");
}
Also used : ProcessApi(com.walmartlabs.concord.client.ProcessApi) ConcordProcess(ca.ibodrov.concord.testcontainers.ConcordProcess) FormListEntry(com.walmartlabs.concord.client.FormListEntry) FormSubmitResponse(com.walmartlabs.concord.client.FormSubmitResponse) Payload(ca.ibodrov.concord.testcontainers.Payload) ITUtils.randomString(com.walmartlabs.concord.it.common.ITUtils.randomString) Test(org.junit.jupiter.api.Test)

Example 2 with ProcessApi

use of com.walmartlabs.concord.client.ProcessApi in project concord by walmartlabs.

the class FormsIT method testDateTimeField.

@Test
public void testDateTimeField() throws Exception {
    ApiClient apiClient = serverRule.getClient();
    // ---
    byte[] payload = archive(FormsIT.class.getResource("dateTimeField").toURI());
    Map<String, Object> input = new HashMap<>();
    input.put("archive", payload);
    ProcessApi processApi = new ProcessApi(apiClient);
    StartProcessResponse spr = serverRule.start(input);
    assertNotNull(spr.getInstanceId());
    ProcessEntry pir = waitForStatus(processApi, spr.getInstanceId(), ProcessEntry.StatusEnum.SUSPENDED);
    // ---
    consoleRule.login(Concord.ADMIN_API_KEY);
    String url = "/#/process/" + pir.getInstanceId();
    consoleRule.navigateToRelative(url);
    WebElement wizardButton = consoleRule.waitFor(By.id("formWizardButton"));
    wizardButton.click();
    WebElement dateField = consoleRule.waitFor(By.name("dateField"));
    dateField.sendKeys("2019-09-04");
    WebElement dateTimeField = consoleRule.waitFor(By.name("dateTimeField"));
    dateTimeField.sendKeys("2019-09-04T01:05:00.000-04:00");
    // close the popup
    consoleRule.waitFor(By.id("root")).click();
    Thread.sleep(1000);
    WebElement submitButton = consoleRule.waitFor(By.id("formSubmitButton"));
    submitButton.click();
    // ---
    pir = waitForCompletion(processApi, pir.getInstanceId());
    byte[] ab = serverRule.getLog(pir.getLogFileName());
    assertLog(".*dateField=2019-09-04.*", ab);
    assertLog(".*dateTimeField=2019-09-04T05:05:00.000Z.*", ab);
}
Also used : ProcessApi(com.walmartlabs.concord.client.ProcessApi) HashMap(java.util.HashMap) ProcessEntry(com.walmartlabs.concord.client.ProcessEntry) ApiClient(com.walmartlabs.concord.ApiClient) WebElement(org.openqa.selenium.WebElement) StartProcessResponse(com.walmartlabs.concord.client.StartProcessResponse) Test(org.junit.jupiter.api.Test)

Example 3 with ProcessApi

use of com.walmartlabs.concord.client.ProcessApi in project concord by walmartlabs.

the class DependenciesIT method testUploadAndRun.

@Test
public void testUploadAndRun() throws Exception {
    String dep = "file:///" + ITConstants.DEPENDENCIES_DIR + "/example.jar";
    String request = "{ \"entryPoint\": \"main\", \"dependencies\": [ \"" + dep + "\" ] }";
    Path tmpDir = createTempDir();
    Path requestFile = tmpDir.resolve(Constants.Files.CONFIGURATION_FILE_NAME);
    Files.write(requestFile, Collections.singletonList(request));
    Path src = Paths.get(DependenciesIT.class.getResource("deps").toURI());
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    try (ZipArchiveOutputStream zip = new ZipArchiveOutputStream(baos)) {
        IOUtils.zip(zip, src);
        IOUtils.zip(zip, tmpDir);
    }
    byte[] payload = baos.toByteArray();
    // ---
    ProcessApi processApi = new ProcessApi(getApiClient());
    StartProcessResponse spr = start(payload);
    assertNotNull(spr.getInstanceId());
    ProcessEntry psr = waitForCompletion(processApi, spr.getInstanceId());
    assertEquals(ProcessEntry.StatusEnum.FINISHED, psr.getStatus());
    // ---
    byte[] ab = getLog(psr.getLogFileName());
    assertLog(".*Hello!.*", ab);
}
Also used : Path(java.nio.file.Path) ProcessApi(com.walmartlabs.concord.client.ProcessApi) ZipArchiveOutputStream(org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream) ProcessEntry(com.walmartlabs.concord.client.ProcessEntry) ByteArrayOutputStream(java.io.ByteArrayOutputStream) StartProcessResponse(com.walmartlabs.concord.client.StartProcessResponse) Test(org.junit.jupiter.api.Test)

Example 4 with ProcessApi

use of com.walmartlabs.concord.client.ProcessApi in project concord by walmartlabs.

the class DependencyManagerIT method test.

@Test
public void test() throws Exception {
    byte[] payload = archive(DependencyManagerIT.class.getResource("dependencyManager").toURI());
    Map<String, Object> input = new HashMap<>();
    input.put("archive", payload);
    Map<String, Object> cfg = new HashMap<>();
    cfg.put("dependencies", new String[] { "mvn://com.walmartlabs.concord.it.tasks:dependency-manager-test:" + ITConstants.PROJECT_VERSION });
    String url = "http://" + env("IT_DOCKER_HOST_ADDR", "localhost") + ":" + rule.getPort() + "/item.txt";
    cfg.put("arguments", Collections.singletonMap("url", url));
    input.put("request", cfg);
    StartProcessResponse spr = start(input);
    // ---
    ProcessApi processApi = new ProcessApi(getApiClient());
    ProcessEntry pir = waitForStatus(processApi, spr.getInstanceId(), ProcessEntry.StatusEnum.SUSPENDED);
    byte[] ab = getLog(pir.getLogFileName());
    assertLog(".*downloading.*", ab);
    assertLog(".*using a cached copy.*", ab);
    assertLog(".*Got: Hello!.*", ab);
}
Also used : ProcessApi(com.walmartlabs.concord.client.ProcessApi) HashMap(java.util.HashMap) ProcessEntry(com.walmartlabs.concord.client.ProcessEntry) StartProcessResponse(com.walmartlabs.concord.client.StartProcessResponse) Test(org.junit.jupiter.api.Test)

Example 5 with ProcessApi

use of com.walmartlabs.concord.client.ProcessApi in project concord by walmartlabs.

the class DockerAnsibleIT method test.

@Test
public void test() throws Exception {
    byte[] payload = archive(DockerIT.class.getResource("dockerAnsible").toURI(), ITConstants.DEPENDENCIES_DIR);
    Map<String, Object> input = new HashMap<>();
    input.put("archive", payload);
    input.put("arguments.image", ITConstants.DOCKER_ANSIBLE_IMAGE);
    StartProcessResponse spr = start(input);
    // --
    ProcessApi processApi = new ProcessApi(getApiClient());
    ProcessEntry pir = waitForCompletion(processApi, spr.getInstanceId());
    assertNotNull(pir.getLogFileName());
    assertEquals(ProcessEntry.StatusEnum.FINISHED, pir.getStatus());
    byte[] ab = getLog(pir.getLogFileName());
    assertLog(".*\"msg\": \"Hello from Docker!\".*", ab);
    // --
    File resp = processApi.downloadAttachment(pir.getInstanceId(), "ansible_stats.json");
    assertNotNull(resp);
}
Also used : ProcessApi(com.walmartlabs.concord.client.ProcessApi) HashMap(java.util.HashMap) ProcessEntry(com.walmartlabs.concord.client.ProcessEntry) File(java.io.File) StartProcessResponse(com.walmartlabs.concord.client.StartProcessResponse) Test(org.junit.jupiter.api.Test)

Aggregations

ProcessApi (com.walmartlabs.concord.client.ProcessApi)58 ProcessEntry (com.walmartlabs.concord.client.ProcessEntry)55 StartProcessResponse (com.walmartlabs.concord.client.StartProcessResponse)54 Test (org.junit.jupiter.api.Test)54 HashMap (java.util.HashMap)34 URI (java.net.URI)23 File (java.io.File)4 Path (java.nio.file.Path)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 UUID (java.util.UUID)2 ZipArchiveOutputStream (org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream)2 ConcordProcess (ca.ibodrov.concord.testcontainers.ConcordProcess)1 Payload (ca.ibodrov.concord.testcontainers.Payload)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ApiClient (com.walmartlabs.concord.ApiClient)1 ApiException (com.walmartlabs.concord.ApiException)1 FormListEntry (com.walmartlabs.concord.client.FormListEntry)1 FormSubmitResponse (com.walmartlabs.concord.client.FormSubmitResponse)1 ITUtils.randomString (com.walmartlabs.concord.it.common.ITUtils.randomString)1 PosixFilePermission (java.nio.file.attribute.PosixFilePermission)1