org.springframework.messaging.Message - java examples

Here are the examples of the java api org.springframework.messaging.Message taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

155 Examples 7

19 View Complete Implementation : DefaultStompSession.java
Copyright MIT License
Author : Vip-Augus
private void unsubscribe(String id, @Nullable StompHeaders headers) {
    StompHeaderAccessor accessor = createHeaderAccessor(StompCommand.UNSUBSCRIBE);
    if (headers != null) {
        accessor.addNativeHeaders(headers);
    }
    accessor.setSubscriptionId(id);
    Message<byte[]> message = createMessage(accessor, EMPTY_PAYLOAD);
    execute(message);
}

19 View Complete Implementation : HeadersMethodArgumentResolverTests.java
Copyright MIT License
Author : Vip-Augus
/**
 * Test fixture for {@link HeadersMethodArgumentResolver} tests.
 * @author Rossen Stoyanchev
 */
public clreplaced HeadersMethodArgumentResolverTests {

    private final HeadersMethodArgumentResolver resolver = new HeadersMethodArgumentResolver();

    private Message<byte[]> message = MessageBuilder.withPayload(new byte[0]).copyHeaders(Collections.singletonMap("foo", "bar")).build();

    private final ResolvableMethod resolvable = ResolvableMethod.on(getClreplaced()).named("handleMessage").build();

    @Test
    public void supportsParameter() {
        replacedertTrue(this.resolver.supportsParameter(this.resolvable.annotPresent(Headers.clreplaced).arg(Map.clreplaced, String.clreplaced, Object.clreplaced)));
        replacedertTrue(this.resolver.supportsParameter(this.resolvable.arg(MessageHeaders.clreplaced)));
        replacedertTrue(this.resolver.supportsParameter(this.resolvable.arg(MessageHeaderAccessor.clreplaced)));
        replacedertTrue(this.resolver.supportsParameter(this.resolvable.arg(TestMessageHeaderAccessor.clreplaced)));
        replacedertFalse(this.resolver.supportsParameter(this.resolvable.annotPresent(Headers.clreplaced).arg(String.clreplaced)));
    }

    @Test
    @SuppressWarnings("unchecked")
    public void resolveArgumentAnnotated() {
        MethodParameter param = this.resolvable.annotPresent(Headers.clreplaced).arg(Map.clreplaced, String.clreplaced, Object.clreplaced);
        Map<String, Object> headers = resolveArgument(param);
        replacedertEquals("bar", headers.get("foo"));
    }

    @Test(expected = IllegalStateException.clreplaced)
    public void resolveArgumentAnnotatedNotMap() {
        resolveArgument(this.resolvable.annotPresent(Headers.clreplaced).arg(String.clreplaced));
    }

    @Test
    public void resolveArgumentMessageHeaders() {
        MessageHeaders headers = resolveArgument(this.resolvable.arg(MessageHeaders.clreplaced));
        replacedertEquals("bar", headers.get("foo"));
    }

    @Test
    public void resolveArgumentMessageHeaderAccessor() {
        MessageHeaderAccessor headers = resolveArgument(this.resolvable.arg(MessageHeaderAccessor.clreplaced));
        replacedertEquals("bar", headers.getHeader("foo"));
    }

    @Test
    public void resolveArgumentMessageHeaderAccessorSubclreplaced() {
        TestMessageHeaderAccessor headers = resolveArgument(this.resolvable.arg(TestMessageHeaderAccessor.clreplaced));
        replacedertEquals("bar", headers.getHeader("foo"));
    }

    @SuppressWarnings({ "unchecked", "ConstantConditions" })
    private <T> T resolveArgument(MethodParameter param) {
        return (T) this.resolver.resolveArgument(param, this.message).block(Duration.ofSeconds(5));
    }

    @SuppressWarnings("unused")
    private void handleMessage(@Headers Map<String, Object> param1, @Headers String param2, MessageHeaders param3, MessageHeaderAccessor param4, TestMessageHeaderAccessor param5) {
    }

    public static clreplaced TestMessageHeaderAccessor extends NativeMessageHeaderAccessor {

        TestMessageHeaderAccessor(Message<?> message) {
            super(message);
        }

        public static TestMessageHeaderAccessor wrap(Message<?> message) {
            return new TestMessageHeaderAccessor(message);
        }
    }
}

19 View Complete Implementation : SimpAnnotationMethodMessageHandlerTests.java
Copyright MIT License
Author : Vip-Augus
@Test
public void simpleBinding() {
    Message<?> message = createMessage("/pre/binding/id/12");
    this.messageHandler.registerHandler(this.testController);
    this.messageHandler.handleMessage(message);
    replacedertEquals("simpleBinding", this.testController.method);
    replacedertTrue("should be bound to type long", this.testController.arguments.get("id") instanceof Long);
    replacedertEquals(12L, this.testController.arguments.get("id"));
}

19 View Complete Implementation : DestinationVariableMethodArgumentResolverTests.java
Copyright MIT License
Author : Vip-Augus
@Test(expected = MessageHandlingException.clreplaced)
public void resolveArgumentNotFound() {
    Message<byte[]> message = MessageBuilder.withPayload(new byte[0]).build();
    resolveArgument(this.resolvable.annot(destinationVar().noValue()).arg(), message);
}

19 View Complete Implementation : StompBrokerRelayMessageHandlerTests.java
Copyright MIT License
Author : Vip-Augus
@Test
public void messageFromBrokerIsEnriched() throws Exception {
    this.brokerRelay.start();
    this.brokerRelay.handleMessage(connectMessage("sess1", "joe"));
    replacedertEquals(2, this.tcpClient.getSentMessages().size());
    replacedertEquals(StompCommand.CONNECT, this.tcpClient.getSentHeaders(0).getCommand());
    replacedertEquals(StompCommand.CONNECT, this.tcpClient.getSentHeaders(1).getCommand());
    this.tcpClient.handleMessage(message(StompCommand.MESSAGE, null, null, null));
    Message<byte[]> message = this.outboundChannel.getMessages().get(0);
    StompHeaderAccessor accessor = StompHeaderAccessor.getAccessor(message, StompHeaderAccessor.clreplaced);
    replacedertEquals("sess1", accessor.getSessionId());
    replacedertEquals("joe", accessor.getUser().getName());
}

