|
| 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.entry; |
| 17 | + |
| 18 | +import org.flowable.cmmn.api.runtime.CaseInstance; |
| 19 | +import org.flowable.cmmn.engine.test.CmmnDeployment; |
| 20 | +import org.flowable.cmmn.test.FlowableCmmnTestCase; |
| 21 | +import org.flowable.variable.api.history.HistoricVariableInstance; |
| 22 | +import org.flowable.variable.api.persistence.entity.VariableInstance; |
| 23 | +import org.flowable.variable.service.impl.types.FloatType; |
| 24 | +import org.junit.jupiter.api.Test; |
| 25 | + |
| 26 | +/** |
| 27 | + * @author Filip Hrisafov |
| 28 | + */ |
| 29 | +class FloatVariableTest extends FlowableCmmnTestCase { |
| 30 | + |
| 31 | + @Test |
| 32 | + @CmmnDeployment(resources = "org/flowable/cmmn/test/one-human-task-model.cmmn") |
| 33 | + void testFloatVariable() { |
| 34 | + CaseInstance caseInstance = cmmnRuntimeService.createCaseInstanceBuilder() |
| 35 | + .caseDefinitionKey("oneTaskCase") |
| 36 | + .variable("floatVar", 1.1f) |
| 37 | + .variable("maxFloatVar", Float.MAX_VALUE) |
| 38 | + .start(); |
| 39 | + |
| 40 | + VariableInstance variableInstance = cmmnRuntimeService.getVariableInstance(caseInstance.getId(), "floatVar"); |
| 41 | + assertThat(variableInstance.getTypeName()).isEqualTo(FloatType.TYPE_NAME); |
| 42 | + assertThat(variableInstance.getValue()).isEqualTo(1.1f); |
| 43 | + |
| 44 | + assertThat(cmmnRuntimeService.getVariables(caseInstance.getId())) |
| 45 | + .containsOnly( |
| 46 | + entry("floatVar", 1.1f), |
| 47 | + entry("maxFloatVar", Float.MAX_VALUE) |
| 48 | + ); |
| 49 | + |
| 50 | + assertThat(cmmnRuntimeService.createCaseInstanceQuery().variableValueEquals("floatVar", 1.1f).list()) |
| 51 | + .extracting(CaseInstance::getId) |
| 52 | + .containsExactly(caseInstance.getId()); |
| 53 | + assertThat(cmmnRuntimeService.createCaseInstanceQuery().variableValueGreaterThan("floatVar", 1.0f).count()).isEqualTo(1); |
| 54 | + assertThat(cmmnRuntimeService.createCaseInstanceQuery().variableValueEquals("floatVar", 1.2f).count()).isZero(); |
| 55 | + |
| 56 | + cmmnRuntimeService.setVariable(caseInstance.getId(), "floatVar", 2.5f); |
| 57 | + assertThat(cmmnRuntimeService.getVariable(caseInstance.getId(), "floatVar")).isEqualTo(2.5f); |
| 58 | + |
| 59 | + HistoricVariableInstance historicVariableInstance = cmmnHistoryService.createHistoricVariableInstanceQuery() |
| 60 | + .caseInstanceId(caseInstance.getId()) |
| 61 | + .variableName("floatVar") |
| 62 | + .singleResult(); |
| 63 | + assertThat(historicVariableInstance.getVariableTypeName()).isEqualTo(FloatType.TYPE_NAME); |
| 64 | + assertThat(historicVariableInstance.getValue()).isEqualTo(2.5f); |
| 65 | + } |
| 66 | +} |
0 commit comments