Skip to content

Commit

Permalink
Dropped support for JUnit 4 (#172)
Browse files Browse the repository at this point in the history
  • Loading branch information
gclaussn committed Jan 12, 2024
1 parent b9edff3 commit 826b1f1
Show file tree
Hide file tree
Showing 123 changed files with 328 additions and 1,735 deletions.
23 changes: 8 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Moreover any breaking changes (e.g. a user task becomes an external task) in the
The extension consists of:

- [Camunda Modeler plugin](camunda-modeler-plugin) for a visual selection and the management of test cases
- [Maven plugin](maven-plugin) / [Gradle plugin](gradle-plugin) for generation of JUnit 4 or 5 based test code
- [Maven plugin](maven-plugin) / [Gradle plugin](gradle-plugin) for generation of JUnit 5 based test code

## Features
- Visual test case selection
Expand Down Expand Up @@ -72,20 +72,13 @@ When the BPMN model is saved, the selected test cases are attached to the BPMN p
```

### Generate test code
To generate the code for the selected test cases, a developer must run the **generator** goal of the [bpmn-driven-testing-maven-plugin](maven-plugin) - in **Eclipse** select the project and press **ALT+F5** to update.
To generate the code for the selected test cases, a developer must run the **generator** goal of the [bpmn-driven-testing-maven-plugin](maven-plugin).

The goal finds all *.bpmn files under `src/main/resources` and looks for BPMN processes with a `bpmndt:testCases` extension element.
Each test case will result in a [JUnit 4 test rule](https://github.com/junit-team/junit4/wiki/Rules) or [JUnit 5 extension](https://junit.org/junit5/docs/current/api/org.junit.jupiter.api/org/junit/jupiter/api/extension/Extension.html) - in this example: `generated.order_fulfillment.TC_Happy_Path`.
Each test case will result in a [JUnit 5 extension](https://junit.org/junit5/docs/current/api/org.junit.jupiter.api/org/junit/jupiter/api/extension/Extension.html) - in this example: `generated.order_fulfillment.TC_Happy_Path`.

### Implement tests
In this example, `TC_Happy_Path` must be imported and either used as a JUnit 4 test rule (a `public` field, which is annotated with `@Rule`)

```java
@Rule
public TC_Happy_Path tc = new TC_Happy_Path();
```

or as a JUnit 5 extension (a `public` field, which is annotated with `@RegisterExtension`),
if `jUnit5Enabled` is set to `true` in the plugin's [configuration](maven-plugin#configuration)
In this example, `TC_Happy_Path` must be imported and used as a JUnit 5 extension (a `public` field, which is annotated with `@RegisterExtension`).

```java
@RegisterExtension
Expand All @@ -100,14 +93,14 @@ Moreover the default behavior of wait states and call activities can be adjusted
For each applicable flow node a "handle*" method is generated - for example: `handleCheckAvailabilityUserTask()`.

```java
import org.junit.Rule;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import generated.order_fulfillment.TC_Happy_Path;

public class OrderFulfillmentTest {

@Rule
@RegisterExtension
public TC_Happy_Path tc = new TC_Happy_Path();

@Test
Expand Down
14 changes: 1 addition & 13 deletions gradle-plugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ Available properties:

| Parameter | Type | Description | Default value |
|:---------------------|:-------------|:---------------------------------------------------------------------------|:--------------|
| junit5Enabled | Boolean | Enables JUnit 5 based test case generation | false |
| packageName | String | Package name, used for the generated test sources | generated |
| processEnginePlugins | List<String> | List of process engine plugins to register at the process engine (not required for Spring Boot, since process engine plugins must be exposed as beans) | - |
| springEnabled | Boolean | Enables Spring based testing (not required for Spring Boot, since here only the [BpmndtProcessEnginePlugin](../impl/src/main/java/org/camunda/community/bpmndt/api/cfg/BpmndtProcessEnginePlugin.java) must be exposed as a bean) | false |
Expand All @@ -70,7 +69,6 @@ The plugin's configuration is done in `build.gradle` within the `bpmndt` extensi

```groovy
bpmndt {
junit5Enabled = false
packageName = 'generated'
processEnginePlugins = []
springEnabled = false
Expand All @@ -84,17 +82,9 @@ Add dependencies, which are required to execute the generated test code:
dependencies {
implementation 'org.camunda.bpm:camunda-engine:7.19.0'
testImplementation 'junit:junit:4.13.2'
testImplementation 'com.h2database:h2:2.2.220'
testImplementation 'org.camunda.bpm.assert:camunda-bpm-assert:15.0.0'
testImplementation 'org.assertj:assertj-core:3.24.2'
}
```

For **JUnit 5** replace the `junit:junit` dependency and enable the JUnit platform:

```groovy
dependencies {
testImplementation 'org.camunda.bpm.assert:camunda-bpm-assert:15.0.0'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.9.3'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.9.3'
Expand Down Expand Up @@ -125,7 +115,6 @@ dependencies {
implementation 'org.camunda.bpm.springboot:camunda-bpm-spring-boot-starter:7.19.0'
testImplementation 'org.springframework.boot:spring-boot-starter-test:2.7.18'
testImplementation 'org.junit.vintage:junit-vintage-engine:5.9.3' // allows usage of JUnit 4
}
```

Expand All @@ -135,7 +124,6 @@ Recommended versions:
|:-------------------|:--------|
| Camunda BPM | 7.19.0 |
| Camunda BPM Assert | 15.0.0 |
| JUnit 4 | 4.13.2 |
| JUnit 5 (Jupiter) | 5.9.3 |
| Assertj | 3.24.2 |
| Spring Framework | 5.3.31 |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,12 @@ public class GeneratorTask extends DefaultTask {

@TaskAction
public void generate() {
boolean jUnit5Enabled = extension.getJunit5Enabled().getOrElse(Boolean.FALSE);
String packageName = extension.getPackageName().getOrElse("generated");
List<String> processEnginePlugins = extension.getProcessEnginePlugins().getOrElse(Collections.emptyList());
boolean springEnabled = extension.getSpringEnabled().getOrElse(Boolean.FALSE);

GeneratorContext ctx = new GeneratorContext();
ctx.setBasePath(getProject().getProjectDir().toPath());
ctx.setJUnit5Enabled(jUnit5Enabled);
ctx.setMainResourcePath(mainResourcePath);
ctx.setPackageName(packageName);
ctx.setProcessEnginePluginNames(processEnginePlugins);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,6 @@
*/
public interface GradleExtension {

/**
* Provides the property, which determines if JUnit 5 based test case generation is enabled or not.
*
* @return {@code true}, if JUnit 5 is enabled. Otherwise {@code false}.
*/
Property<Boolean> getJunit5Enabled(); // getJUnit5Enabled (with uppercased 'U') did not worked

/**
* Returns the package name of the generated Java test case files.
*
Expand Down
6 changes: 0 additions & 6 deletions impl/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
<assertj.version>3.24.2</assertj.version>
<camunda.bpm.assert.version>15.0.0</camunda.bpm.assert.version>
<javapoet.version>1.13.0</javapoet.version>
<junit.version>4.13.2</junit.version>
<spring.version>5.3.31</spring.version>
</properties>

Expand Down Expand Up @@ -94,11 +93,6 @@
</dependency>

<!-- JUnit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

import javax.lang.model.SourceVersion;

import org.camunda.community.bpmndt.api.AbstractJUnit4TestCase;
import org.camunda.community.bpmndt.api.AbstractJUnit5TestCase;
import org.camunda.community.bpmndt.api.AbstractTestCase;
import org.camunda.community.bpmndt.api.CallActivityDefinition;
Expand Down Expand Up @@ -175,11 +174,7 @@ public void generate(GeneratorContext ctx) {
apiClasses.add(BpmndtParseListener.class);
apiClasses.add(BpmndtProcessEnginePlugin.class);

if (ctx.isJUnit5Enabled()) {
apiClasses.add(AbstractJUnit5TestCase.class);
} else {
apiClasses.add(AbstractJUnit4TestCase.class);
}
apiClasses.add(AbstractJUnit5TestCase.class);

if (ctx.isSpringEnabled()) {
apiClasses.add(SpringConfiguration.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
public class GeneratorContext {

private Path basePath;
private boolean jUnit5Enabled;
private Path mainResourcePath;
private String packageName;
private List<String> processEnginePluginNames;
Expand Down Expand Up @@ -45,10 +44,6 @@ public Path getTestSourcePath() {
return testSourcePath;
}

public boolean isJUnit5Enabled() {
return jUnit5Enabled;
}

public boolean isSpringEnabled() {
return springEnabled;
}
Expand All @@ -57,10 +52,6 @@ public void setBasePath(Path basePath) {
this.basePath = basePath;
}

public void setJUnit5Enabled(boolean jUnit5Enabled) {
this.jUnit5Enabled = jUnit5Enabled;
}

public void setMainResourcePath(Path mainResourcePath) {
this.mainResourcePath = mainResourcePath;
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import org.camunda.community.bpmndt.GeneratorResult;
import org.camunda.community.bpmndt.GeneratorStrategy;
import org.camunda.community.bpmndt.TestCaseContext;
import org.camunda.community.bpmndt.api.AbstractJUnit4TestCase;
import org.camunda.community.bpmndt.api.AbstractJUnit5TestCase;
import org.camunda.community.bpmndt.api.AbstractTestCase;
import org.camunda.community.bpmndt.model.TestCase;
Expand All @@ -30,7 +29,6 @@
/**
* Generates a test case, using a test framework (JUnit 4 or 5) specific superclass.
*
* @see AbstractJUnit4TestCase
* @see AbstractJUnit5TestCase
*/
public class GenerateTestCase implements Consumer<TestCaseContext> {
Expand Down Expand Up @@ -240,14 +238,9 @@ protected CodeBlock buildJavadoc(TestCaseContext ctx) {
}

protected TypeName getSuperClass(TestCaseContext ctx) {
ClassName rawType;
if (gCtx.isJUnit5Enabled()) {
rawType = ClassName.get(AbstractJUnit5TestCase.class);
} else {
rawType = ClassName.get(AbstractJUnit4TestCase.class);
}
ClassName rawType = ClassName.get(AbstractJUnit5TestCase.class);

// e.g. AbstractJUnit4TestCase<TC_startEvent__endEvent>
// e.g. AbstractJUnit5TestCase<TC_startEvent__endEvent>
return ParameterizedTypeName.get(rawType, ClassName.bestGuess(ctx.getClassName()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

import org.apache.commons.lang3.StringUtils;
import org.camunda.bpm.engine.runtime.ProcessInstance;
import org.camunda.community.bpmndt.api.AbstractJUnit4TestCase;
import org.camunda.community.bpmndt.api.AbstractJUnit5TestCase;
import org.camunda.community.bpmndt.api.CallActivityHandler;
import org.camunda.community.bpmndt.api.EventHandler;
import org.camunda.community.bpmndt.api.ExternalTaskHandler;
Expand Down Expand Up @@ -76,7 +76,7 @@ public void testSimple() {
TypeSpec typeSpec = javaFile.typeSpec;
assertThat(typeSpec).hasName("TC_startEvent__endEvent");

ClassName rawType = ClassName.get(AbstractJUnit4TestCase.class);
ClassName rawType = ClassName.get(AbstractJUnit5TestCase.class);
ClassName typeArgument = ClassName.bestGuess(typeSpec.name);

assertThat(typeSpec.superclass).isInstanceOf(ParameterizedTypeName.class);
Expand Down Expand Up @@ -122,7 +122,7 @@ public void testSimpleSpringEnabled() {
TypeSpec typeSpec = javaFile.typeSpec;
assertThat(typeSpec).hasName("TC_startEvent__endEvent");

ClassName rawType = ClassName.get(AbstractJUnit4TestCase.class);
ClassName rawType = ClassName.get(AbstractJUnit5TestCase.class);
ClassName typeArgument = ClassName.bestGuess(typeSpec.name);

assertThat(typeSpec.superclass).isInstanceOf(ParameterizedTypeName.class);
Expand Down
Loading

0 comments on commit 826b1f1

Please sign in to comment.