Search in sources :

Example 1 with CEWorkflow

use of io.temporal.samples.payloadconverter.cloudevents.CEWorkflow in project samples-java by temporalio.

the class CloudEventsPayloadConverterTest method testActivityImpl.

@Test
public void testActivityImpl() {
    List<CloudEvent> cloudEventList = new ArrayList<>();
    for (int i = 0; i < 10; i++) {
        cloudEventList.add(CloudEventBuilder.v1().withId(String.valueOf(100 + i)).withType("example.demo").withSource(URI.create("http://temporal.io")).withData("application/json", ("{\n" + "\"greeting\": \"hello " + i + "\"\n" + "}").getBytes(Charset.defaultCharset())).build());
    }
    WorkflowOptions workflowOptions = WorkflowOptions.newBuilder().setTaskQueue(testWorkflowRule.getTaskQueue()).build();
    CEWorkflow workflow = testWorkflowRule.getWorkflowClient().newWorkflowStub(CEWorkflow.class, workflowOptions);
    // start async
    WorkflowClient.start(workflow::exec, cloudEventList.get(0));
    for (int j = 1; j < 10; j++) {
        workflow.addEvent(cloudEventList.get(j));
    }
    // Get the CE result and get its data (JSON)
    String result = ((JsonCloudEventData) workflow.getLastEvent().getData()).getNode().get("greeting").asText();
    assertNotNull(result);
    assertEquals("hello 9", result);
}
Also used : CEWorkflow(io.temporal.samples.payloadconverter.cloudevents.CEWorkflow) ArrayList(java.util.ArrayList) WorkflowOptions(io.temporal.client.WorkflowOptions) JsonCloudEventData(io.cloudevents.jackson.JsonCloudEventData) CloudEvent(io.cloudevents.CloudEvent) Test(org.junit.Test)

Aggregations

CloudEvent (io.cloudevents.CloudEvent)1 JsonCloudEventData (io.cloudevents.jackson.JsonCloudEventData)1 WorkflowOptions (io.temporal.client.WorkflowOptions)1 CEWorkflow (io.temporal.samples.payloadconverter.cloudevents.CEWorkflow)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1