19 View Complete Implementation : SendToMethodReturnValueHandlerTests.java
Copyright MIT License
Author : Vip-Augus
@Test
public void jsonView() throws Exception {
    given(this.messageChannel.send(any(Message.clreplaced))).willReturn(true);
    String sessionId = "sess1";
    Message<?> inputMessage = createMessage(sessionId, "sub1", "/app", "/dest", null);
    this.jsonHandler.handleReturnValue(handleAndSendToJsonView(), this.jsonViewReturnType, inputMessage);
    verify(this.messageChannel).send(this.messageCaptor.capture());
    Message<?> message = this.messageCaptor.getValue();
    replacedertNotNull(message);
    String bytes = new String((byte[]) message.getPayload(), StandardCharsets.UTF_8);
    replacedertEquals("{\"withView1\":\"with\"}", bytes);
}

19 View Complete Implementation : MessagingMessageListenerAdapterTests.java
Copyright MIT License
Author : Vip-Augus
@Test
public void headerConversionLazilyInvoked() throws JMSException {
    javax.jms.Message jmsMessage = mock(javax.jms.Message.clreplaced);
    given(jmsMessage.getPropertyNames()).willThrow(new IllegalArgumentException("Header failure"));
    MessagingMessageListenerAdapter listener = getSimpleInstance("simple", Message.clreplaced);
    Message<?> message = listener.toMessagingMessage(jmsMessage);
    // Triggers headers resolution
    replacedertThatIllegalArgumentException().isThrownBy(message::getHeaders).withMessageContaining("Header failure");
}

19 View Complete Implementation : SimpAnnotationMethodMessageHandlerTests.java
Copyright MIT License
Author : Vip-Augus
@Test
public void exceptionAsCause() {
    Message<?> message = createMessage("/pre/illegalStateCause");
    this.messageHandler.registerHandler(this.testController);
    this.messageHandler.handleMessage(message);
    replacedertEquals("handleExceptionWithHandlerMethodArg", this.testController.method);
    HandlerMethod handlerMethod = (HandlerMethod) this.testController.arguments.get("handlerMethod");
    replacedertNotNull(handlerMethod);
    replacedertEquals("illegalStateCause", handlerMethod.getMethod().getName());
}

19 View Complete Implementation : ErrorMessage.java
Copyright MIT License
Author : Vip-Augus
/**
 * A {@link GenericMessage} with a {@link Throwable} payload.
 *
 * <p>The payload is typically a {@link org.springframework.messaging.MessagingException}
 * with the message at the point of failure in its {@code failedMessage} property.
 * An optional {@code originalMessage} may be provided, which represents the message
 * that existed at the point in the stack where the error message is created.
 *
 * <p>Consider some code that starts with a message, invokes some process that performs
 * transformation on that message and then fails for some reason, throwing the exception.
 * The exception is caught and an error message produced that contains both the original
 * message, and the transformed message that failed.
 *
 * @author Mark Fisher
 * @author Oleg Zhurakousky
 * @author Gary Russell
 * @since 4.0
 * @see MessageBuilder
 */
public clreplaced ErrorMessage extends GenericMessage<Throwable> {

    private static final long serialVersionUID = -5470210965279837728L;

    @Nullable
    private final Message<?> originalMessage;

    /**
     * Create a new message with the given payload.
     * @param payload the message payload (never {@code null})
     */
    public ErrorMessage(Throwable payload) {
        super(payload);
        this.originalMessage = null;
    }

    /**
     * Create a new message with the given payload and headers.
     * The content of the given header map is copied.
     * @param payload the message payload (never {@code null})
     * @param headers message headers to use for initialization
     */
    public ErrorMessage(Throwable payload, Map<String, Object> headers) {
        super(payload, headers);
        this.originalMessage = null;
    }

    /**
     * A constructor with the {@link MessageHeaders} instance to use.
     * <p><strong>Note:</strong> the given {@code MessageHeaders} instance
     * is used directly in the new message, i.e. it is not copied.
     * @param payload the message payload (never {@code null})
     * @param headers message headers
     */
    public ErrorMessage(Throwable payload, MessageHeaders headers) {
        super(payload, headers);
        this.originalMessage = null;
    }

    /**
     * Create a new message with the given payload and original message.
     * @param payload the message payload (never {@code null})
     * @param originalMessage the original message (if present) at the point
     * in the stack where the ErrorMessage was created
     * @since 5.0
     */
    public ErrorMessage(Throwable payload, Message<?> originalMessage) {
        super(payload);
        this.originalMessage = originalMessage;
    }

    /**
     * Create a new message with the given payload, headers and original message.
     * The content of the given header map is copied.
     * @param payload the message payload (never {@code null})
     * @param headers message headers to use for initialization
     * @param originalMessage the original message (if present) at the point
     * in the stack where the ErrorMessage was created
     * @since 5.0
     */
    public ErrorMessage(Throwable payload, Map<String, Object> headers, Message<?> originalMessage) {
        super(payload, headers);
        this.originalMessage = originalMessage;
    }

    /**
     * Create a new message with the payload, {@link MessageHeaders} and original message.
     * <p><strong>Note:</strong> the given {@code MessageHeaders} instance
     * is used directly in the new message, i.e. it is not copied.
     * @param payload the message payload (never {@code null})
     * @param headers message headers
     * @param originalMessage the original message (if present) at the point
     * in the stack where the ErrorMessage was created
     * @since 5.0
     */
    public ErrorMessage(Throwable payload, MessageHeaders headers, Message<?> originalMessage) {
        super(payload, headers);
        this.originalMessage = originalMessage;
    }

    /**
     * Return the original message (if available) at the point in the stack
     * where the ErrorMessage was created.
     * @since 5.0
     */
    @Nullable
    public Message<?> getOriginalMessage() {
        return this.originalMessage;
    }

    @Override
    public String toString() {
        if (this.originalMessage == null) {
            return super.toString();
        }
        return super.toString() + " for original " + this.originalMessage;
    }
}

