Skip to content

Commit 47611cd

Browse files
authored
Merge pull request #667 from camunda-community-hub/feature/valueMapper-improvements
provide java serialization and refactor valueMapper
2 parents 25d1e75 + 6c29a68 commit 47611cd

28 files changed

+1012
-318
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88
target/
99
jgiven-reports/
1010
pom.xml.versionsBackup
11-
11+
spring-shell.log

examples/itest/src/test/kotlin/org/camunda/community/rest/itest/SpringBootConfigurationITest.kt

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
package org.camunda.community.rest.itest
22

3+
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
34
import org.assertj.core.api.Assertions.assertThat
45
import org.assertj.core.api.Assertions.assertThatThrownBy
56
import org.camunda.bpm.engine.RuntimeService
7+
import org.camunda.bpm.engine.variable.Variables
68
import org.camunda.community.rest.client.api.TaskApiClient
79
import org.camunda.community.rest.itest.SpringBootConfigurationITest.CustomValueMapperConfiguration.Companion.VALUE_MAPPER
810
import org.camunda.community.rest.itest.stages.TestApplication
9-
import org.camunda.community.rest.variables.SpinValueMapper
11+
import org.camunda.community.rest.variables.serialization.SpinJsonValueSerializer
1012
import org.camunda.community.rest.variables.ValueMapper
13+
import org.camunda.community.rest.variables.ValueTypeRegistration
14+
import org.camunda.community.rest.variables.ValueTypeResolverImpl
1115
import org.camunda.spin.plugin.variable.value.SpinValue
1216
import org.junit.jupiter.api.Nested
1317
import org.junit.jupiter.api.Test
@@ -27,7 +31,12 @@ internal class SpringBootConfigurationITest {
2731
@Configuration
2832
class CustomValueMapperConfiguration {
2933
companion object {
30-
val VALUE_MAPPER: ValueMapper = ValueMapper()
34+
val VALUE_MAPPER: ValueMapper =
35+
ValueMapper(objectMapper = jacksonObjectMapper(), valueTypeResolver = ValueTypeResolverImpl(),
36+
valueTypeRegistration = ValueTypeRegistration(),
37+
customValueSerializers = emptyList(),
38+
valueSerializers = emptyList(),
39+
serializationFormat = Variables.SerializationDataFormats.JSON)
3140
}
3241

3342
@Bean
@@ -53,7 +62,7 @@ internal class SpringBootConfigurationITest {
5362
lateinit var valueMapper: ValueMapper
5463

5564
@Autowired(required = false)
56-
lateinit var spinValueMapper: SpinValueMapper
65+
lateinit var spinValueSerializer: SpinJsonValueSerializer
5766

5867
@Autowired(required = false)
5968
lateinit var taskApiClient: TaskApiClient
@@ -63,7 +72,7 @@ internal class SpringBootConfigurationITest {
6372
assertThat(this::runtimeService.isInitialized).isTrue()
6473
assertThat(this::taskApiClient.isInitialized).isTrue()
6574
assertThat(this::valueMapper.isInitialized).isTrue()
66-
assertThat(this::spinValueMapper.isInitialized).isTrue()
75+
assertThat(this::spinValueSerializer.isInitialized).isTrue()
6776
assertThat(this.valueMapper).isNotEqualTo(VALUE_MAPPER)
6877
}
6978
}
@@ -134,7 +143,7 @@ internal class SpringBootConfigurationITest {
134143
.withUserConfiguration(TestApplication::class.java)
135144
.withClassLoader(FilteredClassLoader(SpinValue::class.java))
136145
.run {
137-
assertThatThrownBy { it.getBean(SpinValueMapper::class.java) }.isInstanceOf(NoSuchBeanDefinitionException::class.java)
146+
assertThatThrownBy { it.getBean(SpinJsonValueSerializer::class.java) }.isInstanceOf(NoSuchBeanDefinitionException::class.java)
138147
assertThat(it.getBean(ValueMapper::class.java)).isNotNull
139148
}
140149

extension/core/src/main/kotlin/org/camunda/community/rest/config/CamundaRestClientProperties.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
*/
2323
package org.camunda.community.rest.config
2424

25+
import org.camunda.community.rest.variables.CamundaRestClientVariablesProperties
2526
import org.springframework.boot.context.properties.ConfigurationProperties
2627
import org.springframework.boot.context.properties.NestedConfigurationProperty
2728

@@ -47,8 +48,13 @@ data class CamundaRestClientProperties(
4748
* For this to work, the classes all have to be known on the server side.
4849
* Variables will then be deserialized and again serialized with jackson to send them as JSON.
4950
*/
50-
val deserializeVariablesOnServer: Boolean = false
51+
val deserializeVariablesOnServer: Boolean = false,
5152

53+
/**
54+
* Allows configuration of variable handling specific properties, such as serialization format.
55+
*/
56+
@NestedConfigurationProperty
57+
val variables: CamundaRestClientVariablesProperties = CamundaRestClientVariablesProperties()
5258
) {
5359
/**
5460
* Controls decoding of HTTP status response to Camunda Exceptions.

extension/core/src/test/kotlin/org/camunda/community/rest/adapter/LockedExternalTaskAdapterTest.kt

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,33 @@
2222
*/
2323
package org.camunda.community.rest.adapter
2424

25+
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
2526
import org.assertj.core.api.Assertions.assertThat
27+
import org.camunda.bpm.engine.variable.Variables
2628
import org.camunda.community.rest.client.model.LockedExternalTaskDto
2729
import org.camunda.community.rest.client.model.VariableValueDto
2830
import org.camunda.community.rest.impl.toRequiredDate
2931
import org.camunda.community.rest.variables.ValueMapper
32+
import org.camunda.community.rest.variables.ValueTypeRegistration
3033
import org.camunda.community.rest.variables.ValueTypeResolverImpl
34+
import org.camunda.community.rest.variables.serialization.JsonValueSerializer
3135
import org.junit.Test
3236
import java.time.OffsetDateTime
3337

3438
class LockedExternalTaskAdapterTest {
3539

40+
private val objectMapper = jacksonObjectMapper()
41+
private val typeResolver = ValueTypeResolverImpl()
42+
private val typeRegistration = ValueTypeRegistration()
43+
private val valueMapper = ValueMapper(
44+
objectMapper = objectMapper,
45+
valueTypeResolver = typeResolver,
46+
valueTypeRegistration = typeRegistration,
47+
valueSerializers = listOf(JsonValueSerializer(objectMapper)),
48+
serializationFormat = Variables.SerializationDataFormats.JSON,
49+
customValueSerializers = listOf()
50+
)
51+
3652
private val dto = LockedExternalTaskDto()
3753
.id("id")
3854
.processInstanceId("processInstanceId")
@@ -58,14 +74,15 @@ class LockedExternalTaskAdapterTest {
5874

5975
@Test
6076
fun `should delegate`() {
61-
val lockedExternalTaskBean = LockedExternalTaskBean.fromDto(dto, ValueMapper(valueTypeResolver = ValueTypeResolverImpl()))
77+
val lockedExternalTaskBean = LockedExternalTaskBean.fromDto(dto = dto, valueMapper = valueMapper)
6278
val lockedExternalTaskAdapter = LockedExternalTaskAdapter(lockedExternalTaskBean)
63-
assertThat(lockedExternalTaskAdapter).usingRecursiveComparison().ignoringFields("lockedExternalTaskBean").isEqualTo(lockedExternalTaskBean)
79+
assertThat(lockedExternalTaskAdapter).usingRecursiveComparison().ignoringFields("lockedExternalTaskBean")
80+
.isEqualTo(lockedExternalTaskBean)
6481
}
6582

6683
@Test
6784
fun `should construct from dto`() {
68-
val bean = LockedExternalTaskBean.fromDto(dto, ValueMapper(valueTypeResolver = ValueTypeResolverImpl()))
85+
val bean = LockedExternalTaskBean.fromDto(dto = dto, valueMapper = valueMapper)
6986
assertThat(bean).usingRecursiveComparison().ignoringFields("lockExpirationTime", "variables", "createTime").isEqualTo(dto)
7087
assertThat(bean.lockExpirationTime).isEqualTo(dto.lockExpirationTime.toInstant())
7188
assertThat(bean.variables).containsEntry("var1", 1)

extension/core/src/test/kotlin/org/camunda/community/rest/impl/builder/DelegatingDecisionEvaluationBuilderTest.kt

Lines changed: 74 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,32 @@ import org.assertj.core.api.Assertions.assertThatThrownBy
66
import org.camunda.bpm.engine.BadUserRequestException
77
import org.camunda.bpm.engine.exception.NotFoundException
88
import org.camunda.bpm.engine.exception.NotValidException
9+
import org.camunda.bpm.engine.variable.Variables
910
import org.camunda.community.rest.client.api.DecisionDefinitionApiClient
1011
import org.camunda.community.rest.client.model.DecisionDefinitionDto
1112
import org.camunda.community.rest.client.model.VariableValueDto
12-
import org.camunda.community.rest.variables.SpinValueMapper
13+
import org.camunda.community.rest.variables.serialization.SpinJsonValueSerializer
1314
import org.camunda.community.rest.variables.ValueMapper
15+
import org.camunda.community.rest.variables.ValueTypeRegistration
1416
import org.camunda.community.rest.variables.ValueTypeResolverImpl
17+
import org.camunda.community.rest.variables.serialization.JsonValueSerializer
1518
import org.junit.Test
16-
import org.mockito.kotlin.any
17-
import org.mockito.kotlin.eq
18-
import org.mockito.kotlin.isNull
19-
import org.mockito.kotlin.mock
20-
import org.mockito.kotlin.whenever
19+
import org.mockito.kotlin.*
2120
import org.springframework.http.ResponseEntity
2221

2322
internal class DelegatingDecisionEvaluationBuilderTest {
2423

2524
private val decisionDefinitionApiClient = mock<DecisionDefinitionApiClient>()
26-
private val valueTypeResolver = ValueTypeResolverImpl()
25+
private val objectMapper = jacksonObjectMapper()
26+
private val typeResolver = ValueTypeResolverImpl()
27+
private val typeRegistration = ValueTypeRegistration()
2728
private val valueMapper = ValueMapper(
28-
objectMapper = jacksonObjectMapper(),
29-
valueTypeResolver = valueTypeResolver,
30-
customValueMapper = listOf(SpinValueMapper(valueTypeResolver))
29+
objectMapper = objectMapper,
30+
valueTypeResolver = typeResolver,
31+
valueTypeRegistration = typeRegistration,
32+
valueSerializers = listOf(JsonValueSerializer(objectMapper)),
33+
serializationFormat = Variables.SerializationDataFormats.JSON,
34+
customValueSerializers = listOf(SpinJsonValueSerializer(typeResolver, typeRegistration))
3135
)
3236

3337
val builder = DelegatingDecisionEvaluationBuilder(
@@ -69,9 +73,36 @@ internal class DelegatingDecisionEvaluationBuilderTest {
6973
@Test
7074
fun testEvaluateDecisionWithKeyAndVersion() {
7175
builder.version(1)
72-
whenever(decisionDefinitionApiClient.getDecisionDefinitions(isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), isNull(),
73-
isNull(), isNull(), isNull(), isNull(), eq("decisionDefinitionKey"), isNull(), isNull(), isNull(), eq(1), isNull(), isNull(), isNull(),
74-
isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), isNull())
76+
whenever(
77+
decisionDefinitionApiClient.getDecisionDefinitions(
78+
isNull(),
79+
isNull(),
80+
isNull(),
81+
isNull(),
82+
isNull(),
83+
isNull(),
84+
isNull(),
85+
isNull(),
86+
isNull(),
87+
isNull(),
88+
isNull(),
89+
eq("decisionDefinitionKey"),
90+
isNull(),
91+
isNull(),
92+
isNull(),
93+
eq(1),
94+
isNull(),
95+
isNull(),
96+
isNull(),
97+
isNull(),
98+
isNull(),
99+
isNull(),
100+
isNull(),
101+
isNull(),
102+
isNull(),
103+
isNull(),
104+
isNull()
105+
)
75106
).thenReturn(
76107
ResponseEntity.ok(listOf(DecisionDefinitionDto().id("decisionDefinitionId")))
77108
)
@@ -85,9 +116,36 @@ internal class DelegatingDecisionEvaluationBuilderTest {
85116
@Test
86117
fun testEvaluateDecisionWithKeyAndVersionNotFound() {
87118
builder.version(1)
88-
whenever(decisionDefinitionApiClient.getDecisionDefinitions(isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), isNull(),
89-
isNull(), isNull(), isNull(), isNull(), eq("decisionDefinitionKey"), isNull(), isNull(), isNull(), eq(1), isNull(), isNull(), isNull(),
90-
isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), isNull())
119+
whenever(
120+
decisionDefinitionApiClient.getDecisionDefinitions(
121+
isNull(),
122+
isNull(),
123+
isNull(),
124+
isNull(),
125+
isNull(),
126+
isNull(),
127+
isNull(),
128+
isNull(),
129+
isNull(),
130+
isNull(),
131+
isNull(),
132+
eq("decisionDefinitionKey"),
133+
isNull(),
134+
isNull(),
135+
isNull(),
136+
eq(1),
137+
isNull(),
138+
isNull(),
139+
isNull(),
140+
isNull(),
141+
isNull(),
142+
isNull(),
143+
isNull(),
144+
isNull(),
145+
isNull(),
146+
isNull(),
147+
isNull()
148+
)
91149
).thenReturn(
92150
ResponseEntity.ok(listOf())
93151
)

extension/core/src/test/kotlin/org/camunda/community/rest/impl/builder/DelegatingDecisionsEvaluationBuilderTest.kt

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@ package org.camunda.community.rest.impl.builder
22

33
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
44
import org.assertj.core.api.Assertions
5+
import org.camunda.bpm.engine.variable.Variables
56
import org.camunda.community.rest.client.api.DecisionDefinitionApiClient
67
import org.camunda.community.rest.client.model.VariableValueDto
7-
import org.camunda.community.rest.variables.SpinValueMapper
8+
import org.camunda.community.rest.variables.serialization.SpinXmlValueSerializer
89
import org.camunda.community.rest.variables.ValueMapper
10+
import org.camunda.community.rest.variables.ValueTypeRegistration
911
import org.camunda.community.rest.variables.ValueTypeResolverImpl
12+
import org.camunda.community.rest.variables.serialization.JsonValueSerializer
1013
import org.junit.Test
1114
import org.mockito.kotlin.any
1215
import org.mockito.kotlin.eq
@@ -17,14 +20,17 @@ import org.springframework.http.ResponseEntity
1720
internal class DelegatingDecisionsEvaluationBuilderTest {
1821

1922
private val decisionDefinitionApiClient = mock<DecisionDefinitionApiClient>()
20-
private val valueTypeResolver = ValueTypeResolverImpl()
23+
private val objectMapper = jacksonObjectMapper()
24+
private val typeResolver = ValueTypeResolverImpl()
25+
private val typeRegistration = ValueTypeRegistration()
2126
private val valueMapper = ValueMapper(
22-
objectMapper = jacksonObjectMapper(),
23-
valueTypeResolver = valueTypeResolver,
24-
customValueMapper = listOf(SpinValueMapper(valueTypeResolver))
27+
objectMapper = objectMapper,
28+
valueTypeResolver = typeResolver,
29+
valueTypeRegistration = typeRegistration,
30+
valueSerializers = listOf(JsonValueSerializer(objectMapper)),
31+
serializationFormat = Variables.SerializationDataFormats.JSON,
32+
customValueSerializers = listOf(SpinXmlValueSerializer(typeResolver, typeRegistration))
2533
)
26-
27-
2834
val builder = DelegatingDecisionsEvaluationBuilder(
2935
decisionDefinitionApiClient = decisionDefinitionApiClient,
3036
valueMapper = valueMapper,

0 commit comments

Comments
 (0)