Pass headers to STOMP receipt callbacks
See gh-28715
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -576,22 +576,30 @@ public class DefaultStompSessionTests {
|
||||
this.session.setTaskScheduler(mock(TaskScheduler.class));
|
||||
|
||||
AtomicReference<Boolean> received = new AtomicReference<>();
|
||||
AtomicReference<StompHeaders> receivedHeaders = new AtomicReference<>();
|
||||
|
||||
StompHeaders headers = new StompHeaders();
|
||||
headers.setDestination("/topic/foo");
|
||||
headers.setReceipt("my-receipt");
|
||||
Subscription subscription = this.session.subscribe(headers, mock(StompFrameHandler.class));
|
||||
subscription.addReceiptTask(() -> received.set(true));
|
||||
subscription.addReceiptTask(receiptHeaders -> {
|
||||
received.set(true);
|
||||
receivedHeaders.set(receiptHeaders);
|
||||
});
|
||||
|
||||
assertThat((Object) received.get()).isNull();
|
||||
|
||||
StompHeaderAccessor accessor = StompHeaderAccessor.create(StompCommand.RECEIPT);
|
||||
accessor.setReceiptId("my-receipt");
|
||||
accessor.setNativeHeader("foo", "bar");
|
||||
accessor.setLeaveMutable(true);
|
||||
this.session.handleMessage(MessageBuilder.createMessage(new byte[0], accessor.getMessageHeaders()));
|
||||
|
||||
assertThat(received.get()).isNotNull();
|
||||
assertThat(received.get()).isTrue();
|
||||
assertThat(receivedHeaders.get()).isNotNull();
|
||||
assertThat(receivedHeaders.get().get("foo").size()).isEqualTo(1);
|
||||
assertThat(receivedHeaders.get().get("foo").get(0)).isEqualTo("bar");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -600,6 +608,7 @@ public class DefaultStompSessionTests {
|
||||
this.session.setTaskScheduler(mock(TaskScheduler.class));
|
||||
|
||||
AtomicReference<Boolean> received = new AtomicReference<>();
|
||||
AtomicReference<StompHeaders> receivedHeaders = new AtomicReference<>();
|
||||
|
||||
StompHeaders headers = new StompHeaders();
|
||||
headers.setDestination("/topic/foo");
|
||||
@@ -608,13 +617,20 @@ public class DefaultStompSessionTests {
|
||||
|
||||
StompHeaderAccessor accessor = StompHeaderAccessor.create(StompCommand.RECEIPT);
|
||||
accessor.setReceiptId("my-receipt");
|
||||
accessor.setNativeHeader("foo", "bar");
|
||||
accessor.setLeaveMutable(true);
|
||||
this.session.handleMessage(MessageBuilder.createMessage(new byte[0], accessor.getMessageHeaders()));
|
||||
|
||||
subscription.addReceiptTask(() -> received.set(true));
|
||||
subscription.addReceiptTask(receiptHeaders -> {
|
||||
received.set(true);
|
||||
receivedHeaders.set(receiptHeaders);
|
||||
});
|
||||
|
||||
assertThat(received.get()).isNotNull();
|
||||
assertThat(received.get()).isTrue();
|
||||
assertThat(receivedHeaders.get()).isNotNull();
|
||||
assertThat(receivedHeaders.get().get("foo").size()).isEqualTo(1);
|
||||
assertThat(receivedHeaders.get().get("foo").get(0)).isEqualTo("bar");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user