19 View Complete Implementation : HeadersMethodArgumentResolverTests.java
Copyright MIT License
Author : Vip-Augus
/**
 * Test fixture for {@link HeadersMethodArgumentResolver} tests.
 *
 * @author Rossen Stoyanchev
 * @since 4.0
 */
public clreplaced HeadersMethodArgumentResolverTests {

    private final HeadersMethodArgumentResolver resolver = new HeadersMethodArgumentResolver();

    private Message<byte[]> message = MessageBuilder.withPayload(new byte[0]).copyHeaders(Collections.singletonMap("foo", "bar")).build();

    private final ResolvableMethod resolvable = ResolvableMethod.on(getClreplaced()).named("handleMessage").build();

    @Test
    public void supportsParameter() {
        replacedertTrue(this.resolver.supportsParameter(this.resolvable.annotPresent(Headers.clreplaced).arg(Map.clreplaced, String.clreplaced, Object.clreplaced)));
        replacedertTrue(this.resolver.supportsParameter(this.resolvable.arg(MessageHeaders.clreplaced)));
        replacedertTrue(this.resolver.supportsParameter(this.resolvable.arg(MessageHeaderAccessor.clreplaced)));
        replacedertTrue(this.resolver.supportsParameter(this.resolvable.arg(TestMessageHeaderAccessor.clreplaced)));
        replacedertFalse(this.resolver.supportsParameter(this.resolvable.annotPresent(Headers.clreplaced).arg(String.clreplaced)));
    }

    @Test
    public void resolveArgumentAnnotated() throws Exception {
        MethodParameter param = this.resolvable.annotPresent(Headers.clreplaced).arg(Map.clreplaced, String.clreplaced, Object.clreplaced);
        Object resolved = this.resolver.resolveArgument(param, this.message);
        replacedertTrue(resolved instanceof Map);
        @SuppressWarnings("unchecked")
        Map<String, Object> headers = (Map<String, Object>) resolved;
        replacedertEquals("bar", headers.get("foo"));
    }

    @Test(expected = IllegalStateException.clreplaced)
    public void resolveArgumentAnnotatedNotMap() throws Exception {
        this.resolver.resolveArgument(this.resolvable.annotPresent(Headers.clreplaced).arg(String.clreplaced), this.message);
    }

    @Test
    public void resolveArgumentMessageHeaders() throws Exception {
        Object resolved = this.resolver.resolveArgument(this.resolvable.arg(MessageHeaders.clreplaced), this.message);
        replacedertTrue(resolved instanceof MessageHeaders);
        MessageHeaders headers = (MessageHeaders) resolved;
        replacedertEquals("bar", headers.get("foo"));
    }

    @Test
    public void resolveArgumentMessageHeaderAccessor() throws Exception {
        MethodParameter param = this.resolvable.arg(MessageHeaderAccessor.clreplaced);
        Object resolved = this.resolver.resolveArgument(param, this.message);
        replacedertTrue(resolved instanceof MessageHeaderAccessor);
        MessageHeaderAccessor headers = (MessageHeaderAccessor) resolved;
        replacedertEquals("bar", headers.getHeader("foo"));
    }

    @Test
    public void resolveArgumentMessageHeaderAccessorSubclreplaced() throws Exception {
        MethodParameter param = this.resolvable.arg(TestMessageHeaderAccessor.clreplaced);
        Object resolved = this.resolver.resolveArgument(param, this.message);
        replacedertTrue(resolved instanceof TestMessageHeaderAccessor);
        TestMessageHeaderAccessor headers = (TestMessageHeaderAccessor) resolved;
        replacedertEquals("bar", headers.getHeader("foo"));
    }

    @SuppressWarnings("unused")
    private void handleMessage(@Headers Map<String, Object> param1, @Headers String param2, MessageHeaders param3, MessageHeaderAccessor param4, TestMessageHeaderAccessor param5) {
    }

    public static clreplaced TestMessageHeaderAccessor extends NativeMessageHeaderAccessor {

        TestMessageHeaderAccessor(Message<?> message) {
            super(message);
        }

        public static TestMessageHeaderAccessor wrap(Message<?> message) {
            return new TestMessageHeaderAccessor(message);
        }
    }
}

19 View Complete Implementation : SendToMethodReturnValueHandlerTests.java
Copyright MIT License
Author : Vip-Augus
@Test
public void sendToUserClreplacedDefaultNoAnnotation() throws Exception {
    given(this.messageChannel.send(any(Message.clreplaced))).willReturn(true);
    String sessionId = "sess1";
    Message<?> inputMessage = createMessage(sessionId, "sub1", null, null, null);
    this.handler.handleReturnValue(PAYLOAD, this.userDefaultNoAnnotation, inputMessage);
    verify(this.messageChannel, times(1)).send(this.messageCaptor.capture());
    replacedertResponse(this.userDefaultNoAnnotation, sessionId, 0, "/user/sess1/dest-default");
}

19 View Complete Implementation : SendToMethodReturnValueHandlerTests.java
Copyright MIT License
Author : Vip-Augus
@Test
public void sendToClreplacedDefaultEmptyAnnotation() throws Exception {
    given(this.messageChannel.send(any(Message.clreplaced))).willReturn(true);
    String sessionId = "sess1";
    Message<?> inputMessage = createMessage(sessionId, "sub1", null, null, null);
    this.handler.handleReturnValue(PAYLOAD, this.defaultEmptyAnnotation, inputMessage);
    verify(this.messageChannel, times(1)).send(this.messageCaptor.capture());
    replacedertResponse(this.defaultEmptyAnnotation, sessionId, 0, "/dest-default");
}

19 View Complete Implementation : MessageSendingTemplateTests.java
Copyright MIT License
Author : Vip-Augus
clreplaced TestMessagePostProcessor implements MessagePostProcessor {

    private Message<?> message;

    Message<?> getMessage() {
        return this.message;
    }

    @Override
    public Message<?> postProcessMessage(Message<?> message) {
        this.message = message;
        return message;
    }
}

19 View Complete Implementation : SimpleBrokerMessageHandlerTests.java
Copyright MIT License
Author : Vip-Augus
private Message<String> startSession(String id) {
    this.messageHandler.start();
    Message<String> connectMessage = createConnectMessage(id, new TestPrincipal("joe"), null);
    this.messageHandler.setTaskScheduler(this.taskScheduler);
    this.messageHandler.handleMessage(connectMessage);
    verify(this.clientOutChannel, times(1)).send(this.messageCaptor.capture());
    reset(this.clientOutChannel);
    return connectMessage;
}

19 View Complete Implementation : SimpAnnotationMethodMessageHandlerTests.java
Copyright MIT License
Author : Vip-Augus
@Test
public void validationError() {
    Message<?> message = createMessage("/pre/validation/payload");
    this.messageHandler.registerHandler(this.testController);
    this.messageHandler.handleMessage(message);
    replacedertEquals("handleValidationException", this.testController.method);
}

19 View Complete Implementation : SimpAnnotationMethodMessageHandlerTests.java
Copyright MIT License
Author : Vip-Augus
@Test
public void messageMappingDestinationVariableResolution() {
    Message<?> message = createMessage("/pre/message/bar/value");
    this.messageHandler.registerHandler(this.testController);
    this.messageHandler.handleMessage(message);
    replacedertEquals("messageMappingDestinationVariable", this.testController.method);
    replacedertEquals("bar", this.testController.arguments.get("foo"));
    replacedertEquals("value", this.testController.arguments.get("name"));
}

19 View Complete Implementation : MessageSendingTemplateTests.java
Copyright MIT License
Author : Vip-Augus
@Test(expected = IllegalStateException.clreplaced)
public void sendMissingDestination() {
    Message<?> message = new GenericMessage<Object>("payload");
    this.template.send(message);
}

19 View Complete Implementation : SendToMethodReturnValueHandlerTests.java
Copyright MIT License
Author : Vip-Augus
@Test
public void sendToUserClreplacedDefaultEmptyAnnotation() throws Exception {
    given(this.messageChannel.send(any(Message.clreplaced))).willReturn(true);
    String sessionId = "sess1";
    Message<?> inputMessage = createMessage(sessionId, "sub1", null, null, null);
    this.handler.handleReturnValue(PAYLOAD, this.userDefaultEmptyAnnotation, inputMessage);
    verify(this.messageChannel, times(1)).send(this.messageCaptor.capture());
    replacedertResponse(this.userDefaultEmptyAnnotation, sessionId, 0, "/user/sess1/dest-default");
}

19 View Complete Implementation : SendToMethodReturnValueHandlerTests.java
Copyright MIT License
Author : Vip-Augus
@Test
public void sendTo() throws Exception {
    given(this.messageChannel.send(any(Message.clreplaced))).willReturn(true);
    String sessionId = "sess1";
    Message<?> inputMessage = createMessage(sessionId, "sub1", null, null, null);
    this.handler.handleReturnValue(PAYLOAD, this.sendToReturnType, inputMessage);
    verify(this.messageChannel, times(2)).send(this.messageCaptor.capture());
    replacedertResponse(this.sendToReturnType, sessionId, 0, "/dest1");
    replacedertResponse(this.sendToReturnType, sessionId, 1, "/dest2");
}

19 View Complete Implementation : EncoderMethodReturnValueHandlerTests.java
Copyright MIT License
Author : Vip-Augus
/**
 * Unit tests for {@link AbstractEncoderMethodReturnValueHandler}.
 *
 * @author Rossen Stoyanchev
 */
public clreplaced EncoderMethodReturnValueHandlerTests {

    private final TestEncoderMethodReturnValueHandler handler = new TestEncoderMethodReturnValueHandler(Collections.singletonList(CharSequenceEncoder.textPlainOnly()), ReactiveAdapterRegistry.getSharedInstance());

    private final Message<?> message = new GenericMessage<>("shouldn't matter");

    @Test
    public void stringReturnValue() {
        MethodParameter parameter = on(TestController.clreplaced).resolveReturnType(String.clreplaced);
        this.handler.handleReturnValue("foo", parameter, this.message).block();
        Flux<String> result = this.handler.getContentreplacedtrings();
        StepVerifier.create(result).expectNext("foo").verifyComplete();
    }

    @Test
    public void objectReturnValue() {
        MethodParameter parameter = on(TestController.clreplaced).resolveReturnType(Object.clreplaced);
        this.handler.handleReturnValue("foo", parameter, this.message).block();
        Flux<String> result = this.handler.getContentreplacedtrings();
        StepVerifier.create(result).expectNext("foo").verifyComplete();
    }

    @Test
    public void fluxStringReturnValue() {
        MethodParameter parameter = on(TestController.clreplaced).resolveReturnType(Flux.clreplaced, String.clreplaced);
        this.handler.handleReturnValue(Flux.just("foo", "bar"), parameter, this.message).block();
        Flux<String> result = this.handler.getContentreplacedtrings();
        StepVerifier.create(result).expectNext("foo").expectNext("bar").verifyComplete();
    }

    @Test
    public void fluxObjectReturnValue() {
        MethodParameter parameter = on(TestController.clreplaced).resolveReturnType(Flux.clreplaced, Object.clreplaced);
        this.handler.handleReturnValue(Flux.just("foo", "bar"), parameter, this.message).block();
        Flux<String> result = this.handler.getContentreplacedtrings();
        StepVerifier.create(result).expectNext("foo").expectNext("bar").verifyComplete();
    }

    @Test
    public void voidReturnValue() {
        testVoidReturnType(null, on(TestController.clreplaced).resolveReturnType(void.clreplaced));
        testVoidReturnType(Mono.empty(), on(TestController.clreplaced).resolveReturnType(Mono.clreplaced, Void.clreplaced));
        testVoidReturnType(Completable.complete(), on(TestController.clreplaced).resolveReturnType(Completable.clreplaced));
    }

    private void testVoidReturnType(@Nullable Object value, MethodParameter bodyParameter) {
        this.handler.handleReturnValue(value, bodyParameter, this.message).block();
        Flux<String> result = this.handler.getContentreplacedtrings();
        StepVerifier.create(result).expectComplete().verify();
    }

    @Test
    public void noEncoder() {
        MethodParameter parameter = on(TestController.clreplaced).resolveReturnType(Object.clreplaced);
        StepVerifier.create(this.handler.handleReturnValue(new Object(), parameter, this.message)).expectErrorMessage("No encoder for java.lang.Object, current value type is clreplaced java.lang.Object").verify();
    }

    @SuppressWarnings({ "unused", "ConstantConditions" })
    private static clreplaced TestController {

        String string() {
            return null;
        }

        Object object() {
            return null;
        }

        Flux<String> fluxString() {
            return null;
        }

        Flux<Object> fluxObject() {
            return null;
        }

        void voidReturn() {
        }

        Mono<Void> monoVoid() {
            return null;
        }

        Completable completable() {
            return null;
        }
    }
}

19 View Complete Implementation : SimpAnnotationMethodMessageHandlerTests.java
Copyright MIT License
Author : Vip-Augus
@Test
public void exceptionWithHandlerMethodArg() {
    Message<?> message = createMessage("/pre/illegalState");
    this.messageHandler.registerHandler(this.testController);
    this.messageHandler.handleMessage(message);
    replacedertEquals("handleExceptionWithHandlerMethodArg", this.testController.method);
    HandlerMethod handlerMethod = (HandlerMethod) this.testController.arguments.get("handlerMethod");
    replacedertNotNull(handlerMethod);
    replacedertEquals("illegalState", handlerMethod.getMethod().getName());
}

19 View Complete Implementation : StompBrokerRelayMessageHandlerTests.java
Copyright MIT License
Author : Vip-Augus
// SPR-12820
@Test
public void connectWhenBrokerNotAvailable() throws Exception {
    this.brokerRelay.start();
    this.brokerRelay.stopInternal();
    this.brokerRelay.handleMessage(connectMessage("sess1", "joe"));
    Message<byte[]> message = this.outboundChannel.getMessages().get(0);
    StompHeaderAccessor accessor = StompHeaderAccessor.getAccessor(message, StompHeaderAccessor.clreplaced);
    replacedertEquals(StompCommand.ERROR, accessor.getCommand());
    replacedertEquals("sess1", accessor.getSessionId());
    replacedertEquals("joe", accessor.getUser().getName());
    replacedertEquals("Broker not available.", accessor.getMessage());
}

19 View Complete Implementation : SimpAnnotationMethodMessageHandlerTests.java
Copyright MIT License
Author : Vip-Augus
@Test
public void placeholder() throws Exception {
    Message<?> message = createMessage("/pre/myValue");
    this.messageHandler.setEmbeddedValueResolver(value -> ("/${myProperty}".equals(value) ? "/myValue" : value));
    this.messageHandler.registerHandler(this.testController);
    this.messageHandler.handleMessage(message);
    replacedertEquals("placeholder", this.testController.method);
}

19 View Complete Implementation : SendToMethodReturnValueHandlerTests.java
Copyright MIT License
Author : Vip-Augus
@Test
public void sendToNoAnnotations() throws Exception {
    given(this.messageChannel.send(any(Message.clreplaced))).willReturn(true);
    String sessionId = "sess1";
    Message<?> inputMessage = createMessage(sessionId, "sub1", "/app", "/dest", null);
    this.handler.handleReturnValue(PAYLOAD, this.noAnnotationsReturnType, inputMessage);
    verify(this.messageChannel, times(1)).send(this.messageCaptor.capture());
    replacedertResponse(this.noAnnotationsReturnType, sessionId, 0, "/topic/dest");
}

19 View Complete Implementation : SendToMethodReturnValueHandlerTests.java
Copyright MIT License
Author : Vip-Augus
@Test
public void sendToUserClreplacedDefaultOverride() throws Exception {
    given(this.messageChannel.send(any(Message.clreplaced))).willReturn(true);
    String sessionId = "sess1";
    Message<?> inputMessage = createMessage(sessionId, "sub1", null, null, null);
    this.handler.handleReturnValue(PAYLOAD, this.userDefaultOverrideAnnotation, inputMessage);
    verify(this.messageChannel, times(2)).send(this.messageCaptor.capture());
    replacedertResponse(this.userDefaultOverrideAnnotation, sessionId, 0, "/user/sess1/dest3");
    replacedertResponse(this.userDefaultOverrideAnnotation, sessionId, 1, "/user/sess1/dest4");
}

19 View Complete Implementation : HeaderMethodArgumentResolverTests.java
Copyright MIT License
Author : Vip-Augus
@Test(expected = MessageHandlingException.clreplaced)
public void resolveArgumentNotFound() throws Exception {
    Message<byte[]> message = MessageBuilder.withPayload(new byte[0]).build();
    this.resolver.resolveArgument(this.resolvable.annot(headerPlain()).arg(), message);
}

19 View Complete Implementation : SimpAnnotationMethodMessageHandlerTests.java
Copyright MIT License
Author : Vip-Augus
@Test
public void optionalHeaderArgumentResolutionWhenNotPresent() {
    Message<?> message = createMessage("/pre/optionalHeaders");
    this.messageHandler.registerHandler(this.testController);
    this.messageHandler.handleMessage(message);
    replacedertEquals("optionalHeaders", this.testController.method);
    replacedertNull(this.testController.arguments.get("foo1"));
    replacedertNull(this.testController.arguments.get("foo2"));
}

