Skip to content

Commit

Permalink
example use sdk as well
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanlukas committed Dec 16, 2024
1 parent e3740be commit 2918731
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 103 deletions.
13 changes: 2 additions & 11 deletions example/code-migration-detector/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,8 @@
<artifactId>spring-boot-starter</artifactId>
<version>3.3.6</version>
</dependency>
<dependency>
<groupId>io.camunda.spring</groupId>
<artifactId>spring-boot-starter-camunda</artifactId>
<version>8.5.15</version>
</dependency>
<dependency>
<groupId>io.camunda.spring</groupId>
<artifactId>spring-boot-starter-camunda-test-testcontainer</artifactId>
<version>8.5.15</version>
<scope>test</scope>
</dependency>


<dependency>
<groupId>org.camunda.bpm</groupId>
<artifactId>camunda-engine-spring</artifactId>
Expand Down
14 changes: 6 additions & 8 deletions example/process-solution-migrated/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
<version.spring-boot>3.3.6</version.spring-boot>
<version.camunda>7.22.0</version.camunda>
<version.adapter>0.10.2</version.adapter>
<version.spring-zeebe>8.5.13</version.spring-zeebe>

<version.zeebe>8.6.6</version.zeebe>
<plugin.version.maven-surefire-plugin>3.5.2</plugin.version.maven-surefire-plugin>
</properties>

Expand Down Expand Up @@ -54,11 +53,10 @@
<artifactId>camunda-7-adapter</artifactId>
<version>${version.adapter}</version>
</dependency>
<!-- Testcontainers is required as we run on Java 1.8 here. 'spring-boot-starter-camunda-test' can be used with Java 17 upwards-->
<dependency>
<groupId>io.camunda.spring</groupId>
<artifactId>spring-boot-starter-camunda-test-testcontainer</artifactId>
<version>${version.spring-zeebe}</version>
<groupId>io.camunda</groupId>
<artifactId>camunda-process-test-spring</artifactId>
<version>${version.zeebe}</version>
</dependency>
</dependencies>
</dependencyManagement>
Expand All @@ -69,8 +67,8 @@
<artifactId>camunda-7-adapter</artifactId>
</dependency>
<dependency>
<groupId>io.camunda.spring</groupId>
<artifactId>spring-boot-starter-camunda-test-testcontainer</artifactId>
<groupId>io.camunda</groupId>
<artifactId>camunda-process-test-spring</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,72 +1,79 @@
package org.camunda.community.migration.example;

import io.camunda.process.test.api.CamundaAssert;
import io.camunda.process.test.api.CamundaSpringProcessTest;
import io.camunda.zeebe.client.ZeebeClient;
import io.camunda.zeebe.client.api.response.ActivatedJob;
import io.camunda.zeebe.client.api.response.ProcessInstanceEvent;
import io.camunda.zeebe.process.test.api.ZeebeTestEngine;
import io.camunda.zeebe.spring.test.ZeebeSpringTest;
import org.camunda.bpm.engine.variable.Variables;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.testcontainers.Testcontainers;

import java.time.Duration;
import java.util.List;
import java.util.concurrent.TimeoutException;

import static io.camunda.zeebe.process.test.assertions.BpmnAssert.assertThat;
import static io.camunda.zeebe.protocol.Protocol.*;
import static io.camunda.zeebe.spring.test.ZeebeTestThreadSupport.*;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.*;

@SpringBootTest
@ZeebeSpringTest
@CamundaSpringProcessTest
public class ApplicationTest {

@Autowired ZeebeClient zeebeClient;

@Autowired ZeebeTestEngine zeebeTestEngine;
@Autowired
ZeebeClient zeebeClient;

@Test
void shouldRunProcess_withUserTask() throws InterruptedException, TimeoutException {
ProcessInstanceEvent processInstance =
zeebeClient
.newCreateInstanceCommand()
.bpmnProcessId("sample-process-solution-process")
.latestVersion()
.variables(Variables.createVariables().putValue("x", 7))
.send()
.join();
waitForProcessInstanceHasPassedElement(processInstance, "main-process");
zeebeTestEngine.waitForIdleState(Duration.ofMinutes(1));
assertThat(processInstance).isWaitingAtElements("say-hello");
List<ActivatedJob> userTasks =
zeebeClient
.newActivateJobsCommand()
.jobType(USER_TASK_JOB_TYPE)
.maxJobsToActivate(1)
.send()
.join()
.getJobs();
ProcessInstanceEvent processInstance = zeebeClient
.newCreateInstanceCommand()
.bpmnProcessId("sample-process-solution-process")
.latestVersion()
.variables(Variables
.createVariables()
.putValue("x", 7))
.send()
.join();
CamundaAssert
.assertThat(processInstance)
.hasCompletedElements("Sub Process");
CamundaAssert
.assertThat(processInstance)
.hasActiveElements("Say hello to\n" + "demo");
List<ActivatedJob> userTasks = zeebeClient
.newActivateJobsCommand()
.jobType(USER_TASK_JOB_TYPE)
.maxJobsToActivate(100)
.send()
.join()
.getJobs()
.stream()
.filter(j -> j.getProcessInstanceKey() == processInstance.getProcessInstanceKey())
.toList();
assertThat(userTasks).hasSize(1);
zeebeClient.newCompleteCommand(userTasks.get(0)).send().join();
waitForProcessInstanceCompleted(processInstance);
assertThat(processInstance).isCompleted();
zeebeClient
.newCompleteCommand(userTasks.get(0))
.send()
.join();
CamundaAssert
.assertThat(processInstance)
.hasCompletedElements("Say hello to\n" + "demo")
.isCompleted();
}

@Test
void shouldRunProcess_withoutUserTask() throws InterruptedException, TimeoutException {
ProcessInstanceEvent processInstance =
zeebeClient
.newCreateInstanceCommand()
.bpmnProcessId("sample-process-solution-process")
.latestVersion()
.variables(Variables.createVariables().putValue("x", 5))
.send()
.join();
waitForProcessInstanceCompleted(processInstance);
assertThat(processInstance).isCompleted().hasPassedElement("Event_15mbd4d");
ProcessInstanceEvent processInstance = zeebeClient
.newCreateInstanceCommand()
.bpmnProcessId("sample-process-solution-process")
.latestVersion()
.variables(Variables
.createVariables()
.putValue("x", 5))
.send()
.join();
CamundaAssert
.assertThat(processInstance)
.isCompleted();
}
}
21 changes: 8 additions & 13 deletions example/sample-external-task-process-app-migrated/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<version.spring-boot>3.3.6</version.spring-boot>
<version.maven-surefire>3.5.2</version.maven-surefire>
<version.adapter>0.10.2</version.adapter>
<version.spring-zeebe>8.5.13</version.spring-zeebe>
<version.zeebe>8.6.6</version.zeebe>

