Camunda http connector and execution listener unit test

I am writing a unit test to test a bpmn activity.
My bpmn file contains 3 service tasks, each service task makes an http call using http-connector, I am using wiremock to mock http calls.
I am able to mock 2 calls successfully in 2 service tasks.

The 3rd service task which does 2 things,
a. Makes an http call
b. Has a execution listener (event type : end) : this listener, would use the response from abovehttp
call.
As part of testing what I observed was, before it fetches mocked response, its going to execution listener and starts executing (eventType) end script.
In execution listener I am making using of response from 3rd service task
How do I ensure the executionListener waits till it gets the response from 3rd service task?
I attached the bpmn file, the problem is with save task (service task), take a look at response in Connector tab and end script in Listeners tab
create-template.bpmn (38.7 KB)

Can you brief, how you tested http connector?

sorry for the late reply
as part of unit testing, I was not calling the real end point, instead I was using wiremock.
In the wiremock I was intercepting every request, if the request matches then I am sending out the stubbed response
Try to implement ConnectorConfigurator and override configure method



import org.apache.http.client.methods.*;
import org.camunda.connect.httpclient.HttpConnector;
import org.camunda.connect.spi.ConnectorConfigurator;
import org.camunda.connect.spi.ConnectorInvocation;
import org.camunda.connect.spi.ConnectorRequestInterceptor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.net.URI;
import java.net.URISyntaxException;

/**
   
    This class is used to intercept all the http-connector request and replace the host name with localhost.
 */

public class MockHttpConnectorConfigurator implements ConnectorConfigurator<HttpConnector> {

    private static final Logger log = LoggerFactory.getLogger(MockHttpConnectorConfigurator.class);

    public static final String LOCALHOST = "localhost";
    public static final int WIREMOCK_PORT = 8020;

    /**
     * Register the HttpConnector class
     */
    @Override
    public Class<HttpConnector> getConnectorClass() {
        return HttpConnector.class;
    }

    /**
     *  Configure the http connector and intercept http calls when camunda service task calls.
     * @param connector
     */
    @Override
    public void configure(HttpConnector connector) {
        connector.addRequestInterceptor(new ConnectorRequestInterceptor() {
            @Override
            public Object handleInvocation(ConnectorInvocation invocation) throws Exception {
                if (invocation.getTarget() instanceof HttpPost || invocation.getTarget() instanceof HttpPut) {
                    HttpEntityEnclosingRequestBase httpTarget = (HttpEntityEnclosingRequestBase) invocation.getTarget();
                    URI actualURI = httpTarget.getURI();
                    httpTarget.setURI(resetURIToLocalhost(actualURI));
                    log.info("Http connector target URL changed from " + actualURI.toString() + " to " + httpTarget.getURI().toString());
                } else if(invocation.getTarget() instanceof HttpDelete) {
                    HttpRequestBase httpTarget = (HttpRequestBase) invocation.getTarget();
                    URI actualURI = httpTarget.getURI();
                    httpTarget.setURI(resetURIToLocalhost(actualURI));
                    log.info("Http connector target URL changed from " + actualURI.toString() + " to " + httpTarget.getURI().toString());
                } else {
                    HttpGet getRequest = (HttpGet) invocation.getTarget();
                    URI actualURI = getRequest.getURI();
                    getRequest.setURI(resetURIToLocalhost(actualURI));
                    log.info("Http connector target URL changed from " + actualURI.toString() + " to " + getRequest.getURI().toString());
                }
                return invocation.proceed();
            }
        });
    }

    /**
     * This method will generate localhost URL for wiremock by replacing actual URL
     * @param actualURI
     * @return mockURI
     */
    public URI resetURIToLocalhost(URI actualURI) {
        URI mockURI = null;
        try {
            mockURI = new URI(actualURI.getScheme(), actualURI.getUserInfo(), LOCALHOST, WIREMOCK_PORT, actualURI.getPath(), actualURI.getQuery(), actualURI.getFragment());
        } catch(URISyntaxException ex) {
            log.error("Updating URI port failed." + ex.getMessage());
            ex.getStackTrace();
            return actualURI;
        }
        return mockURI;
    }
}

Hi,
Can you tell me how you intercept the http-connector request in your unit tests please?

Add file org.camunda.connect.spi.ConnectorConfigurator in test/resources/META-INF/services, with your package.classname which is intercepting connector request.
below is sample content
com.abnamro.ncto.fulfillment.testhelper.MockSoapHttpConnector

@JeremyFoxAridhia , were you able to resolve this?
You can do either by MockBean or Wiremock.
You can find references on internet