Search in sources :

Example 1 with FormListEntry

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

the class FormIT method testFormValues.

@Test
public void testFormValues() throws Exception {
    Payload payload = new Payload().archive(resource("customFormValues"));
    // ---
    ConcordProcess proc = concord.processes().start(payload);
    ProcessEntry pe = expectStatus(proc, ProcessEntry.StatusEnum.SUSPENDED);
    // ---
    List<FormListEntry> forms = proc.forms();
    assertEquals(1, forms.size());
    // ---
    String formName = forms.get(0).getName();
    assertEquals("myForm", formName);
    // start session
    startCustomFormSession(concord, pe.getInstanceId(), formName);
    // get data.js
    Map<String, Object> dataJs = getDataJs(concord, pe.getInstanceId(), formName);
    Map<String, Object> values = MapUtils.get(dataJs, "values", Collections.emptyMap());
    assertEquals(4, values.size());
    assertEquals("Moo", values.get("firstName"));
    assertEquals("Xaa", values.get("lastName"));
    assertEquals(3, values.get("sum"));
    assertEquals(ImmutableMap.of("city", "Toronto", "province", "Ontario"), values.get("address"));
}
Also used : ConcordProcess(ca.ibodrov.concord.testcontainers.ConcordProcess) FormListEntry(com.walmartlabs.concord.client.FormListEntry) ProcessEntry(com.walmartlabs.concord.client.ProcessEntry) Payload(ca.ibodrov.concord.testcontainers.Payload) ITUtils.randomString(com.walmartlabs.concord.it.common.ITUtils.randomString) Test(org.junit.jupiter.api.Test)

Example 2 with FormListEntry

use of com.walmartlabs.concord.client.FormListEntry 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 3 with FormListEntry

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

the class ProcessIT method testMetaUpdate.

/**
 * Test the process metadata.
 */
@Test
public void testMetaUpdate() throws Exception {
    Payload payload = new Payload().archive(resource("meta")).arg("name", "Concord");
    ConcordProcess proc = concord.processes().start(payload);
    ProcessEntry pe = expectStatus(proc, ProcessEntry.StatusEnum.SUSPENDED);
    // ---
    proc.assertLog(".*Runtime: concord-v2.*");
    proc.assertLog(".*Hello, Concord!.*");
    assertNotNull(pe.getMeta());
    // 2 + plus system meta + entryPoint
    assertEquals(4, pe.getMeta().size());
    assertEquals("init-value", pe.getMeta().get("test"));
    assertEquals("xxx", pe.getMeta().get("myForm.action"));
    assertEquals("default", pe.getMeta().get("entryPoint"));
    // ---
    List<FormListEntry> forms = proc.forms();
    assertEquals(1, forms.size());
    Map<String, Object> data = new HashMap<>();
    data.put("action", "Reject");
    FormSubmitResponse fsr = proc.submitForm(forms.get(0).getName(), data);
    assertTrue(fsr.isOk());
    pe = expectStatus(proc, ProcessEntry.StatusEnum.FINISHED);
    // ---
    proc.assertLog(".*Action: Reject.*");
    assertNotNull(pe.getMeta());
    // 2 + plus system meta + entryPoint
    assertEquals(4, pe.getMeta().size());
    assertEquals("init-value", pe.getMeta().get("test"));
    assertEquals("Reject", pe.getMeta().get("myForm.action"));
    assertEquals("default", pe.getMeta().get("entryPoint"));
}
Also used : ConcordProcess(ca.ibodrov.concord.testcontainers.ConcordProcess) FormListEntry(com.walmartlabs.concord.client.FormListEntry) HashMap(java.util.HashMap) FormSubmitResponse(com.walmartlabs.concord.client.FormSubmitResponse) ProcessEntry(com.walmartlabs.concord.client.ProcessEntry) Payload(ca.ibodrov.concord.testcontainers.Payload) Utils.resourceToString(com.walmartlabs.concord.it.runtime.v2.Utils.resourceToString) ITUtils.randomString(com.walmartlabs.concord.it.common.ITUtils.randomString) Test(org.junit.jupiter.api.Test)

Example 4 with FormListEntry

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

the class ProcessIT method testWorkDir.

@Test
public void testWorkDir() throws Exception {
    byte[] archive = archive(ProcessIT.class.getResource("workDir").toURI());
    ConcordProcess proc = concord.processes().start(new Payload().archive(archive));
    proc.expectStatus(StatusEnum.SUSPENDED);
    proc.assertLog(".*Hello!");
    proc.assertLog(".*Bye!");
    // ---
    List<FormListEntry> forms = proc.forms();
    assertEquals(1, forms.size());
    FormListEntry f = forms.get(0);
    FormSubmitResponse fsr = proc.submitForm(f.getName(), Collections.singletonMap("name", "test"));
    assertNull(fsr.getErrors());
    // ---
    proc.expectStatus(StatusEnum.FINISHED);
    proc.assertLogAtLeast(".*Hello!", 2);
    proc.assertLogAtLeast(".*Bye!", 2);
}
Also used : ConcordProcess(ca.ibodrov.concord.testcontainers.ConcordProcess) FormListEntry(com.walmartlabs.concord.client.FormListEntry) FormSubmitResponse(com.walmartlabs.concord.client.FormSubmitResponse) Payload(ca.ibodrov.concord.testcontainers.Payload) Test(org.junit.jupiter.api.Test)

Example 5 with FormListEntry

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

the class ProfilesIT method testFormOverride.

/**
 * Override/define forms from profiles.
 */
@Test
public void testFormOverride() throws Exception {
    Payload payload = new Payload().activeProfiles("stranger").archive(resource("profileForm"));
    ConcordProcess proc = concord.processes().start(payload);
    // ---
    expectStatus(proc, ProcessEntry.StatusEnum.SUSPENDED);
    // ---
    List<FormListEntry> forms = proc.forms();
    assertEquals(1, forms.size());
    FormListEntry myForm = forms.get(0);
    assertNotNull(myForm);
    String firstName = "john_" + randomString();
    String lastName = "smith_" + randomString();
    Map<String, Object> data = new HashMap<>();
    data.put("lastName", lastName);
    data.put("firstName", firstName);
    FormSubmitResponse fsr = proc.submitForm(myForm.getName(), data);
    assertTrue(fsr.isOk());
    assertTrue(fsr.getErrors() == null || fsr.getErrors().isEmpty());
    expectStatus(proc, ProcessEntry.StatusEnum.FINISHED);
    proc.assertLog(".*firstName=" + firstName + ".*");
    proc.assertLog(".*lastName=" + lastName + ".*");
}
Also used : ConcordProcess(ca.ibodrov.concord.testcontainers.ConcordProcess) FormListEntry(com.walmartlabs.concord.client.FormListEntry) HashMap(java.util.HashMap) 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)

Aggregations

ConcordProcess (ca.ibodrov.concord.testcontainers.ConcordProcess)7 Payload (ca.ibodrov.concord.testcontainers.Payload)7 FormListEntry (com.walmartlabs.concord.client.FormListEntry)7 Test (org.junit.jupiter.api.Test)7 FormSubmitResponse (com.walmartlabs.concord.client.FormSubmitResponse)6 ITUtils.randomString (com.walmartlabs.concord.it.common.ITUtils.randomString)6 ProcessEntry (com.walmartlabs.concord.client.ProcessEntry)2 HashMap (java.util.HashMap)2 ProcessApi (com.walmartlabs.concord.client.ProcessApi)1 Utils.resourceToString (com.walmartlabs.concord.it.runtime.v2.Utils.resourceToString)1