|
55 | 55 | import org.flowable.entitylink.api.EntityLinkType; |
56 | 56 | import org.flowable.entitylink.api.HierarchyType; |
57 | 57 | import org.flowable.entitylink.api.history.HistoricEntityLink; |
| 58 | +import org.flowable.job.api.Job; |
58 | 59 | import org.flowable.task.api.Task; |
59 | 60 | import org.flowable.task.api.history.HistoricTaskInstance; |
60 | 61 | import org.flowable.task.api.history.HistoricTaskLogEntry; |
|
64 | 65 | import org.junit.Before; |
65 | 66 | import org.junit.Test; |
66 | 67 |
|
| 68 | +import com.fasterxml.jackson.databind.JsonNode; |
| 69 | +import com.fasterxml.jackson.databind.ObjectMapper; |
| 70 | +import com.fasterxml.jackson.databind.node.ArrayNode; |
67 | 71 | import com.fasterxml.jackson.databind.node.ObjectNode; |
68 | 72 |
|
69 | 73 | /** |
@@ -2096,4 +2100,110 @@ public void testGetProcessInstanceByParentScopeId() { |
2096 | 2100 | assertThat(subCasePlanItemInstance.getReferenceId()).isEqualTo(processInstance.getId()); |
2097 | 2101 |
|
2098 | 2102 | } |
| 2103 | + |
| 2104 | + @Test |
| 2105 | + @CmmnDeployment(resources = { |
| 2106 | + "org/flowable/cmmn/test/ProcessTaskTest.caseWithInAndOutMapping.cmmn" |
| 2107 | + }) |
| 2108 | + public void testInMappingArrayNodeWithAsyncFirstStep() { |
| 2109 | + |
| 2110 | + Deployment deployment = processEngine.getRepositoryService().createDeployment() |
| 2111 | + .addClasspathResource("org/flowable/cmmn/test/ProcessTaskTest.caseWithInAndOutMappingChildProcessAsync.bpmn20.xml") |
| 2112 | + .deploy(); |
| 2113 | + |
| 2114 | + try { |
| 2115 | + ObjectMapper objectMapper = cmmnEngineConfiguration.getObjectMapper(); |
| 2116 | + ArrayNode arrayNode = objectMapper.createArrayNode(); |
| 2117 | + for (int i = 0; i < 10; i++) { |
| 2118 | + ObjectNode arrayElement = objectMapper.createObjectNode(); |
| 2119 | + arrayElement.put("field", "value-" + i); |
| 2120 | + arrayNode.add(arrayElement); |
| 2121 | + } |
| 2122 | + |
| 2123 | + CaseInstance rootCaseInstance = cmmnRuntimeService.createCaseInstanceBuilder() |
| 2124 | + .caseDefinitionKey("caseTaskMapping") |
| 2125 | + .variable("myRootVariable", arrayNode) |
| 2126 | + .start(); |
| 2127 | + |
| 2128 | + List<ProcessInstance> processInstances = processEngineRuntimeService.createProcessInstanceQuery().list(); |
| 2129 | + processInstances.removeIf(processInstance -> processInstance.getCallbackId() == null); |
| 2130 | + assertThat(processInstances).hasSize(10); |
| 2131 | + |
| 2132 | + // As the first step is an async step, there should be one job. |
| 2133 | + // The variable myElementVariable is mapped as 'myInMappedVariable' into the called process instance |
| 2134 | + // The variable at this point should not have changed at this point. |
| 2135 | + for (ProcessInstance processInstance : processInstances) { |
| 2136 | + JsonNode inMappedJsonNodeVariable = (JsonNode) processEngineRuntimeService.getVariable(processInstance.getId(), "myInMappedVariable"); |
| 2137 | + assertThat(inMappedJsonNodeVariable.path("field").asText()).startsWith("value-"); |
| 2138 | + } |
| 2139 | + |
| 2140 | + // Executing the async job should now change the variable in the child process instances |
| 2141 | + List<Job> jobs = processEngineManagementService.createJobQuery().list(); |
| 2142 | + assertThat(jobs).hasSize(10); |
| 2143 | + for (Job job : jobs) { |
| 2144 | + processEngineManagementService.executeJob(job.getId()); |
| 2145 | + } |
| 2146 | + |
| 2147 | + for (ProcessInstance processInstance : processInstances) { |
| 2148 | + JsonNode inMappedJsonNodeVariable = (JsonNode) processEngineRuntimeService.getVariable(processInstance.getId(), "myInMappedVariable"); |
| 2149 | + assertThat(inMappedJsonNodeVariable.path("field").asText()).startsWith("CHANGED"); |
| 2150 | + } |
| 2151 | + |
| 2152 | + // The variable should not have changed on the root process instance level |
| 2153 | + ArrayNode rootArrayNode = (ArrayNode) cmmnRuntimeService.getVariable(rootCaseInstance.getId(), "myRootVariable"); |
| 2154 | + assertThat(rootArrayNode).hasSize(10); |
| 2155 | + for (JsonNode rootArrayNodeElement : rootArrayNode) { |
| 2156 | + assertThat(rootArrayNodeElement.path("field").asText()).startsWith("value-"); |
| 2157 | + } |
| 2158 | + } finally { |
| 2159 | + processEngine.getRepositoryService().deleteDeployment(deployment.getId(), true); |
| 2160 | + } |
| 2161 | + |
| 2162 | + } |
| 2163 | + |
| 2164 | + @Test |
| 2165 | + @CmmnDeployment(resources = { |
| 2166 | + "org/flowable/cmmn/test/ProcessTaskTest.caseWithInAndOutMapping.cmmn" |
| 2167 | + }) |
| 2168 | + public void testInMappingArrayNodeWithSyncFirstStep() { |
| 2169 | + |
| 2170 | + Deployment deployment = processEngine.getRepositoryService().createDeployment() |
| 2171 | + .addClasspathResource("org/flowable/cmmn/test/ProcessTaskTest.caseWithInAndOutMappingChildProcessSync.bpmn20.xml") |
| 2172 | + .deploy(); |
| 2173 | + |
| 2174 | + try { |
| 2175 | + |
| 2176 | + ObjectMapper objectMapper = cmmnEngineConfiguration.getObjectMapper(); |
| 2177 | + ArrayNode arrayNode = objectMapper.createArrayNode(); |
| 2178 | + for (int i = 0; i < 10; i++) { |
| 2179 | + ObjectNode arrayElement = objectMapper.createObjectNode(); |
| 2180 | + arrayElement.put("field", "value-" + i); |
| 2181 | + arrayNode.add(arrayElement); |
| 2182 | + } |
| 2183 | + |
| 2184 | + CaseInstance rootCaseInstance = cmmnRuntimeService.createCaseInstanceBuilder() |
| 2185 | + .caseDefinitionKey("caseTaskMapping") |
| 2186 | + .variable("myRootVariable", arrayNode) |
| 2187 | + .start(); |
| 2188 | + |
| 2189 | + List<ProcessInstance> processInstances = processEngineRuntimeService.createProcessInstanceQuery().list(); |
| 2190 | + processInstances.removeIf(processInstance -> processInstance.getCallbackId() == null); |
| 2191 | + assertThat(processInstances).hasSize(10); |
| 2192 | + |
| 2193 | + for (ProcessInstance processInstance : processInstances) { |
| 2194 | + JsonNode inMappedJsonNodeVariable = (JsonNode) processEngineRuntimeService.getVariable(processInstance.getId(), "myInMappedVariable"); |
| 2195 | + assertThat(inMappedJsonNodeVariable.path("field").asText()).startsWith("CHANGED"); |
| 2196 | + } |
| 2197 | + |
| 2198 | + // The variable should not have changed on the root process instance level |
| 2199 | + ArrayNode rootArrayNode = (ArrayNode) cmmnRuntimeService.getVariable(rootCaseInstance.getId(), "myRootVariable"); |
| 2200 | + assertThat(rootArrayNode).hasSize(10); |
| 2201 | + for (JsonNode rootArrayNodeElement : rootArrayNode) { |
| 2202 | + assertThat(rootArrayNodeElement.path("field").asText()).startsWith("value-"); |
| 2203 | + } |
| 2204 | + } finally { |
| 2205 | + processEngine.getRepositoryService().deleteDeployment(deployment.getId(), true); |
| 2206 | + } |
| 2207 | + } |
| 2208 | + |
2099 | 2209 | } |
0 commit comments