Skip to content

Commit cdcb2b9

Browse files
committed
Apply maxAllowedLengthVariableType to the StringType
1 parent 725e91e commit cdcb2b9

7 files changed

Lines changed: 390 additions & 4 deletions

File tree

modules/flowable-app-engine/src/main/java/org/flowable/app/engine/AppEngineConfiguration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ public void initVariableTypes() {
392392
}
393393
}
394394
variableTypes.addType(new NullType());
395-
variableTypes.addType(new StringType(getMaxLengthString()));
395+
variableTypes.addType(new StringType(getMaxLengthString(), maxAllowedLengthVariableType));
396396
variableTypes.addType(new LongStringType(getMaxLengthString() + 1, maxAllowedLengthVariableType));
397397
variableTypes.addType(new BooleanType());
398398
variableTypes.addType(new ShortType());
Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
/* Licensed under the Apache License, Version 2.0 (the "License");
2+
* you may not use this file except in compliance with the License.
3+
* You may obtain a copy of the License at
4+
*
5+
* http://www.apache.org/licenses/LICENSE-2.0
6+
*
7+
* Unless required by applicable law or agreed to in writing, software
8+
* distributed under the License is distributed on an "AS IS" BASIS,
9+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
* See the License for the specific language governing permissions and
11+
* limitations under the License.
12+
*/
13+
package org.flowable.rest.app.variable;
14+
15+
import static org.assertj.core.api.Assertions.assertThat;
16+
import static org.assertj.core.api.Assertions.assertThatThrownBy;
17+
18+
import org.apache.commons.lang3.RandomStringUtils;
19+
import org.flowable.app.spring.SpringAppEngineConfiguration;
20+
import org.flowable.cmmn.api.CmmnRuntimeService;
21+
import org.flowable.cmmn.api.CmmnTaskService;
22+
import org.flowable.cmmn.api.runtime.CaseInstance;
23+
import org.flowable.cmmn.engine.test.CmmnDeployment;
24+
import org.flowable.cmmn.spring.impl.test.FlowableCmmnSpringExtension;
25+
import org.flowable.common.engine.api.FlowableIllegalArgumentException;
26+
import org.flowable.engine.RuntimeService;
27+
import org.flowable.engine.TaskService;
28+
import org.flowable.engine.runtime.ProcessInstance;
29+
import org.flowable.engine.test.Deployment;
30+
import org.flowable.spring.boot.EngineConfigurationConfigurer;
31+
import org.flowable.spring.impl.test.FlowableSpringExtension;
32+
import org.flowable.task.api.Task;
33+
import org.junit.jupiter.api.Nested;
34+
import org.junit.jupiter.api.Test;
35+
import org.junit.jupiter.api.extension.ExtendWith;
36+
import org.springframework.beans.factory.annotation.Autowired;
37+
import org.springframework.boot.test.context.SpringBootTest;
38+
import org.springframework.boot.test.context.TestConfiguration;
39+
import org.springframework.context.annotation.Bean;
40+
41+
import com.fasterxml.jackson.databind.ObjectMapper;
42+
43+
/**
44+
* @author Filip Hrisafov
45+
*/
46+
@SpringBootTest
47+
@ExtendWith({
48+
FlowableSpringExtension.class,
49+
FlowableCmmnSpringExtension.class,
50+
})
51+
public class MaxAllowedShortStringVariableLengthTest {
52+
53+
@Autowired
54+
protected RuntimeService runtimeService;
55+
56+
@Autowired
57+
protected TaskService taskService;
58+
59+
@Autowired
60+
protected CmmnRuntimeService cmmnRuntimeService;
61+
62+
@Autowired
63+
protected CmmnTaskService cmmnTaskService;
64+
65+
@Autowired
66+
protected ObjectMapper objectMapper;
67+
68+
@Nested
69+
class Bpmn {
70+
71+
@Test
72+
@Deployment(resources = "oneTaskProcess.bpmn20.xml")
73+
void stringVariable() {
74+
ProcessInstance processInstance = runtimeService.createProcessInstanceBuilder()
75+
.processDefinitionKey("oneTaskProcess")
76+
.variable("stringVar", "Test value")
77+
.start();
78+
79+
assertThatThrownBy(() -> runtimeService.setVariable(processInstance.getId(), "stringVar", RandomStringUtils.insecure().nextAlphanumeric(600)))
80+
.isInstanceOf(FlowableIllegalArgumentException.class)
81+
.hasMessage(
82+
"The length of the string value exceeds the maximum allowed length of 500 characters. Current length: 600, for variable: stringVar in scope bpmn with id "
83+
+ processInstance.getId());
84+
85+
Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
86+
assertThat(task).isNotNull();
87+
assertThatThrownBy(() -> taskService.setVariableLocal(task.getId(), "stringVar", RandomStringUtils.insecure().nextAlphanumeric(600)))
88+
.isInstanceOf(FlowableIllegalArgumentException.class)
89+
.hasMessage(
90+
"The length of the string value exceeds the maximum allowed length of 500 characters. Current length: 600, for variable: stringVar in scope task with id "
91+
+ task.getId());
92+
93+
assertThat(runtimeService.getVariable(processInstance.getId(), "stringVar")).isEqualTo("Test value");
94+
}
95+
96+
@Test
97+
@Deployment(resources = "oneTaskProcess.bpmn20.xml")
98+
void longStringVariable() {
99+
ProcessInstance processInstance = runtimeService.createProcessInstanceBuilder()
100+
.processDefinitionKey("oneTaskProcess")
101+
.variable("stringVar", "Test value")
102+
.start();
103+
104+
assertThatThrownBy(() -> runtimeService.setVariable(processInstance.getId(), "stringVar", RandomStringUtils.insecure().nextAlphanumeric(6000)))
105+
.isInstanceOf(FlowableIllegalArgumentException.class)
106+
.hasMessage(
107+
"The length of the longString value exceeds the maximum allowed length of 500 characters. Current length: 6000, for variable: stringVar in scope bpmn with id "
108+
+ processInstance.getId());
109+
110+
Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
111+
assertThat(task).isNotNull();
112+
assertThatThrownBy(() -> taskService.setVariableLocal(task.getId(), "stringVar", RandomStringUtils.insecure().nextAlphanumeric(6000)))
113+
.isInstanceOf(FlowableIllegalArgumentException.class)
114+
.hasMessage(
115+
"The length of the longString value exceeds the maximum allowed length of 500 characters. Current length: 6000, for variable: stringVar in scope task with id "
116+
+ task.getId());
117+
118+
assertThat(runtimeService.getVariable(processInstance.getId(), "stringVar")).isEqualTo("Test value");
119+
}
120+
121+
}
122+
123+
@Nested
124+
class Cmmn {
125+
126+
@Test
127+
@CmmnDeployment(resources = "oneHumanTaskCase.cmmn")
128+
void stringVariable() {
129+
CaseInstance caseInstance = cmmnRuntimeService.createCaseInstanceBuilder()
130+
.caseDefinitionKey("oneHumanTaskCase")
131+
.variable("stringVar", "Test value")
132+
.start();
133+
134+
assertThatThrownBy(() -> cmmnRuntimeService.setVariable(caseInstance.getId(), "stringVar", RandomStringUtils.insecure().nextAlphanumeric(600)))
135+
.isInstanceOf(FlowableIllegalArgumentException.class)
136+
.hasMessage(
137+
"The length of the string value exceeds the maximum allowed length of 500 characters. Current length: 600, for variable: stringVar in scope cmmn with id "
138+
+ caseInstance.getId());
139+
140+
Task task = cmmnTaskService.createTaskQuery().caseInstanceId(caseInstance.getId()).singleResult();
141+
assertThat(task).isNotNull();
142+
assertThatThrownBy(() -> cmmnTaskService.setVariableLocal(task.getId(), "stringVar", RandomStringUtils.insecure().nextAlphanumeric(600)))
143+
.isInstanceOf(FlowableIllegalArgumentException.class)
144+
.hasMessage(
145+
"The length of the string value exceeds the maximum allowed length of 500 characters. Current length: 600, for variable: stringVar in scope task with id "
146+
+ task.getId());
147+
148+
assertThat(cmmnRuntimeService.getVariable(caseInstance.getId(), "stringVar")).isEqualTo("Test value");
149+
}
150+
151+
@Test
152+
@CmmnDeployment(resources = "oneHumanTaskCase.cmmn")
153+
void longStringVariable() {
154+
CaseInstance caseInstance = cmmnRuntimeService.createCaseInstanceBuilder()
155+
.caseDefinitionKey("oneHumanTaskCase")
156+
.variable("stringVar", "Test value")
157+
.start();
158+
159+
assertThatThrownBy(() -> cmmnRuntimeService.setVariable(caseInstance.getId(), "stringVar", RandomStringUtils.insecure().nextAlphanumeric(6000)))
160+
.isInstanceOf(FlowableIllegalArgumentException.class)
161+
.hasMessage(
162+
"The length of the longString value exceeds the maximum allowed length of 500 characters. Current length: 6000, for variable: stringVar in scope cmmn with id "
163+
+ caseInstance.getId());
164+
165+
Task task = cmmnTaskService.createTaskQuery().caseInstanceId(caseInstance.getId()).singleResult();
166+
assertThat(task).isNotNull();
167+
assertThatThrownBy(() -> cmmnTaskService.setVariableLocal(task.getId(), "stringVar", RandomStringUtils.insecure().nextAlphanumeric(6000)))
168+
.isInstanceOf(FlowableIllegalArgumentException.class)
169+
.hasMessage(
170+
"The length of the longString value exceeds the maximum allowed length of 500 characters. Current length: 6000, for variable: stringVar in scope task with id "
171+
+ task.getId());
172+
173+
assertThat(cmmnRuntimeService.getVariable(caseInstance.getId(), "stringVar")).isEqualTo("Test value");
174+
}
175+
176+
}
177+
178+
@TestConfiguration
179+
static class CustomConfiguration {
180+
181+
@Bean
182+
public EngineConfigurationConfigurer<SpringAppEngineConfiguration> customAppEngineConfigurationConfigurer() {
183+
return appEngineConfiguration -> {
184+
appEngineConfiguration.setMaxAllowedLengthVariableType(500);
185+
};
186+
}
187+
}
188+
189+
}

modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/CmmnEngineConfiguration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1395,7 +1395,7 @@ public void initVariableTypes() {
13951395
}
13961396
}
13971397
variableTypes.addType(new NullType());
1398-
variableTypes.addType(new StringType(getMaxLengthString()));
1398+
variableTypes.addType(new StringType(getMaxLengthString(), maxAllowedLengthVariableType));
13991399
variableTypes.addType(new LongStringType(getMaxLengthString() + 1, maxAllowedLengthVariableType));
14001400
variableTypes.addType(new BooleanType());
14011401
variableTypes.addType(new ShortType());
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/* Licensed under the Apache License, Version 2.0 (the "License");
2+
* you may not use this file except in compliance with the License.
3+
* You may obtain a copy of the License at
4+
*
5+
* http://www.apache.org/licenses/LICENSE-2.0
6+
*
7+
* Unless required by applicable law or agreed to in writing, software
8+
* distributed under the License is distributed on an "AS IS" BASIS,
9+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
* See the License for the specific language governing permissions and
11+
* limitations under the License.
12+
*/
13+
package org.flowable.cmmn.test.runtime;
14+
15+
import static org.assertj.core.api.Assertions.assertThat;
16+
import static org.assertj.core.api.Assertions.assertThatThrownBy;
17+
18+
import org.apache.commons.lang3.RandomStringUtils;
19+
import org.flowable.cmmn.api.runtime.CaseInstance;
20+
import org.flowable.cmmn.engine.CmmnEngineConfiguration;
21+
import org.flowable.cmmn.engine.test.CmmnDeployment;
22+
import org.flowable.cmmn.test.impl.CustomCmmnConfigurationFlowableTestCase;
23+
import org.flowable.common.engine.api.FlowableIllegalArgumentException;
24+
import org.flowable.task.api.Task;
25+
import org.junit.Test;
26+
27+
/**
28+
* @author Filip Hrisafov
29+
*/
30+
public class MaxAllowedShortStringVariableLengthTest extends CustomCmmnConfigurationFlowableTestCase {
31+
32+
@Override
33+
protected String getEngineName() {
34+
return this.getClass().getSimpleName();
35+
}
36+
37+
@Override
38+
protected void configureConfiguration(CmmnEngineConfiguration cmmnEngineConfiguration) {
39+
cmmnEngineConfiguration.setMaxAllowedLengthVariableType(500);
40+
}
41+
42+
@Test
43+
@CmmnDeployment(resources = "org/flowable/cmmn/test/runtime/oneHumanTaskCase.cmmn")
44+
public void stringVariable() {
45+
CaseInstance caseInstance = cmmnRuntimeService.createCaseInstanceBuilder()
46+
.caseDefinitionKey("oneHumanTaskCase")
47+
.variable("stringVar", "Test value")
48+
.start();
49+
50+
assertThatThrownBy(() -> cmmnRuntimeService.setVariable(caseInstance.getId(), "stringVar", RandomStringUtils.insecure().nextAlphanumeric(600)))
51+
.isInstanceOf(FlowableIllegalArgumentException.class)
52+
.hasMessage(
53+
"The length of the string value exceeds the maximum allowed length of 500 characters. Current length: 600, for variable: stringVar in scope cmmn with id "
54+
+ caseInstance.getId());
55+
56+
Task task = cmmnTaskService.createTaskQuery().caseInstanceId(caseInstance.getId()).singleResult();
57+
assertThat(task).isNotNull();
58+
assertThatThrownBy(() -> cmmnTaskService.setVariableLocal(task.getId(), "stringVar", RandomStringUtils.insecure().nextAlphanumeric(600)))
59+
.isInstanceOf(FlowableIllegalArgumentException.class)
60+
.hasMessage(
61+
"The length of the string value exceeds the maximum allowed length of 500 characters. Current length: 600, for variable: stringVar in scope task with id "
62+
+ task.getId());
63+
64+
assertThat(cmmnRuntimeService.getVariable(caseInstance.getId(), "stringVar")).isEqualTo("Test value");
65+
}
66+
67+
@Test
68+
@CmmnDeployment(resources = "org/flowable/cmmn/test/runtime/oneHumanTaskCase.cmmn")
69+
public void longStringVariable() {
70+
CaseInstance caseInstance = cmmnRuntimeService.createCaseInstanceBuilder()
71+
.caseDefinitionKey("oneHumanTaskCase")
72+
.variable("stringVar", "Test value")
73+
.start();
74+
75+
assertThatThrownBy(() -> cmmnRuntimeService.setVariable(caseInstance.getId(), "stringVar", RandomStringUtils.insecure().nextAlphanumeric(6000)))
76+
.isInstanceOf(FlowableIllegalArgumentException.class)
77+
.hasMessage(
78+
"The length of the longString value exceeds the maximum allowed length of 500 characters. Current length: 6000, for variable: stringVar in scope cmmn with id "
79+
+ caseInstance.getId());
80+
81+
Task task = cmmnTaskService.createTaskQuery().caseInstanceId(caseInstance.getId()).singleResult();
82+
assertThat(task).isNotNull();
83+
assertThatThrownBy(() -> cmmnTaskService.setVariableLocal(task.getId(), "stringVar", RandomStringUtils.insecure().nextAlphanumeric(6000)))
84+
.isInstanceOf(FlowableIllegalArgumentException.class)
85+
.hasMessage(
86+
"The length of the longString value exceeds the maximum allowed length of 500 characters. Current length: 6000, for variable: stringVar in scope task with id "
87+
+ task.getId());
88+
89+
assertThat(cmmnRuntimeService.getVariable(caseInstance.getId(), "stringVar")).isEqualTo("Test value");
90+
}
91+
92+
}

modules/flowable-engine/src/main/java/org/flowable/engine/impl/cfg/ProcessEngineConfigurationImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2175,7 +2175,7 @@ public void initVariableTypes() {
21752175
}
21762176
}
21772177
variableTypes.addType(new NullType());
2178-
variableTypes.addType(new StringType(getMaxLengthString()));
2178+
variableTypes.addType(new StringType(getMaxLengthString(), maxAllowedLengthVariableType));
21792179
variableTypes.addType(new LongStringType(getMaxLengthString() + 1, maxAllowedLengthVariableType));
21802180
variableTypes.addType(new BooleanType());
21812181
variableTypes.addType(new ShortType());

0 commit comments

Comments
 (0)