3535import org .junit .jupiter .api .AfterEach ;
3636import org .junit .jupiter .api .BeforeEach ;
3737import org .junit .jupiter .api .Test ;
38+ import org .springframework .util .LinkedCaseInsensitiveMap ;
3839
3940import com .fasterxml .jackson .core .JsonProcessingException ;
4041import com .fasterxml .jackson .databind .ObjectMapper ;
@@ -112,6 +113,58 @@ public void testProcessStartWithHeaders() {
112113 );
113114 }
114115
116+ @ Test
117+ @ Deployment (resources = "org/flowable/engine/test/eventregistry/BpmnHeaderEventRegistryConsumerTest.testProcessStartWithHeaders.bpmn20.xml" )
118+ public void testProcessStartWithMissingHeaders () {
119+ ProcessDefinition processDefinition = repositoryService .createProcessDefinitionQuery ().processDefinitionKey ("process" ).singleResult ();
120+ assertThat (processDefinition ).isNotNull ();
121+
122+ EventSubscription eventSubscription = runtimeService .createEventSubscriptionQuery ()
123+ .processDefinitionId (processDefinition .getId ())
124+ .scopeType (ScopeTypes .BPMN )
125+ .singleResult ();
126+ assertThat (eventSubscription ).isNotNull ();
127+ assertThat (eventSubscription .getEventType ()).isEqualTo ("myEvent" );
128+
129+ assertThat (runtimeService .createProcessInstanceQuery ().list ()).isEmpty ();
130+
131+ inboundEventChannelAdapter .triggerTestEventWithHeaders ("payloadStartCustomer" , null , null );
132+ ProcessInstance processInstance = runtimeService .createProcessInstanceQuery ().processDefinitionKey ("process" ).singleResult ();
133+ assertThat (runtimeService .getVariables (processInstance .getId ()))
134+ .containsOnly (
135+ entry ("customerIdVar" , "payloadStartCustomer" ),
136+ entry ("payload1" , "Hello World" ),
137+ entry ("myHeaderValue1" , null ),
138+ entry ("myHeaderValue2" , null )
139+ );
140+ }
141+
142+ @ Test
143+ @ Deployment (resources = "org/flowable/engine/test/eventregistry/BpmnHeaderEventRegistryConsumerTest.testProcessStartWithHeaders.bpmn20.xml" )
144+ public void testProcessStartWithCaseInsensitiveEventHeaders () {
145+ ProcessDefinition processDefinition = repositoryService .createProcessDefinitionQuery ().processDefinitionKey ("process" ).singleResult ();
146+ assertThat (processDefinition ).isNotNull ();
147+
148+ EventSubscription eventSubscription = runtimeService .createEventSubscriptionQuery ()
149+ .processDefinitionId (processDefinition .getId ())
150+ .scopeType (ScopeTypes .BPMN )
151+ .singleResult ();
152+ assertThat (eventSubscription ).isNotNull ();
153+ assertThat (eventSubscription .getEventType ()).isEqualTo ("myEvent" );
154+
155+ assertThat (runtimeService .createProcessInstanceQuery ().list ()).isEmpty ();
156+
157+ inboundEventChannelAdapter .triggerTestEventWithCaseInsensitiveHeaders ("payloadStartCustomer" , "testHeader" , 1234 );
158+ ProcessInstance processInstance = runtimeService .createProcessInstanceQuery ().processDefinitionKey ("process" ).singleResult ();
159+ assertThat (runtimeService .getVariables (processInstance .getId ()))
160+ .containsOnly (
161+ entry ("customerIdVar" , "payloadStartCustomer" ),
162+ entry ("payload1" , "Hello World" ),
163+ entry ("myHeaderValue1" , "testHeader" ),
164+ entry ("myHeaderValue2" , 1234 )
165+ );
166+ }
167+
115168 private static class TestInboundEventChannelAdapter implements InboundEventChannelAdapter {
116169
117170 public InboundChannelModel inboundChannelModel ;
@@ -135,8 +188,25 @@ public void setEventRegistry(EventRegistry eventRegistry) {
135188 public void triggerTestEventWithHeaders (String customerId , String headerValue1 , Integer headerValue2 ) {
136189 ObjectNode eventNode = createTestEventNode (customerId , null );
137190 Map <String , Object > headers = new HashMap <>();
138- headers .put ("headerProperty1" , headerValue1 );
139- headers .put ("headerProperty2" , headerValue2 );
191+ if (headerValue1 != null ) {
192+ headers .put ("headerProperty1" , headerValue1 );
193+ }
194+ if (headerValue2 != null ) {
195+ headers .put ("headerProperty2" , headerValue2 );
196+ }
197+ try {
198+ String event = objectMapper .writeValueAsString (eventNode );
199+ eventRegistry .eventReceived (inboundChannelModel , new DefaultInboundEvent (event , headers ));
200+ } catch (JsonProcessingException e ) {
201+ throw new RuntimeException (e );
202+ }
203+ }
204+
205+ public void triggerTestEventWithCaseInsensitiveHeaders (String customerId , String headerValue1 , Integer headerValue2 ) {
206+ ObjectNode eventNode = createTestEventNode (customerId , null );
207+ Map <String , Object > headers = new LinkedCaseInsensitiveMap <>();
208+ headers .put ("HeaderProperty1" , headerValue1 );
209+ headers .put ("HeaderProperty2" , headerValue2 );
140210 try {
141211 String event = objectMapper .writeValueAsString (eventNode );
142212 eventRegistry .eventReceived (inboundChannelModel , new DefaultInboundEvent (event , headers ));
0 commit comments