Not able to invoke actual method behind service task

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);
    }

Hi @12vineet, welcome to the forums! I’m a bit unclear on your question. Are you expecting your passcode() method to be called within your test? If so, that’s not how ZPT works, it is not registering your job worker with the test engine, and your code isn’t calling passcode() before the CompleteJobResponse.

Yes i want my passcode() method to be called within my test.
can you suggest what changes i need to do here in order to invoke passcode() method within test.

@12vineet - the line client.newCompleteCommand is completing the job; you would need to invoke the job before that in your test, passing along the required parameters. I admit I have not done this so I don’t have any deeper guidance.

I do think it’s worth considering why you want to invoke your job there. ZPT is meant to unit test the process itself, not the external interfaces, which are mocked just as you would mock something like a database in unit tests in “normal” application code. The process itself doesn’t care what method completed the job, just that the job was completed with a defined result to move the process to the next task, which is what you are doing with the newCompleteCommand.