Skip to content

Instantly share code, notes, and snippets.

@berndruecker
Created November 16, 2023 09:43
Show Gist options
  • Save berndruecker/fed8fd0f70badf151fc6a94e810fa16f to your computer and use it in GitHub Desktop.
Save berndruecker/fed8fd0f70badf151fc6a94e810fa16f to your computer and use it in GitHub Desktop.
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE)
@ZeebeSpringTest
public class TestCustomerOnboardingProcess {
// ...
@Test
public void testAutomaticOnboarding() throws Exception {
// Define expectations on the REST calls
// 1. http://localhost:8080/crm/customer
mockRestServer
.expect(requestTo("http://localhost:8080/crm/customer")) //
.andExpect(method(HttpMethod.PUT))
.andRespond(withSuccess("{\"customerId\": \"12345\"}", MediaType.APPLICATION_JSON));
// given a REST call
customerOnboardingRestController.onboardCustomer();
// Retrieve process instances started because of the above call
InspectedProcessInstance processInstance = InspectionUtility.findProcessInstances().findLastProcessInstance().get();
// We expect to have a user task, complete it
waitForUserTaskAndComplete("TaskApproveCustomerOrder", Collections.singletonMap("approved", true));
// Now the process should run to the end
waitForProcessInstanceCompleted(processInstance, Duration.ofSeconds(10));
// Let's assert that it passed certain BPMN elements (more to show off features here)
assertThat(processInstance)
.hasPassedElement("EndEventProcessed")
.isCompleted();
// And verify it caused the right side effects on the REST endpoints
mockRestServer.verify();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment