@@ -664,70 +664,48 @@ public void receiptNotReceived() {
664
664
}
665
665
666
666
@ Test
667
- void unsubscribeWithReceipt () {
667
+ void unsubscribeWithoutReceipt () {
668
668
this .session .afterConnected (this .connection );
669
669
assertThat (this .session .isConnected ()).isTrue ();
670
670
Subscription subscription = this .session .subscribe ("/topic/foo" , mock ());
671
671
672
672
Receiptable receipt = subscription .unsubscribe ();
673
673
assertThat (receipt ).isNotNull ();
674
674
assertThat (receipt .getReceiptId ()).isNull ();
675
-
676
- Message <byte []> message = this .messageCaptor .getValue ();
677
- StompHeaderAccessor accessor = MessageHeaderAccessor .getAccessor (message , StompHeaderAccessor .class );
678
- assertThat (accessor .getCommand ()).isEqualTo (StompCommand .UNSUBSCRIBE );
679
-
680
- StompHeaders stompHeaders = StompHeaders .readOnlyStompHeaders (accessor .getNativeHeaders ());
681
- assertThat (stompHeaders ).hasSize (1 );
682
- assertThat (stompHeaders .getId ()).isEqualTo (subscription .getSubscriptionId ());
683
675
}
684
676
685
677
@ Test
686
- void unsubscribeWithCustomHeaderAndReceipt () {
678
+ void unsubscribeWithReceipt () {
687
679
this .session .afterConnected (this .connection );
688
680
this .session .setTaskScheduler (mock ());
689
681
this .session .setAutoReceipt (true );
682
+ Subscription subscription = this .session .subscribe ("/topic/foo" , mock ());
690
683
691
- StompHeaders subHeaders = new StompHeaders ();
692
- subHeaders .setDestination ("/topic/foo" );
693
- Subscription subscription = this .session .subscribe (subHeaders , mock ());
694
-
695
- StompHeaders custom = new StompHeaders ();
696
- custom .set ("x-cust" , "value" );
697
-
698
- Receiptable receipt = subscription .unsubscribe (custom );
684
+ Receiptable receipt = subscription .unsubscribe ();
699
685
assertThat (receipt ).isNotNull ();
700
686
assertThat (receipt .getReceiptId ()).isNotNull ();
701
687
702
688
Message <byte []> message = this .messageCaptor .getValue ();
703
689
StompHeaderAccessor accessor = MessageHeaderAccessor .getAccessor (message , StompHeaderAccessor .class );
704
- assertThat (accessor .getCommand ()).isEqualTo (StompCommand .UNSUBSCRIBE );
705
-
706
- StompHeaders stompHeaders = StompHeaders .readOnlyStompHeaders (accessor .getNativeHeaders ());
707
- assertThat (stompHeaders .getId ()).isEqualTo (subscription .getSubscriptionId ());
708
- assertThat (stompHeaders .get ("x-cust" )).containsExactly ("value" );
709
- assertThat (stompHeaders .getReceipt ()).isEqualTo (receipt .getReceiptId ());
690
+ assertThat (accessor .getReceipt ()).isEqualTo (receipt .getReceiptId ());
710
691
}
711
692
712
693
@ Test
713
694
void receiptReceivedOnUnsubscribe () {
714
695
this .session .afterConnected (this .connection );
715
- TaskScheduler scheduler = mock ();
716
- this .session .setTaskScheduler (scheduler );
696
+ this .session .setTaskScheduler (mock ());
717
697
this .session .setAutoReceipt (true );
718
698
719
699
Subscription subscription = this .session .subscribe ("/topic/foo" , mock ());
720
700
Receiptable receipt = subscription .unsubscribe ();
721
701
722
- StompHeaderAccessor ack = StompHeaderAccessor .create (StompCommand .RECEIPT );
723
- ack .setReceiptId (receipt .getReceiptId ());
724
- ack .setLeaveMutable (true );
725
- Message <byte []> receiptMessage = MessageBuilder .createMessage (new byte [0 ], ack .getMessageHeaders ());
726
-
727
702
AtomicBoolean called = new AtomicBoolean (false );
728
703
receipt .addReceiptTask (() -> called .set (true ));
729
704
730
- this .session .handleMessage (receiptMessage );
705
+ StompHeaderAccessor ack = StompHeaderAccessor .create (StompCommand .RECEIPT );
706
+ ack .setReceiptId (receipt .getReceiptId ());
707
+ ack .setLeaveMutable (true );
708
+ this .session .handleMessage (MessageBuilder .createMessage (new byte [0 ], ack .getMessageHeaders ()));
731
709
732
710
assertThat (called .get ()).isTrue ();
733
711
}
0 commit comments