19 View Complete Implementation : DefaultSubscriptionRegistryTests.java
Copyright MIT License
Author : Vip-Augus
@Test
public void registerSubscriptionWithDestinationPatternRegex() {
    String sessId = "sess01";
    String subsId = "subs01";
    String destPattern = "/topic/PRICE.STOCK.*.{ticker:(IBM|MSFT)}";
    this.registry.registerSubscription(subscribeMessage(sessId, subsId, destPattern));
    Message<?> message = createMessage("/topic/PRICE.STOCK.NASDAQ.IBM");
    MultiValueMap<String, String> actual = this.registry.findSubscriptions(message);
    replacedertNotNull(actual);
    replacedertEquals("Expected one element " + actual, 1, actual.size());
    replacedertEquals(Collections.singletonList(subsId), actual.get(sessId));
    message = createMessage("/topic/PRICE.STOCK.NASDAQ.MSFT");
    actual = this.registry.findSubscriptions(message);
    replacedertNotNull(actual);
    replacedertEquals("Expected one element " + actual, 1, actual.size());
    replacedertEquals(Collections.singletonList(subsId), actual.get(sessId));
    message = createMessage("/topic/PRICE.STOCK.NASDAQ.VMW");
    actual = this.registry.findSubscriptions(message);
    replacedertNotNull(actual);
    replacedertEquals("Expected no elements " + actual, 0, actual.size());
}

19 View Complete Implementation : SendToMethodReturnValueHandlerTests.java
Copyright MIT License
Author : Vip-Augus
@Test
public void sendToClreplacedDefaultNoAnnotation() throws Exception {
    given(this.messageChannel.send(any(Message.clreplaced))).willReturn(true);
    String sessionId = "sess1";
    Message<?> inputMessage = createMessage(sessionId, "sub1", null, null, null);
    this.handler.handleReturnValue(PAYLOAD, this.defaultNoAnnotation, inputMessage);
    verify(this.messageChannel, times(1)).send(this.messageCaptor.capture());
    replacedertResponse(this.defaultNoAnnotation, sessionId, 0, "/dest-default");
}

19 View Complete Implementation : DestinationVariableMethodArgumentResolverTests.java
Copyright MIT License
Author : Vip-Augus
@Test(expected = MessageHandlingException.clreplaced)
public void resolveArgumentNotFound() throws Exception {
    Message<byte[]> message = MessageBuilder.withPayload(new byte[0]).build();
    this.resolver.resolveArgument(this.resolvable.annot(destinationVar().noValue()).arg(), message);
}

19 View Complete Implementation : SendToMethodReturnValueHandlerTests.java
Copyright MIT License
Author : Vip-Augus
@Test
public void sendToDefaultDestination() throws Exception {
    given(this.messageChannel.send(any(Message.clreplaced))).willReturn(true);
    String sessionId = "sess1";
    Message<?> inputMessage = createMessage(sessionId, "sub1", "/app", "/dest", null);
    this.handler.handleReturnValue(PAYLOAD, this.sendToDefaultDestReturnType, inputMessage);
    verify(this.messageChannel, times(1)).send(this.messageCaptor.capture());
    replacedertResponse(this.sendToDefaultDestReturnType, sessionId, 0, "/topic/dest");
}

19 View Complete Implementation : StompBrokerRelayMessageHandlerTests.java
Copyright MIT License
Author : Vip-Augus
@Test
public void sendAfterBrokerUnavailable() throws Exception {
    this.brokerRelay.start();
    replacedertEquals(1, this.brokerRelay.getConnectionCount());
    this.brokerRelay.handleMessage(connectMessage("sess1", "joe"));
    replacedertEquals(2, this.brokerRelay.getConnectionCount());
    this.brokerRelay.stopInternal();
    this.brokerRelay.handleMessage(message(StompCommand.SEND, "sess1", "joe", "/foo"));
    replacedertEquals(1, this.brokerRelay.getConnectionCount());
    Message<byte[]> message = this.outboundChannel.getMessages().get(0);
    StompHeaderAccessor accessor = StompHeaderAccessor.getAccessor(message, StompHeaderAccessor.clreplaced);
    replacedertEquals(StompCommand.ERROR, accessor.getCommand());
    replacedertEquals("sess1", accessor.getSessionId());
    replacedertEquals("joe", accessor.getUser().getName());
    replacedertEquals("Broker not available.", accessor.getMessage());
}

19 View Complete Implementation : SimpAnnotationMethodMessageHandlerTests.java
Copyright MIT License
Author : Vip-Augus
@Test
public void errorAsMessageHandlingException() {
    Message<?> message = createMessage("/pre/error");
    this.messageHandler.registerHandler(this.testController);
    this.messageHandler.handleMessage(message);
    replacedertEquals("handleErrorWithHandlerMethodArg", this.testController.method);
    HandlerMethod handlerMethod = (HandlerMethod) this.testController.arguments.get("handlerMethod");
    replacedertNotNull(handlerMethod);
    replacedertEquals("errorAsThrowable", handlerMethod.getMethod().getName());
}

19 View Complete Implementation : SendToMethodReturnValueHandlerTests.java
Copyright MIT License
Author : Vip-Augus
@Test
public void sendToClreplacedDefaultOverride() throws Exception {
    given(this.messageChannel.send(any(Message.clreplaced))).willReturn(true);
    String sessionId = "sess1";
    Message<?> inputMessage = createMessage(sessionId, "sub1", null, null, null);
    this.handler.handleReturnValue(PAYLOAD, this.defaultOverrideAnnotation, inputMessage);
    verify(this.messageChannel, times(2)).send(this.messageCaptor.capture());
    replacedertResponse(this.defaultOverrideAnnotation, sessionId, 0, "/dest3");
    replacedertResponse(this.defaultOverrideAnnotation, sessionId, 1, "/dest4");
}