<version.java>17</version.java>
<maven.compiler.source>${version.java}</maven.compiler.source>
Expand Down Expand Up @@ -58,12 +58,12 @@
<artifactId>camunda-7-adapter</artifactId>
<version>${version.adapter}</version>
</dependency>
<!-- Testcontainers is required as we run on Java 1.8 here. 'spring-boot-starter-camunda-test' can be used with Java 17 upwards-->
<dependency>
<groupId>io.camunda.spring</groupId>
<artifactId>spring-boot-starter-camunda-test-testcontainer</artifactId>
<version>${version.spring-zeebe}</version>
<groupId>io.camunda</groupId>
<artifactId>camunda-process-test-spring</artifactId>
<version>${version.zeebe}</version>
</dependency>

</dependencies>
</dependencyManagement>

Expand All @@ -84,15 +84,10 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>io.camunda.spring</groupId>
<artifactId>spring-boot-starter-camunda-test-testcontainer</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.camunda.community.process_test_coverage</groupId>
<artifactId>camunda-process-test-coverage-spring-test-platform-8</artifactId>
<version>2.7.0</version>
<groupId>io.camunda</groupId>
<artifactId>camunda-process-test-spring</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,37 +1,27 @@
package org.camunda.community.migration_example;

import static io.camunda.zeebe.process.test.assertions.BpmnAssert.assertThat;
import static io.camunda.zeebe.spring.test.ZeebeTestThreadSupport.*;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.*;
import java.time.Duration;
import java.util.concurrent.TimeoutException;
import io.camunda.process.test.api.CamundaAssert;
import io.camunda.process.test.api.CamundaSpringProcessTest;
import io.camunda.zeebe.client.ZeebeClient;
import io.camunda.zeebe.client.api.response.ProcessInstanceEvent;
import org.camunda.bpm.engine.variable.Variables;
import org.camunda.community.migration_example.services.CustomerService;
import org.camunda.community.process_test_coverage.spring_test.platform8.ProcessEngineCoverageConfiguration;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.context.annotation.Import;
import io.camunda.zeebe.client.ZeebeClient;
import io.camunda.zeebe.client.api.response.ProcessInstanceEvent;
import io.camunda.zeebe.process.test.api.ZeebeTestEngine;
import io.camunda.zeebe.spring.test.ZeebeSpringTest;

import java.util.concurrent.TimeoutException;

import static org.mockito.Mockito.*;

@SpringBootTest
@ZeebeSpringTest
@Import(ProcessEngineCoverageConfiguration.class)
@Disabled
@CamundaSpringProcessTest
public class ApplicationTest {

@Autowired
ZeebeClient zeebeClient;

@Autowired
ZeebeTestEngine zeebeTestEngine;

@MockBean
CustomerService mockedCustomerService;

Expand All @@ -41,14 +31,23 @@ void shouldRunProcess_HappyPath() throws InterruptedException, TimeoutException
when(mockedCustomerService.getCustomerCredit("cust50")).thenReturn(50.0);
when(mockedCustomerService.deductCredit("cust50", 40.0)).thenReturn(0.0);

ProcessInstanceEvent processInstance = zeebeClient.newCreateInstanceCommand()
.bpmnProcessId("PaymentProcess").latestVersion().variables(Variables.createVariables()
.putValue("orderTotal", 40.0).putValue("customerId", "cust50"))
.send().join();

waitForProcessInstanceCompleted(processInstance, Duration.ofMinutes(1));
assertThat(processInstance).isCompleted().hasPassedElement("Event_1xh41u2")
.hasNotPassedElement("Activity_0rwd82t");
ProcessInstanceEvent processInstance = zeebeClient
.newCreateInstanceCommand()
.bpmnProcessId("PaymentProcess")
.latestVersion()
.variables(Variables
.createVariables()
.putValue("orderTotal", 40.0)
.putValue("customerId", "cust50"))
.send()
.join();

CamundaAssert
.assertThat(processInstance)
.isCompleted()
.hasCompletedElements("Payment completed");
// .hasNotPassedElement("Activity_0rwd82t");
// missing hasNotCompleted()
}

}

0 comments on commit 2918731

Please sign in to comment.