package io.nimbuspay.apply;
import io.camunda.zeebe.client.ZeebeClient;
import io.camunda.zeebe.client.api.response.*;
import io.camunda.zeebe.client.impl.ZeebeObjectMapper;
import io.camunda.zeebe.process.test.api.ZeebeTestEngine;
import io.camunda.zeebe.process.test.assertions.BpmnAssert;
import io.camunda.zeebe.process.test.assertions.ProcessInstanceAssert;
import io.camunda.zeebe.process.test.extension.ZeebeProcessTest;
import io.camunda.zeebe.process.test.filters.RecordStream;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.util.Collections;
import java.util.List;
@ZeebeProcessTest
public class EmailValidationBpmnTest {
private ZeebeClient client;
private ZeebeTestEngine engine;
private RecordStream recordStream;
private static final String RESOURCE = "email_validation.bpmn";
private static final String PROCESS_ID = "email";
@BeforeEach
void deployProcesses() {
final DeploymentEvent deploymentEvent = initDeployment(RESOURCE);
BpmnAssert.assertThat(deploymentEvent).containsProcessesByResourceName(RESOURCE);
}
@Test
public void shouldExecuteProcess() {
try {
initDeployment(RESOURCE);
initProcessInstanceStart();
ActivateJobsResponse jobsResponse = client.newActivateJobsCommand()
.jobType("passcode")
.maxJobsToActivate(1)
.send().join();
final String json = new ZeebeObjectMapper().toJson(Collections.singletonMap("emailAddress", "emailAddress@com"));
List<ActivatedJob> activatedJobList = jobsResponse.getJobs();
System.out.println(activatedJobList.get(0));
CompleteJobResponse result = client.newCompleteCommand(activatedJobList.stream().findFirst().get())
.variables(json).send().join();
System.out.println(result);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
private ProcessInstanceEvent initProcessInstanceStart() {
final ProcessInstanceEvent events = client.newCreateInstanceCommand()
.bpmnProcessId(PROCESS_ID)
.latestVersion()
.send()
.join();
ProcessInstanceAssert assertions = BpmnAssert.assertThat(events);
assertions.hasPassedElement("StartEvent_1");
return events;
}
private DeploymentEvent initDeployment(String resource) {
DeploymentEvent event = client.newDeployCommand()
.addResourceFromClasspath(resource)
.send()
.join();
return event;
}
}
Here below code should invoke actual method attached to service task but unfortunately its not
CompleteJobResponse result = client.newCompleteCommand(activatedJobList.stream().findFirst().get())
.variables(json).send().join();
@JobWorker(type = "passcode", autoComplete = false)
public void passcode(@VariablesAsType EmailAddress emailAddress) {
System.out.println(emailAddress);
}