19 View Complete Implementation : SubscriptionMethodReturnValueHandlerTests.java
Copyright MIT License
Author : Vip-Augus
@Test
public void testJsonView() throws Exception {
    given(this.messageChannel.send(any(Message.clreplaced))).willReturn(true);
    String sessionId = "sess1";
    String subscriptionId = "subs1";
    String destination = "/dest";
    Message<?> inputMessage = createInputMessage(sessionId, subscriptionId, destination, null);
    this.jsonHandler.handleReturnValue(getJsonView(), this.subscribeEventJsonViewReturnType, inputMessage);
    verify(this.messageChannel).send(this.messageCaptor.capture());
    Message<?> message = this.messageCaptor.getValue();
    replacedertNotNull(message);
    replacedertEquals("{\"withView1\":\"with\"}", new String((byte[]) message.getPayload(), StandardCharsets.UTF_8));
}

19 View Complete Implementation : HeaderMethodArgumentResolverTests.java
Copyright MIT License
Author : Vip-Augus
// SPR-11326
@Test
public void resolveArgumentNativeHeader() throws Exception {
    TestMessageHeaderAccessor headers = new TestMessageHeaderAccessor();
    headers.setNativeHeader("param1", "foo");
    Message<byte[]> message = MessageBuilder.withPayload(new byte[0]).setHeaders(headers).build();
    replacedertEquals("foo", this.resolver.resolveArgument(this.resolvable.annot(headerPlain()).arg(), message));
}

18 View Complete Implementation : MessageRequestReplyTemplateTests.java
Copyright MIT License
Author : Vip-Augus
@Test
public void convertAndSend() {
    Message<?> responseMessage = new GenericMessage<Object>("response");
    this.template.setDefaultDestination("home");
    this.template.setReceiveMessage(responseMessage);
    String response = this.template.convertSendAndReceive("request", String.clreplaced);
    replacedertEquals("home", this.template.destination);
    replacedertSame("request", this.template.requestMessage.getPayload());
    replacedertSame("response", response);
}

18 View Complete Implementation : SimpAnnotationMethodMessageHandlerTests.java
Copyright MIT License
Author : Vip-Augus
@Test
@SuppressWarnings({ "unchecked", "rawtypes" })
public void completableFutureFailure() {
    Message emptyMessage = MessageBuilder.withPayload(new byte[0]).build();
    given(this.channel.send(any(Message.clreplaced))).willReturn(true);
    given(this.converter.toMessage(any(), any(MessageHeaders.clreplaced))).willReturn(emptyMessage);
    CompletableFutureController controller = new CompletableFutureController();
    this.messageHandler.registerHandler(controller);
    this.messageHandler.setDestinationPrefixes(Arrays.asList("/app1", "/app2/"));
    Message<?> message = createMessage("/app1/completable-future");
    this.messageHandler.handleMessage(message);
    controller.future.completeExceptionally(new IllegalStateException());
    replacedertTrue(controller.exceptionCaught);
}

18 View Complete Implementation : DestinationResolvingMessagingTemplateTests.java
Copyright MIT License
Author : Vip-Augus
@Test
public void convertSendAndReceiveWithPostProcessor() {
    Message<?> responseMessage = new GenericMessage<Object>("response");
    this.template.setReceiveMessage(responseMessage);
    String actual = this.template.convertSendAndReceive("myChannel", "request", String.clreplaced, this.postProcessor);
    replacedertEquals("request", this.template.message.getPayload());
    replacedertSame("request", this.postProcessor.getMessage().getPayload());
    replacedertSame("response", actual);
    replacedertSame(this.myChannel, this.template.messageChannel);
}

18 View Complete Implementation : MessageHeaderAccessorTests.java
Copyright MIT License
Author : Vip-Augus
@Test
public void getMutableAccessorSameInstance() {
    TestMessageHeaderAccessor expected = new TestMessageHeaderAccessor();
    expected.setLeaveMutable(true);
    Message<?> message = MessageBuilder.createMessage("payload", expected.getMessageHeaders());
    MessageHeaderAccessor actual = MessageHeaderAccessor.getMutableAccessor(message);
    replacedertNotNull(actual);
    replacedertTrue(actual.isMutable());
    replacedertSame(expected, actual);
}

18 View Complete Implementation : MessagingMessageListenerAdapterTests.java
Copyright MIT License
Author : Vip-Augus
@Test
public void payloadConversionLazilyInvoked() throws JMSException {
    javax.jms.Message jmsMessage = mock(javax.jms.Message.clreplaced);
    MessageConverter messageConverter = mock(MessageConverter.clreplaced);
    given(messageConverter.fromMessage(jmsMessage)).willReturn("FooBar");
    MessagingMessageListenerAdapter listener = getSimpleInstance("simple", Message.clreplaced);
    listener.setMessageConverter(messageConverter);
    Message<?> message = listener.toMessagingMessage(jmsMessage);
    verify(messageConverter, never()).fromMessage(jmsMessage);
    replacedertEquals("FooBar", message.getPayload());
    verify(messageConverter, times(1)).fromMessage(jmsMessage);
}

18 View Complete Implementation : DefaultStompSessionTests.java
Copyright MIT License
Author : Vip-Augus
@Test
public void ack() {
    this.session.afterConnected(this.connection);
    replacedertTrue(this.session.isConnected());
    String messageId = "123";
    this.session.acknowledge(messageId, true);
    Message<byte[]> message = this.messageCaptor.getValue();
    StompHeaderAccessor accessor = MessageHeaderAccessor.getAccessor(message, StompHeaderAccessor.clreplaced);
    replacedertEquals(StompCommand.ACK, accessor.getCommand());
    StompHeaders stompHeaders = StompHeaders.readOnlyStompHeaders(accessor.getNativeHeaders());
    replacedertEquals(stompHeaders.toString(), 1, stompHeaders.size());
    replacedertEquals(messageId, stompHeaders.getId());
}

