19
19
package org .jbpm .bpmn2 .structureref ;
20
20
21
21
import java .io .StringReader ;
22
+ import java .util .Collections ;
22
23
import java .util .HashMap ;
23
24
import java .util .Map ;
24
25
25
26
import org .jbpm .bpmn2 .JbpmBpmn2TestCase ;
27
+ import org .jbpm .bpmn2 .flow .BooleanStructureRefModel ;
28
+ import org .jbpm .bpmn2 .flow .BooleanStructureRefProcess ;
26
29
import org .jbpm .bpmn2 .objects .Person ;
27
30
import org .jbpm .bpmn2 .objects .TestWorkItemHandler ;
28
- import org .jbpm .process .core .context .variable .VariableScope ;
29
31
import org .jbpm .process .core .datatype .impl .coverter .TypeConverterRegistry ;
32
+ import org .jbpm .test .utils .ProcessTestHelper ;
30
33
import org .junit .jupiter .api .Test ;
34
+ import org .kie .kogito .Application ;
31
35
import org .kie .kogito .internal .process .runtime .KogitoProcessInstance ;
32
-
33
- import jakarta .xml .bind .JAXBContext ;
34
- import jakarta .xml .bind .JAXBException ;
36
+ import org .kie .kogito .process .bpmn2 .BpmnVariables ;
35
37
36
38
import static org .assertj .core .api .Assertions .assertThat ;
37
39
import static org .assertj .core .api .Assertions .assertThatExceptionOfType ;
38
40
import static org .assertj .core .api .Assertions .fail ;
39
41
42
+ import jakarta .xml .bind .JAXBContext ;
43
+ import jakarta .xml .bind .JAXBException ;
44
+
40
45
public class StructureRefTest extends JbpmBpmn2TestCase {
41
46
42
47
@ Test
@@ -59,20 +64,19 @@ public void testStringStructureRef() throws Exception {
59
64
60
65
@ Test
61
66
public void testBooleanStructureRef () throws Exception {
62
- kruntime = createKogitoProcessRuntime ( "BPMN2-BooleanStructureRef.bpmn2" );
67
+ Application app = ProcessTestHelper . newApplication ( );
63
68
64
69
TestWorkItemHandler workItemHandler = new TestWorkItemHandler ();
65
- kruntime .getKogitoWorkItemManager ().registerWorkItemHandler ("Human Task" ,
66
- workItemHandler );
67
- KogitoProcessInstance processInstance = kruntime .startProcess ("StructureRef" );
68
- assertThat (processInstance .getState ()).isEqualTo (KogitoProcessInstance .STATE_ACTIVE );
70
+ ProcessTestHelper .registerHandler (app , "Human Task" , workItemHandler );
71
+ org .kie .kogito .process .Process <BooleanStructureRefModel > definition = BooleanStructureRefProcess .newProcess (app );
69
72
70
- Map <String , Object > res = new HashMap <>();
71
- res .put ("testHT" , "true" );
72
- kruntime .getKogitoWorkItemManager ().completeWorkItem (
73
- workItemHandler .getWorkItem ().getStringId (), res );
73
+ org .kie .kogito .process .ProcessInstance <BooleanStructureRefModel > instance = definition .createInstance (definition .createModel ());
74
+ instance .start ();
75
+ assertThat (instance .status ()).isEqualTo (org .kie .kogito .process .ProcessInstance .STATE_ACTIVE );
74
76
75
- assertProcessInstanceCompleted (processInstance .getStringId (), kruntime );
77
+ ProcessTestHelper .completeWorkItem (instance , "john" , Collections .singletonMap ("testHT" , "true" ));
78
+
79
+ assertThat (instance .status ()).isEqualTo (org .kie .kogito .process .ProcessInstance .STATE_COMPLETED );
76
80
}
77
81
78
82
@ Test
@@ -161,29 +165,29 @@ public void testDefaultObjectStructureRef() throws Exception {
161
165
162
166
@ Test
163
167
public void testNotExistingVarBooleanStructureRefOnStart () throws Exception {
164
- kruntime = createKogitoProcessRuntime ( "BPMN2-BooleanStructureRef.bpmn2" );
168
+ Application app = ProcessTestHelper . newApplication ( );
165
169
166
170
TestWorkItemHandler workItemHandler = new TestWorkItemHandler ();
167
- kruntime .getKogitoWorkItemManager ().registerWorkItemHandler ("Human Task" ,
168
- workItemHandler );
169
-
170
- Map <String , Object > params = new HashMap <>();
171
- params .put ("not existing" , "invalid boolean" );
172
- assertThatExceptionOfType (IllegalArgumentException .class ).isThrownBy (() -> kruntime .startProcess ("StructureRef" , params ));
171
+ ProcessTestHelper .registerHandler (app , "Human Task" , workItemHandler );
172
+ org .kie .kogito .process .Process <BooleanStructureRefModel > definition = BooleanStructureRefProcess .newProcess (app );
173
+ org .kie .kogito .Model model = BpmnVariables .create (Collections .singletonMap ("not existing" , "invalid boolean" ));
174
+ org .kie .kogito .process .ProcessInstance <? extends org .kie .kogito .Model > instance = definition .createInstance (model );
175
+ assertThat (instance .variables ().toMap ()).doesNotContainKey ("non existing" );
173
176
174
177
}
175
178
176
179
@ Test
177
180
public void testInvalidBooleanStructureRefOnStart () throws Exception {
178
- kruntime = createKogitoProcessRuntime ( "BPMN2-BooleanStructureRef.bpmn2" );
181
+ Application app = ProcessTestHelper . newApplication ( );
179
182
180
183
TestWorkItemHandler workItemHandler = new TestWorkItemHandler ();
181
- kruntime .getKogitoWorkItemManager ().registerWorkItemHandler ("Human Task" ,
182
- workItemHandler );
184
+ ProcessTestHelper .registerHandler (app , "Human Task" , workItemHandler );
185
+ org .kie .kogito .process .Process <BooleanStructureRefModel > definition = BooleanStructureRefProcess .newProcess (app );
186
+ org .kie .kogito .Model model = BpmnVariables .create (Collections .singletonMap ("test" , "invalid boolean" ));
183
187
184
- Map < String , Object > params = new HashMap <>();
185
- params . put ( "test" , "invalid boolean" );
186
- assertThatExceptionOfType ( IllegalArgumentException . class ). isThrownBy (() -> kruntime . startProcess ( "StructureRef" , params ) );
188
+ assertThatExceptionOfType ( IllegalArgumentException . class ). isThrownBy (() -> {
189
+ org . kie . kogito . process . ProcessInstance <? extends org . kie . kogito . Model > instance = definition . createInstance ( model );
190
+ } );
187
191
}
188
192
189
193
@ Test
@@ -213,38 +217,21 @@ public void testInvalidBooleanStructureRefOnWIComplete() throws Exception {
213
217
214
218
@ Test
215
219
public void testInvalidBooleanStructureRefOnStartVerifyErrorMsg () throws Exception {
216
- kruntime = createKogitoProcessRuntime ( "BPMN2-BooleanStructureRef.bpmn2" );
220
+ Application app = ProcessTestHelper . newApplication ( );
217
221
218
222
TestWorkItemHandler workItemHandler = new TestWorkItemHandler ();
219
- kruntime .getKogitoWorkItemManager ().registerWorkItemHandler ("Human Task" ,
220
- workItemHandler );
223
+ ProcessTestHelper .registerHandler (app , "Human Task" , workItemHandler );
224
+ org .kie .kogito .process .Process <BooleanStructureRefModel > definition = BooleanStructureRefProcess .newProcess (app );
225
+ org .kie .kogito .Model model = BpmnVariables .create (Collections .singletonMap ("test" , "invalid boolean" ));
226
+
221
227
try {
222
- Map <String , Object > params = new HashMap <>();
223
- params .put ("test" , "invalid boolean" );
224
- kruntime .startProcess ("StructureRef" , params );
228
+ definition .createInstance (model );
225
229
} catch (IllegalArgumentException e ) {
226
- assertThat (e .getMessage ()).isEqualTo ("Variable 'test' has incorrect data type expected: java.lang.Boolean actual: java.lang.String" );
230
+ assertThat (e .getMessage ()).isEqualTo ("Can not set java.lang.Boolean field org.jbpm.bpmn2.flow.BooleanStructureRefModel.test to java.lang.String" );
227
231
}
228
232
229
233
}
230
234
231
- @ Test
232
- public void testInvalidBooleanStructureRefOnStartWithDisabledCheck () throws Exception {
233
- // Temporarily disable check for variables strict that is enabled by default for tests
234
- VariableScope .setVariableStrictOption (false );
235
- kruntime = createKogitoProcessRuntime ("BPMN2-BooleanStructureRef.bpmn2" );
236
-
237
- TestWorkItemHandler workItemHandler = new TestWorkItemHandler ();
238
- kruntime .getKogitoWorkItemManager ().registerWorkItemHandler ("Human Task" ,
239
- workItemHandler );
240
-
241
- Map <String , Object > params = new HashMap <>();
242
- params .put ("test" , "invalid boolean" );
243
- kruntime .startProcess ("StructureRef" , params );
244
- // enable it back for other tests
245
- VariableScope .setVariableStrictOption (true );
246
- }
247
-
248
235
@ Test
249
236
public void testNotExistingBooleanStructureRefOnWIComplete () throws Exception {
250
237
kruntime = createKogitoProcessRuntime ("BPMN2-IntegerStructureRef.bpmn2" );
0 commit comments