Skip to content

Commit 48560e8

Browse files
committed
added a test to assert on the bug fix
1 parent 0bff089 commit 48560e8

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

spring-boot-starter-camunda/src/main/java/io/camunda/zeebe/spring/client/properties/PropertyBasedZeebeWorkerValueCustomizer.java

+11-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import static org.apache.commons.lang3.StringUtils.*;
44

5+
import io.camunda.zeebe.client.api.response.ActivatedJob;
56
import io.camunda.zeebe.spring.client.annotation.Variable;
67
import io.camunda.zeebe.spring.client.annotation.VariablesAsType;
78
import io.camunda.zeebe.spring.client.annotation.ZeebeVariable;
@@ -44,7 +45,11 @@ public void customize(ZeebeWorkerValue zeebeWorker) {
4445
}
4546

4647
private void applyFetchVariables(ZeebeWorkerValue zeebeWorkerValue) {
47-
if (zeebeWorkerValue.isForceFetchAllVariables()) {
48+
if (hasActivatedJobInjected(zeebeWorkerValue)) {
49+
LOG.debug(
50+
"Worker '{}': ActivatedJob is injected, no variable filtering possible",
51+
zeebeWorkerValue.getName());
52+
} else if (zeebeWorkerValue.isForceFetchAllVariables()) {
4853
LOG.debug("Worker '{}': Force fetch all variables is enabled", zeebeWorkerValue.getName());
4954
zeebeWorkerValue.setFetchVariables(new String[0]);
5055
} else {
@@ -65,6 +70,11 @@ private void applyFetchVariables(ZeebeWorkerValue zeebeWorkerValue) {
6570
}
6671
}
6772

73+
private boolean hasActivatedJobInjected(ZeebeWorkerValue zeebeWorkerValue) {
74+
return zeebeWorkerValue.getMethodInfo().getParameters().stream()
75+
.anyMatch(p -> p.getParameterInfo().getType().isAssignableFrom(ActivatedJob.class));
76+
}
77+
6878
private List<ParameterInfo> readZeebeVariableParameters(MethodInfo methodInfo) {
6979
List<ParameterInfo> result = methodInfo.getParametersFilteredByAnnotation(Variable.class);
7080
result.addAll(methodInfo.getParametersFilteredByAnnotation(ZeebeVariable.class));

spring-boot-starter-camunda/src/test/java/io/camunda/zeebe/spring/client/properties/PropertyBasedZeebeWorkerValueCustomizerTest.java

+19
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import static org.assertj.core.api.Assertions.*;
44

5+
import io.camunda.zeebe.client.api.response.ActivatedJob;
56
import io.camunda.zeebe.spring.client.annotation.JobWorker;
67
import io.camunda.zeebe.spring.client.annotation.Variable;
78
import io.camunda.zeebe.spring.client.annotation.VariablesAsType;
@@ -38,6 +39,24 @@ private static ZeebeClientConfigurationProperties properties() {
3839
@JobWorker
3940
void sampleWorker(@Variable String var1, @VariablesAsType ComplexProcessVariable var2) {}
4041

42+
@JobWorker
43+
void activatedJobWorker(@Variable String var1, ActivatedJob activatedJob) {}
44+
45+
@Test
46+
void shouldNotAdjustVariableFilterVariablesAsActivatedJobIsInjected() {
47+
// given
48+
ZeebeClientConfigurationProperties properties = properties();
49+
PropertyBasedZeebeWorkerValueCustomizer customizer =
50+
new PropertyBasedZeebeWorkerValueCustomizer(properties);
51+
ZeebeWorkerValue zeebeWorkerValue = new ZeebeWorkerValue();
52+
zeebeWorkerValue.setFetchVariables(new String[] {"a", "var1", "b"});
53+
zeebeWorkerValue.setMethodInfo(methodInfo(this, "testBean", "activatedJobWorker"));
54+
// when
55+
customizer.customize(zeebeWorkerValue);
56+
// then
57+
assertThat(zeebeWorkerValue.getFetchVariables()).containsExactly("a", "var1", "b");
58+
}
59+
4160
@Test
4261
void shouldSetDefaultName() throws NoSuchMethodException {
4362
// given

0 commit comments

Comments
 (0)