|
| 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 | +} |
0 commit comments