@@ -253,7 +253,7 @@ void registerSubscriptionWithDestinationPatternRegex() {
253
253
}
254
254
255
255
@ Test
256
- void registerSubscriptionWithSelector () {
256
+ void registerSubscriptionWithSelectorHeaderEnabledByDefault () {
257
257
String sessionId1 = "sess01" ;
258
258
String sessionId2 = "sess02" ;
259
259
String sessionId3 = "sess03" ;
@@ -278,41 +278,70 @@ void registerSubscriptionWithSelector() {
278
278
accessor .setNativeHeader ("foo" , "bar" );
279
279
Message <?> message = MessageBuilder .createMessage ("" , accessor .getMessageHeaders ());
280
280
281
- MultiValueMap <String , String > actual = this .registry .findSubscriptions (message );
282
- assertThat (actual ).hasSize (2 );
281
+ MultiValueMap <String , String > subscriptions = this .registry .findSubscriptions (message );
282
+ assertThat (subscriptions ).hasSize (2 );
283
283
284
284
// Subscription #1 has a 'selector' header that DOES match.
285
- assertThat (actual .get (sessionId1 )).containsExactly (subscriptionId1 );
285
+ assertThat (subscriptions .get (sessionId1 )).containsExactly (subscriptionId1 );
286
286
// Subscription #2 has a 'selector' header that does NOT match.
287
- assertThat (actual .get (sessionId2 )).isNull ();
287
+ assertThat (subscriptions .get (sessionId2 )).isNull ();
288
288
// Subscription #3 does NOT have a 'selector' header, so it matches anyway.
289
- assertThat (actual .get (sessionId3 )).containsExactly (subscriptionId3 );
289
+ assertThat (subscriptions .get (sessionId3 )).containsExactly (subscriptionId3 );
290
290
291
291
// Then try with message WITHOUT selected 'foo' header present
292
292
293
- actual = this .registry .findSubscriptions (createMessage (destination ));
293
+ subscriptions = this .registry .findSubscriptions (createMessage (destination ));
294
+ assertThat (subscriptions ).hasSize (1 );
294
295
// Subscription #3 does NOT have a 'selector' header, so it matches anyway.
295
- assertThat (actual .get (sessionId3 )).containsExactly (subscriptionId3 );
296
+ assertThat (subscriptions .get (sessionId3 )).containsExactly (subscriptionId3 );
296
297
}
297
298
298
299
@ Test
299
- void registerSubscriptionWithSelectorNotSupported () {
300
- String sessionId = "sess01" ;
301
- String subscriptionId = "subs01" ;
300
+ void registerSubscriptionWithSelectorHeaderDisabled () {
301
+ String sessionId1 = "sess01" ;
302
+ String sessionId2 = "sess02" ;
303
+ String sessionId3 = "sess03" ;
304
+ String subscriptionId1 = "subs01" ;
305
+ String subscriptionId2 = "subs02" ;
306
+ String subscriptionId3 = "subs02" ;
302
307
String destination = "/foo" ;
303
- String selector = "headers.foo == 'bar'" ;
308
+ String selector1 = "headers.foo == 'bar'" ;
309
+ String selector2 = "headers.foo == 'enigma'" ;
304
310
311
+ // Explicitly disable selector header support
305
312
this .registry .setSelectorHeaderName (null );
306
- this .registry .registerSubscription (subscribeMessage (sessionId , subscriptionId , destination , selector ));
313
+
314
+ // Register subscription with matching selector header
315
+ this .registry .registerSubscription (subscribeMessage (sessionId1 , subscriptionId1 , destination , selector1 ));
316
+ // Register subscription with non-matching selector header
317
+ this .registry .registerSubscription (subscribeMessage (sessionId2 , subscriptionId2 , destination , selector2 ));
318
+ // Register subscription without a selector header
319
+ this .registry .registerSubscription (subscribeMessage (sessionId3 , subscriptionId3 , destination , null ));
320
+
321
+ // First, try with message WITH selected 'foo' header present
307
322
308
323
SimpMessageHeaderAccessor accessor = SimpMessageHeaderAccessor .create ();
309
324
accessor .setDestination (destination );
310
- accessor .setNativeHeader ("foo" , "bazz " );
325
+ accessor .setNativeHeader ("foo" , "bar " );
311
326
Message <?> message = MessageBuilder .createMessage ("" , accessor .getMessageHeaders ());
312
327
313
- MultiValueMap <String , String > actual = this .registry .findSubscriptions (message );
314
- assertThat (actual ).hasSize (1 );
315
- assertThat (actual .get (sessionId )).containsExactly (subscriptionId );
328
+ MultiValueMap <String , String > subscriptions = this .registry .findSubscriptions (message );
329
+
330
+ // 'selector' header is ignored, so all 3 subscriptions should be found
331
+ assertThat (subscriptions ).hasSize (3 );
332
+ assertThat (subscriptions .get (sessionId1 )).containsExactly (subscriptionId1 );
333
+ assertThat (subscriptions .get (sessionId2 )).containsExactly (subscriptionId2 );
334
+ assertThat (subscriptions .get (sessionId3 )).containsExactly (subscriptionId3 );
335
+
336
+ // Then try with message WITHOUT selected 'foo' header present
337
+
338
+ subscriptions = this .registry .findSubscriptions (createMessage (destination ));
339
+
340
+ // 'selector' header is ignored, so all 3 subscriptions should be found
341
+ assertThat (subscriptions ).hasSize (3 );
342
+ assertThat (subscriptions .get (sessionId1 )).containsExactly (subscriptionId1 );
343
+ assertThat (subscriptions .get (sessionId2 )).containsExactly (subscriptionId2 );
344
+ assertThat (subscriptions .get (sessionId3 )).containsExactly (subscriptionId3 );
316
345
}
317
346
318
347
@ Test // SPR-11931
0 commit comments