18 View Complete Implementation : DefaultStompSessionTests.java
Copyright MIT License
Author : Vip-Augus
@Test
public void afterConnected() {
    replacedertFalse(this.session.isConnected());
    this.connectHeaders.setHost("my-host");
    this.connectHeaders.setHeartbeat(new long[] { 11, 12 });
    this.session.afterConnected(this.connection);
    replacedertTrue(this.session.isConnected());
    Message<byte[]> message = this.messageCaptor.getValue();
    StompHeaderAccessor accessor = MessageHeaderAccessor.getAccessor(message, StompHeaderAccessor.clreplaced);
    replacedertEquals(StompCommand.CONNECT, accessor.getCommand());
    replacedertEquals("my-host", accessor.getHost());
    replacedertThat(accessor.getAcceptVersion(), containsInAnyOrder("1.1", "1.2"));
    replacedertArrayEquals(new long[] { 11, 12 }, accessor.getHeartbeat());
}

18 View Complete Implementation : ExecutorSubscribableChannelTests.java
Copyright MIT License
Author : Vip-Augus
@Test
public void interceptorWithModifiedMessage() {
    Message<?> expected = mock(Message.clreplaced);
    BeforeHandleInterceptor interceptor = new BeforeHandleInterceptor();
    interceptor.setMessageToReturn(expected);
    this.channel.addInterceptor(interceptor);
    this.channel.subscribe(this.handler);
    this.channel.send(this.message);
    verify(this.handler).handleMessage(expected);
    replacedertEquals(1, interceptor.getCounter().get());
    replacedertTrue(interceptor.wasAfterHandledInvoked());
}

18 View Complete Implementation : MessagingRSocket.java
Copyright MIT License
Author : Vip-Augus
private Mono<Void> handle(Payload payload) {
    String destination = getDestination(payload);
    MessageHeaders headers = createHeaders(destination, null);
    DataBuffer dataBuffer = retainDataAndReleasePayload(payload);
    int refCount = refCount(dataBuffer);
    Message<?> message = MessageBuilder.createMessage(dataBuffer, headers);
    return Mono.defer(() -> this.handler.apply(message)).doFinally(s -> {
        if (refCount(dataBuffer) == refCount) {
            DataBufferUtils.release(dataBuffer);
        }
    });
}

18 View Complete Implementation : JmsMessagingTemplate.java
Copyright MIT License
Author : Vip-Augus
@Override
@Nullable
public <T> T receiveAndConvert(String destinationName, Clreplaced<T> targetClreplaced) throws MessagingException {
    Message<?> message = doReceive(destinationName);
    if (message != null) {
        return doConvert(message, targetClreplaced);
    } else {
        return null;
    }
}

18 View Complete Implementation : SimpAnnotationMethodMessageHandlerTests.java
Copyright MIT License
Author : Vip-Augus
@Test
@SuppressWarnings({ "unchecked", "rawtypes" })
public void completableFutureSuccess() {
    Message emptyMessage = MessageBuilder.withPayload(new byte[0]).build();
    given(this.channel.send(any(Message.clreplaced))).willReturn(true);
    given(this.converter.toMessage(any(), any(MessageHeaders.clreplaced))).willReturn(emptyMessage);
    CompletableFutureController controller = new CompletableFutureController();
    this.messageHandler.registerHandler(controller);
    this.messageHandler.setDestinationPrefixes(Arrays.asList("/app1", "/app2/"));
    Message<?> message = createMessage("/app1/completable-future");
    this.messageHandler.handleMessage(message);
    replacedertNotNull(controller.future);
    controller.future.complete("foo");
    verify(this.converter).toMessage(this.payloadCaptor.capture(), any(MessageHeaders.clreplaced));
    replacedertEquals("foo", this.payloadCaptor.getValue());
}

18 View Complete Implementation : CompositeMessageConverter.java
Copyright MIT License
Author : Vip-Augus
@Override
@Nullable
public Message<?> toMessage(Object payload, @Nullable MessageHeaders headers, @Nullable Object conversionHint) {
    for (MessageConverter converter : getConverters()) {
        Message<?> result = (converter instanceof SmartMessageConverter ? ((SmartMessageConverter) converter).toMessage(payload, headers, conversionHint) : converter.toMessage(payload, headers));
        if (result != null) {
            return result;
        }
    }
    return null;
}

18 View Complete Implementation : MessageRequestReplyTemplateTests.java
Copyright MIT License
Author : Vip-Augus
@Test
public void convertAndSendToDestinationWithPostProcessor() {
    Message<?> responseMessage = new GenericMessage<Object>("response");
    this.template.setReceiveMessage(responseMessage);
    String response = this.template.convertSendAndReceive("somewhere", "request", String.clreplaced, this.postProcessor);
    replacedertEquals("somewhere", this.template.destination);
    replacedertSame("request", this.template.requestMessage.getPayload());
    replacedertSame("response", response);
    replacedertSame(this.postProcessor.getMessage(), this.template.requestMessage);
}

18 View Complete Implementation : SimpAnnotationMethodMessageHandlerTests.java
Copyright MIT License
Author : Vip-Augus
@Test
@SuppressWarnings({ "unchecked", "rawtypes" })
public void listenableFutureSuccess() {
    Message emptyMessage = MessageBuilder.withPayload(new byte[0]).build();
    given(this.channel.send(any(Message.clreplaced))).willReturn(true);
    given(this.converter.toMessage(any(), any(MessageHeaders.clreplaced))).willReturn(emptyMessage);
    ListenableFutureController controller = new ListenableFutureController();
    this.messageHandler.registerHandler(controller);
    this.messageHandler.setDestinationPrefixes(Arrays.asList("/app1", "/app2/"));
    Message<?> message = createMessage("/app1/listenable-future/success");
    this.messageHandler.handleMessage(message);
    replacedertNotNull(controller.future);
    controller.future.run();
    verify(this.converter).toMessage(this.payloadCaptor.capture(), any(MessageHeaders.clreplaced));
    replacedertEquals("foo", this.payloadCaptor.getValue());
}