Connectors
You can run your process test with Connectors to verify the integration with external systems or the configuration of the connector tasks in your processes.
For more unit-focused tests, mock the interaction; for example, by completing connector jobs with an expected result.
The instructions on this page are based on the default Testcontainer runtime. If you are using a remote runtime, consult the relevant distribution documentation, such as Camunda 8 Run.
Enable connectors
By default, the connectors are disabled. You need to change the configuration in the following way.
- Camunda Spring Boot Starter
- Java client
In your application.yml
(or application.properties
):
camunda:
process-test:
# Enable connectors
connectors-enabled: true
Or, directly on your test class:
@SpringBootTest(properties = {"camunda.process-test.connectors-enabled=true"})
@CamundaSpringProcessTest
public class MyProcessTest {
//
}
In your /camunda-container-runtime.properties
file:
# Enable Connectors
connectorsEnabled=true
Or, register the JUnit extension manually and use the fluent builder:
// No annotation: @CamundaProcessTest
public class MyProcessTest {
@RegisterExtension
private static final CamundaProcessTestExtension EXTENSION =
new CamundaProcessTestExtension()
// Enable Connectors
.withConnectorsEnabled(true);
}
Connector secrets
If you use Connectors secrets in your processes, you can add the secrets to the test runtime in the following way.
- Camunda Spring Boot Starter
- Java client
In your application.yml
(or application.properties
):
camunda:
process-test:
connectors-enabled: true
connectors-secrets:
GITHUB_TOKEN: ghp_secret
SLACK_TOKEN: xoxb-secret
Or, on your test class:
@SpringBootTest(
properties = {
"camunda.process-test.connectors-enabled=true",
"camunda.process-test.connectors-secrets.GITHUB_TOKEN=ghp_secret",
"camunda.process-test.connectors-secrets.SLACK_TOKEN=xoxb-secret"
}
)
@CamundaSpringProcessTest
public class MyProcessTest {
//
}
In your /camunda-container-runtime.properties
file:
connectorsEnabled=true
connectorsSecrets.GITHUB_TOKEN=ghp_secret
connectorsSecrets.SLACK_TOKEN=xoxb-secret
Or, via JUnit extension:
// No annotation: @CamundaProcessTest
public class MyProcessTest {
@RegisterExtension
private static final CamundaProcessTestExtension EXTENSION =
new CamundaProcessTestExtension()
.withConnectorsEnabled(true)
.withConnectorsSecret("GITHUB_TOKEN", "ghp_secret")
.withConnectorsSecret("SLACK_TOKEN", "xoxb-secret");
}
Invoke an inbound connector
You can retrieve the URL address to invoke an inbound connector in your test from the CamundaProcessTestContext
.
- Camunda Spring Boot Starter
- Java client
@SpringBootTest
@CamundaSpringProcessTest
public class MyProcessTest {
@Autowired private CamundaClient client;
@Autowired private CamundaProcessTestContext processTestContext;
@Test
void shouldInvokeConnector() {
// given: a process instance waiting at a connector event
// when
final String inboundConnectorAddress =
processTestContext.getConnectorsAddress() + "/inbound/" + CONNECTOR_ID;
// invoke the connector address, for example, via HTTP request
// then: verify that the connector event is completed
}
}
@CamundaProcessTest
public class MyProcessTest {
// to be injected
private CamundaClient client;
private CamundaProcessTestContext processTestContext;
@Test
void shouldInvokeConnector() {
// given: a process instance waiting at a connector event
// when
final String inboundConnectorAddress =
processTestContext.getConnectorsAddress() + "/inbound/" + CONNECTOR_ID;
// invoke the connector address, for example, via HTTP request
// then: verify that the connector event is completed
}
}
You might need to wrap the invocation of the connector in a retry loop, for example, by using Awaitility.
There can be a delay between verifying that the connectors event is active and opening the connectors inbound subscription.
Access host ports
By default, the connectors run inside the Testcontainers environment in isolation and can't access your local machine. However, you can expose host ports to the containers, for example, to invoke a mock HTTP server running on your local machine from an outbound REST connector.
Expose the host ports using TestContainers.exposeHostPorts(port)
. Inside the container, the local machine is available
under the hostname host.testcontainers.internal
.
- Camunda Spring Boot Starter
- Java client
@WireMockTest(httpPort = 9999)
@SpringBootTest(
properties = {
"camunda.process-test.connectors-enabled=true",
"camunda.process-test.connectors-secrets.BASE_URL=http://host.testcontainers.internal:9999"
})
@CamundaSpringProcessTest
public class MyProcessTest {
@Autowired private CamundaClient client;
@BeforeAll
static void setup() {
Testcontainers.exposeHostPorts(9999);
}
@Test
void shouldInvokeUrlFromConnector() {
// given: stub the HTTP server
stubFor(
get(urlPathMatching("/test"))
.willReturn(
aResponse()
.withHeader("Content-Type", "application/json")
.withStatus(200)
.withBody("{\"status\":\"okay\"}")));
// when: a process instance invoked the outbound connector
// then: verify the HTTP request
CamundaAssert.assertThat(processInstance)
.isCompleted()
.hasVariable("status", "okay");
verify(getRequestedFor(urlEqualTo("/test")));
}
}
@WireMockTest(httpPort = 9999)
public class MyProcessTest {
@RegisterExtension
private static final CamundaProcessTestExtension EXTENSION =
new CamundaProcessTestExtension()
.withConnectorsEnabled(true)
.withConnectorsSecret("BASE_URL", "http://host.testcontainers.internal:9999");
private CamundaClient client;
@BeforeAll
static void setup() {
Testcontainers.exposeHostPorts(9999);
}
@Test
void shouldInvokeUrlFromConnector() {
// given: stub the HTTP server
stubFor(
get(urlPathMatching("/test"))
.willReturn(
aResponse()
.withHeader("Content-Type", "application/json")
.withStatus(200)
.withBody("{\"status\":\"okay\"}")));
// when: a process instance invoked the outbound connector
// then: verify the HTTP request
CamundaAssert.assertThat(processInstance)
.isCompleted()
.hasVariable("status", "okay");
verify(getRequestedFor(urlEqualTo("/test")));
}
}
You can configure the URL of an outbound connector in your BPMN process
using Connectors secrets to replace it in the
tests, for example, setting the URL expression to "{{secrets.BASE_URL}}" + "/test"
.
Custom connectors
By default, the runtime uses the Camunda connectors bundle in the same version as the Maven module. You can change the version or use a custom connectors bundle in the following way.
- Camunda Spring Boot Starter
- Java client
In your application.yml
(or application.properties
):
camunda:
process-test:
connectors-enabled: true
connectors-docker-image-name: my-org/my-connectors
connectors-docker-image-version: 1.0.0
In your /camunda-container-runtime.properties
file:
connectorsEnabled=true
connectorsDockerImageName=my-org/my-connectors
connectorsDockerImageVersion=1.0.0
Or, via JUnit extension:
// No annotation: @CamundaProcessTest
public class MyProcessTest {
@RegisterExtension
private static final CamundaProcessTestExtension EXTENSION =
new CamundaProcessTestExtension()
.withConnectorsEnabled(true)
.withConnectorsDockerImageName("my-org/my-connectors")
.withConnectorsDockerImageVersion("1.0.0");
}