This commit is contained in:
Stéphane Nicoll 2024-01-07 16:58:28 +01:00
parent 9912a52bb8
commit 01c62f86b3
86 changed files with 853 additions and 876 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -36,16 +36,16 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException
* @author Gary Russell * @author Gary Russell
* @author Juergen Hoeller * @author Juergen Hoeller
*/ */
public class MessageHeadersTests { class MessageHeadersTests {
@Test @Test
public void testTimestamp() { void testTimestamp() {
MessageHeaders headers = new MessageHeaders(null); MessageHeaders headers = new MessageHeaders(null);
assertThat(headers.getTimestamp()).isNotNull(); assertThat(headers.getTimestamp()).isNotNull();
} }
@Test @Test
public void testTimestampOverwritten() throws Exception { void testTimestampOverwritten() throws Exception {
MessageHeaders headers1 = new MessageHeaders(null); MessageHeaders headers1 = new MessageHeaders(null);
Thread.sleep(50L); Thread.sleep(50L);
MessageHeaders headers2 = new MessageHeaders(headers1); MessageHeaders headers2 = new MessageHeaders(headers1);
@ -53,59 +53,59 @@ public class MessageHeadersTests {
} }
@Test @Test
public void testTimestampProvided() throws Exception { void testTimestampProvided() {
MessageHeaders headers = new MessageHeaders(null, null, 10L); MessageHeaders headers = new MessageHeaders(null, null, 10L);
assertThat(headers.getTimestamp()).isEqualTo(10L); assertThat(headers.getTimestamp()).isEqualTo(10L);
} }
@Test @Test
public void testTimestampProvidedNullValue() throws Exception { void testTimestampProvidedNullValue() {
Map<String, Object> input = Collections.<String, Object>singletonMap(MessageHeaders.TIMESTAMP, 1L); Map<String, Object> input = Collections.singletonMap(MessageHeaders.TIMESTAMP, 1L);
MessageHeaders headers = new MessageHeaders(input, null, null); MessageHeaders headers = new MessageHeaders(input, null, null);
assertThat(headers.getTimestamp()).isNotNull(); assertThat(headers.getTimestamp()).isNotNull();
} }
@Test @Test
public void testTimestampNone() throws Exception { void testTimestampNone() {
MessageHeaders headers = new MessageHeaders(null, null, -1L); MessageHeaders headers = new MessageHeaders(null, null, -1L);
assertThat(headers.getTimestamp()).isNull(); assertThat(headers.getTimestamp()).isNull();
} }
@Test @Test
public void testIdOverwritten() throws Exception { void testIdOverwritten() {
MessageHeaders headers1 = new MessageHeaders(null); MessageHeaders headers1 = new MessageHeaders(null);
MessageHeaders headers2 = new MessageHeaders(headers1); MessageHeaders headers2 = new MessageHeaders(headers1);
assertThat(headers2.getId()).isNotSameAs(headers1.getId()); assertThat(headers2.getId()).isNotSameAs(headers1.getId());
} }
@Test @Test
public void testId() { void testId() {
MessageHeaders headers = new MessageHeaders(null); MessageHeaders headers = new MessageHeaders(null);
assertThat(headers.getId()).isNotNull(); assertThat(headers.getId()).isNotNull();
} }
@Test @Test
public void testIdProvided() { void testIdProvided() {
UUID id = new UUID(0L, 25L); UUID id = new UUID(0L, 25L);
MessageHeaders headers = new MessageHeaders(null, id, null); MessageHeaders headers = new MessageHeaders(null, id, null);
assertThat(headers.getId()).isEqualTo(id); assertThat(headers.getId()).isEqualTo(id);
} }
@Test @Test
public void testIdProvidedNullValue() { void testIdProvidedNullValue() {
Map<String, Object> input = Collections.<String, Object>singletonMap(MessageHeaders.ID, new UUID(0L, 25L)); Map<String, Object> input = Collections.singletonMap(MessageHeaders.ID, new UUID(0L, 25L));
MessageHeaders headers = new MessageHeaders(input, null, null); MessageHeaders headers = new MessageHeaders(input, null, null);
assertThat(headers.getId()).isNotNull(); assertThat(headers.getId()).isNotNull();
} }
@Test @Test
public void testIdNone() { void testIdNone() {
MessageHeaders headers = new MessageHeaders(null, MessageHeaders.ID_VALUE_NONE, null); MessageHeaders headers = new MessageHeaders(null, MessageHeaders.ID_VALUE_NONE, null);
assertThat(headers.getId()).isNull(); assertThat(headers.getId()).isNull();
} }
@Test @Test
public void testNonTypedAccessOfHeaderValue() { void testNonTypedAccessOfHeaderValue() {
Integer value = 123; Integer value = 123;
Map<String, Object> map = new HashMap<>(); Map<String, Object> map = new HashMap<>();
map.put("test", value); map.put("test", value);
@ -114,7 +114,7 @@ public class MessageHeadersTests {
} }
@Test @Test
public void testTypedAccessOfHeaderValue() { void testTypedAccessOfHeaderValue() {
Integer value = 123; Integer value = 123;
Map<String, Object> map = new HashMap<>(); Map<String, Object> map = new HashMap<>();
map.put("test", value); map.put("test", value);
@ -123,7 +123,7 @@ public class MessageHeadersTests {
} }
@Test @Test
public void testHeaderValueAccessWithIncorrectType() { void testHeaderValueAccessWithIncorrectType() {
Integer value = 123; Integer value = 123;
Map<String, Object> map = new HashMap<>(); Map<String, Object> map = new HashMap<>();
map.put("test", value); map.put("test", value);
@ -133,21 +133,21 @@ public class MessageHeadersTests {
} }
@Test @Test
public void testNullHeaderValue() { void testNullHeaderValue() {
Map<String, Object> map = new HashMap<>(); Map<String, Object> map = new HashMap<>();
MessageHeaders headers = new MessageHeaders(map); MessageHeaders headers = new MessageHeaders(map);
assertThat(headers.get("nosuchattribute")).isNull(); assertThat(headers.get("nosuchattribute")).isNull();
} }
@Test @Test
public void testNullHeaderValueWithTypedAccess() { void testNullHeaderValueWithTypedAccess() {
Map<String, Object> map = new HashMap<>(); Map<String, Object> map = new HashMap<>();
MessageHeaders headers = new MessageHeaders(map); MessageHeaders headers = new MessageHeaders(map);
assertThat(headers.get("nosuchattribute", String.class)).isNull(); assertThat(headers.get("nosuchattribute", String.class)).isNull();
} }
@Test @Test
public void testHeaderKeys() { void testHeaderKeys() {
Map<String, Object> map = new HashMap<>(); Map<String, Object> map = new HashMap<>();
map.put("key1", "val1"); map.put("key1", "val1");
map.put("key2", 123); map.put("key2", 123);
@ -156,7 +156,7 @@ public class MessageHeadersTests {
} }
@Test @Test
public void serializeWithAllSerializableHeaders() throws Exception { void serializeWithAllSerializableHeaders() throws Exception {
Map<String, Object> map = new HashMap<>(); Map<String, Object> map = new HashMap<>();
map.put("name", "joe"); map.put("name", "joe");
map.put("age", 42); map.put("age", 42);
@ -169,7 +169,7 @@ public class MessageHeadersTests {
} }
@Test @Test
public void serializeWithNonSerializableHeader() throws Exception { void serializeWithNonSerializableHeader() throws Exception {
Object address = new Object(); Object address = new Object();
Map<String, Object> map = new HashMap<>(); Map<String, Object> map = new HashMap<>();
map.put("name", "joe"); map.put("name", "joe");
@ -183,7 +183,7 @@ public class MessageHeadersTests {
} }
@Test @Test
public void subclassWithCustomIdAndNoTimestamp() { void subclassWithCustomIdAndNoTimestamp() {
final AtomicLong id = new AtomicLong(); final AtomicLong id = new AtomicLong();
@SuppressWarnings("serial") @SuppressWarnings("serial")
class MyMH extends MessageHeaders { class MyMH extends MessageHeaders {

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -35,43 +35,43 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException
* *
* @author Rossen Stoyanchev * @author Rossen Stoyanchev
*/ */
public class DefaultContentTypeResolverTests { class DefaultContentTypeResolverTests {
private final DefaultContentTypeResolver resolver = new DefaultContentTypeResolver(); private final DefaultContentTypeResolver resolver = new DefaultContentTypeResolver();
@Test @Test
public void resolve() { void resolve() {
MessageHeaders headers = headers(MimeTypeUtils.APPLICATION_JSON); MessageHeaders headers = headers(MimeTypeUtils.APPLICATION_JSON);
assertThat(this.resolver.resolve(headers)).isEqualTo(MimeTypeUtils.APPLICATION_JSON); assertThat(this.resolver.resolve(headers)).isEqualTo(MimeTypeUtils.APPLICATION_JSON);
} }
@Test @Test
public void resolveStringContentType() { void resolveStringContentType() {
MessageHeaders headers = headers(MimeTypeUtils.APPLICATION_JSON_VALUE); MessageHeaders headers = headers(MimeTypeUtils.APPLICATION_JSON_VALUE);
assertThat(this.resolver.resolve(headers)).isEqualTo(MimeTypeUtils.APPLICATION_JSON); assertThat(this.resolver.resolve(headers)).isEqualTo(MimeTypeUtils.APPLICATION_JSON);
} }
@Test @Test
public void resolveInvalidStringContentType() { void resolveInvalidStringContentType() {
MessageHeaders headers = headers("invalidContentType"); MessageHeaders headers = headers("invalidContentType");
assertThatExceptionOfType(InvalidMimeTypeException.class).isThrownBy(() -> this.resolver.resolve(headers)); assertThatExceptionOfType(InvalidMimeTypeException.class).isThrownBy(() -> this.resolver.resolve(headers));
} }
@Test @Test
public void resolveUnknownHeaderType() { void resolveUnknownHeaderType() {
MessageHeaders headers = headers(1); MessageHeaders headers = headers(1);
assertThatIllegalArgumentException().isThrownBy(() -> this.resolver.resolve(headers)); assertThatIllegalArgumentException().isThrownBy(() -> this.resolver.resolve(headers));
} }
@Test @Test
public void resolveNoContentTypeHeader() { void resolveNoContentTypeHeader() {
MessageHeaders headers = new MessageHeaders(Collections.emptyMap()); MessageHeaders headers = new MessageHeaders(Collections.emptyMap());
assertThat(this.resolver.resolve(headers)).isNull(); assertThat(this.resolver.resolve(headers)).isNull();
} }
@Test @Test
public void resolveDefaultMimeType() { void resolveDefaultMimeType() {
this.resolver.setDefaultMimeType(MimeTypeUtils.APPLICATION_JSON); this.resolver.setDefaultMimeType(MimeTypeUtils.APPLICATION_JSON);
MessageHeaders headers = new MessageHeaders(Collections.emptyMap()); MessageHeaders headers = new MessageHeaders(Collections.emptyMap());
@ -79,7 +79,7 @@ public class DefaultContentTypeResolverTests {
} }
@Test @Test
public void resolveDefaultMimeTypeWithNoHeader() { void resolveDefaultMimeTypeWithNoHeader() {
this.resolver.setDefaultMimeType(MimeTypeUtils.APPLICATION_JSON); this.resolver.setDefaultMimeType(MimeTypeUtils.APPLICATION_JSON);
assertThat(this.resolver.resolve(null)).isEqualTo(MimeTypeUtils.APPLICATION_JSON); assertThat(this.resolver.resolve(null)).isEqualTo(MimeTypeUtils.APPLICATION_JSON);
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2019 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -33,25 +33,25 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
* *
* @author Stephane Nicoll * @author Stephane Nicoll
*/ */
public class GenericMessageConverterTests { class GenericMessageConverterTests {
private final ConversionService conversionService = new DefaultConversionService(); private final ConversionService conversionService = new DefaultConversionService();
private final GenericMessageConverter converter = new GenericMessageConverter(conversionService); private final GenericMessageConverter converter = new GenericMessageConverter(conversionService);
@Test @Test
public void fromMessageWithConversion() { void fromMessageWithConversion() {
Message<String> content = MessageBuilder.withPayload("33").build(); Message<String> content = MessageBuilder.withPayload("33").build();
assertThat(converter.fromMessage(content, Integer.class)).isEqualTo(33); assertThat(converter.fromMessage(content, Integer.class)).isEqualTo(33);
} }
@Test @Test
public void fromMessageNoConverter() { void fromMessageNoConverter() {
Message<Integer> content = MessageBuilder.withPayload(1234).build(); Message<Integer> content = MessageBuilder.withPayload(1234).build();
assertThat(converter.fromMessage(content, Locale.class)).as("No converter from integer to locale").isNull(); assertThat(converter.fromMessage(content, Locale.class)).as("No converter from integer to locale").isNull();
} }
@Test @Test
public void fromMessageWithFailedConversion() { void fromMessageWithFailedConversion() {
Message<String> content = MessageBuilder.withPayload("test not a number").build(); Message<String> content = MessageBuilder.withPayload("test not a number").build();
assertThatExceptionOfType(MessageConversionException.class).isThrownBy(() -> assertThatExceptionOfType(MessageConversionException.class).isThrownBy(() ->
converter.fromMessage(content, Integer.class)) converter.fromMessage(content, Integer.class))

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -41,16 +41,16 @@ import static org.assertj.core.api.Assertions.within;
* @author Rossen Stoyanchev * @author Rossen Stoyanchev
* @author Sebastien Deleuze * @author Sebastien Deleuze
*/ */
public class GsonMessageConverterTests { class GsonMessageConverterTests {
@Test @Test
public void defaultConstructor() { void defaultConstructor() {
GsonMessageConverter converter = new GsonMessageConverter(); GsonMessageConverter converter = new GsonMessageConverter();
assertThat(converter.getSupportedMimeTypes()).contains(new MimeType("application", "json")); assertThat(converter.getSupportedMimeTypes()).contains(new MimeType("application", "json"));
} }
@Test @Test
public void fromMessage() { void fromMessage() {
GsonMessageConverter converter = new GsonMessageConverter(); GsonMessageConverter converter = new GsonMessageConverter();
String payload = "{\"array\":[\"Foo\",\"Bar\"]," + String payload = "{\"array\":[\"Foo\",\"Bar\"]," +
"\"number\":42,\"string\":\"Foo\",\"bool\":true,\"fraction\":42.0}"; "\"number\":42,\"string\":\"Foo\",\"bool\":true,\"fraction\":42.0}";
@ -65,7 +65,7 @@ public class GsonMessageConverterTests {
} }
@Test @Test
public void fromMessageUntyped() { void fromMessageUntyped() {
GsonMessageConverter converter = new GsonMessageConverter(); GsonMessageConverter converter = new GsonMessageConverter();
String payload = "{\"array\":[\"Foo\",\"Bar\"]," + String payload = "{\"array\":[\"Foo\",\"Bar\"]," +
"\"number\":42,\"string\":\"Foo\",\"bool\":true,\"fraction\":42.0}"; "\"number\":42,\"string\":\"Foo\",\"bool\":true,\"fraction\":42.0}";
@ -81,7 +81,7 @@ public class GsonMessageConverterTests {
} }
@Test @Test
public void fromMessageMatchingInstance() { void fromMessageMatchingInstance() {
MyBean myBean = new MyBean(); MyBean myBean = new MyBean();
GsonMessageConverter converter = new GsonMessageConverter(); GsonMessageConverter converter = new GsonMessageConverter();
Message<?> message = MessageBuilder.withPayload(myBean).build(); Message<?> message = MessageBuilder.withPayload(myBean).build();
@ -89,7 +89,7 @@ public class GsonMessageConverterTests {
} }
@Test @Test
public void fromMessageInvalidJson() { void fromMessageInvalidJson() {
GsonMessageConverter converter = new GsonMessageConverter(); GsonMessageConverter converter = new GsonMessageConverter();
String payload = "FooBar"; String payload = "FooBar";
Message<?> message = MessageBuilder.withPayload(payload.getBytes(StandardCharsets.UTF_8)).build(); Message<?> message = MessageBuilder.withPayload(payload.getBytes(StandardCharsets.UTF_8)).build();
@ -98,7 +98,7 @@ public class GsonMessageConverterTests {
} }
@Test @Test
public void fromMessageValidJsonWithUnknownProperty() { void fromMessageValidJsonWithUnknownProperty() {
GsonMessageConverter converter = new GsonMessageConverter(); GsonMessageConverter converter = new GsonMessageConverter();
String payload = "{\"string\":\"string\",\"unknownProperty\":\"value\"}"; String payload = "{\"string\":\"string\",\"unknownProperty\":\"value\"}";
Message<?> message = MessageBuilder.withPayload(payload.getBytes(StandardCharsets.UTF_8)).build(); Message<?> message = MessageBuilder.withPayload(payload.getBytes(StandardCharsets.UTF_8)).build();
@ -107,7 +107,7 @@ public class GsonMessageConverterTests {
} }
@Test @Test
public void fromMessageToList() throws Exception { void fromMessageToList() throws Exception {
GsonMessageConverter converter = new GsonMessageConverter(); GsonMessageConverter converter = new GsonMessageConverter();
String payload = "[1, 2, 3, 4, 5, 6, 7, 8, 9]"; String payload = "[1, 2, 3, 4, 5, 6, 7, 8, 9]";
Message<?> message = MessageBuilder.withPayload(payload.getBytes(StandardCharsets.UTF_8)).build(); Message<?> message = MessageBuilder.withPayload(payload.getBytes(StandardCharsets.UTF_8)).build();
@ -121,7 +121,7 @@ public class GsonMessageConverterTests {
} }
@Test @Test
public void fromMessageToMessageWithPojo() throws Exception { void fromMessageToMessageWithPojo() throws Exception {
GsonMessageConverter converter = new GsonMessageConverter(); GsonMessageConverter converter = new GsonMessageConverter();
String payload = "{\"string\":\"foo\"}"; String payload = "{\"string\":\"foo\"}";
Message<?> message = MessageBuilder.withPayload(payload.getBytes(StandardCharsets.UTF_8)).build(); Message<?> message = MessageBuilder.withPayload(payload.getBytes(StandardCharsets.UTF_8)).build();
@ -135,7 +135,7 @@ public class GsonMessageConverterTests {
} }
@Test @Test
public void toMessage() { void toMessage() {
GsonMessageConverter converter = new GsonMessageConverter(); GsonMessageConverter converter = new GsonMessageConverter();
MyBean payload = new MyBean(); MyBean payload = new MyBean();
payload.setString("Foo"); payload.setString("Foo");
@ -156,7 +156,7 @@ public class GsonMessageConverterTests {
} }
@Test @Test
public void toMessageUtf16() { void toMessageUtf16() {
GsonMessageConverter converter = new GsonMessageConverter(); GsonMessageConverter converter = new GsonMessageConverter();
MimeType contentType = new MimeType("application", "json", StandardCharsets.UTF_16BE); MimeType contentType = new MimeType("application", "json", StandardCharsets.UTF_16BE);
Map<String, Object> map = new HashMap<>(); Map<String, Object> map = new HashMap<>();
@ -170,7 +170,7 @@ public class GsonMessageConverterTests {
} }
@Test @Test
public void toMessageUtf16String() { void toMessageUtf16String() {
GsonMessageConverter converter = new GsonMessageConverter(); GsonMessageConverter converter = new GsonMessageConverter();
converter.setSerializedPayloadClass(String.class); converter.setSerializedPayloadClass(String.class);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -42,16 +42,16 @@ import static org.assertj.core.api.Assertions.within;
* @author Rossen Stoyanchev * @author Rossen Stoyanchev
* @author Sebastien Deleuze * @author Sebastien Deleuze
*/ */
public class JsonbMessageConverterTests { class JsonbMessageConverterTests {
@Test @Test
public void defaultConstructor() { void defaultConstructor() {
JsonbMessageConverter converter = new JsonbMessageConverter(); JsonbMessageConverter converter = new JsonbMessageConverter();
assertThat(converter.getSupportedMimeTypes()).contains(new MimeType("application", "json")); assertThat(converter.getSupportedMimeTypes()).contains(new MimeType("application", "json"));
} }
@Test @Test
public void fromMessage() { void fromMessage() {
JsonbMessageConverter converter = new JsonbMessageConverter(); JsonbMessageConverter converter = new JsonbMessageConverter();
String payload = "{\"array\":[\"Foo\",\"Bar\"]," + String payload = "{\"array\":[\"Foo\",\"Bar\"]," +
"\"number\":42,\"string\":\"Foo\",\"bool\":true,\"fraction\":42.0}"; "\"number\":42,\"string\":\"Foo\",\"bool\":true,\"fraction\":42.0}";
@ -66,7 +66,7 @@ public class JsonbMessageConverterTests {
} }
@Test @Test
public void fromMessageUntyped() { void fromMessageUntyped() {
JsonbMessageConverter converter = new JsonbMessageConverter(); JsonbMessageConverter converter = new JsonbMessageConverter();
String payload = "{\"array\":[\"Foo\",\"Bar\"]," + String payload = "{\"array\":[\"Foo\",\"Bar\"]," +
"\"number\":42,\"string\":\"Foo\",\"bool\":true,\"fraction\":42.0}"; "\"number\":42,\"string\":\"Foo\",\"bool\":true,\"fraction\":42.0}";
@ -82,7 +82,7 @@ public class JsonbMessageConverterTests {
} }
@Test @Test
public void fromMessageMatchingInstance() { void fromMessageMatchingInstance() {
MyBean myBean = new MyBean(); MyBean myBean = new MyBean();
JsonbMessageConverter converter = new JsonbMessageConverter(); JsonbMessageConverter converter = new JsonbMessageConverter();
Message<?> message = MessageBuilder.withPayload(myBean).build(); Message<?> message = MessageBuilder.withPayload(myBean).build();
@ -90,7 +90,7 @@ public class JsonbMessageConverterTests {
} }
@Test @Test
public void fromMessageInvalidJson() { void fromMessageInvalidJson() {
JsonbMessageConverter converter = new JsonbMessageConverter(); JsonbMessageConverter converter = new JsonbMessageConverter();
String payload = "FooBar"; String payload = "FooBar";
Message<?> message = MessageBuilder.withPayload(payload.getBytes(StandardCharsets.UTF_8)).build(); Message<?> message = MessageBuilder.withPayload(payload.getBytes(StandardCharsets.UTF_8)).build();
@ -99,7 +99,7 @@ public class JsonbMessageConverterTests {
} }
@Test @Test
public void fromMessageValidJsonWithUnknownProperty() { void fromMessageValidJsonWithUnknownProperty() {
JsonbMessageConverter converter = new JsonbMessageConverter(); JsonbMessageConverter converter = new JsonbMessageConverter();
String payload = "{\"string\":\"string\",\"unknownProperty\":\"value\"}"; String payload = "{\"string\":\"string\",\"unknownProperty\":\"value\"}";
Message<?> message = MessageBuilder.withPayload(payload.getBytes(StandardCharsets.UTF_8)).build(); Message<?> message = MessageBuilder.withPayload(payload.getBytes(StandardCharsets.UTF_8)).build();
@ -108,7 +108,7 @@ public class JsonbMessageConverterTests {
} }
@Test @Test
public void fromMessageToList() throws Exception { void fromMessageToList() throws Exception {
JsonbMessageConverter converter = new JsonbMessageConverter(); JsonbMessageConverter converter = new JsonbMessageConverter();
String payload = "[1, 2, 3, 4, 5, 6, 7, 8, 9]"; String payload = "[1, 2, 3, 4, 5, 6, 7, 8, 9]";
Message<?> message = MessageBuilder.withPayload(payload.getBytes(StandardCharsets.UTF_8)).build(); Message<?> message = MessageBuilder.withPayload(payload.getBytes(StandardCharsets.UTF_8)).build();
@ -122,7 +122,7 @@ public class JsonbMessageConverterTests {
} }
@Test @Test
public void fromMessageToMessageWithPojo() throws Exception { void fromMessageToMessageWithPojo() throws Exception {
JsonbMessageConverter converter = new JsonbMessageConverter(); JsonbMessageConverter converter = new JsonbMessageConverter();
String payload = "{\"string\":\"foo\"}"; String payload = "{\"string\":\"foo\"}";
Message<?> message = MessageBuilder.withPayload(payload.getBytes(StandardCharsets.UTF_8)).build(); Message<?> message = MessageBuilder.withPayload(payload.getBytes(StandardCharsets.UTF_8)).build();
@ -136,7 +136,7 @@ public class JsonbMessageConverterTests {
} }
@Test @Test
public void toMessage() { void toMessage() {
JsonbMessageConverter converter = new JsonbMessageConverter(); JsonbMessageConverter converter = new JsonbMessageConverter();
MyBean payload = new MyBean(); MyBean payload = new MyBean();
payload.setString("Foo"); payload.setString("Foo");
@ -157,7 +157,7 @@ public class JsonbMessageConverterTests {
} }
@Test @Test
public void toMessageUtf16() { void toMessageUtf16() {
JsonbMessageConverter converter = new JsonbMessageConverter(); JsonbMessageConverter converter = new JsonbMessageConverter();
MimeType contentType = new MimeType("application", "json", StandardCharsets.UTF_16BE); MimeType contentType = new MimeType("application", "json", StandardCharsets.UTF_16BE);
Map<String, Object> map = new HashMap<>(); Map<String, Object> map = new HashMap<>();
@ -171,7 +171,7 @@ public class JsonbMessageConverterTests {
} }
@Test @Test
public void toMessageUtf16String() { void toMessageUtf16String() {
JsonbMessageConverter converter = new JsonbMessageConverter(); JsonbMessageConverter converter = new JsonbMessageConverter();
converter.setSerializedPayloadClass(String.class); converter.setSerializedPayloadClass(String.class);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -43,10 +43,10 @@ import static org.assertj.core.api.Assertions.within;
* @author Rossen Stoyanchev * @author Rossen Stoyanchev
* @author Sebastien Deleuze * @author Sebastien Deleuze
*/ */
public class MappingJackson2MessageConverterTests { class MappingJackson2MessageConverterTests {
@Test @Test
public void defaultConstructor() { void defaultConstructor() {
MappingJackson2MessageConverter converter = new MappingJackson2MessageConverter(); MappingJackson2MessageConverter converter = new MappingJackson2MessageConverter();
assertThat(converter.getSupportedMimeTypes()).contains(new MimeType("application", "json")); assertThat(converter.getSupportedMimeTypes()).contains(new MimeType("application", "json"));
assertThat(converter.getObjectMapper().getDeserializationConfig() assertThat(converter.getObjectMapper().getDeserializationConfig()
@ -73,7 +73,7 @@ public class MappingJackson2MessageConverterTests {
} }
@Test @Test
public void fromMessage() { void fromMessage() {
MappingJackson2MessageConverter converter = new MappingJackson2MessageConverter(); MappingJackson2MessageConverter converter = new MappingJackson2MessageConverter();
String payload = "{\"bytes\":\"AQI=\",\"array\":[\"Foo\",\"Bar\"]," + String payload = "{\"bytes\":\"AQI=\",\"array\":[\"Foo\",\"Bar\"]," +
"\"number\":42,\"string\":\"Foo\",\"bool\":true,\"fraction\":42.0}"; "\"number\":42,\"string\":\"Foo\",\"bool\":true,\"fraction\":42.0}";
@ -89,7 +89,7 @@ public class MappingJackson2MessageConverterTests {
} }
@Test @Test
public void fromMessageUntyped() { void fromMessageUntyped() {
MappingJackson2MessageConverter converter = new MappingJackson2MessageConverter(); MappingJackson2MessageConverter converter = new MappingJackson2MessageConverter();
String payload = "{\"bytes\":\"AQI=\",\"array\":[\"Foo\",\"Bar\"]," + String payload = "{\"bytes\":\"AQI=\",\"array\":[\"Foo\",\"Bar\"]," +
"\"number\":42,\"string\":\"Foo\",\"bool\":true,\"fraction\":42.0}"; "\"number\":42,\"string\":\"Foo\",\"bool\":true,\"fraction\":42.0}";
@ -114,7 +114,7 @@ public class MappingJackson2MessageConverterTests {
} }
@Test @Test
public void fromMessageInvalidJson() { void fromMessageInvalidJson() {
MappingJackson2MessageConverter converter = new MappingJackson2MessageConverter(); MappingJackson2MessageConverter converter = new MappingJackson2MessageConverter();
String payload = "FooBar"; String payload = "FooBar";
Message<?> message = MessageBuilder.withPayload(payload.getBytes(StandardCharsets.UTF_8)).build(); Message<?> message = MessageBuilder.withPayload(payload.getBytes(StandardCharsets.UTF_8)).build();
@ -123,7 +123,7 @@ public class MappingJackson2MessageConverterTests {
} }
@Test @Test
public void fromMessageValidJsonWithUnknownProperty() { void fromMessageValidJsonWithUnknownProperty() {
MappingJackson2MessageConverter converter = new MappingJackson2MessageConverter(); MappingJackson2MessageConverter converter = new MappingJackson2MessageConverter();
String payload = "{\"string\":\"string\",\"unknownProperty\":\"value\"}"; String payload = "{\"string\":\"string\",\"unknownProperty\":\"value\"}";
Message<?> message = MessageBuilder.withPayload(payload.getBytes(StandardCharsets.UTF_8)).build(); Message<?> message = MessageBuilder.withPayload(payload.getBytes(StandardCharsets.UTF_8)).build();
@ -160,7 +160,7 @@ public class MappingJackson2MessageConverterTests {
} }
@Test @Test
public void toMessage() { void toMessage() {
MappingJackson2MessageConverter converter = new MappingJackson2MessageConverter(); MappingJackson2MessageConverter converter = new MappingJackson2MessageConverter();
MyBean payload = new MyBean(); MyBean payload = new MyBean();
payload.setString("Foo"); payload.setString("Foo");
@ -183,7 +183,7 @@ public class MappingJackson2MessageConverterTests {
} }
@Test @Test
public void toMessageUtf16() { void toMessageUtf16() {
MappingJackson2MessageConverter converter = new MappingJackson2MessageConverter(); MappingJackson2MessageConverter converter = new MappingJackson2MessageConverter();
MimeType contentType = new MimeType("application", "json", StandardCharsets.UTF_16BE); MimeType contentType = new MimeType("application", "json", StandardCharsets.UTF_16BE);
Map<String, Object> map = new HashMap<>(); Map<String, Object> map = new HashMap<>();
@ -197,7 +197,7 @@ public class MappingJackson2MessageConverterTests {
} }
@Test @Test
public void toMessageUtf16String() { void toMessageUtf16String() {
MappingJackson2MessageConverter converter = new MappingJackson2MessageConverter(); MappingJackson2MessageConverter converter = new MappingJackson2MessageConverter();
converter.setSerializedPayloadClass(String.class); converter.setSerializedPayloadClass(String.class);
@ -213,7 +213,7 @@ public class MappingJackson2MessageConverterTests {
} }
@Test @Test
public void toMessageJsonView() throws Exception { void toMessageJsonView() throws Exception {
MappingJackson2MessageConverter converter = new MappingJackson2MessageConverter(); MappingJackson2MessageConverter converter = new MappingJackson2MessageConverter();
Map<String, Object> map = new HashMap<>(); Map<String, Object> map = new HashMap<>();

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2019 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -16,7 +16,6 @@
package org.springframework.messaging.converter; package org.springframework.messaging.converter;
import java.io.IOException;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import jakarta.xml.bind.annotation.XmlRootElement; import jakarta.xml.bind.annotation.XmlRootElement;
@ -39,13 +38,13 @@ import static org.xmlunit.diff.DifferenceEvaluators.downgradeDifferencesToEqual;
/** /**
* @author Arjen Poutsma * @author Arjen Poutsma
*/ */
public class MarshallingMessageConverterTests { class MarshallingMessageConverterTests {
private MarshallingMessageConverter converter; private MarshallingMessageConverter converter;
@BeforeEach @BeforeEach
public void createMarshaller() throws Exception { void createMarshaller() throws Exception {
Jaxb2Marshaller marshaller = new Jaxb2Marshaller(); Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
marshaller.setClassesToBeBound(MyBean.class); marshaller.setClassesToBeBound(MyBean.class);
marshaller.afterPropertiesSet(); marshaller.afterPropertiesSet();
@ -55,7 +54,7 @@ public class MarshallingMessageConverterTests {
@Test @Test
public void fromMessage() throws Exception { void fromMessage() {
String payload = "<myBean><name>Foo</name></myBean>"; String payload = "<myBean><name>Foo</name></myBean>";
Message<?> message = MessageBuilder.withPayload(payload.getBytes(StandardCharsets.UTF_8)).build(); Message<?> message = MessageBuilder.withPayload(payload.getBytes(StandardCharsets.UTF_8)).build();
MyBean actual = (MyBean) this.converter.fromMessage(message, MyBean.class); MyBean actual = (MyBean) this.converter.fromMessage(message, MyBean.class);
@ -65,7 +64,7 @@ public class MarshallingMessageConverterTests {
} }
@Test @Test
public void fromMessageInvalidXml() throws Exception { void fromMessageInvalidXml() {
String payload = "<myBean><name>Foo</name><myBean>"; String payload = "<myBean><name>Foo</name><myBean>";
Message<?> message = MessageBuilder.withPayload(payload.getBytes(StandardCharsets.UTF_8)).build(); Message<?> message = MessageBuilder.withPayload(payload.getBytes(StandardCharsets.UTF_8)).build();
assertThatExceptionOfType(MessageConversionException.class).isThrownBy(() -> assertThatExceptionOfType(MessageConversionException.class).isThrownBy(() ->
@ -73,7 +72,7 @@ public class MarshallingMessageConverterTests {
} }
@Test @Test
public void fromMessageValidXmlWithUnknownProperty() throws IOException { void fromMessageValidXmlWithUnknownProperty() {
String payload = "<myBean><age>42</age><myBean>"; String payload = "<myBean><age>42</age><myBean>";
Message<?> message = MessageBuilder.withPayload(payload.getBytes(StandardCharsets.UTF_8)).build(); Message<?> message = MessageBuilder.withPayload(payload.getBytes(StandardCharsets.UTF_8)).build();
assertThatExceptionOfType(MessageConversionException.class).isThrownBy(() -> assertThatExceptionOfType(MessageConversionException.class).isThrownBy(() ->
@ -81,7 +80,7 @@ public class MarshallingMessageConverterTests {
} }
@Test @Test
public void toMessage() throws Exception { void toMessage() {
MyBean payload = new MyBean(); MyBean payload = new MyBean();
payload.setName("Foo"); payload.setName("Foo");

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -39,13 +39,13 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException
* *
* @author Rossen Stoyanchev * @author Rossen Stoyanchev
*/ */
public class MessageConverterTests { class MessageConverterTests {
private TestMessageConverter converter = new TestMessageConverter(); private TestMessageConverter converter = new TestMessageConverter();
@Test @Test
public void supportsTargetClass() { void supportsTargetClass() {
Message<String> message = MessageBuilder.withPayload("ABC").build(); Message<String> message = MessageBuilder.withPayload("ABC").build();
assertThat(this.converter.fromMessage(message, String.class)).isEqualTo("success-from"); assertThat(this.converter.fromMessage(message, String.class)).isEqualTo("success-from");
@ -53,7 +53,7 @@ public class MessageConverterTests {
} }
@Test @Test
public void supportsMimeType() { void supportsMimeType() {
Message<String> message = MessageBuilder.withPayload( Message<String> message = MessageBuilder.withPayload(
"ABC").setHeader(MessageHeaders.CONTENT_TYPE, MimeTypeUtils.TEXT_PLAIN).build(); "ABC").setHeader(MessageHeaders.CONTENT_TYPE, MimeTypeUtils.TEXT_PLAIN).build();
@ -61,7 +61,7 @@ public class MessageConverterTests {
} }
@Test @Test
public void supportsMimeTypeNotSupported() { void supportsMimeTypeNotSupported() {
Message<String> message = MessageBuilder.withPayload( Message<String> message = MessageBuilder.withPayload(
"ABC").setHeader(MessageHeaders.CONTENT_TYPE, MimeTypeUtils.APPLICATION_JSON).build(); "ABC").setHeader(MessageHeaders.CONTENT_TYPE, MimeTypeUtils.APPLICATION_JSON).build();
@ -69,13 +69,13 @@ public class MessageConverterTests {
} }
@Test @Test
public void supportsMimeTypeNotSpecified() { void supportsMimeTypeNotSpecified() {
Message<String> message = MessageBuilder.withPayload("ABC").build(); Message<String> message = MessageBuilder.withPayload("ABC").build();
assertThat(this.converter.fromMessage(message, String.class)).isEqualTo("success-from"); assertThat(this.converter.fromMessage(message, String.class)).isEqualTo("success-from");
} }
@Test @Test
public void supportsMimeTypeNoneConfigured() { void supportsMimeTypeNoneConfigured() {
Message<String> message = MessageBuilder.withPayload( Message<String> message = MessageBuilder.withPayload(
"ABC").setHeader(MessageHeaders.CONTENT_TYPE, MimeTypeUtils.APPLICATION_JSON).build(); "ABC").setHeader(MessageHeaders.CONTENT_TYPE, MimeTypeUtils.APPLICATION_JSON).build();
this.converter = new TestMessageConverter(new MimeType[0]); this.converter = new TestMessageConverter(new MimeType[0]);
@ -84,7 +84,7 @@ public class MessageConverterTests {
} }
@Test @Test
public void canConvertFromStrictContentTypeMatch() { void canConvertFromStrictContentTypeMatch() {
this.converter = new TestMessageConverter(MimeTypeUtils.TEXT_PLAIN); this.converter = new TestMessageConverter(MimeTypeUtils.TEXT_PLAIN);
this.converter.setStrictContentTypeMatch(true); this.converter.setStrictContentTypeMatch(true);
@ -98,13 +98,13 @@ public class MessageConverterTests {
} }
@Test @Test
public void setStrictContentTypeMatchWithNoSupportedMimeTypes() { void setStrictContentTypeMatchWithNoSupportedMimeTypes() {
this.converter = new TestMessageConverter(new MimeType[0]); this.converter = new TestMessageConverter(new MimeType[0]);
assertThatIllegalArgumentException().isThrownBy(() -> this.converter.setStrictContentTypeMatch(true)); assertThatIllegalArgumentException().isThrownBy(() -> this.converter.setStrictContentTypeMatch(true));
} }
@Test @Test
public void toMessageWithHeaders() { void toMessageWithHeaders() {
Map<String, Object> map = new HashMap<>(); Map<String, Object> map = new HashMap<>();
map.put("foo", "bar"); map.put("foo", "bar");
MessageHeaders headers = new MessageHeaders(map); MessageHeaders headers = new MessageHeaders(map);
@ -117,7 +117,7 @@ public class MessageConverterTests {
} }
@Test @Test
public void toMessageWithMutableMessageHeaders() { void toMessageWithMutableMessageHeaders() {
SimpMessageHeaderAccessor accessor = SimpMessageHeaderAccessor.create(SimpMessageType.MESSAGE); SimpMessageHeaderAccessor accessor = SimpMessageHeaderAccessor.create(SimpMessageType.MESSAGE);
accessor.setHeader("foo", "bar"); accessor.setHeader("foo", "bar");
accessor.setNativeHeader("fooNative", "barNative"); accessor.setNativeHeader("fooNative", "barNative");
@ -133,7 +133,7 @@ public class MessageConverterTests {
} }
@Test @Test
public void toMessageContentTypeHeader() { void toMessageContentTypeHeader() {
Message<?> message = this.converter.toMessage("ABC", null); Message<?> message = this.converter.toMessage("ABC", null);
assertThat(message.getHeaders().get(MessageHeaders.CONTENT_TYPE)).isEqualTo(MimeTypeUtils.TEXT_PLAIN); assertThat(message.getHeaders().get(MessageHeaders.CONTENT_TYPE)).isEqualTo(MimeTypeUtils.TEXT_PLAIN);
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2019 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -32,14 +32,14 @@ import static org.assertj.core.api.Assertions.assertThat;
* *
* @author Rossen Stoyanchev * @author Rossen Stoyanchev
*/ */
public class SimpleMessageConverterTests { class SimpleMessageConverterTests {
private final SimpleMessageConverter converter = new SimpleMessageConverter(); private final SimpleMessageConverter converter = new SimpleMessageConverter();
@Test @Test
public void toMessageWithPayloadAndHeaders() { void toMessageWithPayloadAndHeaders() {
MessageHeaders headers = new MessageHeaders(Collections.<String, Object>singletonMap("foo", "bar")); MessageHeaders headers = new MessageHeaders(Collections.singletonMap("foo", "bar"));
Message<?> message = this.converter.toMessage("payload", headers); Message<?> message = this.converter.toMessage("payload", headers);
assertThat(message.getPayload()).isEqualTo("payload"); assertThat(message.getPayload()).isEqualTo("payload");
@ -47,7 +47,7 @@ public class SimpleMessageConverterTests {
} }
@Test @Test
public void toMessageWithPayloadAndMutableHeaders() { void toMessageWithPayloadAndMutableHeaders() {
MessageHeaderAccessor accessor = new MessageHeaderAccessor(); MessageHeaderAccessor accessor = new MessageHeaderAccessor();
accessor.setHeader("foo", "bar"); accessor.setHeader("foo", "bar");
accessor.setLeaveMutable(true); accessor.setLeaveMutable(true);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2019 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -35,33 +35,33 @@ import static org.assertj.core.api.Assertions.assertThat;
* *
* @author Rossen Stoyanchev * @author Rossen Stoyanchev
*/ */
public class StringMessageConverterTests { class StringMessageConverterTests {
private final StringMessageConverter converter = new StringMessageConverter(); private final StringMessageConverter converter = new StringMessageConverter();
@Test @Test
public void fromByteArrayMessage() { void fromByteArrayMessage() {
Message<byte[]> message = MessageBuilder.withPayload( Message<byte[]> message = MessageBuilder.withPayload(
"ABC".getBytes()).setHeader(MessageHeaders.CONTENT_TYPE, MimeTypeUtils.TEXT_PLAIN).build(); "ABC".getBytes()).setHeader(MessageHeaders.CONTENT_TYPE, MimeTypeUtils.TEXT_PLAIN).build();
assertThat(this.converter.fromMessage(message, String.class)).isEqualTo("ABC"); assertThat(this.converter.fromMessage(message, String.class)).isEqualTo("ABC");
} }
@Test @Test
public void fromStringMessage() { void fromStringMessage() {
Message<String> message = MessageBuilder.withPayload( Message<String> message = MessageBuilder.withPayload(
"ABC").setHeader(MessageHeaders.CONTENT_TYPE, MimeTypeUtils.TEXT_PLAIN).build(); "ABC").setHeader(MessageHeaders.CONTENT_TYPE, MimeTypeUtils.TEXT_PLAIN).build();
assertThat(this.converter.fromMessage(message, String.class)).isEqualTo("ABC"); assertThat(this.converter.fromMessage(message, String.class)).isEqualTo("ABC");
} }
@Test @Test
public void fromMessageNoContentTypeHeader() { void fromMessageNoContentTypeHeader() {
Message<byte[]> message = MessageBuilder.withPayload("ABC".getBytes()).build(); Message<byte[]> message = MessageBuilder.withPayload("ABC".getBytes()).build();
assertThat(this.converter.fromMessage(message, String.class)).isEqualTo("ABC"); assertThat(this.converter.fromMessage(message, String.class)).isEqualTo("ABC");
} }
@Test @Test
public void fromMessageCharset() { void fromMessageCharset() {
String payload = "H\u00e9llo W\u00f6rld"; String payload = "H\u00e9llo W\u00f6rld";
Message<byte[]> message = MessageBuilder.withPayload(payload.getBytes(StandardCharsets.ISO_8859_1)) Message<byte[]> message = MessageBuilder.withPayload(payload.getBytes(StandardCharsets.ISO_8859_1))
.setHeader(MessageHeaders.CONTENT_TYPE, new MimeType("text", "plain", StandardCharsets.ISO_8859_1)).build(); .setHeader(MessageHeaders.CONTENT_TYPE, new MimeType("text", "plain", StandardCharsets.ISO_8859_1)).build();
@ -69,27 +69,27 @@ public class StringMessageConverterTests {
} }
@Test @Test
public void fromMessageDefaultCharset() { void fromMessageDefaultCharset() {
String payload = "H\u00e9llo W\u00f6rld"; String payload = "H\u00e9llo W\u00f6rld";
Message<byte[]> message = MessageBuilder.withPayload(payload.getBytes(StandardCharsets.UTF_8)).build(); Message<byte[]> message = MessageBuilder.withPayload(payload.getBytes(StandardCharsets.UTF_8)).build();
assertThat(this.converter.fromMessage(message, String.class)).isEqualTo(payload); assertThat(this.converter.fromMessage(message, String.class)).isEqualTo(payload);
} }
@Test @Test
public void fromMessageTargetClassNotSupported() { void fromMessageTargetClassNotSupported() {
Message<byte[]> message = MessageBuilder.withPayload("ABC".getBytes()).build(); Message<byte[]> message = MessageBuilder.withPayload("ABC".getBytes()).build();
assertThat(this.converter.fromMessage(message, Integer.class)).isNull(); assertThat(this.converter.fromMessage(message, Integer.class)).isNull();
} }
@Test @Test
public void fromMessageByteArray() { void fromMessageByteArray() {
Message<byte[]> message = MessageBuilder.withPayload( Message<byte[]> message = MessageBuilder.withPayload(
"ABC".getBytes()).setHeader(MessageHeaders.CONTENT_TYPE, MimeTypeUtils.TEXT_PLAIN).build(); "ABC".getBytes()).setHeader(MessageHeaders.CONTENT_TYPE, MimeTypeUtils.TEXT_PLAIN).build();
assertThat(this.converter.fromMessage(message, String.class)).isEqualTo("ABC"); assertThat(this.converter.fromMessage(message, String.class)).isEqualTo("ABC");
} }
@Test @Test
public void toMessage() { void toMessage() {
Map<String, Object> map = new HashMap<>(); Map<String, Object> map = new HashMap<>();
map.put(MessageHeaders.CONTENT_TYPE, MimeTypeUtils.TEXT_PLAIN); map.put(MessageHeaders.CONTENT_TYPE, MimeTypeUtils.TEXT_PLAIN);
MessageHeaders headers = new MessageHeaders(map); MessageHeaders headers = new MessageHeaders(map);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -31,11 +31,10 @@ import static org.mockito.Mockito.verify;
* @author Agim Emruli * @author Agim Emruli
* @author Juergen Hoeller * @author Juergen Hoeller
*/ */
public class CachingDestinationResolverTests { class CachingDestinationResolverTests {
@Test @Test
public void cachedDestination() { void cachedDestination() {
@SuppressWarnings("unchecked")
DestinationResolver<String> resolver = mock(); DestinationResolver<String> resolver = mock();
CachingDestinationResolverProxy<String> resolverProxy = new CachingDestinationResolverProxy<>(resolver); CachingDestinationResolverProxy<String> resolverProxy = new CachingDestinationResolverProxy<>(resolver);
@ -52,14 +51,14 @@ public class CachingDestinationResolverTests {
} }
@Test @Test
public void noTargetSet() { void noTargetSet() {
CachingDestinationResolverProxy<String> resolverProxy = new CachingDestinationResolverProxy<>(); CachingDestinationResolverProxy<String> resolverProxy = new CachingDestinationResolverProxy<>();
assertThatIllegalArgumentException().isThrownBy( assertThatIllegalArgumentException().isThrownBy(
resolverProxy::afterPropertiesSet); resolverProxy::afterPropertiesSet);
} }
@Test @Test
public void nullTargetThroughConstructor() { void nullTargetThroughConstructor() {
assertThatIllegalArgumentException().isThrownBy(() -> assertThatIllegalArgumentException().isThrownBy(() ->
new CachingDestinationResolverProxy<String>(null)); new CachingDestinationResolverProxy<String>(null));
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2019 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -36,7 +36,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
* *
* @author Rossen Stoyanchev * @author Rossen Stoyanchev
*/ */
public class DestinationResolvingMessagingTemplateTests { class DestinationResolvingMessagingTemplateTests {
private TestDestinationResolvingMessagingTemplate template; private TestDestinationResolvingMessagingTemplate template;
@ -48,7 +48,7 @@ public class DestinationResolvingMessagingTemplateTests {
@BeforeEach @BeforeEach
public void setup() { void setup() {
TestMessageChannelDestinationResolver resolver = new TestMessageChannelDestinationResolver(); TestMessageChannelDestinationResolver resolver = new TestMessageChannelDestinationResolver();
@ -58,14 +58,14 @@ public class DestinationResolvingMessagingTemplateTests {
this.template = new TestDestinationResolvingMessagingTemplate(); this.template = new TestDestinationResolvingMessagingTemplate();
this.template.setDestinationResolver(resolver); this.template.setDestinationResolver(resolver);
this.headers = Collections.<String, Object>singletonMap("key", "value"); this.headers = Collections.singletonMap("key", "value");
this.postProcessor = new TestMessagePostProcessor(); this.postProcessor = new TestMessagePostProcessor();
} }
@Test @Test
public void send() { void send() {
Message<?> message = new GenericMessage<Object>("payload"); Message<?> message = new GenericMessage<Object>("payload");
this.template.send("myChannel", message); this.template.send("myChannel", message);
@ -74,14 +74,14 @@ public class DestinationResolvingMessagingTemplateTests {
} }
@Test @Test
public void sendNoDestinationResolver() { void sendNoDestinationResolver() {
TestDestinationResolvingMessagingTemplate template = new TestDestinationResolvingMessagingTemplate(); TestDestinationResolvingMessagingTemplate template = new TestDestinationResolvingMessagingTemplate();
assertThatIllegalStateException().isThrownBy(() -> assertThatIllegalStateException().isThrownBy(() ->
template.send("myChannel", new GenericMessage<Object>("payload"))); template.send("myChannel", new GenericMessage<Object>("payload")));
} }
@Test @Test
public void convertAndSendPayload() { void convertAndSendPayload() {
this.template.convertAndSend("myChannel", "payload"); this.template.convertAndSend("myChannel", "payload");
assertThat(this.template.messageChannel).isSameAs(this.myChannel); assertThat(this.template.messageChannel).isSameAs(this.myChannel);
@ -90,7 +90,7 @@ public class DestinationResolvingMessagingTemplateTests {
} }
@Test @Test
public void convertAndSendPayloadAndHeaders() { void convertAndSendPayloadAndHeaders() {
this.template.convertAndSend("myChannel", "payload", this.headers); this.template.convertAndSend("myChannel", "payload", this.headers);
assertThat(this.template.messageChannel).isSameAs(this.myChannel); assertThat(this.template.messageChannel).isSameAs(this.myChannel);
@ -100,7 +100,7 @@ public class DestinationResolvingMessagingTemplateTests {
} }
@Test @Test
public void convertAndSendPayloadWithPostProcessor() { void convertAndSendPayloadWithPostProcessor() {
this.template.convertAndSend("myChannel", "payload", this.postProcessor); this.template.convertAndSend("myChannel", "payload", this.postProcessor);
assertThat(this.template.messageChannel).isSameAs(this.myChannel); assertThat(this.template.messageChannel).isSameAs(this.myChannel);
@ -112,7 +112,7 @@ public class DestinationResolvingMessagingTemplateTests {
} }
@Test @Test
public void convertAndSendPayloadAndHeadersWithPostProcessor() { void convertAndSendPayloadAndHeadersWithPostProcessor() {
this.template.convertAndSend("myChannel", "payload", this.headers, this.postProcessor); this.template.convertAndSend("myChannel", "payload", this.headers, this.postProcessor);
assertThat(this.template.messageChannel).isSameAs(this.myChannel); assertThat(this.template.messageChannel).isSameAs(this.myChannel);
@ -125,7 +125,7 @@ public class DestinationResolvingMessagingTemplateTests {
} }
@Test @Test
public void receive() { void receive() {
Message<?> expected = new GenericMessage<Object>("payload"); Message<?> expected = new GenericMessage<Object>("payload");
this.template.setReceiveMessage(expected); this.template.setReceiveMessage(expected);
Message<?> actual = this.template.receive("myChannel"); Message<?> actual = this.template.receive("myChannel");
@ -135,7 +135,7 @@ public class DestinationResolvingMessagingTemplateTests {
} }
@Test @Test
public void receiveAndConvert() { void receiveAndConvert() {
Message<?> expected = new GenericMessage<Object>("payload"); Message<?> expected = new GenericMessage<Object>("payload");
this.template.setReceiveMessage(expected); this.template.setReceiveMessage(expected);
String payload = this.template.receiveAndConvert("myChannel", String.class); String payload = this.template.receiveAndConvert("myChannel", String.class);
@ -145,7 +145,7 @@ public class DestinationResolvingMessagingTemplateTests {
} }
@Test @Test
public void sendAndReceive() { void sendAndReceive() {
Message<?> requestMessage = new GenericMessage<Object>("request"); Message<?> requestMessage = new GenericMessage<Object>("request");
Message<?> responseMessage = new GenericMessage<Object>("response"); Message<?> responseMessage = new GenericMessage<Object>("response");
this.template.setReceiveMessage(responseMessage); this.template.setReceiveMessage(responseMessage);
@ -157,7 +157,7 @@ public class DestinationResolvingMessagingTemplateTests {
} }
@Test @Test
public void convertSendAndReceive() { void convertSendAndReceive() {
Message<?> responseMessage = new GenericMessage<Object>("response"); Message<?> responseMessage = new GenericMessage<Object>("response");
this.template.setReceiveMessage(responseMessage); this.template.setReceiveMessage(responseMessage);
String actual = this.template.convertSendAndReceive("myChannel", "request", String.class); String actual = this.template.convertSendAndReceive("myChannel", "request", String.class);
@ -168,7 +168,7 @@ public class DestinationResolvingMessagingTemplateTests {
} }
@Test @Test
public void convertSendAndReceiveWithHeaders() { void convertSendAndReceiveWithHeaders() {
Message<?> responseMessage = new GenericMessage<Object>("response"); Message<?> responseMessage = new GenericMessage<Object>("response");
this.template.setReceiveMessage(responseMessage); this.template.setReceiveMessage(responseMessage);
String actual = this.template.convertSendAndReceive("myChannel", "request", this.headers, String.class); String actual = this.template.convertSendAndReceive("myChannel", "request", this.headers, String.class);
@ -180,7 +180,7 @@ public class DestinationResolvingMessagingTemplateTests {
} }
@Test @Test
public void convertSendAndReceiveWithPostProcessor() { void convertSendAndReceiveWithPostProcessor() {
Message<?> responseMessage = new GenericMessage<Object>("response"); Message<?> responseMessage = new GenericMessage<Object>("response");
this.template.setReceiveMessage(responseMessage); this.template.setReceiveMessage(responseMessage);
String actual = this.template.convertSendAndReceive("myChannel", "request", String.class, this.postProcessor); String actual = this.template.convertSendAndReceive("myChannel", "request", String.class, this.postProcessor);
@ -192,7 +192,7 @@ public class DestinationResolvingMessagingTemplateTests {
} }
@Test @Test
public void convertSendAndReceiveWithHeadersAndPostProcessor() { void convertSendAndReceiveWithHeadersAndPostProcessor() {
Message<?> responseMessage = new GenericMessage<Object>("response"); Message<?> responseMessage = new GenericMessage<Object>("response");
this.template.setReceiveMessage(responseMessage); this.template.setReceiveMessage(responseMessage);
String actual = this.template.convertSendAndReceive("myChannel", "request", this.headers, String actual = this.template.convertSendAndReceive("myChannel", "request", this.headers,

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -51,7 +51,7 @@ import static org.mockito.Mockito.verify;
* @author Rossen Stoyanchev * @author Rossen Stoyanchev
* @author Gary Russell * @author Gary Russell
*/ */
public class GenericMessagingTemplateTests { class GenericMessagingTemplateTests {
private GenericMessagingTemplate template; private GenericMessagingTemplate template;
@ -61,7 +61,7 @@ public class GenericMessagingTemplateTests {
@BeforeEach @BeforeEach
public void setup() { void setup() {
this.messageChannel = new StubMessageChannel(); this.messageChannel = new StubMessageChannel();
this.template = new GenericMessagingTemplate(); this.template = new GenericMessagingTemplate();
this.template.setDefaultDestination(this.messageChannel); this.template.setDefaultDestination(this.messageChannel);
@ -71,7 +71,7 @@ public class GenericMessagingTemplateTests {
} }
@Test @Test
public void sendWithTimeout() { void sendWithTimeout() {
SubscribableChannel channel = mock(); SubscribableChannel channel = mock();
final AtomicReference<Message<?>> sent = new AtomicReference<>(); final AtomicReference<Message<?>> sent = new AtomicReference<>();
willAnswer(invocation -> { willAnswer(invocation -> {
@ -90,7 +90,7 @@ public class GenericMessagingTemplateTests {
} }
@Test @Test
public void sendWithTimeoutMutable() { void sendWithTimeoutMutable() {
SubscribableChannel channel = mock(); SubscribableChannel channel = mock();
final AtomicReference<Message<?>> sent = new AtomicReference<>(); final AtomicReference<Message<?>> sent = new AtomicReference<>();
willAnswer(invocation -> { willAnswer(invocation -> {
@ -109,7 +109,7 @@ public class GenericMessagingTemplateTests {
} }
@Test @Test
public void sendAndReceive() { void sendAndReceive() {
SubscribableChannel channel = new ExecutorSubscribableChannel(this.executor); SubscribableChannel channel = new ExecutorSubscribableChannel(this.executor);
channel.subscribe(message -> { channel.subscribe(message -> {
MessageChannel replyChannel = (MessageChannel) message.getHeaders().getReplyChannel(); MessageChannel replyChannel = (MessageChannel) message.getHeaders().getReplyChannel();
@ -121,7 +121,7 @@ public class GenericMessagingTemplateTests {
} }
@Test @Test
public void sendAndReceiveTimeout() throws InterruptedException { void sendAndReceiveTimeout() throws InterruptedException {
final AtomicReference<Throwable> failure = new AtomicReference<>(); final AtomicReference<Throwable> failure = new AtomicReference<>();
final CountDownLatch latch = new CountDownLatch(1); final CountDownLatch latch = new CountDownLatch(1);
@ -147,7 +147,7 @@ public class GenericMessagingTemplateTests {
} }
@Test @Test
public void sendAndReceiveVariableTimeout() throws InterruptedException { void sendAndReceiveVariableTimeout() throws InterruptedException {
final AtomicReference<Throwable> failure = new AtomicReference<>(); final AtomicReference<Throwable> failure = new AtomicReference<>();
final CountDownLatch latch = new CountDownLatch(1); final CountDownLatch latch = new CountDownLatch(1);
@ -177,7 +177,7 @@ public class GenericMessagingTemplateTests {
} }
@Test @Test
public void sendAndReceiveVariableTimeoutCustomHeaders() throws InterruptedException { void sendAndReceiveVariableTimeoutCustomHeaders() throws InterruptedException {
final AtomicReference<Throwable> failure = new AtomicReference<>(); final AtomicReference<Throwable> failure = new AtomicReference<>();
final CountDownLatch latch = new CountDownLatch(1); final CountDownLatch latch = new CountDownLatch(1);
@ -209,7 +209,7 @@ public class GenericMessagingTemplateTests {
} }
private MessageHandler createLateReplier(final CountDownLatch latch, final AtomicReference<Throwable> failure) { private MessageHandler createLateReplier(final CountDownLatch latch, final AtomicReference<Throwable> failure) {
MessageHandler handler = message -> { return message -> {
try { try {
Thread.sleep(500); Thread.sleep(500);
MessageChannel replyChannel = (MessageChannel) message.getHeaders().getReplyChannel(); MessageChannel replyChannel = (MessageChannel) message.getHeaders().getReplyChannel();
@ -231,11 +231,10 @@ public class GenericMessagingTemplateTests {
latch.countDown(); latch.countDown();
} }
}; };
return handler;
} }
@Test @Test
public void convertAndSendWithSimpMessageHeaders() { void convertAndSendWithSimpMessageHeaders() {
MessageHeaderAccessor accessor = new MessageHeaderAccessor(); MessageHeaderAccessor accessor = new MessageHeaderAccessor();
accessor.setHeader("key", "value"); accessor.setHeader("key", "value");
accessor.setLeaveMutable(true); accessor.setLeaveMutable(true);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -37,18 +37,18 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
* @author Rossen Stoyanchev * @author Rossen Stoyanchev
* @see MessageRequestReplyTemplateTests * @see MessageRequestReplyTemplateTests
*/ */
public class MessageReceivingTemplateTests { class MessageReceivingTemplateTests {
private TestMessagingTemplate template; private TestMessagingTemplate template;
@BeforeEach @BeforeEach
public void setup() { void setup() {
this.template = new TestMessagingTemplate(); this.template = new TestMessagingTemplate();
} }
@Test @Test
public void receive() { void receive() {
Message<?> expected = new GenericMessage<>("payload"); Message<?> expected = new GenericMessage<>("payload");
this.template.setDefaultDestination("home"); this.template.setDefaultDestination("home");
this.template.setReceiveMessage(expected); this.template.setReceiveMessage(expected);
@ -59,13 +59,13 @@ public class MessageReceivingTemplateTests {
} }
@Test @Test
public void receiveMissingDefaultDestination() { void receiveMissingDefaultDestination() {
assertThatIllegalStateException().isThrownBy( assertThatIllegalStateException().isThrownBy(
this.template::receive); this.template::receive);
} }
@Test @Test
public void receiveFromDestination() { void receiveFromDestination() {
Message<?> expected = new GenericMessage<>("payload"); Message<?> expected = new GenericMessage<>("payload");
this.template.setReceiveMessage(expected); this.template.setReceiveMessage(expected);
Message<?> actual = this.template.receive("somewhere"); Message<?> actual = this.template.receive("somewhere");
@ -75,7 +75,7 @@ public class MessageReceivingTemplateTests {
} }
@Test @Test
public void receiveAndConvert() { void receiveAndConvert() {
Message<?> expected = new GenericMessage<>("payload"); Message<?> expected = new GenericMessage<>("payload");
this.template.setDefaultDestination("home"); this.template.setDefaultDestination("home");
this.template.setReceiveMessage(expected); this.template.setReceiveMessage(expected);
@ -86,7 +86,7 @@ public class MessageReceivingTemplateTests {
} }
@Test @Test
public void receiveAndConvertFromDestination() { void receiveAndConvertFromDestination() {
Message<?> expected = new GenericMessage<>("payload"); Message<?> expected = new GenericMessage<>("payload");
this.template.setReceiveMessage(expected); this.template.setReceiveMessage(expected);
String payload = this.template.receiveAndConvert("somewhere", String.class); String payload = this.template.receiveAndConvert("somewhere", String.class);
@ -96,7 +96,7 @@ public class MessageReceivingTemplateTests {
} }
@Test @Test
public void receiveAndConvertFailed() { void receiveAndConvertFailed() {
Message<?> expected = new GenericMessage<>("not a number test"); Message<?> expected = new GenericMessage<>("not a number test");
this.template.setReceiveMessage(expected); this.template.setReceiveMessage(expected);
this.template.setMessageConverter(new GenericMessageConverter()); this.template.setMessageConverter(new GenericMessageConverter());
@ -107,7 +107,7 @@ public class MessageReceivingTemplateTests {
} }
@Test @Test
public void receiveAndConvertNoConverter() { void receiveAndConvertNoConverter() {
Message<?> expected = new GenericMessage<>("payload"); Message<?> expected = new GenericMessage<>("payload");
this.template.setDefaultDestination("home"); this.template.setDefaultDestination("home");
this.template.setReceiveMessage(expected); this.template.setReceiveMessage(expected);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2019 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -35,7 +35,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
* *
* @see MessageReceivingTemplateTests * @see MessageReceivingTemplateTests
*/ */
public class MessageRequestReplyTemplateTests { class MessageRequestReplyTemplateTests {
private TestMessagingTemplate template; private TestMessagingTemplate template;
@ -45,15 +45,15 @@ public class MessageRequestReplyTemplateTests {
@BeforeEach @BeforeEach
public void setup() { void setup() {
this.template = new TestMessagingTemplate(); this.template = new TestMessagingTemplate();
this.postProcessor = new TestMessagePostProcessor(); this.postProcessor = new TestMessagePostProcessor();
this.headers = Collections.<String, Object>singletonMap("key", "value"); this.headers = Collections.singletonMap("key", "value");
} }
@Test @Test
public void sendAndReceive() { void sendAndReceive() {
Message<?> requestMessage = new GenericMessage<Object>("request"); Message<?> requestMessage = new GenericMessage<Object>("request");
Message<?> responseMessage = new GenericMessage<Object>("response"); Message<?> responseMessage = new GenericMessage<Object>("response");
this.template.setDefaultDestination("home"); this.template.setDefaultDestination("home");
@ -66,13 +66,13 @@ public class MessageRequestReplyTemplateTests {
} }
@Test @Test
public void sendAndReceiveMissingDestination() { void sendAndReceiveMissingDestination() {
assertThatIllegalStateException().isThrownBy(() -> assertThatIllegalStateException().isThrownBy(() ->
this.template.sendAndReceive(new GenericMessage<Object>("request"))); this.template.sendAndReceive(new GenericMessage<Object>("request")));
} }
@Test @Test
public void sendAndReceiveToDestination() { void sendAndReceiveToDestination() {
Message<?> requestMessage = new GenericMessage<Object>("request"); Message<?> requestMessage = new GenericMessage<Object>("request");
Message<?> responseMessage = new GenericMessage<Object>("response"); Message<?> responseMessage = new GenericMessage<Object>("response");
this.template.setReceiveMessage(responseMessage); this.template.setReceiveMessage(responseMessage);
@ -84,7 +84,7 @@ public class MessageRequestReplyTemplateTests {
} }
@Test @Test
public void convertAndSend() { void convertAndSend() {
Message<?> responseMessage = new GenericMessage<Object>("response"); Message<?> responseMessage = new GenericMessage<Object>("response");
this.template.setDefaultDestination("home"); this.template.setDefaultDestination("home");
this.template.setReceiveMessage(responseMessage); this.template.setReceiveMessage(responseMessage);
@ -96,7 +96,7 @@ public class MessageRequestReplyTemplateTests {
} }
@Test @Test
public void convertAndSendToDestination() { void convertAndSendToDestination() {
Message<?> responseMessage = new GenericMessage<Object>("response"); Message<?> responseMessage = new GenericMessage<Object>("response");
this.template.setReceiveMessage(responseMessage); this.template.setReceiveMessage(responseMessage);
String response = this.template.convertSendAndReceive("somewhere", "request", String.class); String response = this.template.convertSendAndReceive("somewhere", "request", String.class);
@ -107,7 +107,7 @@ public class MessageRequestReplyTemplateTests {
} }
@Test @Test
public void convertAndSendToDestinationWithHeaders() { void convertAndSendToDestinationWithHeaders() {
Message<?> responseMessage = new GenericMessage<Object>("response"); Message<?> responseMessage = new GenericMessage<Object>("response");
this.template.setReceiveMessage(responseMessage); this.template.setReceiveMessage(responseMessage);
String response = this.template.convertSendAndReceive("somewhere", "request", this.headers, String.class); String response = this.template.convertSendAndReceive("somewhere", "request", this.headers, String.class);
@ -119,7 +119,7 @@ public class MessageRequestReplyTemplateTests {
} }
@Test @Test
public void convertAndSendWithPostProcessor() { void convertAndSendWithPostProcessor() {
Message<?> responseMessage = new GenericMessage<Object>("response"); Message<?> responseMessage = new GenericMessage<Object>("response");
this.template.setDefaultDestination("home"); this.template.setDefaultDestination("home");
this.template.setReceiveMessage(responseMessage); this.template.setReceiveMessage(responseMessage);
@ -132,7 +132,7 @@ public class MessageRequestReplyTemplateTests {
} }
@Test @Test
public void convertAndSendToDestinationWithPostProcessor() { void convertAndSendToDestinationWithPostProcessor() {
Message<?> responseMessage = new GenericMessage<Object>("response"); Message<?> responseMessage = new GenericMessage<Object>("response");
this.template.setReceiveMessage(responseMessage); this.template.setReceiveMessage(responseMessage);
String response = this.template.convertSendAndReceive("somewhere", "request", String.class, this.postProcessor); String response = this.template.convertSendAndReceive("somewhere", "request", String.class, this.postProcessor);
@ -144,7 +144,7 @@ public class MessageRequestReplyTemplateTests {
} }
@Test @Test
public void convertAndSendToDestinationWithHeadersAndPostProcessor() { void convertAndSendToDestinationWithHeadersAndPostProcessor() {
Message<?> responseMessage = new GenericMessage<Object>("response"); Message<?> responseMessage = new GenericMessage<Object>("response");
this.template.setReceiveMessage(responseMessage); this.template.setReceiveMessage(responseMessage);
String response = this.template.convertSendAndReceive("somewhere", "request", this.headers, String response = this.template.convertSendAndReceive("somewhere", "request", this.headers,

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -17,8 +17,8 @@
package org.springframework.messaging.core; package org.springframework.messaging.core;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
@ -45,7 +45,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
* *
* @author Rossen Stoyanchev * @author Rossen Stoyanchev
*/ */
public class MessageSendingTemplateTests { class MessageSendingTemplateTests {
private TestMessageSendingTemplate template; private TestMessageSendingTemplate template;
@ -55,7 +55,7 @@ public class MessageSendingTemplateTests {
@BeforeEach @BeforeEach
public void setup() { void setup() {
this.template = new TestMessageSendingTemplate(); this.template = new TestMessageSendingTemplate();
this.postProcessor = new TestMessagePostProcessor(); this.postProcessor = new TestMessagePostProcessor();
this.headers = new HashMap<>(); this.headers = new HashMap<>();
@ -63,7 +63,7 @@ public class MessageSendingTemplateTests {
} }
@Test @Test
public void send() { void send() {
Message<?> message = new GenericMessage<Object>("payload"); Message<?> message = new GenericMessage<Object>("payload");
this.template.setDefaultDestination("home"); this.template.setDefaultDestination("home");
this.template.send(message); this.template.send(message);
@ -73,7 +73,7 @@ public class MessageSendingTemplateTests {
} }
@Test @Test
public void sendToDestination() { void sendToDestination() {
Message<?> message = new GenericMessage<Object>("payload"); Message<?> message = new GenericMessage<Object>("payload");
this.template.send("somewhere", message); this.template.send("somewhere", message);
@ -82,14 +82,14 @@ public class MessageSendingTemplateTests {
} }
@Test @Test
public void sendMissingDestination() { void sendMissingDestination() {
Message<?> message = new GenericMessage<Object>("payload"); Message<?> message = new GenericMessage<Object>("payload");
assertThatIllegalStateException().isThrownBy(() -> assertThatIllegalStateException().isThrownBy(() ->
this.template.send(message)); this.template.send(message));
} }
@Test @Test
public void convertAndSend() { void convertAndSend() {
this.template.convertAndSend("somewhere", "payload", headers, this.postProcessor); this.template.convertAndSend("somewhere", "payload", headers, this.postProcessor);
assertThat(this.template.destination).isEqualTo("somewhere"); assertThat(this.template.destination).isEqualTo("somewhere");
@ -102,7 +102,7 @@ public class MessageSendingTemplateTests {
} }
@Test @Test
public void convertAndSendPayload() { void convertAndSendPayload() {
this.template.setDefaultDestination("home"); this.template.setDefaultDestination("home");
this.template.convertAndSend("payload"); this.template.convertAndSend("payload");
@ -113,7 +113,7 @@ public class MessageSendingTemplateTests {
} }
@Test @Test
public void convertAndSendPayloadToDestination() { void convertAndSendPayloadToDestination() {
this.template.convertAndSend("somewhere", "payload"); this.template.convertAndSend("somewhere", "payload");
assertThat(this.template.destination).isEqualTo("somewhere"); assertThat(this.template.destination).isEqualTo("somewhere");
@ -123,7 +123,7 @@ public class MessageSendingTemplateTests {
} }
@Test @Test
public void convertAndSendPayloadAndHeadersToDestination() { void convertAndSendPayloadAndHeadersToDestination() {
this.template.convertAndSend("somewhere", "payload", headers); this.template.convertAndSend("somewhere", "payload", headers);
assertThat(this.template.destination).isEqualTo("somewhere"); assertThat(this.template.destination).isEqualTo("somewhere");
@ -133,7 +133,7 @@ public class MessageSendingTemplateTests {
} }
@Test @Test
public void convertAndSendPayloadAndMutableHeadersToDestination() { void convertAndSendPayloadAndMutableHeadersToDestination() {
MessageHeaderAccessor accessor = new MessageHeaderAccessor(); MessageHeaderAccessor accessor = new MessageHeaderAccessor();
accessor.setHeader("foo", "bar"); accessor.setHeader("foo", "bar");
accessor.setLeaveMutable(true); accessor.setLeaveMutable(true);
@ -149,7 +149,7 @@ public class MessageSendingTemplateTests {
} }
@Test @Test
public void convertAndSendPayloadWithPostProcessor() { void convertAndSendPayloadWithPostProcessor() {
this.template.setDefaultDestination("home"); this.template.setDefaultDestination("home");
this.template.convertAndSend((Object) "payload", this.postProcessor); this.template.convertAndSend((Object) "payload", this.postProcessor);
@ -163,7 +163,7 @@ public class MessageSendingTemplateTests {
} }
@Test @Test
public void convertAndSendPayloadWithPostProcessorToDestination() { void convertAndSendPayloadWithPostProcessorToDestination() {
this.template.convertAndSend("somewhere", "payload", this.postProcessor); this.template.convertAndSend("somewhere", "payload", this.postProcessor);
assertThat(this.template.destination).isEqualTo("somewhere"); assertThat(this.template.destination).isEqualTo("somewhere");
@ -176,10 +176,10 @@ public class MessageSendingTemplateTests {
} }
@Test @Test
public void convertAndSendNoMatchingConverter() { void convertAndSendNoMatchingConverter() {
MessageConverter converter = new CompositeMessageConverter( MessageConverter converter = new CompositeMessageConverter(
Arrays.<MessageConverter>asList(new MappingJackson2MessageConverter())); List.of(new MappingJackson2MessageConverter()));
this.template.setMessageConverter(converter); this.template.setMessageConverter(converter);
this.headers.put(MessageHeaders.CONTENT_TYPE, MimeTypeUtils.APPLICATION_XML); this.headers.put(MessageHeaders.CONTENT_TYPE, MimeTypeUtils.APPLICATION_XML);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -29,32 +29,34 @@ import static org.assertj.core.api.Assertions.assertThat;
* *
* @author Rossen Stoyanchev * @author Rossen Stoyanchev
*/ */
public class DestinationPatternsMessageConditionTests { class DestinationPatternsMessageConditionTests {
@Test @Test
public void prependSlash() { void prependSlash() {
DestinationPatternsMessageCondition c = condition("foo"); DestinationPatternsMessageCondition c = condition("foo");
assertThat(c.getPatterns()).element(0).isEqualTo("/foo"); assertThat(c.getPatterns()).containsExactly("/foo");
} }
@Test @Test
public void prependSlashWithCustomPathSeparator() { void prependSlashWithCustomPathSeparator() {
DestinationPatternsMessageCondition c = DestinationPatternsMessageCondition c =
new DestinationPatternsMessageCondition(new String[] {"foo"}, new AntPathMatcher(".")); new DestinationPatternsMessageCondition(new String[] {"foo"}, new AntPathMatcher("."));
assertThat(c.getPatterns()).element(0).as("Pre-pending should be disabled when not using '/' as path separator").isEqualTo("foo"); assertThat(c.getPatterns())
.as("Pre-pending should be disabled when not using '/' as path separator")
.containsExactly("foo");
} }
// SPR-8255 // SPR-8255
@Test @Test
public void prependNonEmptyPatternsOnly() { void prependNonEmptyPatternsOnly() {
DestinationPatternsMessageCondition c = condition(""); DestinationPatternsMessageCondition c = condition("");
assertThat(c.getPatterns()).element(0).asString().isEmpty(); assertThat(c.getPatterns()).element(0).asString().isEmpty();
} }
@Test @Test
public void combineEmptySets() { void combineEmptySets() {
DestinationPatternsMessageCondition c1 = condition(); DestinationPatternsMessageCondition c1 = condition();
DestinationPatternsMessageCondition c2 = condition(); DestinationPatternsMessageCondition c2 = condition();
@ -62,7 +64,7 @@ public class DestinationPatternsMessageConditionTests {
} }
@Test @Test
public void combineOnePatternWithEmptySet() { void combineOnePatternWithEmptySet() {
DestinationPatternsMessageCondition c1 = condition("/type1", "/type2"); DestinationPatternsMessageCondition c1 = condition("/type1", "/type2");
DestinationPatternsMessageCondition c2 = condition(); DestinationPatternsMessageCondition c2 = condition();
@ -75,7 +77,7 @@ public class DestinationPatternsMessageConditionTests {
} }
@Test @Test
public void combineMultiplePatterns() { void combineMultiplePatterns() {
DestinationPatternsMessageCondition c1 = condition("/t1", "/t2"); DestinationPatternsMessageCondition c1 = condition("/t1", "/t2");
DestinationPatternsMessageCondition c2 = condition("/m1", "/m2"); DestinationPatternsMessageCondition c2 = condition("/m1", "/m2");
@ -84,7 +86,7 @@ public class DestinationPatternsMessageConditionTests {
} }
@Test @Test
public void matchDirectPath() { void matchDirectPath() {
DestinationPatternsMessageCondition condition = condition("/foo"); DestinationPatternsMessageCondition condition = condition("/foo");
DestinationPatternsMessageCondition match = condition.getMatchingCondition(messageTo("/foo")); DestinationPatternsMessageCondition match = condition.getMatchingCondition(messageTo("/foo"));
@ -92,7 +94,7 @@ public class DestinationPatternsMessageConditionTests {
} }
@Test @Test
public void matchPattern() { void matchPattern() {
DestinationPatternsMessageCondition condition = condition("/foo/*"); DestinationPatternsMessageCondition condition = condition("/foo/*");
DestinationPatternsMessageCondition match = condition.getMatchingCondition(messageTo("/foo/bar")); DestinationPatternsMessageCondition match = condition.getMatchingCondition(messageTo("/foo/bar"));
@ -100,7 +102,7 @@ public class DestinationPatternsMessageConditionTests {
} }
@Test @Test
public void matchSortPatterns() { void matchSortPatterns() {
DestinationPatternsMessageCondition condition = condition("/**", "/foo/bar", "/foo/*"); DestinationPatternsMessageCondition condition = condition("/**", "/foo/bar", "/foo/*");
DestinationPatternsMessageCondition match = condition.getMatchingCondition(messageTo("/foo/bar")); DestinationPatternsMessageCondition match = condition.getMatchingCondition(messageTo("/foo/bar"));
DestinationPatternsMessageCondition expected = condition("/foo/bar", "/foo/*", "/**"); DestinationPatternsMessageCondition expected = condition("/foo/bar", "/foo/*", "/**");
@ -109,7 +111,7 @@ public class DestinationPatternsMessageConditionTests {
} }
@Test @Test
public void compareEqualPatterns() { void compareEqualPatterns() {
DestinationPatternsMessageCondition c1 = condition("/foo*"); DestinationPatternsMessageCondition c1 = condition("/foo*");
DestinationPatternsMessageCondition c2 = condition("/foo*"); DestinationPatternsMessageCondition c2 = condition("/foo*");
@ -117,7 +119,7 @@ public class DestinationPatternsMessageConditionTests {
} }
@Test @Test
public void comparePatternSpecificity() { void comparePatternSpecificity() {
DestinationPatternsMessageCondition c1 = condition("/fo*"); DestinationPatternsMessageCondition c1 = condition("/fo*");
DestinationPatternsMessageCondition c2 = condition("/foo"); DestinationPatternsMessageCondition c2 = condition("/foo");
@ -125,7 +127,7 @@ public class DestinationPatternsMessageConditionTests {
} }
@Test @Test
public void compareNumberOfMatchingPatterns() throws Exception { void compareNumberOfMatchingPatterns() {
Message<?> message = messageTo("/foo"); Message<?> message = messageTo("/foo");
DestinationPatternsMessageCondition c1 = condition("/foo", "bar"); DestinationPatternsMessageCondition c1 = condition("/foo", "bar");

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -38,7 +38,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* *
* @author Sebastien Deleuze * @author Sebastien Deleuze
*/ */
public class MessageMappingReflectiveProcessorTests { class MessageMappingReflectiveProcessorTests {
private final MessageMappingReflectiveProcessor processor = new MessageMappingReflectiveProcessor(); private final MessageMappingReflectiveProcessor processor = new MessageMappingReflectiveProcessor();

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2019 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -38,7 +38,7 @@ import static org.springframework.messaging.handler.annotation.MessagingPredicat
* Test fixture for {@link DestinationVariableMethodArgumentResolver} tests. * Test fixture for {@link DestinationVariableMethodArgumentResolver} tests.
* @author Rossen Stoyanchev * @author Rossen Stoyanchev
*/ */
public class DestinationVariableMethodArgumentResolverTests { class DestinationVariableMethodArgumentResolverTests {
private final DestinationVariableMethodArgumentResolver resolver = private final DestinationVariableMethodArgumentResolver resolver =
new DestinationVariableMethodArgumentResolver(new DefaultConversionService()); new DestinationVariableMethodArgumentResolver(new DefaultConversionService());
@ -48,13 +48,13 @@ public class DestinationVariableMethodArgumentResolverTests {
@Test @Test
public void supportsParameter() { void supportsParameter() {
assertThat(resolver.supportsParameter(this.resolvable.annot(destinationVar().noValue()).arg())).isTrue(); assertThat(resolver.supportsParameter(this.resolvable.annot(destinationVar().noValue()).arg())).isTrue();
assertThat(resolver.supportsParameter(this.resolvable.annotNotPresent(DestinationVariable.class).arg())).isFalse(); assertThat(resolver.supportsParameter(this.resolvable.annotNotPresent(DestinationVariable.class).arg())).isFalse();
} }
@Test @Test
public void resolveArgument() { void resolveArgument() {
Map<String, Object> vars = new HashMap<>(); Map<String, Object> vars = new HashMap<>();
vars.put("foo", "bar"); vars.put("foo", "bar");
@ -71,7 +71,7 @@ public class DestinationVariableMethodArgumentResolverTests {
} }
@Test @Test
public void resolveArgumentNotFound() { void resolveArgumentNotFound() {
Message<byte[]> message = MessageBuilder.withPayload(new byte[0]).build(); Message<byte[]> message = MessageBuilder.withPayload(new byte[0]).build();
assertThatExceptionOfType(MessageHandlingException.class).isThrownBy(() -> assertThatExceptionOfType(MessageHandlingException.class).isThrownBy(() ->
resolveArgument(this.resolvable.annot(destinationVar().noValue()).arg(), message)); resolveArgument(this.resolvable.annot(destinationVar().noValue()).arg(), message));

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2019 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -43,7 +43,7 @@ import static org.springframework.messaging.handler.annotation.MessagingPredicat
* Test fixture for {@link HeaderMethodArgumentResolver} tests. * Test fixture for {@link HeaderMethodArgumentResolver} tests.
* @author Rossen Stoyanchev * @author Rossen Stoyanchev
*/ */
public class HeaderMethodArgumentResolverTests { class HeaderMethodArgumentResolverTests {
private HeaderMethodArgumentResolver resolver; private HeaderMethodArgumentResolver resolver;
@ -51,7 +51,6 @@ public class HeaderMethodArgumentResolverTests {
@BeforeEach @BeforeEach
@SuppressWarnings("resource")
public void setup() { public void setup() {
GenericApplicationContext context = new GenericApplicationContext(); GenericApplicationContext context = new GenericApplicationContext();
context.refresh(); context.refresh();
@ -60,13 +59,13 @@ public class HeaderMethodArgumentResolverTests {
@Test @Test
public void supportsParameter() { void supportsParameter() {
assertThat(this.resolver.supportsParameter(this.resolvable.annot(headerPlain()).arg())).isTrue(); assertThat(this.resolver.supportsParameter(this.resolvable.annot(headerPlain()).arg())).isTrue();
assertThat(this.resolver.supportsParameter(this.resolvable.annotNotPresent(Header.class).arg())).isFalse(); assertThat(this.resolver.supportsParameter(this.resolvable.annotNotPresent(Header.class).arg())).isFalse();
} }
@Test @Test
public void resolveArgument() { void resolveArgument() {
Message<byte[]> message = MessageBuilder.withPayload(new byte[0]).setHeader("param1", "foo").build(); Message<byte[]> message = MessageBuilder.withPayload(new byte[0]).setHeader("param1", "foo").build();
Object result = resolveArgument(this.resolvable.annot(headerPlain()).arg(), message); Object result = resolveArgument(this.resolvable.annot(headerPlain()).arg(), message);
assertThat(result).isEqualTo("foo"); assertThat(result).isEqualTo("foo");
@ -81,7 +80,7 @@ public class HeaderMethodArgumentResolverTests {
} }
@Test @Test
public void resolveArgumentNativeHeaderAmbiguity() { void resolveArgumentNativeHeaderAmbiguity() {
TestMessageHeaderAccessor headers = new TestMessageHeaderAccessor(); TestMessageHeaderAccessor headers = new TestMessageHeaderAccessor();
headers.setHeader("param1", "foo"); headers.setHeader("param1", "foo");
headers.setNativeHeader("param1", "native-foo"); headers.setNativeHeader("param1", "native-foo");
@ -95,21 +94,21 @@ public class HeaderMethodArgumentResolverTests {
} }
@Test @Test
public void resolveArgumentNotFound() { void resolveArgumentNotFound() {
Message<byte[]> message = MessageBuilder.withPayload(new byte[0]).build(); Message<byte[]> message = MessageBuilder.withPayload(new byte[0]).build();
assertThatExceptionOfType(MessageHandlingException.class).isThrownBy(() -> assertThatExceptionOfType(MessageHandlingException.class).isThrownBy(() ->
resolveArgument(this.resolvable.annot(headerPlain()).arg(), message)); resolveArgument(this.resolvable.annot(headerPlain()).arg(), message));
} }
@Test @Test
public void resolveArgumentDefaultValue() { void resolveArgumentDefaultValue() {
Message<byte[]> message = MessageBuilder.withPayload(new byte[0]).build(); Message<byte[]> message = MessageBuilder.withPayload(new byte[0]).build();
Object result = resolveArgument(this.resolvable.annot(header("name", "bar")).arg(), message); Object result = resolveArgument(this.resolvable.annot(header("name", "bar")).arg(), message);
assertThat(result).isEqualTo("bar"); assertThat(result).isEqualTo("bar");
} }
@Test @Test
public void resolveDefaultValueSystemProperty() { void resolveDefaultValueSystemProperty() {
System.setProperty("systemProperty", "sysbar"); System.setProperty("systemProperty", "sysbar");
try { try {
Message<byte[]> message = MessageBuilder.withPayload(new byte[0]).build(); Message<byte[]> message = MessageBuilder.withPayload(new byte[0]).build();
@ -123,7 +122,7 @@ public class HeaderMethodArgumentResolverTests {
} }
@Test @Test
public void resolveNameFromSystemProperty() { void resolveNameFromSystemProperty() {
System.setProperty("systemProperty", "sysbar"); System.setProperty("systemProperty", "sysbar");
try { try {
Message<byte[]> message = MessageBuilder.withPayload(new byte[0]).setHeader("sysbar", "foo").build(); Message<byte[]> message = MessageBuilder.withPayload(new byte[0]).setHeader("sysbar", "foo").build();
@ -137,7 +136,7 @@ public class HeaderMethodArgumentResolverTests {
} }
@Test @Test
public void resolveOptionalHeaderWithValue() { void resolveOptionalHeaderWithValue() {
Message<String> message = MessageBuilder.withPayload("foo").setHeader("foo", "bar").build(); Message<String> message = MessageBuilder.withPayload("foo").setHeader("foo", "bar").build();
MethodParameter param = this.resolvable.annot(header("foo")).arg(Optional.class, String.class); MethodParameter param = this.resolvable.annot(header("foo")).arg(Optional.class, String.class);
Object result = resolveArgument(param, message); Object result = resolveArgument(param, message);
@ -145,7 +144,7 @@ public class HeaderMethodArgumentResolverTests {
} }
@Test @Test
public void resolveOptionalHeaderAsEmpty() { void resolveOptionalHeaderAsEmpty() {
Message<String> message = MessageBuilder.withPayload("foo").build(); Message<String> message = MessageBuilder.withPayload("foo").build();
MethodParameter param = this.resolvable.annot(header("foo")).arg(Optional.class, String.class); MethodParameter param = this.resolvable.annot(header("foo")).arg(Optional.class, String.class);
Object result = resolveArgument(param, message); Object result = resolveArgument(param, message);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2019 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -38,7 +38,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
* Test fixture for {@link HeadersMethodArgumentResolver} tests. * Test fixture for {@link HeadersMethodArgumentResolver} tests.
* @author Rossen Stoyanchev * @author Rossen Stoyanchev
*/ */
public class HeadersMethodArgumentResolverTests { class HeadersMethodArgumentResolverTests {
private final HeadersMethodArgumentResolver resolver = new HeadersMethodArgumentResolver(); private final HeadersMethodArgumentResolver resolver = new HeadersMethodArgumentResolver();
@ -49,7 +49,7 @@ public class HeadersMethodArgumentResolverTests {
@Test @Test
public void supportsParameter() { void supportsParameter() {
assertThat(this.resolver.supportsParameter( assertThat(this.resolver.supportsParameter(
this.resolvable.annotPresent(Headers.class).arg(Map.class, String.class, Object.class))).isTrue(); this.resolvable.annotPresent(Headers.class).arg(Map.class, String.class, Object.class))).isTrue();
@ -62,7 +62,6 @@ public class HeadersMethodArgumentResolverTests {
} }
@Test @Test
@SuppressWarnings("unchecked")
public void resolveArgumentAnnotated() { public void resolveArgumentAnnotated() {
MethodParameter param = this.resolvable.annotPresent(Headers.class).arg(Map.class, String.class, Object.class); MethodParameter param = this.resolvable.annotPresent(Headers.class).arg(Map.class, String.class, Object.class);
Map<String, Object> headers = resolveArgument(param); Map<String, Object> headers = resolveArgument(param);
@ -70,25 +69,25 @@ public class HeadersMethodArgumentResolverTests {
} }
@Test @Test
public void resolveArgumentAnnotatedNotMap() { void resolveArgumentAnnotatedNotMap() {
assertThatIllegalStateException().isThrownBy(() -> assertThatIllegalStateException().isThrownBy(() ->
resolveArgument(this.resolvable.annotPresent(Headers.class).arg(String.class))); resolveArgument(this.resolvable.annotPresent(Headers.class).arg(String.class)));
} }
@Test @Test
public void resolveArgumentMessageHeaders() { void resolveArgumentMessageHeaders() {
MessageHeaders headers = resolveArgument(this.resolvable.arg(MessageHeaders.class)); MessageHeaders headers = resolveArgument(this.resolvable.arg(MessageHeaders.class));
assertThat(headers.get("foo")).isEqualTo("bar"); assertThat(headers.get("foo")).isEqualTo("bar");
} }
@Test @Test
public void resolveArgumentMessageHeaderAccessor() { void resolveArgumentMessageHeaderAccessor() {
MessageHeaderAccessor headers = resolveArgument(this.resolvable.arg(MessageHeaderAccessor.class)); MessageHeaderAccessor headers = resolveArgument(this.resolvable.arg(MessageHeaderAccessor.class));
assertThat(headers.getHeader("foo")).isEqualTo("bar"); assertThat(headers.getHeader("foo")).isEqualTo("bar");
} }
@Test @Test
public void resolveArgumentMessageHeaderAccessorSubclass() { void resolveArgumentMessageHeaderAccessorSubclass() {
TestMessageHeaderAccessor headers = resolveArgument(this.resolvable.arg(TestMessageHeaderAccessor.class)); TestMessageHeaderAccessor headers = resolveArgument(this.resolvable.arg(TestMessageHeaderAccessor.class));
assertThat(headers.getHeader("foo")).isEqualTo("bar"); assertThat(headers.getHeader("foo")).isEqualTo("bar");
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2020 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -64,56 +64,56 @@ public class MessageMappingMessageHandlerTests {
@Test @Test
public void handleString() { void handleString() {
MessageMappingMessageHandler messsageHandler = initMesssageHandler(); MessageMappingMessageHandler messsageHandler = initMesssageHandler();
messsageHandler.handleMessage(message("string", "abcdef")).block(Duration.ofSeconds(5)); messsageHandler.handleMessage(message("string", "abcdef")).block(Duration.ofSeconds(5));
verifyOutputContent(Collections.singletonList("abcdef::response")); verifyOutputContent(Collections.singletonList("abcdef::response"));
} }
@Test @Test
public void handleMonoString() { void handleMonoString() {
MessageMappingMessageHandler messsageHandler = initMesssageHandler(); MessageMappingMessageHandler messsageHandler = initMesssageHandler();
messsageHandler.handleMessage(message("monoString", "abcdef")).block(Duration.ofSeconds(5)); messsageHandler.handleMessage(message("monoString", "abcdef")).block(Duration.ofSeconds(5));
verifyOutputContent(Collections.singletonList("abcdef::response")); verifyOutputContent(Collections.singletonList("abcdef::response"));
} }
@Test @Test
public void handleFluxString() { void handleFluxString() {
MessageMappingMessageHandler messsageHandler = initMesssageHandler(); MessageMappingMessageHandler messsageHandler = initMesssageHandler();
messsageHandler.handleMessage(message("fluxString", "abc", "def", "ghi")).block(Duration.ofSeconds(5)); messsageHandler.handleMessage(message("fluxString", "abc", "def", "ghi")).block(Duration.ofSeconds(5));
verifyOutputContent(Arrays.asList("abc::response", "def::response", "ghi::response")); verifyOutputContent(Arrays.asList("abc::response", "def::response", "ghi::response"));
} }
@Test @Test
public void handleWithPlaceholderInMapping() { void handleWithPlaceholderInMapping() {
MessageMappingMessageHandler messsageHandler = initMesssageHandler(); MessageMappingMessageHandler messsageHandler = initMesssageHandler();
messsageHandler.handleMessage(message("path123", "abcdef")).block(Duration.ofSeconds(5)); messsageHandler.handleMessage(message("path123", "abcdef")).block(Duration.ofSeconds(5));
verifyOutputContent(Collections.singletonList("abcdef::response")); verifyOutputContent(Collections.singletonList("abcdef::response"));
} }
@Test @Test
public void handleWithDestinationVariable() { void handleWithDestinationVariable() {
MessageMappingMessageHandler messsageHandler = initMesssageHandler(); MessageMappingMessageHandler messsageHandler = initMesssageHandler();
messsageHandler.handleMessage(message("destination.test", "abcdef")).block(Duration.ofSeconds(5)); messsageHandler.handleMessage(message("destination.test", "abcdef")).block(Duration.ofSeconds(5));
verifyOutputContent(Collections.singletonList("test::abcdef::response")); verifyOutputContent(Collections.singletonList("test::abcdef::response"));
} }
@Test @Test
public void handleException() { void handleException() {
MessageMappingMessageHandler messsageHandler = initMesssageHandler(); MessageMappingMessageHandler messsageHandler = initMesssageHandler();
messsageHandler.handleMessage(message("exception", "abc")).block(Duration.ofSeconds(5)); messsageHandler.handleMessage(message("exception", "abc")).block(Duration.ofSeconds(5));
verifyOutputContent(Collections.singletonList("rejected::handled")); verifyOutputContent(Collections.singletonList("rejected::handled"));
} }
@Test @Test
public void handleErrorSignal() { void handleErrorSignal() {
MessageMappingMessageHandler messsageHandler = initMesssageHandler(); MessageMappingMessageHandler messsageHandler = initMesssageHandler();
messsageHandler.handleMessage(message("errorSignal", "abc")).block(Duration.ofSeconds(5)); messsageHandler.handleMessage(message("errorSignal", "abc")).block(Duration.ofSeconds(5));
verifyOutputContent(Collections.singletonList("rejected::handled")); verifyOutputContent(Collections.singletonList("rejected::handled"));
} }
@Test @Test
public void unhandledExceptionShouldFlowThrough() { void unhandledExceptionShouldFlowThrough() {
GenericMessage<?> message = new GenericMessage<>(new Object(), GenericMessage<?> message = new GenericMessage<>(new Object(),
Collections.singletonMap(DestinationPatternsMessageCondition.LOOKUP_DESTINATION_HEADER, Collections.singletonMap(DestinationPatternsMessageCondition.LOOKUP_DESTINATION_HEADER,

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -56,7 +56,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* *
* @author Rossen Stoyanchev * @author Rossen Stoyanchev
*/ */
public class PayloadMethodArgumentResolverTests { class PayloadMethodArgumentResolverTests {
private final List<Decoder<?>> decoders = new ArrayList<>(); private final List<Decoder<?>> decoders = new ArrayList<>();
@ -64,7 +64,7 @@ public class PayloadMethodArgumentResolverTests {
@Test @Test
public void supportsParameter() { void supportsParameter() {
boolean useDefaultResolution = true; boolean useDefaultResolution = true;
PayloadMethodArgumentResolver resolver = createResolver(null, useDefaultResolution); PayloadMethodArgumentResolver resolver = createResolver(null, useDefaultResolution);
@ -80,7 +80,7 @@ public class PayloadMethodArgumentResolverTests {
} }
@Test @Test
public void emptyBodyWhenRequired() { void emptyBodyWhenRequired() {
MethodParameter param = this.testMethod.arg(ResolvableType.forClassWithGenerics(Mono.class, String.class)); MethodParameter param = this.testMethod.arg(ResolvableType.forClassWithGenerics(Mono.class, String.class));
Mono<Object> mono = resolveValue(param, Mono.empty(), null); Mono<Object> mono = resolveValue(param, Mono.empty(), null);
@ -93,13 +93,13 @@ public class PayloadMethodArgumentResolverTests {
} }
@Test @Test
public void emptyBodyWhenNotRequired() { void emptyBodyWhenNotRequired() {
MethodParameter param = this.testMethod.annotPresent(Payload.class).arg(); MethodParameter param = this.testMethod.annotPresent(Payload.class).arg();
assertThat(this.<Object>resolveValue(param, Mono.empty(), null)).isNull(); assertThat(this.<Object>resolveValue(param, Mono.empty(), null)).isNull();
} }
@Test @Test
public void stringMono() { void stringMono() {
String body = "foo"; String body = "foo";
MethodParameter param = this.testMethod.arg(ResolvableType.forClassWithGenerics(Mono.class, String.class)); MethodParameter param = this.testMethod.arg(ResolvableType.forClassWithGenerics(Mono.class, String.class));
Mono<Object> mono = resolveValue(param, Mono<Object> mono = resolveValue(param,
@ -109,7 +109,7 @@ public class PayloadMethodArgumentResolverTests {
} }
@Test @Test
public void stringFlux() { void stringFlux() {
List<String> body = Arrays.asList("foo", "bar"); List<String> body = Arrays.asList("foo", "bar");
ResolvableType type = ResolvableType.forClassWithGenerics(Flux.class, String.class); ResolvableType type = ResolvableType.forClassWithGenerics(Flux.class, String.class);
MethodParameter param = this.testMethod.arg(type); MethodParameter param = this.testMethod.arg(type);
@ -120,7 +120,7 @@ public class PayloadMethodArgumentResolverTests {
} }
@Test @Test
public void string() { void string() {
String body = "foo"; String body = "foo";
MethodParameter param = this.testMethod.annotNotPresent(Payload.class).arg(String.class); MethodParameter param = this.testMethod.annotNotPresent(Payload.class).arg(String.class);
Object value = resolveValue(param, Mono.just(toDataBuffer(body)), null); Object value = resolveValue(param, Mono.just(toDataBuffer(body)), null);
@ -129,7 +129,7 @@ public class PayloadMethodArgumentResolverTests {
} }
@Test @Test
public void validateStringMono() { void validateStringMono() {
TestValidator validator = new TestValidator(); TestValidator validator = new TestValidator();
ResolvableType type = ResolvableType.forClassWithGenerics(Mono.class, String.class); ResolvableType type = ResolvableType.forClassWithGenerics(Mono.class, String.class);
MethodParameter param = this.testMethod.arg(type); MethodParameter param = this.testMethod.arg(type);
@ -140,7 +140,7 @@ public class PayloadMethodArgumentResolverTests {
} }
@Test @Test
public void validateStringFlux() { void validateStringFlux() {
TestValidator validator = new TestValidator(); TestValidator validator = new TestValidator();
ResolvableType type = ResolvableType.forClassWithGenerics(Flux.class, String.class); ResolvableType type = ResolvableType.forClassWithGenerics(Flux.class, String.class);
MethodParameter param = this.testMethod.arg(type); MethodParameter param = this.testMethod.arg(type);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -36,32 +36,32 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
* @author Rossen Stoyanchev * @author Rossen Stoyanchev
* @author Juergen Hoeller * @author Juergen Hoeller
*/ */
public class AnnotationExceptionHandlerMethodResolverTests { class AnnotationExceptionHandlerMethodResolverTests {
private final AnnotationExceptionHandlerMethodResolver resolver = private final AnnotationExceptionHandlerMethodResolver resolver =
new AnnotationExceptionHandlerMethodResolver(ExceptionController.class); new AnnotationExceptionHandlerMethodResolver(ExceptionController.class);
@Test @Test
public void resolveMethodFromAnnotation() { void resolveMethodFromAnnotation() {
IOException exception = new IOException(); IOException exception = new IOException();
assertThat(this.resolver.resolveMethod(exception).getName()).isEqualTo("handleIOException"); assertThat(this.resolver.resolveMethod(exception).getName()).isEqualTo("handleIOException");
} }
@Test @Test
public void resolveMethodFromArgument() { void resolveMethodFromArgument() {
IllegalArgumentException exception = new IllegalArgumentException(); IllegalArgumentException exception = new IllegalArgumentException();
assertThat(this.resolver.resolveMethod(exception).getName()).isEqualTo("handleIllegalArgumentException"); assertThat(this.resolver.resolveMethod(exception).getName()).isEqualTo("handleIllegalArgumentException");
} }
@Test @Test
public void resolveMethodFromArgumentWithErrorType() { void resolveMethodFromArgumentWithErrorType() {
AssertionError exception = new AssertionError(); AssertionError exception = new AssertionError();
assertThat(this.resolver.resolveMethod(new IllegalStateException(exception)).getName()).isEqualTo("handleAssertionError"); assertThat(this.resolver.resolveMethod(new IllegalStateException(exception)).getName()).isEqualTo("handleAssertionError");
} }
@Test @Test
public void resolveMethodExceptionSubType() { void resolveMethodExceptionSubType() {
IOException ioException = new FileNotFoundException(); IOException ioException = new FileNotFoundException();
assertThat(this.resolver.resolveMethod(ioException).getName()).isEqualTo("handleIOException"); assertThat(this.resolver.resolveMethod(ioException).getName()).isEqualTo("handleIOException");
SocketException bindException = new BindException(); SocketException bindException = new BindException();
@ -69,38 +69,38 @@ public class AnnotationExceptionHandlerMethodResolverTests {
} }
@Test @Test
public void resolveMethodBestMatch() { void resolveMethodBestMatch() {
SocketException exception = new SocketException(); SocketException exception = new SocketException();
assertThat(this.resolver.resolveMethod(exception).getName()).isEqualTo("handleSocketException"); assertThat(this.resolver.resolveMethod(exception).getName()).isEqualTo("handleSocketException");
} }
@Test @Test
public void resolveMethodNoMatch() { void resolveMethodNoMatch() {
Exception exception = new Exception(); Exception exception = new Exception();
assertThat(this.resolver.resolveMethod(exception)).as("1st lookup").isNull(); assertThat(this.resolver.resolveMethod(exception)).as("1st lookup").isNull();
assertThat(this.resolver.resolveMethod(exception)).as("2nd lookup from cache").isNull(); assertThat(this.resolver.resolveMethod(exception)).as("2nd lookup from cache").isNull();
} }
@Test @Test
public void resolveMethodInherited() { void resolveMethodInherited() {
IOException exception = new IOException(); IOException exception = new IOException();
assertThat(this.resolver.resolveMethod(exception).getName()).isEqualTo("handleIOException"); assertThat(this.resolver.resolveMethod(exception).getName()).isEqualTo("handleIOException");
} }
@Test @Test
public void resolveMethodAgainstCause() { void resolveMethodAgainstCause() {
IllegalStateException exception = new IllegalStateException(new IOException()); IllegalStateException exception = new IllegalStateException(new IOException());
assertThat(this.resolver.resolveMethod(exception).getName()).isEqualTo("handleIOException"); assertThat(this.resolver.resolveMethod(exception).getName()).isEqualTo("handleIOException");
} }
@Test @Test
public void ambiguousExceptionMapping() { void ambiguousExceptionMapping() {
assertThatIllegalStateException().isThrownBy(() -> assertThatIllegalStateException().isThrownBy(() ->
new AnnotationExceptionHandlerMethodResolver(AmbiguousController.class)); new AnnotationExceptionHandlerMethodResolver(AmbiguousController.class));
} }
@Test @Test
public void noExceptionMapping() { void noExceptionMapping() {
assertThatIllegalStateException().isThrownBy(() -> assertThatIllegalStateException().isThrownBy(() ->
new AnnotationExceptionHandlerMethodResolver(NoExceptionController.class)); new AnnotationExceptionHandlerMethodResolver(NoExceptionController.class));
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2019 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -49,13 +49,13 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
/** /**
* @author Stephane Nicoll * @author Stephane Nicoll
*/ */
public class DefaultMessageHandlerMethodFactoryTests { class DefaultMessageHandlerMethodFactoryTests {
private final SampleBean sample = new SampleBean(); private final SampleBean sample = new SampleBean();
@Test @Test
public void customConversion() throws Exception { void customConversion() throws Exception {
DefaultMessageHandlerMethodFactory instance = createInstance(); DefaultMessageHandlerMethodFactory instance = createInstance();
GenericConversionService conversionService = new GenericConversionService(); GenericConversionService conversionService = new GenericConversionService();
conversionService.addConverter(SampleBean.class, String.class, source -> "foo bar"); conversionService.addConverter(SampleBean.class, String.class, source -> "foo bar");
@ -70,7 +70,7 @@ public class DefaultMessageHandlerMethodFactoryTests {
} }
@Test @Test
public void customConversionServiceFailure() throws Exception { void customConversionServiceFailure() {
DefaultMessageHandlerMethodFactory instance = createInstance(); DefaultMessageHandlerMethodFactory instance = createInstance();
GenericConversionService conversionService = new GenericConversionService(); GenericConversionService conversionService = new GenericConversionService();
assertThat(conversionService.canConvert(Integer.class, String.class)).as("conversion service should fail to convert payload").isFalse(); assertThat(conversionService.canConvert(Integer.class, String.class)).as("conversion service should fail to convert payload").isFalse();
@ -85,7 +85,7 @@ public class DefaultMessageHandlerMethodFactoryTests {
} }
@Test @Test
public void customMessageConverterFailure() throws Exception { void customMessageConverterFailure() {
DefaultMessageHandlerMethodFactory instance = createInstance(); DefaultMessageHandlerMethodFactory instance = createInstance();
MessageConverter messageConverter = new ByteArrayMessageConverter(); MessageConverter messageConverter = new ByteArrayMessageConverter();
instance.setMessageConverter(messageConverter); instance.setMessageConverter(messageConverter);
@ -99,7 +99,7 @@ public class DefaultMessageHandlerMethodFactoryTests {
} }
@Test @Test
public void customArgumentResolver() throws Exception { void customArgumentResolver() throws Exception {
DefaultMessageHandlerMethodFactory instance = createInstance(); DefaultMessageHandlerMethodFactory instance = createInstance();
List<HandlerMethodArgumentResolver> customResolvers = new ArrayList<>(); List<HandlerMethodArgumentResolver> customResolvers = new ArrayList<>();
customResolvers.add(new CustomHandlerMethodArgumentResolver()); customResolvers.add(new CustomHandlerMethodArgumentResolver());
@ -114,7 +114,7 @@ public class DefaultMessageHandlerMethodFactoryTests {
} }
@Test @Test
public void overrideArgumentResolvers() throws Exception { void overrideArgumentResolvers() throws Exception {
DefaultMessageHandlerMethodFactory instance = createInstance(); DefaultMessageHandlerMethodFactory instance = createInstance();
List<HandlerMethodArgumentResolver> customResolvers = new ArrayList<>(); List<HandlerMethodArgumentResolver> customResolvers = new ArrayList<>();
customResolvers.add(new CustomHandlerMethodArgumentResolver()); customResolvers.add(new CustomHandlerMethodArgumentResolver());
@ -138,7 +138,7 @@ public class DefaultMessageHandlerMethodFactoryTests {
} }
@Test @Test
public void noValidationByDefault() throws Exception { void noValidationByDefault() throws Exception {
DefaultMessageHandlerMethodFactory instance = createInstance(); DefaultMessageHandlerMethodFactory instance = createInstance();
instance.afterPropertiesSet(); instance.afterPropertiesSet();
@ -149,7 +149,7 @@ public class DefaultMessageHandlerMethodFactoryTests {
} }
@Test @Test
public void customValidation() throws Exception { void customValidation() {
DefaultMessageHandlerMethodFactory instance = createInstance(); DefaultMessageHandlerMethodFactory instance = createInstance();
instance.setValidator(new Validator() { instance.setValidator(new Validator() {
@Override @Override

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2019 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -38,7 +38,7 @@ import static org.springframework.messaging.handler.annotation.MessagingPredicat
* *
* @author Brian Clozel * @author Brian Clozel
*/ */
public class DestinationVariableMethodArgumentResolverTests { class DestinationVariableMethodArgumentResolverTests {
private final DestinationVariableMethodArgumentResolver resolver = private final DestinationVariableMethodArgumentResolver resolver =
new DestinationVariableMethodArgumentResolver(new DefaultConversionService()); new DestinationVariableMethodArgumentResolver(new DefaultConversionService());
@ -48,13 +48,13 @@ public class DestinationVariableMethodArgumentResolverTests {
@Test @Test
public void supportsParameter() { void supportsParameter() {
assertThat(resolver.supportsParameter(this.resolvable.annot(destinationVar().noValue()).arg())).isTrue(); assertThat(resolver.supportsParameter(this.resolvable.annot(destinationVar().noValue()).arg())).isTrue();
assertThat(resolver.supportsParameter(this.resolvable.annotNotPresent(DestinationVariable.class).arg())).isFalse(); assertThat(resolver.supportsParameter(this.resolvable.annotNotPresent(DestinationVariable.class).arg())).isFalse();
} }
@Test @Test
public void resolveArgument() throws Exception { void resolveArgument() throws Exception {
Map<String, Object> vars = new HashMap<>(); Map<String, Object> vars = new HashMap<>();
vars.put("foo", "bar"); vars.put("foo", "bar");
@ -73,7 +73,7 @@ public class DestinationVariableMethodArgumentResolverTests {
} }
@Test @Test
public void resolveArgumentNotFound() throws Exception { void resolveArgumentNotFound() {
Message<byte[]> message = MessageBuilder.withPayload(new byte[0]).build(); Message<byte[]> message = MessageBuilder.withPayload(new byte[0]).build();
assertThatExceptionOfType(MessageHandlingException.class).isThrownBy(() -> assertThatExceptionOfType(MessageHandlingException.class).isThrownBy(() ->
this.resolver.resolveArgument(this.resolvable.annot(destinationVar().noValue()).arg(), message)); this.resolver.resolveArgument(this.resolvable.annot(destinationVar().noValue()).arg(), message));

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2019 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -45,7 +45,7 @@ import static org.springframework.messaging.handler.annotation.MessagingPredicat
* @author Juergen Hoeller * @author Juergen Hoeller
* @since 4.0 * @since 4.0
*/ */
public class HeaderMethodArgumentResolverTests { class HeaderMethodArgumentResolverTests {
private HeaderMethodArgumentResolver resolver; private HeaderMethodArgumentResolver resolver;
@ -53,7 +53,6 @@ public class HeaderMethodArgumentResolverTests {
@BeforeEach @BeforeEach
@SuppressWarnings("resource")
public void setup() { public void setup() {
GenericApplicationContext context = new GenericApplicationContext(); GenericApplicationContext context = new GenericApplicationContext();
context.refresh(); context.refresh();
@ -62,13 +61,13 @@ public class HeaderMethodArgumentResolverTests {
@Test @Test
public void supportsParameter() { void supportsParameter() {
assertThat(this.resolver.supportsParameter(this.resolvable.annot(headerPlain()).arg())).isTrue(); assertThat(this.resolver.supportsParameter(this.resolvable.annot(headerPlain()).arg())).isTrue();
assertThat(this.resolver.supportsParameter(this.resolvable.annotNotPresent(Header.class).arg())).isFalse(); assertThat(this.resolver.supportsParameter(this.resolvable.annotNotPresent(Header.class).arg())).isFalse();
} }
@Test @Test
public void resolveArgument() throws Exception { void resolveArgument() throws Exception {
Message<byte[]> message = MessageBuilder.withPayload(new byte[0]).setHeader("param1", "foo").build(); Message<byte[]> message = MessageBuilder.withPayload(new byte[0]).setHeader("param1", "foo").build();
Object result = this.resolver.resolveArgument(this.resolvable.annot(headerPlain()).arg(), message); Object result = this.resolver.resolveArgument(this.resolvable.annot(headerPlain()).arg(), message);
assertThat(result).isEqualTo("foo"); assertThat(result).isEqualTo("foo");
@ -83,7 +82,7 @@ public class HeaderMethodArgumentResolverTests {
} }
@Test @Test
public void resolveArgumentNativeHeaderAmbiguity() throws Exception { void resolveArgumentNativeHeaderAmbiguity() throws Exception {
TestMessageHeaderAccessor headers = new TestMessageHeaderAccessor(); TestMessageHeaderAccessor headers = new TestMessageHeaderAccessor();
headers.setHeader("param1", "foo"); headers.setHeader("param1", "foo");
headers.setNativeHeader("param1", "native-foo"); headers.setNativeHeader("param1", "native-foo");
@ -97,21 +96,21 @@ public class HeaderMethodArgumentResolverTests {
} }
@Test @Test
public void resolveArgumentNotFound() throws Exception { void resolveArgumentNotFound() {
Message<byte[]> message = MessageBuilder.withPayload(new byte[0]).build(); Message<byte[]> message = MessageBuilder.withPayload(new byte[0]).build();
assertThatExceptionOfType(MessageHandlingException.class).isThrownBy(() -> assertThatExceptionOfType(MessageHandlingException.class).isThrownBy(() ->
this.resolver.resolveArgument(this.resolvable.annot(headerPlain()).arg(), message)); this.resolver.resolveArgument(this.resolvable.annot(headerPlain()).arg(), message));
} }
@Test @Test
public void resolveArgumentDefaultValue() throws Exception { void resolveArgumentDefaultValue() throws Exception {
Message<byte[]> message = MessageBuilder.withPayload(new byte[0]).build(); Message<byte[]> message = MessageBuilder.withPayload(new byte[0]).build();
Object result = this.resolver.resolveArgument(this.resolvable.annot(header("name", "bar")).arg(), message); Object result = this.resolver.resolveArgument(this.resolvable.annot(header("name", "bar")).arg(), message);
assertThat(result).isEqualTo("bar"); assertThat(result).isEqualTo("bar");
} }
@Test @Test
public void resolveDefaultValueSystemProperty() throws Exception { void resolveDefaultValueSystemProperty() throws Exception {
System.setProperty("systemProperty", "sysbar"); System.setProperty("systemProperty", "sysbar");
try { try {
Message<byte[]> message = MessageBuilder.withPayload(new byte[0]).build(); Message<byte[]> message = MessageBuilder.withPayload(new byte[0]).build();
@ -125,7 +124,7 @@ public class HeaderMethodArgumentResolverTests {
} }
@Test @Test
public void resolveNameFromSystemProperty() throws Exception { void resolveNameFromSystemProperty() throws Exception {
System.setProperty("systemProperty", "sysbar"); System.setProperty("systemProperty", "sysbar");
try { try {
Message<byte[]> message = MessageBuilder.withPayload(new byte[0]).setHeader("sysbar", "foo").build(); Message<byte[]> message = MessageBuilder.withPayload(new byte[0]).setHeader("sysbar", "foo").build();
@ -139,7 +138,7 @@ public class HeaderMethodArgumentResolverTests {
} }
@Test @Test
public void resolveOptionalHeaderWithValue() throws Exception { void resolveOptionalHeaderWithValue() throws Exception {
Message<String> message = MessageBuilder.withPayload("foo").setHeader("foo", "bar").build(); Message<String> message = MessageBuilder.withPayload("foo").setHeader("foo", "bar").build();
MethodParameter param = this.resolvable.annot(header("foo")).arg(Optional.class, String.class); MethodParameter param = this.resolvable.annot(header("foo")).arg(Optional.class, String.class);
Object result = resolver.resolveArgument(param, message); Object result = resolver.resolveArgument(param, message);
@ -147,7 +146,7 @@ public class HeaderMethodArgumentResolverTests {
} }
@Test @Test
public void resolveOptionalHeaderAsEmpty() throws Exception { void resolveOptionalHeaderAsEmpty() throws Exception {
Message<String> message = MessageBuilder.withPayload("foo").build(); Message<String> message = MessageBuilder.withPayload("foo").build();
MethodParameter param = this.resolvable.annot(header("foo")).arg(Optional.class, String.class); MethodParameter param = this.resolvable.annot(header("foo")).arg(Optional.class, String.class);
Object result = resolver.resolveArgument(param, message); Object result = resolver.resolveArgument(param, message);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2019 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -39,7 +39,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
* @author Rossen Stoyanchev * @author Rossen Stoyanchev
* @since 4.0 * @since 4.0
*/ */
public class HeadersMethodArgumentResolverTests { class HeadersMethodArgumentResolverTests {
private final HeadersMethodArgumentResolver resolver = new HeadersMethodArgumentResolver(); private final HeadersMethodArgumentResolver resolver = new HeadersMethodArgumentResolver();
@ -50,7 +50,7 @@ public class HeadersMethodArgumentResolverTests {
@Test @Test
public void supportsParameter() { void supportsParameter() {
assertThat(this.resolver.supportsParameter( assertThat(this.resolver.supportsParameter(
this.resolvable.annotPresent(Headers.class).arg(Map.class, String.class, Object.class))).isTrue(); this.resolvable.annotPresent(Headers.class).arg(Map.class, String.class, Object.class))).isTrue();
@ -63,7 +63,7 @@ public class HeadersMethodArgumentResolverTests {
} }
@Test @Test
public void resolveArgumentAnnotated() throws Exception { void resolveArgumentAnnotated() throws Exception {
MethodParameter param = this.resolvable.annotPresent(Headers.class).arg(Map.class, String.class, Object.class); MethodParameter param = this.resolvable.annotPresent(Headers.class).arg(Map.class, String.class, Object.class);
Object resolved = this.resolver.resolveArgument(param, this.message); Object resolved = this.resolver.resolveArgument(param, this.message);
@ -75,13 +75,13 @@ public class HeadersMethodArgumentResolverTests {
} }
@Test @Test
public void resolveArgumentAnnotatedNotMap() throws Exception { void resolveArgumentAnnotatedNotMap() {
assertThatIllegalStateException().isThrownBy(() -> assertThatIllegalStateException().isThrownBy(() ->
this.resolver.resolveArgument(this.resolvable.annotPresent(Headers.class).arg(String.class), this.message)); this.resolver.resolveArgument(this.resolvable.annotPresent(Headers.class).arg(String.class), this.message));
} }
@Test @Test
public void resolveArgumentMessageHeaders() throws Exception { void resolveArgumentMessageHeaders() throws Exception {
Object resolved = this.resolver.resolveArgument(this.resolvable.arg(MessageHeaders.class), this.message); Object resolved = this.resolver.resolveArgument(this.resolvable.arg(MessageHeaders.class), this.message);
boolean condition = resolved instanceof MessageHeaders; boolean condition = resolved instanceof MessageHeaders;
@ -91,7 +91,7 @@ public class HeadersMethodArgumentResolverTests {
} }
@Test @Test
public void resolveArgumentMessageHeaderAccessor() throws Exception { void resolveArgumentMessageHeaderAccessor() throws Exception {
MethodParameter param = this.resolvable.arg(MessageHeaderAccessor.class); MethodParameter param = this.resolvable.arg(MessageHeaderAccessor.class);
Object resolved = this.resolver.resolveArgument(param, this.message); Object resolved = this.resolver.resolveArgument(param, this.message);
@ -102,7 +102,7 @@ public class HeadersMethodArgumentResolverTests {
} }
@Test @Test
public void resolveArgumentMessageHeaderAccessorSubclass() throws Exception { void resolveArgumentMessageHeaderAccessorSubclass() throws Exception {
MethodParameter param = this.resolvable.arg(TestMessageHeaderAccessor.class); MethodParameter param = this.resolvable.arg(TestMessageHeaderAccessor.class);
Object resolved = this.resolver.resolveArgument(param, this.message); Object resolved = this.resolver.resolveArgument(param, this.message);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -42,7 +42,7 @@ import static org.mockito.Mockito.mock;
* @author Stephane Nicoll * @author Stephane Nicoll
* @author Juergen Hoeller * @author Juergen Hoeller
*/ */
public class MessageMethodArgumentResolverTests { class MessageMethodArgumentResolverTests {
private MessageConverter converter = mock(); private MessageConverter converter = mock();
@ -52,14 +52,14 @@ public class MessageMethodArgumentResolverTests {
@BeforeEach @BeforeEach
public void setup() throws Exception { void setup() throws Exception {
this.method = getClass().getDeclaredMethod("handle", this.method = getClass().getDeclaredMethod("handle",
Message.class, Message.class, Message.class, Message.class, ErrorMessage.class, Message.class); Message.class, Message.class, Message.class, Message.class, ErrorMessage.class, Message.class);
} }
@Test @Test
public void resolveWithPayloadTypeAsWildcard() throws Exception { void resolveWithPayloadTypeAsWildcard() throws Exception {
Message<String> message = MessageBuilder.withPayload("test").build(); Message<String> message = MessageBuilder.withPayload("test").build();
MethodParameter parameter = new MethodParameter(this.method, 0); MethodParameter parameter = new MethodParameter(this.method, 0);
@ -68,7 +68,7 @@ public class MessageMethodArgumentResolverTests {
} }
@Test @Test
public void resolveWithMatchingPayloadType() throws Exception { void resolveWithMatchingPayloadType() throws Exception {
Message<Integer> message = MessageBuilder.withPayload(123).build(); Message<Integer> message = MessageBuilder.withPayload(123).build();
MethodParameter parameter = new MethodParameter(this.method, 1); MethodParameter parameter = new MethodParameter(this.method, 1);
@ -77,7 +77,7 @@ public class MessageMethodArgumentResolverTests {
} }
@Test @Test
public void resolveWithPayloadTypeSubclass() throws Exception { void resolveWithPayloadTypeSubclass() throws Exception {
Message<Integer> message = MessageBuilder.withPayload(123).build(); Message<Integer> message = MessageBuilder.withPayload(123).build();
MethodParameter parameter = new MethodParameter(this.method, 2); MethodParameter parameter = new MethodParameter(this.method, 2);
@ -86,7 +86,7 @@ public class MessageMethodArgumentResolverTests {
} }
@Test @Test
public void resolveWithConversion() throws Exception { void resolveWithConversion() throws Exception {
Message<String> message = MessageBuilder.withPayload("test").build(); Message<String> message = MessageBuilder.withPayload("test").build();
MethodParameter parameter = new MethodParameter(this.method, 1); MethodParameter parameter = new MethodParameter(this.method, 1);
@ -101,7 +101,7 @@ public class MessageMethodArgumentResolverTests {
} }
@Test @Test
public void resolveWithConversionNoMatchingConverter() throws Exception { void resolveWithConversionNoMatchingConverter() {
Message<String> message = MessageBuilder.withPayload("test").build(); Message<String> message = MessageBuilder.withPayload("test").build();
MethodParameter parameter = new MethodParameter(this.method, 1); MethodParameter parameter = new MethodParameter(this.method, 1);
@ -113,7 +113,7 @@ public class MessageMethodArgumentResolverTests {
} }
@Test @Test
public void resolveWithConversionEmptyPayload() throws Exception { void resolveWithConversionEmptyPayload() {
Message<String> message = MessageBuilder.withPayload("").build(); Message<String> message = MessageBuilder.withPayload("").build();
MethodParameter parameter = new MethodParameter(this.method, 1); MethodParameter parameter = new MethodParameter(this.method, 1);
@ -126,7 +126,7 @@ public class MessageMethodArgumentResolverTests {
} }
@Test @Test
public void resolveWithPayloadTypeUpperBound() throws Exception { void resolveWithPayloadTypeUpperBound() throws Exception {
Message<Integer> message = MessageBuilder.withPayload(123).build(); Message<Integer> message = MessageBuilder.withPayload(123).build();
MethodParameter parameter = new MethodParameter(this.method, 3); MethodParameter parameter = new MethodParameter(this.method, 3);
@ -135,7 +135,7 @@ public class MessageMethodArgumentResolverTests {
} }
@Test @Test
public void resolveWithPayloadTypeOutOfBound() throws Exception { void resolveWithPayloadTypeOutOfBound() {
Message<Locale> message = MessageBuilder.withPayload(Locale.getDefault()).build(); Message<Locale> message = MessageBuilder.withPayload(Locale.getDefault()).build();
MethodParameter parameter = new MethodParameter(this.method, 3); MethodParameter parameter = new MethodParameter(this.method, 3);
@ -147,7 +147,7 @@ public class MessageMethodArgumentResolverTests {
} }
@Test @Test
public void resolveMessageSubclassMatch() throws Exception { void resolveMessageSubclassMatch() throws Exception {
ErrorMessage message = new ErrorMessage(new UnsupportedOperationException()); ErrorMessage message = new ErrorMessage(new UnsupportedOperationException());
MethodParameter parameter = new MethodParameter(this.method, 4); MethodParameter parameter = new MethodParameter(this.method, 4);
@ -156,7 +156,7 @@ public class MessageMethodArgumentResolverTests {
} }
@Test @Test
public void resolveWithMessageSubclassAndPayloadWildcard() throws Exception { void resolveWithMessageSubclassAndPayloadWildcard() throws Exception {
ErrorMessage message = new ErrorMessage(new UnsupportedOperationException()); ErrorMessage message = new ErrorMessage(new UnsupportedOperationException());
MethodParameter parameter = new MethodParameter(this.method, 0); MethodParameter parameter = new MethodParameter(this.method, 0);
@ -165,7 +165,7 @@ public class MessageMethodArgumentResolverTests {
} }
@Test @Test
public void resolveWithWrongMessageType() throws Exception { void resolveWithWrongMessageType() {
UnsupportedOperationException ex = new UnsupportedOperationException(); UnsupportedOperationException ex = new UnsupportedOperationException();
Message<? extends Throwable> message = new GenericMessage<Throwable>(ex); Message<? extends Throwable> message = new GenericMessage<Throwable>(ex);
MethodParameter parameter = new MethodParameter(this.method, 4); MethodParameter parameter = new MethodParameter(this.method, 4);
@ -178,7 +178,7 @@ public class MessageMethodArgumentResolverTests {
} }
@Test @Test
public void resolveWithPayloadTypeAsWildcardAndNoConverter() throws Exception { void resolveWithPayloadTypeAsWildcardAndNoConverter() throws Exception {
this.resolver = new MessageMethodArgumentResolver(); this.resolver = new MessageMethodArgumentResolver();
Message<String> message = MessageBuilder.withPayload("test").build(); Message<String> message = MessageBuilder.withPayload("test").build();
@ -189,7 +189,7 @@ public class MessageMethodArgumentResolverTests {
} }
@Test @Test
public void resolveWithConversionNeededButNoConverter() throws Exception { void resolveWithConversionNeededButNoConverter() {
this.resolver = new MessageMethodArgumentResolver(); this.resolver = new MessageMethodArgumentResolver();
Message<String> message = MessageBuilder.withPayload("test").build(); Message<String> message = MessageBuilder.withPayload("test").build();
@ -203,7 +203,7 @@ public class MessageMethodArgumentResolverTests {
} }
@Test @Test
public void resolveWithConversionEmptyPayloadButNoConverter() throws Exception { void resolveWithConversionEmptyPayloadButNoConverter() {
this.resolver = new MessageMethodArgumentResolver(); this.resolver = new MessageMethodArgumentResolver();
Message<String> message = MessageBuilder.withPayload("").build(); Message<String> message = MessageBuilder.withPayload("").build();

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -50,7 +50,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
* @author Brian Clozel * @author Brian Clozel
* @author Stephane Nicoll * @author Stephane Nicoll
*/ */
public class PayloadMethodArgumentResolverTests { class PayloadMethodArgumentResolverTests {
private PayloadMethodArgumentResolver resolver; private PayloadMethodArgumentResolver resolver;
@ -72,7 +72,7 @@ public class PayloadMethodArgumentResolverTests {
@BeforeEach @BeforeEach
public void setup() throws Exception { void setup() throws Exception {
this.resolver = new PayloadMethodArgumentResolver(new StringMessageConverter(), testValidator()); this.resolver = new PayloadMethodArgumentResolver(new StringMessageConverter(), testValidator());
Method payloadMethod = PayloadMethodArgumentResolverTests.class.getDeclaredMethod( Method payloadMethod = PayloadMethodArgumentResolverTests.class.getDeclaredMethod(
@ -91,7 +91,7 @@ public class PayloadMethodArgumentResolverTests {
} }
@Test @Test
public void supportsParameter() { void supportsParameter() {
assertThat(this.resolver.supportsParameter(this.paramAnnotated)).isTrue(); assertThat(this.resolver.supportsParameter(this.paramAnnotated)).isTrue();
assertThat(this.resolver.supportsParameter(this.paramNotAnnotated)).isTrue(); assertThat(this.resolver.supportsParameter(this.paramNotAnnotated)).isTrue();
@ -103,7 +103,7 @@ public class PayloadMethodArgumentResolverTests {
} }
@Test @Test
public void resolveRequired() throws Exception { void resolveRequired() throws Exception {
Message<?> message = MessageBuilder.withPayload("ABC".getBytes()).build(); Message<?> message = MessageBuilder.withPayload("ABC".getBytes()).build();
Object actual = this.resolver.resolveArgument(paramAnnotated, message); Object actual = this.resolver.resolveArgument(paramAnnotated, message);
@ -111,7 +111,7 @@ public class PayloadMethodArgumentResolverTests {
} }
@Test @Test
public void resolveRequiredEmpty() { void resolveRequiredEmpty() {
Message<?> message = MessageBuilder.withPayload("").build(); Message<?> message = MessageBuilder.withPayload("").build();
// required but empty // required but empty
assertThatExceptionOfType(MethodArgumentNotValidException.class) assertThatExceptionOfType(MethodArgumentNotValidException.class)
@ -119,7 +119,7 @@ public class PayloadMethodArgumentResolverTests {
} }
@Test @Test
public void resolveRequiredEmptyNonAnnotatedParameter() { void resolveRequiredEmptyNonAnnotatedParameter() {
Message<?> message = MessageBuilder.withPayload("").build(); Message<?> message = MessageBuilder.withPayload("").build();
// required but empty // required but empty
assertThatExceptionOfType(MethodArgumentNotValidException.class) assertThatExceptionOfType(MethodArgumentNotValidException.class)
@ -127,7 +127,7 @@ public class PayloadMethodArgumentResolverTests {
} }
@Test @Test
public void resolveNotRequired() throws Exception { void resolveNotRequired() throws Exception {
Message<?> emptyByteArrayMessage = MessageBuilder.withPayload(new byte[0]).build(); Message<?> emptyByteArrayMessage = MessageBuilder.withPayload(new byte[0]).build();
assertThat(this.resolver.resolveArgument(this.paramAnnotatedNotRequired, emptyByteArrayMessage)).isNull(); assertThat(this.resolver.resolveArgument(this.paramAnnotatedNotRequired, emptyByteArrayMessage)).isNull();
@ -143,7 +143,7 @@ public class PayloadMethodArgumentResolverTests {
} }
@Test @Test
public void resolveOptionalTarget() throws Exception { void resolveOptionalTarget() throws Exception {
Message<?> message = MessageBuilder.withPayload("ABC".getBytes()).build(); Message<?> message = MessageBuilder.withPayload("ABC".getBytes()).build();
Object actual = this.resolver.resolveArgument(paramOptional, message); Object actual = this.resolver.resolveArgument(paramOptional, message);
@ -151,7 +151,7 @@ public class PayloadMethodArgumentResolverTests {
} }
@Test @Test
public void resolveOptionalSource() throws Exception { void resolveOptionalSource() throws Exception {
Message<?> message = MessageBuilder.withPayload(Optional.of("ABC".getBytes())).build(); Message<?> message = MessageBuilder.withPayload(Optional.of("ABC".getBytes())).build();
Object actual = this.resolver.resolveArgument(paramAnnotated, message); Object actual = this.resolver.resolveArgument(paramAnnotated, message);
@ -159,7 +159,7 @@ public class PayloadMethodArgumentResolverTests {
} }
@Test @Test
public void resolveNonConvertibleParam() { void resolveNonConvertibleParam() {
Message<?> notEmptyMessage = MessageBuilder.withPayload(123).build(); Message<?> notEmptyMessage = MessageBuilder.withPayload(123).build();
assertThatExceptionOfType(MessageConversionException.class) assertThatExceptionOfType(MessageConversionException.class)
@ -168,7 +168,7 @@ public class PayloadMethodArgumentResolverTests {
} }
@Test @Test
public void resolveSpelExpressionNotSupported() { void resolveSpelExpressionNotSupported() {
Message<?> message = MessageBuilder.withPayload("ABC".getBytes()).build(); Message<?> message = MessageBuilder.withPayload("ABC".getBytes()).build();
assertThatIllegalStateException() assertThatIllegalStateException()
@ -176,13 +176,13 @@ public class PayloadMethodArgumentResolverTests {
} }
@Test @Test
public void resolveValidation() throws Exception { void resolveValidation() throws Exception {
Message<?> message = MessageBuilder.withPayload("ABC".getBytes()).build(); Message<?> message = MessageBuilder.withPayload("ABC".getBytes()).build();
this.resolver.resolveArgument(this.paramValidated, message); this.resolver.resolveArgument(this.paramValidated, message);
} }
@Test @Test
public void resolveFailValidation() { void resolveFailValidation() {
// See testValidator() // See testValidator()
Message<?> message = MessageBuilder.withPayload("invalidValue".getBytes()).build(); Message<?> message = MessageBuilder.withPayload("invalidValue".getBytes()).build();
@ -191,7 +191,7 @@ public class PayloadMethodArgumentResolverTests {
} }
@Test @Test
public void resolveFailValidationNoConversionNecessary() { void resolveFailValidationNoConversionNecessary() {
Message<?> message = MessageBuilder.withPayload("invalidValue").build(); Message<?> message = MessageBuilder.withPayload("invalidValue").build();
assertThatExceptionOfType(MethodArgumentNotValidException.class) assertThatExceptionOfType(MethodArgumentNotValidException.class)
@ -199,7 +199,7 @@ public class PayloadMethodArgumentResolverTests {
} }
@Test @Test
public void resolveNonAnnotatedParameter() throws Exception { void resolveNonAnnotatedParameter() throws Exception {
Message<?> notEmptyMessage = MessageBuilder.withPayload("ABC".getBytes()).build(); Message<?> notEmptyMessage = MessageBuilder.withPayload("ABC".getBytes()).build();
assertThat(this.resolver.resolveArgument(this.paramNotAnnotated, notEmptyMessage)).isEqualTo("ABC"); assertThat(this.resolver.resolveArgument(this.paramNotAnnotated, notEmptyMessage)).isEqualTo("ABC");
@ -209,7 +209,7 @@ public class PayloadMethodArgumentResolverTests {
} }
@Test @Test
public void resolveNonAnnotatedParameterFailValidation() { void resolveNonAnnotatedParameterFailValidation() {
// See testValidator() // See testValidator()
Message<?> message = MessageBuilder.withPayload("invalidValue".getBytes()).build(); Message<?> message = MessageBuilder.withPayload("invalidValue".getBytes()).build();

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -37,7 +37,7 @@ import static org.mockito.Mockito.mock;
* *
* @author Rossen Stoyanchev * @author Rossen Stoyanchev
*/ */
public class InvocableHandlerMethodTests { class InvocableHandlerMethodTests {
private final Message<?> message = mock(); private final Message<?> message = mock();
@ -45,7 +45,7 @@ public class InvocableHandlerMethodTests {
@Test @Test
public void resolveArg() throws Exception { void resolveArg() throws Exception {
this.resolvers.addResolver(new StubArgumentResolver(99)); this.resolvers.addResolver(new StubArgumentResolver(99));
this.resolvers.addResolver(new StubArgumentResolver("value")); this.resolvers.addResolver(new StubArgumentResolver("value"));
Method method = ResolvableMethod.on(Handler.class).mockCall(c -> c.handle(0, "")).method(); Method method = ResolvableMethod.on(Handler.class).mockCall(c -> c.handle(0, "")).method();
@ -59,7 +59,7 @@ public class InvocableHandlerMethodTests {
} }
@Test @Test
public void resolveNoArgValue() throws Exception { void resolveNoArgValue() throws Exception {
this.resolvers.addResolver(new StubArgumentResolver(Integer.class)); this.resolvers.addResolver(new StubArgumentResolver(Integer.class));
this.resolvers.addResolver(new StubArgumentResolver(String.class)); this.resolvers.addResolver(new StubArgumentResolver(String.class));
Method method = ResolvableMethod.on(Handler.class).mockCall(c -> c.handle(0, "")).method(); Method method = ResolvableMethod.on(Handler.class).mockCall(c -> c.handle(0, "")).method();
@ -71,7 +71,7 @@ public class InvocableHandlerMethodTests {
} }
@Test @Test
public void cannotResolveArg() throws Exception { void cannotResolveArg() {
Method method = ResolvableMethod.on(Handler.class).mockCall(c -> c.handle(0, "")).method(); Method method = ResolvableMethod.on(Handler.class).mockCall(c -> c.handle(0, "")).method();
assertThatExceptionOfType(MethodArgumentResolutionException.class) assertThatExceptionOfType(MethodArgumentResolutionException.class)
.isThrownBy(() -> invoke(new Handler(), method)) .isThrownBy(() -> invoke(new Handler(), method))
@ -79,7 +79,7 @@ public class InvocableHandlerMethodTests {
} }
@Test @Test
public void resolveProvidedArg() throws Exception { void resolveProvidedArg() throws Exception {
Method method = ResolvableMethod.on(Handler.class).mockCall(c -> c.handle(0, "")).method(); Method method = ResolvableMethod.on(Handler.class).mockCall(c -> c.handle(0, "")).method();
Object value = invoke(new Handler(), method, 99, "value"); Object value = invoke(new Handler(), method, 99, "value");
@ -89,7 +89,7 @@ public class InvocableHandlerMethodTests {
} }
@Test @Test
public void resolveProvidedArgFirst() throws Exception { void resolveProvidedArgFirst() throws Exception {
this.resolvers.addResolver(new StubArgumentResolver(1)); this.resolvers.addResolver(new StubArgumentResolver(1));
this.resolvers.addResolver(new StubArgumentResolver("value1")); this.resolvers.addResolver(new StubArgumentResolver("value1"));
Method method = ResolvableMethod.on(Handler.class).mockCall(c -> c.handle(0, "")).method(); Method method = ResolvableMethod.on(Handler.class).mockCall(c -> c.handle(0, "")).method();
@ -99,7 +99,7 @@ public class InvocableHandlerMethodTests {
} }
@Test @Test
public void exceptionInResolvingArg() throws Exception { void exceptionInResolvingArg() {
this.resolvers.addResolver(new ExceptionRaisingArgumentResolver()); this.resolvers.addResolver(new ExceptionRaisingArgumentResolver());
Method method = ResolvableMethod.on(Handler.class).mockCall(c -> c.handle(0, "")).method(); Method method = ResolvableMethod.on(Handler.class).mockCall(c -> c.handle(0, "")).method();
assertThatIllegalArgumentException().isThrownBy(() -> assertThatIllegalArgumentException().isThrownBy(() ->
@ -108,7 +108,7 @@ public class InvocableHandlerMethodTests {
} }
@Test @Test
public void illegalArgumentException() throws Exception { void illegalArgumentException() {
this.resolvers.addResolver(new StubArgumentResolver(Integer.class, "__not_an_int__")); this.resolvers.addResolver(new StubArgumentResolver(Integer.class, "__not_an_int__"));
this.resolvers.addResolver(new StubArgumentResolver("value")); this.resolvers.addResolver(new StubArgumentResolver("value"));
Method method = ResolvableMethod.on(Handler.class).mockCall(c -> c.handle(0, "")).method(); Method method = ResolvableMethod.on(Handler.class).mockCall(c -> c.handle(0, "")).method();
@ -123,7 +123,7 @@ public class InvocableHandlerMethodTests {
} }
@Test @Test
public void invocationTargetException() throws Exception { void invocationTargetException() {
Handler handler = new Handler(); Handler handler = new Handler();
Method method = ResolvableMethod.on(Handler.class).argTypes(Throwable.class).resolveMethod(); Method method = ResolvableMethod.on(Handler.class).argTypes(Throwable.class).resolveMethod();
RuntimeException runtimeException = new RuntimeException("error"); RuntimeException runtimeException = new RuntimeException("error");
@ -146,7 +146,7 @@ public class InvocableHandlerMethodTests {
} }
@Test // Based on SPR-13917 (spring-web) @Test // Based on SPR-13917 (spring-web)
public void invocationErrorMessage() throws Exception { public void invocationErrorMessage() {
this.resolvers.addResolver(new StubArgumentResolver(double.class)); this.resolvers.addResolver(new StubArgumentResolver(double.class));
Method method = ResolvableMethod.on(Handler.class).mockCall(c -> c.handle(0.0)).method(); Method method = ResolvableMethod.on(Handler.class).mockCall(c -> c.handle(0.0)).method();
assertThatIllegalStateException().isThrownBy(() -> assertThatIllegalStateException().isThrownBy(() ->

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2019 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -18,7 +18,6 @@ package org.springframework.messaging.handler.invocation;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator; import java.util.Comparator;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
@ -50,7 +49,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
* @author Brian Clozel * @author Brian Clozel
* @author Rossen Stoyanchev * @author Rossen Stoyanchev
*/ */
public class MethodMessageHandlerTests { class MethodMessageHandlerTests {
private static final String DESTINATION_HEADER = "destination"; private static final String DESTINATION_HEADER = "destination";
@ -60,9 +59,9 @@ public class MethodMessageHandlerTests {
@BeforeEach @BeforeEach
public void setup() { void setup() {
List<String> destinationPrefixes = Arrays.asList("/test"); List<String> destinationPrefixes = List.of("/test");
this.messageHandler = new TestMethodMessageHandler(); this.messageHandler = new TestMethodMessageHandler();
this.messageHandler.setApplicationContext(new StaticApplicationContext()); this.messageHandler.setApplicationContext(new StaticApplicationContext());
@ -74,13 +73,13 @@ public class MethodMessageHandlerTests {
} }
@Test @Test
public void duplicateMapping() { void duplicateMapping() {
assertThatIllegalStateException().isThrownBy(() -> assertThatIllegalStateException().isThrownBy(() ->
this.messageHandler.registerHandler(new DuplicateMappingsController())); this.messageHandler.registerHandler(new DuplicateMappingsController()));
} }
@Test @Test
public void registeredMappings() { void registeredMappings() {
Map<String, HandlerMethod> handlerMethods = this.messageHandler.getHandlerMethods(); Map<String, HandlerMethod> handlerMethods = this.messageHandler.getHandlerMethods();
@ -89,7 +88,7 @@ public class MethodMessageHandlerTests {
} }
@Test @Test
public void patternMatch() throws Exception { void patternMatch() throws Exception {
Method method = this.testController.getClass().getMethod("handlerPathMatchWildcard"); Method method = this.testController.getClass().getMethod("handlerPathMatchWildcard");
this.messageHandler.registerHandlerMethod(this.testController, method, "/handlerPathMatch*"); this.messageHandler.registerHandlerMethod(this.testController, method, "/handlerPathMatch*");
@ -100,7 +99,7 @@ public class MethodMessageHandlerTests {
} }
@Test @Test
public void bestMatch() throws Exception { void bestMatch() throws Exception {
Method method = this.testController.getClass().getMethod("bestMatch"); Method method = this.testController.getClass().getMethod("bestMatch");
this.messageHandler.registerHandlerMethod(this.testController, method, "/bestmatch/{foo}/path"); this.messageHandler.registerHandlerMethod(this.testController, method, "/bestmatch/{foo}/path");
@ -114,7 +113,7 @@ public class MethodMessageHandlerTests {
} }
@Test @Test
public void argumentResolution() { void argumentResolution() {
this.messageHandler.handleMessage(toDestination("/test/handlerArgumentResolver")); this.messageHandler.handleMessage(toDestination("/test/handlerArgumentResolver"));
@ -123,7 +122,7 @@ public class MethodMessageHandlerTests {
} }
@Test @Test
public void handleException() { void handleException() {
this.messageHandler.handleMessage(toDestination("/test/handlerThrowsExc")); this.messageHandler.handleMessage(toDestination("/test/handlerThrowsExc"));
@ -205,8 +204,7 @@ public class MethodMessageHandlerTests {
@Override @Override
protected List<? extends HandlerMethodReturnValueHandler> initReturnValueHandlers() { protected List<? extends HandlerMethodReturnValueHandler> initReturnValueHandlers() {
List<HandlerMethodReturnValueHandler> handlers = new ArrayList<>(getCustomReturnValueHandlers()); return new ArrayList<>(getCustomReturnValueHandlers());
return handlers;
} }
@Override @Override

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2020 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -38,7 +38,7 @@ import static org.springframework.messaging.handler.invocation.ResolvableMethod.
* *
* @author Rossen Stoyanchev * @author Rossen Stoyanchev
*/ */
public class EncoderMethodReturnValueHandlerTests { class EncoderMethodReturnValueHandlerTests {
private final TestEncoderMethodReturnValueHandler handler = new TestEncoderMethodReturnValueHandler( private final TestEncoderMethodReturnValueHandler handler = new TestEncoderMethodReturnValueHandler(
Collections.singletonList(CharSequenceEncoder.textPlainOnly()), Collections.singletonList(CharSequenceEncoder.textPlainOnly()),
@ -48,7 +48,7 @@ public class EncoderMethodReturnValueHandlerTests {
@Test @Test
public void stringReturnValue() { void stringReturnValue() {
MethodParameter parameter = on(TestController.class).resolveReturnType(String.class); MethodParameter parameter = on(TestController.class).resolveReturnType(String.class);
this.handler.handleReturnValue("foo", parameter, this.message).block(); this.handler.handleReturnValue("foo", parameter, this.message).block();
Flux<String> result = this.handler.getContentAsStrings(); Flux<String> result = this.handler.getContentAsStrings();
@ -57,7 +57,7 @@ public class EncoderMethodReturnValueHandlerTests {
} }
@Test @Test
public void objectReturnValue() { void objectReturnValue() {
MethodParameter parameter = on(TestController.class).resolveReturnType(Object.class); MethodParameter parameter = on(TestController.class).resolveReturnType(Object.class);
this.handler.handleReturnValue("foo", parameter, this.message).block(); this.handler.handleReturnValue("foo", parameter, this.message).block();
Flux<String> result = this.handler.getContentAsStrings(); Flux<String> result = this.handler.getContentAsStrings();
@ -66,7 +66,7 @@ public class EncoderMethodReturnValueHandlerTests {
} }
@Test @Test
public void fluxStringReturnValue() { void fluxStringReturnValue() {
MethodParameter parameter = on(TestController.class).resolveReturnType(Flux.class, String.class); MethodParameter parameter = on(TestController.class).resolveReturnType(Flux.class, String.class);
this.handler.handleReturnValue(Flux.just("foo", "bar"), parameter, this.message).block(); this.handler.handleReturnValue(Flux.just("foo", "bar"), parameter, this.message).block();
Flux<String> result = this.handler.getContentAsStrings(); Flux<String> result = this.handler.getContentAsStrings();
@ -75,7 +75,7 @@ public class EncoderMethodReturnValueHandlerTests {
} }
@Test @Test
public void fluxObjectReturnValue() { void fluxObjectReturnValue() {
MethodParameter parameter = on(TestController.class).resolveReturnType(Flux.class, Object.class); MethodParameter parameter = on(TestController.class).resolveReturnType(Flux.class, Object.class);
this.handler.handleReturnValue(Flux.just("foo", "bar"), parameter, this.message).block(); this.handler.handleReturnValue(Flux.just("foo", "bar"), parameter, this.message).block();
Flux<String> result = this.handler.getContentAsStrings(); Flux<String> result = this.handler.getContentAsStrings();
@ -84,7 +84,7 @@ public class EncoderMethodReturnValueHandlerTests {
} }
@Test @Test
public void voidReturnValue() { void voidReturnValue() {
testVoidReturnType(null, on(TestController.class).resolveReturnType(void.class)); testVoidReturnType(null, on(TestController.class).resolveReturnType(void.class));
testVoidReturnType(Mono.empty(), on(TestController.class).resolveReturnType(Mono.class, Void.class)); testVoidReturnType(Mono.empty(), on(TestController.class).resolveReturnType(Mono.class, Void.class));
testVoidReturnType(Completable.complete(), on(TestController.class).resolveReturnType(Completable.class)); testVoidReturnType(Completable.complete(), on(TestController.class).resolveReturnType(Completable.class));
@ -97,7 +97,7 @@ public class EncoderMethodReturnValueHandlerTests {
} }
@Test @Test
public void noEncoder() { void noEncoder() {
MethodParameter parameter = on(TestController.class).resolveReturnType(Object.class); MethodParameter parameter = on(TestController.class).resolveReturnType(Object.class);
StepVerifier.create(this.handler.handleReturnValue(new Object(), parameter, this.message)) StepVerifier.create(this.handler.handleReturnValue(new Object(), parameter, this.message))
.expectErrorMessage("No encoder for java.lang.Object, current value type is class java.lang.Object") .expectErrorMessage("No encoder for java.lang.Object, current value type is class java.lang.Object")

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -44,7 +44,7 @@ import static org.mockito.Mockito.mock;
* @author Rossen Stoyanchev * @author Rossen Stoyanchev
* @author Juergen Hoeller * @author Juergen Hoeller
*/ */
public class InvocableHandlerMethodTests { class InvocableHandlerMethodTests {
private final Message<?> message = mock(); private final Message<?> message = mock();
@ -52,7 +52,7 @@ public class InvocableHandlerMethodTests {
@Test @Test
public void resolveArg() { void resolveArg() {
this.resolvers.add(new StubArgumentResolver(99)); this.resolvers.add(new StubArgumentResolver(99));
this.resolvers.add(new StubArgumentResolver("value")); this.resolvers.add(new StubArgumentResolver("value"));
Method method = ResolvableMethod.on(Handler.class).mockCall(c -> c.handle(0, "")).method(); Method method = ResolvableMethod.on(Handler.class).mockCall(c -> c.handle(0, "")).method();
@ -66,7 +66,7 @@ public class InvocableHandlerMethodTests {
} }
@Test @Test
public void resolveNoArgValue() { void resolveNoArgValue() {
this.resolvers.add(new StubArgumentResolver(Integer.class)); this.resolvers.add(new StubArgumentResolver(Integer.class));
this.resolvers.add(new StubArgumentResolver(String.class)); this.resolvers.add(new StubArgumentResolver(String.class));
Method method = ResolvableMethod.on(Handler.class).mockCall(c -> c.handle(0, "")).method(); Method method = ResolvableMethod.on(Handler.class).mockCall(c -> c.handle(0, "")).method();
@ -78,7 +78,7 @@ public class InvocableHandlerMethodTests {
} }
@Test @Test
public void cannotResolveArg() { void cannotResolveArg() {
Method method = ResolvableMethod.on(Handler.class).mockCall(c -> c.handle(0, "")).method(); Method method = ResolvableMethod.on(Handler.class).mockCall(c -> c.handle(0, "")).method();
assertThatExceptionOfType(MethodArgumentResolutionException.class).isThrownBy(() -> assertThatExceptionOfType(MethodArgumentResolutionException.class).isThrownBy(() ->
invokeAndBlock(new Handler(), method)) invokeAndBlock(new Handler(), method))
@ -86,7 +86,7 @@ public class InvocableHandlerMethodTests {
} }
@Test @Test
public void resolveProvidedArg() { void resolveProvidedArg() {
Method method = ResolvableMethod.on(Handler.class).mockCall(c -> c.handle(0, "")).method(); Method method = ResolvableMethod.on(Handler.class).mockCall(c -> c.handle(0, "")).method();
Object value = invokeAndBlock(new Handler(), method, 99, "value"); Object value = invokeAndBlock(new Handler(), method, 99, "value");
@ -96,7 +96,7 @@ public class InvocableHandlerMethodTests {
} }
@Test @Test
public void resolveProvidedArgFirst() { void resolveProvidedArgFirst() {
this.resolvers.add(new StubArgumentResolver(1)); this.resolvers.add(new StubArgumentResolver(1));
this.resolvers.add(new StubArgumentResolver("value1")); this.resolvers.add(new StubArgumentResolver("value1"));
Method method = ResolvableMethod.on(Handler.class).mockCall(c -> c.handle(0, "")).method(); Method method = ResolvableMethod.on(Handler.class).mockCall(c -> c.handle(0, "")).method();
@ -106,7 +106,7 @@ public class InvocableHandlerMethodTests {
} }
@Test @Test
public void exceptionInResolvingArg() { void exceptionInResolvingArg() {
this.resolvers.add(new InvocableHandlerMethodTests.ExceptionRaisingArgumentResolver()); this.resolvers.add(new InvocableHandlerMethodTests.ExceptionRaisingArgumentResolver());
Method method = ResolvableMethod.on(Handler.class).mockCall(c -> c.handle(0, "")).method(); Method method = ResolvableMethod.on(Handler.class).mockCall(c -> c.handle(0, "")).method();
assertThatIllegalArgumentException().isThrownBy(() -> assertThatIllegalArgumentException().isThrownBy(() ->
@ -114,7 +114,7 @@ public class InvocableHandlerMethodTests {
} }
@Test @Test
public void illegalArgumentException() { void illegalArgumentException() {
this.resolvers.add(new StubArgumentResolver(Integer.class, "__not_an_int__")); this.resolvers.add(new StubArgumentResolver(Integer.class, "__not_an_int__"));
this.resolvers.add(new StubArgumentResolver("value")); this.resolvers.add(new StubArgumentResolver("value"));
Method method = ResolvableMethod.on(Handler.class).mockCall(c -> c.handle(0, "")).method(); Method method = ResolvableMethod.on(Handler.class).mockCall(c -> c.handle(0, "")).method();
@ -129,7 +129,7 @@ public class InvocableHandlerMethodTests {
} }
@Test @Test
public void invocationTargetException() { void invocationTargetException() {
Method method = ResolvableMethod.on(Handler.class).argTypes(Throwable.class).resolveMethod(); Method method = ResolvableMethod.on(Handler.class).argTypes(Throwable.class).resolveMethod();
Throwable expected = new Throwable("error"); Throwable expected = new Throwable("error");
@ -138,7 +138,7 @@ public class InvocableHandlerMethodTests {
} }
@Test @Test
public void voidMethod() { void voidMethod() {
this.resolvers.add(new StubArgumentResolver(double.class, 5.25)); this.resolvers.add(new StubArgumentResolver(double.class, 5.25));
Method method = ResolvableMethod.on(Handler.class).mockCall(c -> c.handle(0.0d)).method(); Method method = ResolvableMethod.on(Handler.class).mockCall(c -> c.handle(0.0d)).method();
Handler handler = new Handler(); Handler handler = new Handler();
@ -151,7 +151,7 @@ public class InvocableHandlerMethodTests {
} }
@Test @Test
public void voidMonoMethod() { void voidMonoMethod() {
Method method = ResolvableMethod.on(Handler.class).mockCall(Handler::handleAsync).method(); Method method = ResolvableMethod.on(Handler.class).mockCall(Handler::handleAsync).method();
Handler handler = new Handler(); Handler handler = new Handler();
Object value = invokeAndBlock(handler, method); Object value = invokeAndBlock(handler, method);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -52,17 +52,17 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
* Unit tests for {@link AbstractMethodMessageHandler}. * Unit tests for {@link AbstractMethodMessageHandler}.
* @author Rossen Stoyanchev * @author Rossen Stoyanchev
*/ */
public class MethodMessageHandlerTests { class MethodMessageHandlerTests {
@Test @Test
public void duplicateMapping() { void duplicateMapping() {
assertThatIllegalStateException().isThrownBy(() -> assertThatIllegalStateException().isThrownBy(() ->
initMethodMessageHandler(DuplicateMappingsController.class)); initMethodMessageHandler(DuplicateMappingsController.class));
} }
@Test @Test
public void registeredMappings() { void registeredMappings() {
TestMethodMessageHandler messageHandler = initMethodMessageHandler(TestController.class); TestMethodMessageHandler messageHandler = initMethodMessageHandler(TestController.class);
Map<String, HandlerMethod> mappings = messageHandler.getHandlerMethods(); Map<String, HandlerMethod> mappings = messageHandler.getHandlerMethods();

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2022 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -53,7 +53,7 @@ import static org.springframework.util.MimeTypeUtils.TEXT_XML;
*/ */
class DefaultMetadataExtractorTests { class DefaultMetadataExtractorTests {
private static MimeType COMPOSITE_METADATA = private static final MimeType COMPOSITE_METADATA =
MimeTypeUtils.parseMimeType(WellKnownMimeType.MESSAGE_RSOCKET_COMPOSITE_METADATA.getString()); MimeTypeUtils.parseMimeType(WellKnownMimeType.MESSAGE_RSOCKET_COMPOSITE_METADATA.getString());

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -64,7 +64,7 @@ import static org.mockito.Mockito.verify;
* *
* @author Brian Clozel * @author Brian Clozel
*/ */
public class DefaultRSocketRequesterBuilderTests { class DefaultRSocketRequesterBuilderTests {
private ClientTransport transport = mock(); private ClientTransport transport = mock();
@ -74,14 +74,13 @@ public class DefaultRSocketRequesterBuilderTests {
@BeforeEach @BeforeEach
public void setup() { void setup() {
given(this.transport.connect()).willReturn(Mono.just(this.connection)); given(this.transport.connect()).willReturn(Mono.just(this.connection));
given(this.transport.maxFrameLength()).willReturn(16777215); given(this.transport.maxFrameLength()).willReturn(16777215);
} }
@Test @Test
@SuppressWarnings("unchecked")
public void rsocketConnectorConfigurer() { public void rsocketConnectorConfigurer() {
Consumer<RSocketStrategies.Builder> strategiesConfigurer = mock(); Consumer<RSocketStrategies.Builder> strategiesConfigurer = mock();
RSocketRequester.builder() RSocketRequester.builder()
@ -96,7 +95,7 @@ public class DefaultRSocketRequesterBuilderTests {
} }
@Test @Test
public void defaultDataMimeType() { void defaultDataMimeType() {
RSocketRequester requester = RSocketRequester.builder().transport(this.transport); RSocketRequester requester = RSocketRequester.builder().transport(this.transport);
assertThat(requester.dataMimeType()) assertThat(requester.dataMimeType())
@ -105,7 +104,7 @@ public class DefaultRSocketRequesterBuilderTests {
} }
@Test @Test
public void defaultDataMimeTypeWithCustomDecoderRegistered() { void defaultDataMimeTypeWithCustomDecoderRegistered() {
RSocketStrategies strategies = RSocketStrategies.builder() RSocketStrategies strategies = RSocketStrategies.builder()
.decoder(new TestJsonDecoder(MimeTypeUtils.APPLICATION_JSON)) .decoder(new TestJsonDecoder(MimeTypeUtils.APPLICATION_JSON))
.build(); .build();
@ -120,7 +119,7 @@ public class DefaultRSocketRequesterBuilderTests {
} }
@Test @Test
public void dataMimeTypeExplicitlySet() { void dataMimeTypeExplicitlySet() {
RSocketRequester requester = RSocketRequester.builder() RSocketRequester requester = RSocketRequester.builder()
.dataMimeType(MimeTypeUtils.APPLICATION_JSON) .dataMimeType(MimeTypeUtils.APPLICATION_JSON)
.transport(this.transport); .transport(this.transport);
@ -132,7 +131,7 @@ public class DefaultRSocketRequesterBuilderTests {
} }
@Test @Test
public void mimeTypesCannotBeChangedAtRSocketConnectorLevel() { void mimeTypesCannotBeChangedAtRSocketConnectorLevel() {
MimeType dataMimeType = MimeTypeUtils.APPLICATION_JSON; MimeType dataMimeType = MimeTypeUtils.APPLICATION_JSON;
MimeType metaMimeType = MimeTypeUtils.parseMimeType(WellKnownMimeType.MESSAGE_RSOCKET_ROUTING.getString()); MimeType metaMimeType = MimeTypeUtils.parseMimeType(WellKnownMimeType.MESSAGE_RSOCKET_ROUTING.getString());
@ -154,7 +153,7 @@ public class DefaultRSocketRequesterBuilderTests {
} }
@Test @Test
public void setupRoute() { void setupRoute() {
RSocketRequester requester = RSocketRequester.builder() RSocketRequester requester = RSocketRequester.builder()
.dataMimeType(MimeTypeUtils.TEXT_PLAIN) .dataMimeType(MimeTypeUtils.TEXT_PLAIN)
.metadataMimeType(MimeTypeUtils.TEXT_PLAIN) .metadataMimeType(MimeTypeUtils.TEXT_PLAIN)
@ -169,7 +168,7 @@ public class DefaultRSocketRequesterBuilderTests {
} }
@Test @Test
public void setupWithAsyncValues() { void setupWithAsyncValues() {
Mono<String> asyncMeta1 = Mono.delay(Duration.ofMillis(1)).map(aLong -> "Async Metadata 1"); Mono<String> asyncMeta1 = Mono.delay(Duration.ofMillis(1)).map(aLong -> "Async Metadata 1");
Mono<String> asyncMeta2 = Mono.delay(Duration.ofMillis(1)).map(aLong -> "Async Metadata 2"); Mono<String> asyncMeta2 = Mono.delay(Duration.ofMillis(1)).map(aLong -> "Async Metadata 2");
@ -199,7 +198,7 @@ public class DefaultRSocketRequesterBuilderTests {
} }
@Test @Test
public void frameDecoderMatchesDataBufferFactory() throws Exception { void frameDecoderMatchesDataBufferFactory() throws Exception {
testPayloadDecoder(new NettyDataBufferFactory(ByteBufAllocator.DEFAULT), PayloadDecoder.ZERO_COPY); testPayloadDecoder(new NettyDataBufferFactory(ByteBufAllocator.DEFAULT), PayloadDecoder.ZERO_COPY);
testPayloadDecoder(DefaultDataBufferFactory.sharedInstance, PayloadDecoder.DEFAULT); testPayloadDecoder(DefaultDataBufferFactory.sharedInstance, PayloadDecoder.DEFAULT);
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -51,7 +51,7 @@ import static org.springframework.util.MimeTypeUtils.TEXT_PLAIN;
* *
* @author Rossen Stoyanchev * @author Rossen Stoyanchev
*/ */
public class DefaultRSocketRequesterTests { class DefaultRSocketRequesterTests {
private static final Duration MILLIS_10 = Duration.ofMillis(10); private static final Duration MILLIS_10 = Duration.ofMillis(10);
@ -64,14 +64,14 @@ public class DefaultRSocketRequesterTests {
@BeforeEach @BeforeEach
public void setUp() { void setUp() {
this.rsocket = new TestRSocket(); this.rsocket = new TestRSocket();
this.requester = RSocketRequester.wrap(this.rsocket, TEXT_PLAIN, TEXT_PLAIN, this.strategies); this.requester = RSocketRequester.wrap(this.rsocket, TEXT_PLAIN, TEXT_PLAIN, this.strategies);
} }
@Test @Test
public void sendMono() { void sendMono() {
// data(Object) // data(Object)
testSendMono(spec -> spec.data("bodyA"), "bodyA"); testSendMono(spec -> spec.data("bodyA"), "bodyA");
@ -95,7 +95,7 @@ public class DefaultRSocketRequesterTests {
} }
@Test @Test
public void sendFlux() { void sendFlux() {
String[] values = new String[] {"bodyA", "bodyB", "bodyC"}; String[] values = new String[] {"bodyA", "bodyB", "bodyC"};
Flux<String> stringFlux = Flux.fromArray(values).delayElements(MILLIS_10); Flux<String> stringFlux = Flux.fromArray(values).delayElements(MILLIS_10);
@ -132,7 +132,7 @@ public class DefaultRSocketRequesterTests {
} }
@Test @Test
public void sendWithoutData() { void sendWithoutData() {
this.requester.route("toA").send().block(Duration.ofSeconds(5)); this.requester.route("toA").send().block(Duration.ofSeconds(5));
assertThat(this.rsocket.getSavedMethodName()).isEqualTo("fireAndForget"); assertThat(this.rsocket.getSavedMethodName()).isEqualTo("fireAndForget");
@ -141,7 +141,7 @@ public class DefaultRSocketRequesterTests {
} }
@Test @Test
public void testSendWithAsyncMetadata() { void testSendWithAsyncMetadata() {
MimeType compositeMimeType = MimeType compositeMimeType =
MimeTypeUtils.parseMimeType(WellKnownMimeType.MESSAGE_RSOCKET_COMPOSITE_METADATA.getString()); MimeTypeUtils.parseMimeType(WellKnownMimeType.MESSAGE_RSOCKET_COMPOSITE_METADATA.getString());
@ -171,7 +171,7 @@ public class DefaultRSocketRequesterTests {
} }
@Test @Test
public void retrieveMono() { void retrieveMono() {
String value = "bodyA"; String value = "bodyA";
this.rsocket.setPayloadMonoToReturn(Mono.delay(MILLIS_10).thenReturn(toPayload(value))); this.rsocket.setPayloadMonoToReturn(Mono.delay(MILLIS_10).thenReturn(toPayload(value)));
Mono<String> response = this.requester.route("").data("").retrieveMono(String.class); Mono<String> response = this.requester.route("").data("").retrieveMono(String.class);
@ -181,7 +181,7 @@ public class DefaultRSocketRequesterTests {
} }
@Test @Test
public void retrieveMonoVoid() { void retrieveMonoVoid() {
AtomicBoolean consumed = new AtomicBoolean(); AtomicBoolean consumed = new AtomicBoolean();
Mono<Payload> mono = Mono.delay(MILLIS_10).thenReturn(toPayload("bodyA")).doOnSuccess(p -> consumed.set(true)); Mono<Payload> mono = Mono.delay(MILLIS_10).thenReturn(toPayload("bodyA")).doOnSuccess(p -> consumed.set(true));
this.rsocket.setPayloadMonoToReturn(mono); this.rsocket.setPayloadMonoToReturn(mono);
@ -192,7 +192,7 @@ public class DefaultRSocketRequesterTests {
} }
@Test @Test
public void retrieveMonoWithoutData() { void retrieveMonoWithoutData() {
this.requester.route("toA").retrieveMono(String.class).block(Duration.ofSeconds(5)); this.requester.route("toA").retrieveMono(String.class).block(Duration.ofSeconds(5));
assertThat(this.rsocket.getSavedMethodName()).isEqualTo("requestResponse"); assertThat(this.rsocket.getSavedMethodName()).isEqualTo("requestResponse");
@ -201,7 +201,7 @@ public class DefaultRSocketRequesterTests {
} }
@Test @Test
public void retrieveFlux() { void retrieveFlux() {
String[] values = new String[] {"bodyA", "bodyB", "bodyC"}; String[] values = new String[] {"bodyA", "bodyB", "bodyC"};
this.rsocket.setPayloadFluxToReturn(Flux.fromArray(values).delayElements(MILLIS_10).map(this::toPayload)); this.rsocket.setPayloadFluxToReturn(Flux.fromArray(values).delayElements(MILLIS_10).map(this::toPayload));
Flux<String> response = this.requester.route("").data("").retrieveFlux(String.class); Flux<String> response = this.requester.route("").data("").retrieveFlux(String.class);
@ -211,7 +211,7 @@ public class DefaultRSocketRequesterTests {
} }
@Test @Test
public void retrieveFluxVoid() { void retrieveFluxVoid() {
AtomicBoolean consumed = new AtomicBoolean(); AtomicBoolean consumed = new AtomicBoolean();
Flux<Payload> flux = Flux.just("bodyA", "bodyB") Flux<Payload> flux = Flux.just("bodyA", "bodyB")
.delayElements(MILLIS_10).map(this::toPayload).doOnComplete(() -> consumed.set(true)); .delayElements(MILLIS_10).map(this::toPayload).doOnComplete(() -> consumed.set(true));
@ -223,7 +223,7 @@ public class DefaultRSocketRequesterTests {
} }
@Test @Test
public void retrieveFluxWithoutData() { void retrieveFluxWithoutData() {
this.requester.route("toA").retrieveFlux(String.class).blockLast(Duration.ofSeconds(5)); this.requester.route("toA").retrieveFlux(String.class).blockLast(Duration.ofSeconds(5));
assertThat(this.rsocket.getSavedMethodName()).isEqualTo("requestStream"); assertThat(this.rsocket.getSavedMethodName()).isEqualTo("requestStream");
@ -232,7 +232,7 @@ public class DefaultRSocketRequesterTests {
} }
@Test @Test
public void fluxToMonoIsRejected() { void fluxToMonoIsRejected() {
assertThatIllegalStateException() assertThatIllegalStateException()
.isThrownBy(() -> this.requester.route("").data(Flux.just("a", "b")).retrieveMono(String.class)) .isThrownBy(() -> this.requester.route("").data(Flux.just("a", "b")).retrieveMono(String.class))
.withMessage("No RSocket interaction with Flux request and Mono response."); .withMessage("No RSocket interaction with Flux request and Mono response.");

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -108,7 +108,6 @@ class DefaultRSocketStrategiesTests {
} }
@Test @Test
@SuppressWarnings("unchecked")
void applyMetadataExtractors() { void applyMetadataExtractors() {
Consumer<MetadataExtractorRegistry> consumer = mock(); Consumer<MetadataExtractorRegistry> consumer = mock();
RSocketStrategies.builder().metadataExtractorRegistry(consumer).build(); RSocketStrategies.builder().metadataExtractorRegistry(consumer).build();

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2022 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -106,7 +106,7 @@ public class LeakAwareNettyDataBufferFactory extends NettyDataBufferFactory {
} }
private static record DataBufferLeakInfo(DataBuffer dataBuffer, AssertionError error) { private record DataBufferLeakInfo(DataBuffer dataBuffer, AssertionError error) {
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -47,7 +47,7 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy;
*/ */
class MetadataEncoderTests { class MetadataEncoderTests {
private static MimeType COMPOSITE_METADATA = private static final MimeType COMPOSITE_METADATA =
MimeTypeUtils.parseMimeType(WellKnownMimeType.MESSAGE_RSOCKET_COMPOSITE_METADATA.getString()); MimeTypeUtils.parseMimeType(WellKnownMimeType.MESSAGE_RSOCKET_COMPOSITE_METADATA.getString());

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2022 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -43,7 +43,7 @@ import static org.assertj.core.api.Assertions.assertThat;
*/ */
class PayloadUtilsTests { class PayloadUtilsTests {
private LeakAwareNettyDataBufferFactory nettyBufferFactory = private final LeakAwareNettyDataBufferFactory nettyBufferFactory =
new LeakAwareNettyDataBufferFactory(PooledByteBufAllocator.DEFAULT); new LeakAwareNettyDataBufferFactory(PooledByteBufAllocator.DEFAULT);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -157,7 +157,7 @@ class RSocketBufferLeakTests {
} }
@Test @Test
public void echoChannel() { void echoChannel() {
Flux<String> result = requester.route("echo-channel") Flux<String> result = requester.route("echo-channel")
.data(Flux.range(1, 10).map(i -> "Hello " + i), String.class) .data(Flux.range(1, 10).map(i -> "Hello " + i), String.class)
.retrieveFlux(String.class); .retrieveFlux(String.class);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -58,7 +58,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Rossen Stoyanchev * @author Rossen Stoyanchev
* @author Sebastien Deleuze * @author Sebastien Deleuze
*/ */
public class RSocketClientToServerIntegrationTests { class RSocketClientToServerIntegrationTests {
private static final MimeType FOO_MIME_TYPE = MimeTypeUtils.parseMimeType("messaging/x.foo"); private static final MimeType FOO_MIME_TYPE = MimeTypeUtils.parseMimeType("messaging/x.foo");
@ -103,7 +103,7 @@ public class RSocketClientToServerIntegrationTests {
@Test @Test
public void fireAndForget() { void fireAndForget() {
Flux.range(1, 3) Flux.range(1, 3)
.delayElements(Duration.ofMillis(10)) .delayElements(Duration.ofMillis(10))
.concatMap(i -> requester.route("receive").data("Hello " + i).send()) .concatMap(i -> requester.route("receive").data("Hello " + i).send())
@ -123,7 +123,7 @@ public class RSocketClientToServerIntegrationTests {
} }
@Test @Test
public void echo() { void echo() {
Flux<String> result = Flux.range(1, 3).concatMap(i -> Flux<String> result = Flux.range(1, 3).concatMap(i ->
requester.route("echo").data("Hello " + i).retrieveMono(String.class)); requester.route("echo").data("Hello " + i).retrieveMono(String.class));
@ -134,7 +134,7 @@ public class RSocketClientToServerIntegrationTests {
} }
@Test @Test
public void echoAsync() { void echoAsync() {
Flux<String> result = Flux.range(1, 3).concatMap(i -> Flux<String> result = Flux.range(1, 3).concatMap(i ->
requester.route("echo-async").data("Hello " + i).retrieveMono(String.class)); requester.route("echo-async").data("Hello " + i).retrieveMono(String.class));
@ -145,7 +145,7 @@ public class RSocketClientToServerIntegrationTests {
} }
@Test @Test
public void echoStream() { void echoStream() {
Flux<String> result = requester.route("echo-stream").data("Hello").retrieveFlux(String.class); Flux<String> result = requester.route("echo-stream").data("Hello").retrieveFlux(String.class);
StepVerifier.create(result) StepVerifier.create(result)
@ -155,7 +155,7 @@ public class RSocketClientToServerIntegrationTests {
} }
@Test @Test
public void echoChannel() { void echoChannel() {
Flux<String> result = requester.route("echo-channel") Flux<String> result = requester.route("echo-channel")
.data(Flux.range(1, 10).map(i -> "Hello " + i), String.class) .data(Flux.range(1, 10).map(i -> "Hello " + i), String.class)
.retrieveFlux(String.class); .retrieveFlux(String.class);
@ -173,7 +173,7 @@ public class RSocketClientToServerIntegrationTests {
} }
@Test @Test
public void metadataPush() { void metadataPush() {
Flux.just("bar", "baz") Flux.just("bar", "baz")
.delayElements(Duration.ofMillis(10)) .delayElements(Duration.ofMillis(10))
.concatMap(s -> requester.route("foo-updates").metadata(s, FOO_MIME_TYPE).sendMetadata()) .concatMap(s -> requester.route("foo-updates").metadata(s, FOO_MIME_TYPE).sendMetadata())
@ -192,19 +192,19 @@ public class RSocketClientToServerIntegrationTests {
} }
@Test @Test
public void voidReturnValue() { void voidReturnValue() {
Mono<String> result = requester.route("void-return-value").data("Hello").retrieveMono(String.class); Mono<String> result = requester.route("void-return-value").data("Hello").retrieveMono(String.class);
StepVerifier.create(result).expectComplete().verify(Duration.ofSeconds(5)); StepVerifier.create(result).expectComplete().verify(Duration.ofSeconds(5));
} }
@Test @Test
public void voidReturnValueFromExceptionHandler() { void voidReturnValueFromExceptionHandler() {
Mono<String> result = requester.route("void-return-value").data("bad").retrieveMono(String.class); Mono<String> result = requester.route("void-return-value").data("bad").retrieveMono(String.class);
StepVerifier.create(result).expectComplete().verify(Duration.ofSeconds(5)); StepVerifier.create(result).expectComplete().verify(Duration.ofSeconds(5));
} }
@Test @Test
public void handleWithThrownException() { void handleWithThrownException() {
Mono<String> result = requester.route("thrown-exception").data("a").retrieveMono(String.class); Mono<String> result = requester.route("thrown-exception").data("a").retrieveMono(String.class);
StepVerifier.create(result) StepVerifier.create(result)
.expectNext("Invalid input error handled") .expectNext("Invalid input error handled")
@ -213,7 +213,7 @@ public class RSocketClientToServerIntegrationTests {
} }
@Test @Test
public void handleWithErrorSignal() { void handleWithErrorSignal() {
Mono<String> result = requester.route("error-signal").data("a").retrieveMono(String.class); Mono<String> result = requester.route("error-signal").data("a").retrieveMono(String.class);
StepVerifier.create(result) StepVerifier.create(result)
.expectNext("Invalid input error handled") .expectNext("Invalid input error handled")
@ -222,7 +222,7 @@ public class RSocketClientToServerIntegrationTests {
} }
@Test @Test
public void noMatchingRoute() { void noMatchingRoute() {
Mono<String> result = requester.route("invalid").data("anything").retrieveMono(String.class); Mono<String> result = requester.route("invalid").data("anything").retrieveMono(String.class);
StepVerifier.create(result) StepVerifier.create(result)
.expectErrorMessage("No handler for destination 'invalid'") .expectErrorMessage("No handler for destination 'invalid'")

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2020 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -121,7 +121,7 @@ class RSocketServerToClientIntegrationTests {
@Controller @Controller
@SuppressWarnings({"unused", "NullableProblems"}) @SuppressWarnings("unused")
static class ServerController { static class ServerController {
// Must be initialized by @Test method... // Must be initialized by @Test method...

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2019 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -33,14 +33,14 @@ import static org.springframework.messaging.rsocket.annotation.support.RSocketFr
* Unit tests for {@link RSocketFrameTypeMessageCondition}. * Unit tests for {@link RSocketFrameTypeMessageCondition}.
* @author Rossen Stoyanchev * @author Rossen Stoyanchev
*/ */
public class RSocketFrameTypeMessageConditionTests { class RSocketFrameTypeMessageConditionTests {
private static final RSocketFrameTypeMessageCondition FNF_RR_CONDITION = private static final RSocketFrameTypeMessageCondition FNF_RR_CONDITION =
new RSocketFrameTypeMessageCondition(FrameType.REQUEST_FNF, FrameType.REQUEST_RESPONSE); new RSocketFrameTypeMessageCondition(FrameType.REQUEST_FNF, FrameType.REQUEST_RESPONSE);
@Test @Test
public void getMatchingCondition() { void getMatchingCondition() {
Message<?> message = message(FrameType.REQUEST_RESPONSE); Message<?> message = message(FrameType.REQUEST_RESPONSE);
RSocketFrameTypeMessageCondition actual = FNF_RR_CONDITION.getMatchingCondition(message); RSocketFrameTypeMessageCondition actual = FNF_RR_CONDITION.getMatchingCondition(message);
@ -49,7 +49,7 @@ public class RSocketFrameTypeMessageConditionTests {
} }
@Test @Test
public void getMatchingConditionEmpty() { void getMatchingConditionEmpty() {
Message<?> message = message(FrameType.REQUEST_RESPONSE); Message<?> message = message(FrameType.REQUEST_RESPONSE);
RSocketFrameTypeMessageCondition actual = EMPTY_CONDITION.getMatchingCondition(message); RSocketFrameTypeMessageCondition actual = EMPTY_CONDITION.getMatchingCondition(message);
@ -57,7 +57,7 @@ public class RSocketFrameTypeMessageConditionTests {
} }
@Test @Test
public void combine() { void combine() {
assertThat(EMPTY_CONDITION.combine(CONNECT_CONDITION).getFrameTypes()) assertThat(EMPTY_CONDITION.combine(CONNECT_CONDITION).getFrameTypes())
.containsExactly(FrameType.SETUP, FrameType.METADATA_PUSH); .containsExactly(FrameType.SETUP, FrameType.METADATA_PUSH);
@ -67,7 +67,7 @@ public class RSocketFrameTypeMessageConditionTests {
} }
@Test @Test
public void compareTo() { void compareTo() {
Message<byte[]> message = message(null); Message<byte[]> message = message(null);
assertThat(condition(FrameType.SETUP).compareTo(condition(FrameType.SETUP), message)).isEqualTo(0); assertThat(condition(FrameType.SETUP).compareTo(condition(FrameType.SETUP), message)).isEqualTo(0);
assertThat(condition(FrameType.SETUP).compareTo(condition(FrameType.METADATA_PUSH), message)).isEqualTo(0); assertThat(condition(FrameType.SETUP).compareTo(condition(FrameType.METADATA_PUSH), message)).isEqualTo(0);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2019 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -56,10 +56,10 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy;
* @author Rossen Stoyanchev * @author Rossen Stoyanchev
* @since 5.2 * @since 5.2
*/ */
public class RSocketMessageHandlerTests { class RSocketMessageHandlerTests {
@Test @Test
public void getRSocketStrategies() { void getRSocketStrategies() {
RSocketMessageHandler handler = new RSocketMessageHandler(); RSocketMessageHandler handler = new RSocketMessageHandler();
handler.setDecoders(Collections.singletonList(new ByteArrayDecoder())); handler.setDecoders(Collections.singletonList(new ByteArrayDecoder()));
handler.setEncoders(Collections.singletonList(new ByteArrayEncoder())); handler.setEncoders(Collections.singletonList(new ByteArrayEncoder()));
@ -77,7 +77,7 @@ public class RSocketMessageHandlerTests {
} }
@Test @Test
public void setRSocketStrategies() { void setRSocketStrategies() {
RSocketStrategies strategies = RSocketStrategies.builder() RSocketStrategies strategies = RSocketStrategies.builder()
.encoder(new ByteArrayEncoder()) .encoder(new ByteArrayEncoder())
.decoder(new ByteArrayDecoder()) .decoder(new ByteArrayDecoder())
@ -97,7 +97,7 @@ public class RSocketMessageHandlerTests {
} }
@Test @Test
public void getRSocketStrategiesReflectsCurrentState() { void getRSocketStrategiesReflectsCurrentState() {
RSocketMessageHandler handler = new RSocketMessageHandler(); RSocketMessageHandler handler = new RSocketMessageHandler();
@ -132,7 +132,7 @@ public class RSocketMessageHandlerTests {
} }
@Test @Test
public void metadataExtractorWithExplicitlySetDecoders() { void metadataExtractorWithExplicitlySetDecoders() {
DefaultMetadataExtractor extractor = new DefaultMetadataExtractor(StringDecoder.allMimeTypes()); DefaultMetadataExtractor extractor = new DefaultMetadataExtractor(StringDecoder.allMimeTypes());
RSocketMessageHandler handler = new RSocketMessageHandler(); RSocketMessageHandler handler = new RSocketMessageHandler();
@ -145,7 +145,7 @@ public class RSocketMessageHandlerTests {
} }
@Test @Test
public void mappings() { void mappings() {
testMapping(new SimpleController(), "path"); testMapping(new SimpleController(), "path");
testMapping(new TypeLevelMappingController(), "base.path"); testMapping(new TypeLevelMappingController(), "base.path");
testMapping(new HandleAllController()); testMapping(new HandleAllController());
@ -175,7 +175,7 @@ public class RSocketMessageHandlerTests {
} }
@Test @Test
public void rejectConnectMappingMethodsThatCanReply() { void rejectConnectMappingMethodsThatCanReply() {
RSocketMessageHandler handler = new RSocketMessageHandler(); RSocketMessageHandler handler = new RSocketMessageHandler();
handler.setHandlers(Collections.singletonList(new InvalidConnectMappingController())); handler.setHandlers(Collections.singletonList(new InvalidConnectMappingController()));
@ -196,7 +196,7 @@ public class RSocketMessageHandlerTests {
} }
@Test @Test
public void ignoreFireAndForgetToHandlerThatCanReply() { void ignoreFireAndForgetToHandlerThatCanReply() {
InteractionMismatchController controller = new InteractionMismatchController(); InteractionMismatchController controller = new InteractionMismatchController();
@ -217,7 +217,7 @@ public class RSocketMessageHandlerTests {
} }
@Test @Test
public void rejectRequestResponseToStreamingHandler() { void rejectRequestResponseToStreamingHandler() {
RSocketMessageHandler handler = new RSocketMessageHandler(); RSocketMessageHandler handler = new RSocketMessageHandler();
handler.setHandlers(Collections.singletonList(new InteractionMismatchController())); handler.setHandlers(Collections.singletonList(new InteractionMismatchController()));
@ -238,7 +238,7 @@ public class RSocketMessageHandlerTests {
} }
@Test @Test
public void handleNoMatch() { void handleNoMatch() {
testHandleNoMatch(FrameType.SETUP); testHandleNoMatch(FrameType.SETUP);
testHandleNoMatch(FrameType.METADATA_PUSH); testHandleNoMatch(FrameType.METADATA_PUSH);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2022 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -30,7 +30,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* Unit tests for {@link DestinationVariableArgumentResolver}. * Unit tests for {@link DestinationVariableArgumentResolver}.
* @author Rossen Stoyanchev * @author Rossen Stoyanchev
*/ */
public class DestinationVariableArgumentResolverTests extends RSocketServiceArgumentResolverTestSupport { class DestinationVariableArgumentResolverTests extends RSocketServiceArgumentResolverTestSupport {
@Override @Override
protected RSocketServiceArgumentResolver initResolver() { protected RSocketServiceArgumentResolver initResolver() {

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2022 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -31,7 +31,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* Unit tests for {@link MetadataArgumentResolver}. * Unit tests for {@link MetadataArgumentResolver}.
* @author Rossen Stoyanchev * @author Rossen Stoyanchev
*/ */
public class MetadataArgumentResolverTests extends RSocketServiceArgumentResolverTestSupport { class MetadataArgumentResolverTests extends RSocketServiceArgumentResolverTestSupport {
@Override @Override
protected RSocketServiceArgumentResolver initResolver() { protected RSocketServiceArgumentResolver initResolver() {

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2022 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -34,7 +34,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException
* Unit tests for {@link PayloadArgumentResolver}. * Unit tests for {@link PayloadArgumentResolver}.
* @author Rossen Stoyanchev * @author Rossen Stoyanchev
*/ */
public class PayloadArgumentResolverTests extends RSocketServiceArgumentResolverTestSupport { class PayloadArgumentResolverTests extends RSocketServiceArgumentResolverTestSupport {
@Override @Override
protected RSocketServiceArgumentResolver initResolver() { protected RSocketServiceArgumentResolver initResolver() {

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2022 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -30,7 +30,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException
* Unit tests for {@link RSocketRequestValues}. * Unit tests for {@link RSocketRequestValues}.
* @author Rossen Stoyanchev * @author Rossen Stoyanchev
*/ */
public class RSocketRequestValuesTests { class RSocketRequestValuesTests {
@Test @Test
void route() { void route() {

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2022 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -39,7 +39,7 @@ import static org.springframework.util.MimeTypeUtils.TEXT_PLAIN;
* *
* @author Rossen Stoyanchev * @author Rossen Stoyanchev
*/ */
public class RSocketServiceMethodTests { class RSocketServiceMethodTests {
private TestRSocket rsocket; private TestRSocket rsocket;
@ -47,7 +47,7 @@ public class RSocketServiceMethodTests {
@BeforeEach @BeforeEach
public void setUp() { void setUp() {
this.rsocket = new TestRSocket(); this.rsocket = new TestRSocket();
RSocketRequester requester = RSocketRequester.wrap(this.rsocket, TEXT_PLAIN, TEXT_PLAIN, RSocketStrategies.create()); RSocketRequester requester = RSocketRequester.wrap(this.rsocket, TEXT_PLAIN, TEXT_PLAIN, RSocketStrategies.create());
this.proxyFactory = RSocketServiceProxyFactory.builder(requester).build(); this.proxyFactory = RSocketServiceProxyFactory.builder(requester).build();

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2019 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -42,25 +42,25 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
* @author Rossen Stoyanchev * @author Rossen Stoyanchev
* @since 4.1 * @since 4.1
*/ */
public class SimpAttributesContextHolderTests { class SimpAttributesContextHolderTests {
private SimpAttributes simpAttributes; private SimpAttributes simpAttributes;
@BeforeEach @BeforeEach
public void setUp() { void setUp() {
Map<String, Object> map = new ConcurrentHashMap<>(); Map<String, Object> map = new ConcurrentHashMap<>();
this.simpAttributes = new SimpAttributes("session1", map); this.simpAttributes = new SimpAttributes("session1", map);
} }
@AfterEach @AfterEach
public void tearDown() { void tearDown() {
SimpAttributesContextHolder.resetAttributes(); SimpAttributesContextHolder.resetAttributes();
} }
@Test @Test
public void resetAttributes() { void resetAttributes() {
SimpAttributesContextHolder.setAttributes(this.simpAttributes); SimpAttributesContextHolder.setAttributes(this.simpAttributes);
assertThat(SimpAttributesContextHolder.getAttributes()).isSameAs(this.simpAttributes); assertThat(SimpAttributesContextHolder.getAttributes()).isSameAs(this.simpAttributes);
@ -69,7 +69,7 @@ public class SimpAttributesContextHolderTests {
} }
@Test @Test
public void getAttributes() { void getAttributes() {
assertThat(SimpAttributesContextHolder.getAttributes()).isNull(); assertThat(SimpAttributesContextHolder.getAttributes()).isNull();
SimpAttributesContextHolder.setAttributes(this.simpAttributes); SimpAttributesContextHolder.setAttributes(this.simpAttributes);
@ -77,7 +77,7 @@ public class SimpAttributesContextHolderTests {
} }
@Test @Test
public void setAttributes() { void setAttributes() {
SimpAttributesContextHolder.setAttributes(this.simpAttributes); SimpAttributesContextHolder.setAttributes(this.simpAttributes);
assertThat(SimpAttributesContextHolder.getAttributes()).isSameAs(this.simpAttributes); assertThat(SimpAttributesContextHolder.getAttributes()).isSameAs(this.simpAttributes);
@ -86,7 +86,7 @@ public class SimpAttributesContextHolderTests {
} }
@Test @Test
public void setAttributesFromMessage() { void setAttributesFromMessage() {
String sessionId = "session1"; String sessionId = "session1";
ConcurrentHashMap<String, Object> map = new ConcurrentHashMap<>(); ConcurrentHashMap<String, Object> map = new ConcurrentHashMap<>();
@ -107,14 +107,14 @@ public class SimpAttributesContextHolderTests {
} }
@Test @Test
public void setAttributesFromMessageWithMissingSessionId() { void setAttributesFromMessageWithMissingSessionId() {
assertThatIllegalStateException().isThrownBy(() -> assertThatIllegalStateException().isThrownBy(() ->
SimpAttributesContextHolder.setAttributesFromMessage(new GenericMessage<Object>(""))) SimpAttributesContextHolder.setAttributesFromMessage(new GenericMessage<Object>("")))
.withMessageStartingWith("No session id in"); .withMessageStartingWith("No session id in");
} }
@Test @Test
public void setAttributesFromMessageWithMissingSessionAttributes() { void setAttributesFromMessageWithMissingSessionAttributes() {
SimpMessageHeaderAccessor headerAccessor = SimpMessageHeaderAccessor.create(); SimpMessageHeaderAccessor headerAccessor = SimpMessageHeaderAccessor.create();
headerAccessor.setSessionId("session1"); headerAccessor.setSessionId("session1");
Message<?> message = MessageBuilder.createMessage("", headerAccessor.getMessageHeaders()); Message<?> message = MessageBuilder.createMessage("", headerAccessor.getMessageHeaders());
@ -124,13 +124,13 @@ public class SimpAttributesContextHolderTests {
} }
@Test @Test
public void currentAttributes() { void currentAttributes() {
SimpAttributesContextHolder.setAttributes(this.simpAttributes); SimpAttributesContextHolder.setAttributes(this.simpAttributes);
assertThat(SimpAttributesContextHolder.currentAttributes()).isSameAs(this.simpAttributes); assertThat(SimpAttributesContextHolder.currentAttributes()).isSameAs(this.simpAttributes);
} }
@Test @Test
public void currentAttributesNone() { void currentAttributesNone() {
assertThatIllegalStateException().isThrownBy(SimpAttributesContextHolder::currentAttributes) assertThatIllegalStateException().isThrownBy(SimpAttributesContextHolder::currentAttributes)
.withMessageStartingWith("No thread-bound SimpAttributes found"); .withMessageStartingWith("No thread-bound SimpAttributes found");
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -33,7 +33,7 @@ import static org.mockito.Mockito.verify;
* @author Rossen Stoyanchev * @author Rossen Stoyanchev
* @since 4.1 * @since 4.1
*/ */
public class SimpAttributesTests { class SimpAttributesTests {
private final Map<String, Object> map = new ConcurrentHashMap<>(); private final Map<String, Object> map = new ConcurrentHashMap<>();
@ -41,7 +41,7 @@ public class SimpAttributesTests {
@Test @Test
public void getAttribute() { void getAttribute() {
this.simpAttributes.setAttribute("name1", "value1"); this.simpAttributes.setAttribute("name1", "value1");
assertThat(this.simpAttributes.getAttribute("name1")).isEqualTo("value1"); assertThat(this.simpAttributes.getAttribute("name1")).isEqualTo("value1");
@ -49,7 +49,7 @@ public class SimpAttributesTests {
} }
@Test @Test
public void getAttributeNames() { void getAttributeNames() {
this.simpAttributes.setAttribute("name1", "value1"); this.simpAttributes.setAttribute("name1", "value1");
this.simpAttributes.setAttribute("name2", "value1"); this.simpAttributes.setAttribute("name2", "value1");
this.simpAttributes.setAttribute("name3", "value1"); this.simpAttributes.setAttribute("name3", "value1");
@ -59,7 +59,7 @@ public class SimpAttributesTests {
} }
@Test @Test
public void registerDestructionCallback() { void registerDestructionCallback() {
Runnable callback = mock(); Runnable callback = mock();
this.simpAttributes.registerDestructionCallback("name1", callback); this.simpAttributes.registerDestructionCallback("name1", callback);
@ -68,7 +68,7 @@ public class SimpAttributesTests {
} }
@Test @Test
public void registerDestructionCallbackAfterSessionCompleted() { void registerDestructionCallbackAfterSessionCompleted() {
this.simpAttributes.sessionCompleted(); this.simpAttributes.sessionCompleted();
assertThatIllegalStateException() assertThatIllegalStateException()
.isThrownBy(() -> this.simpAttributes.registerDestructionCallback("name1", mock())) .isThrownBy(() -> this.simpAttributes.registerDestructionCallback("name1", mock()))
@ -76,7 +76,7 @@ public class SimpAttributesTests {
} }
@Test @Test
public void removeDestructionCallback() { void removeDestructionCallback() {
Runnable callback1 = mock(); Runnable callback1 = mock();
Runnable callback2 = mock(); Runnable callback2 = mock();
this.simpAttributes.registerDestructionCallback("name1", callback1); this.simpAttributes.registerDestructionCallback("name1", callback1);
@ -86,12 +86,12 @@ public class SimpAttributesTests {
} }
@Test @Test
public void getSessionMutex() { void getSessionMutex() {
assertThat(this.simpAttributes.getSessionMutex()).isSameAs(this.map); assertThat(this.simpAttributes.getSessionMutex()).isSameAs(this.map);
} }
@Test @Test
public void getSessionMutexExplicit() { void getSessionMutexExplicit() {
Object mutex = new Object(); Object mutex = new Object();
this.simpAttributes.setAttribute(SimpAttributes.SESSION_MUTEX_NAME, mutex); this.simpAttributes.setAttribute(SimpAttributes.SESSION_MUTEX_NAME, mutex);
@ -99,7 +99,7 @@ public class SimpAttributesTests {
} }
@Test @Test
public void sessionCompleted() { void sessionCompleted() {
Runnable callback1 = mock(); Runnable callback1 = mock();
Runnable callback2 = mock(); Runnable callback2 = mock();
this.simpAttributes.registerDestructionCallback("name1", callback1); this.simpAttributes.registerDestructionCallback("name1", callback1);
@ -112,7 +112,7 @@ public class SimpAttributesTests {
} }
@Test @Test
public void sessionCompletedIsIdempotent() { void sessionCompletedIsIdempotent() {
Runnable callback1 = mock(); Runnable callback1 = mock();
this.simpAttributes.registerDestructionCallback("name1", callback1); this.simpAttributes.registerDestructionCallback("name1", callback1);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -32,23 +32,23 @@ import static org.mockito.Mockito.mock;
* *
* @author Rossen Stoyanchev * @author Rossen Stoyanchev
*/ */
public class SimpMessageHeaderAccessorTests { class SimpMessageHeaderAccessorTests {
@Test @Test
public void getShortLogMessage() { void getShortLogMessage() {
assertThat(SimpMessageHeaderAccessor.create().getShortLogMessage("p")) assertThat(SimpMessageHeaderAccessor.create().getShortLogMessage("p"))
.isEqualTo("MESSAGE session=null payload=p"); .isEqualTo("MESSAGE session=null payload=p");
} }
@Test @Test
public void getLogMessageWithValuesSet() { void getLogMessageWithValuesSet() {
SimpMessageHeaderAccessor accessor = SimpMessageHeaderAccessor.create(); SimpMessageHeaderAccessor accessor = SimpMessageHeaderAccessor.create();
accessor.setDestination("/destination"); accessor.setDestination("/destination");
accessor.setSubscriptionId("subscription"); accessor.setSubscriptionId("subscription");
accessor.setSessionId("session"); accessor.setSessionId("session");
accessor.setUser(new TestPrincipal("user")); accessor.setUser(new TestPrincipal("user"));
accessor.setSessionAttributes(Collections.<String, Object>singletonMap("key", "value")); accessor.setSessionAttributes(Collections.singletonMap("key", "value"));
assertThat(accessor.getShortLogMessage("p")) assertThat(accessor.getShortLogMessage("p"))
.isEqualTo(("MESSAGE destination=/destination subscriptionId=subscription " + .isEqualTo(("MESSAGE destination=/destination subscriptionId=subscription " +
@ -56,13 +56,13 @@ public class SimpMessageHeaderAccessorTests {
} }
@Test @Test
public void getDetailedLogMessageWithValuesSet() { void getDetailedLogMessageWithValuesSet() {
SimpMessageHeaderAccessor accessor = SimpMessageHeaderAccessor.create(); SimpMessageHeaderAccessor accessor = SimpMessageHeaderAccessor.create();
accessor.setDestination("/destination"); accessor.setDestination("/destination");
accessor.setSubscriptionId("subscription"); accessor.setSubscriptionId("subscription");
accessor.setSessionId("session"); accessor.setSessionId("session");
accessor.setUser(new TestPrincipal("user")); accessor.setUser(new TestPrincipal("user"));
accessor.setSessionAttributes(Collections.<String, Object>singletonMap("key", "value")); accessor.setSessionAttributes(Collections.singletonMap("key", "value"));
accessor.setNativeHeader("nativeKey", "nativeValue"); accessor.setNativeHeader("nativeKey", "nativeValue");
assertThat(accessor.getDetailedLogMessage("p")) assertThat(accessor.getDetailedLogMessage("p"))
@ -72,7 +72,7 @@ public class SimpMessageHeaderAccessorTests {
} }
@Test @Test
public void userChangeCallback() { void userChangeCallback() {
UserCallback userCallback = new UserCallback(); UserCallback userCallback = new UserCallback();
SimpMessageHeaderAccessor accessor = SimpMessageHeaderAccessor.create(); SimpMessageHeaderAccessor accessor = SimpMessageHeaderAccessor.create();
accessor.setUserChangeCallback(userCallback); accessor.setUserChangeCallback(userCallback);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2019 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -28,10 +28,10 @@ import static org.assertj.core.api.Assertions.assertThat;
* *
* @author Rossen Stoyanchev * @author Rossen Stoyanchev
*/ */
public class SimpMessageTypeMessageConditionTests { class SimpMessageTypeMessageConditionTests {
@Test @Test
public void combine() { void combine() {
SimpMessageType messageType = SimpMessageType.MESSAGE; SimpMessageType messageType = SimpMessageType.MESSAGE;
SimpMessageType subscribeType = SimpMessageType.SUBSCRIBE; SimpMessageType subscribeType = SimpMessageType.SUBSCRIBE;
@ -46,7 +46,7 @@ public class SimpMessageTypeMessageConditionTests {
} }
@Test @Test
public void getMatchingCondition() { void getMatchingCondition() {
Message<?> message = message(SimpMessageType.MESSAGE); Message<?> message = message(SimpMessageType.MESSAGE);
SimpMessageTypeMessageCondition condition = condition(SimpMessageType.MESSAGE); SimpMessageTypeMessageCondition condition = condition(SimpMessageType.MESSAGE);
SimpMessageTypeMessageCondition actual = condition.getMatchingCondition(message); SimpMessageTypeMessageCondition actual = condition.getMatchingCondition(message);
@ -56,7 +56,7 @@ public class SimpMessageTypeMessageConditionTests {
} }
@Test @Test
public void getMatchingConditionNoMessageType() { void getMatchingConditionNoMessageType() {
Message<?> message = message(null); Message<?> message = message(null);
SimpMessageTypeMessageCondition condition = condition(SimpMessageType.MESSAGE); SimpMessageTypeMessageCondition condition = condition(SimpMessageType.MESSAGE);
@ -64,7 +64,7 @@ public class SimpMessageTypeMessageConditionTests {
} }
@Test @Test
public void compareTo() { void compareTo() {
Message<byte[]> message = message(null); Message<byte[]> message = message(null);
assertThat(condition(SimpMessageType.MESSAGE).compareTo(condition(SimpMessageType.MESSAGE), message)).isEqualTo(0); assertThat(condition(SimpMessageType.MESSAGE).compareTo(condition(SimpMessageType.MESSAGE), message)).isEqualTo(0);
assertThat(condition(SimpMessageType.MESSAGE).compareTo(condition(SimpMessageType.SUBSCRIBE), message)).isEqualTo(0); assertThat(condition(SimpMessageType.MESSAGE).compareTo(condition(SimpMessageType.SUBSCRIBE), message)).isEqualTo(0);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -16,7 +16,6 @@
package org.springframework.messaging.simp; package org.springframework.messaging.simp;
import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
@ -43,7 +42,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException
* *
* @author Rossen Stoyanchev * @author Rossen Stoyanchev
*/ */
public class SimpMessagingTemplateTests { class SimpMessagingTemplateTests {
private SimpMessagingTemplate messagingTemplate; private SimpMessagingTemplate messagingTemplate;
@ -51,14 +50,14 @@ public class SimpMessagingTemplateTests {
@BeforeEach @BeforeEach
public void setup() { void setup() {
this.messageChannel = new StubMessageChannel(); this.messageChannel = new StubMessageChannel();
this.messagingTemplate = new SimpMessagingTemplate(this.messageChannel); this.messagingTemplate = new SimpMessagingTemplate(this.messageChannel);
} }
@Test @Test
public void convertAndSendToUser() { void convertAndSendToUser() {
this.messagingTemplate.convertAndSendToUser("joe", "/queue/foo", "data"); this.messagingTemplate.convertAndSendToUser("joe", "/queue/foo", "data");
List<Message<byte[]>> messages = this.messageChannel.getMessages(); List<Message<byte[]>> messages = this.messageChannel.getMessages();
@ -74,7 +73,7 @@ public class SimpMessagingTemplateTests {
} }
@Test @Test
public void convertAndSendToUserWithEncoding() { void convertAndSendToUserWithEncoding() {
this.messagingTemplate.convertAndSendToUser("https://joe.openid.example.org/", "/queue/foo", "data"); this.messagingTemplate.convertAndSendToUser("https://joe.openid.example.org/", "/queue/foo", "data");
List<Message<byte[]>> messages = this.messageChannel.getMessages(); List<Message<byte[]>> messages = this.messageChannel.getMessages();
@ -94,8 +93,8 @@ public class SimpMessagingTemplateTests {
} }
@Test @Test
public void convertAndSendWithCustomHeader() { void convertAndSendWithCustomHeader() {
Map<String, Object> headers = Collections.<String, Object>singletonMap("key", "value"); Map<String, Object> headers = Collections.singletonMap("key", "value");
this.messagingTemplate.convertAndSend("/foo", "data", headers); this.messagingTemplate.convertAndSend("/foo", "data", headers);
List<Message<byte[]>> messages = this.messageChannel.getMessages(); List<Message<byte[]>> messages = this.messageChannel.getMessages();
@ -105,11 +104,11 @@ public class SimpMessagingTemplateTests {
assertThat(headerAccessor).isNotNull(); assertThat(headerAccessor).isNotNull();
assertThat(headerAccessor.toMap().get("key")).isNull(); assertThat(headerAccessor.toMap().get("key")).isNull();
assertThat(headerAccessor.getNativeHeader("key")).isEqualTo(Arrays.asList("value")); assertThat(headerAccessor.getNativeHeader("key")).containsExactly("value");
} }
@Test @Test
public void convertAndSendWithCustomHeaderNonNative() { void convertAndSendWithCustomHeaderNonNative() {
Map<String, Object> headers = new HashMap<>(); Map<String, Object> headers = new HashMap<>();
headers.put("key", "value"); headers.put("key", "value");
headers.put(NativeMessageHeaderAccessor.NATIVE_HEADERS, new LinkedMultiValueMap<String, String>()); headers.put(NativeMessageHeaderAccessor.NATIVE_HEADERS, new LinkedMultiValueMap<String, String>());
@ -128,7 +127,7 @@ public class SimpMessagingTemplateTests {
// SPR-11868 // SPR-11868
@Test @Test
public void convertAndSendWithCustomDestinationPrefix() { void convertAndSendWithCustomDestinationPrefix() {
this.messagingTemplate.setUserDestinationPrefix("/prefix"); this.messagingTemplate.setUserDestinationPrefix("/prefix");
this.messagingTemplate.convertAndSendToUser("joe", "/queue/foo", "data"); this.messagingTemplate.convertAndSendToUser("joe", "/queue/foo", "data");
List<Message<byte[]>> messages = this.messageChannel.getMessages(); List<Message<byte[]>> messages = this.messageChannel.getMessages();
@ -145,7 +144,7 @@ public class SimpMessagingTemplateTests {
} }
@Test @Test
public void convertAndSendWithMutableSimpMessageHeaders() { void convertAndSendWithMutableSimpMessageHeaders() {
SimpMessageHeaderAccessor accessor = SimpMessageHeaderAccessor.create(); SimpMessageHeaderAccessor accessor = SimpMessageHeaderAccessor.create();
accessor.setHeader("key", "value"); accessor.setHeader("key", "value");
accessor.setNativeHeader("fooNative", "barNative"); accessor.setNativeHeader("fooNative", "barNative");
@ -161,11 +160,11 @@ public class SimpMessagingTemplateTests {
} }
@Test @Test
public void processHeadersToSend() { void processHeadersToSend() {
Map<String, Object> map = this.messagingTemplate.processHeadersToSend(null); Map<String, Object> map = this.messagingTemplate.processHeadersToSend(null);
assertThat(map).isNotNull(); assertThat(map).isNotNull();
assertThat(MessageHeaders.class.isAssignableFrom(map.getClass())).as("Actual: " + map.getClass().toString()).isTrue(); assertThat(MessageHeaders.class.isAssignableFrom(map.getClass())).as("Actual: " + map.getClass()).isTrue();
SimpMessageHeaderAccessor headerAccessor = SimpMessageHeaderAccessor headerAccessor =
MessageHeaderAccessor.getAccessor((MessageHeaders) map, SimpMessageHeaderAccessor.class); MessageHeaderAccessor.getAccessor((MessageHeaders) map, SimpMessageHeaderAccessor.class);
@ -175,7 +174,7 @@ public class SimpMessagingTemplateTests {
} }
@Test @Test
public void doSendWithMutableHeaders() { void doSendWithMutableHeaders() {
SimpMessageHeaderAccessor accessor = SimpMessageHeaderAccessor.create(); SimpMessageHeaderAccessor accessor = SimpMessageHeaderAccessor.create();
accessor.setHeader("key", "value"); accessor.setHeader("key", "value");
accessor.setNativeHeader("fooNative", "barNative"); accessor.setNativeHeader("fooNative", "barNative");
@ -192,7 +191,7 @@ public class SimpMessagingTemplateTests {
} }
@Test @Test
public void doSendWithStompHeaders() { void doSendWithStompHeaders() {
StompHeaderAccessor accessor = StompHeaderAccessor.create(StompCommand.SUBSCRIBE); StompHeaderAccessor accessor = StompHeaderAccessor.create(StompCommand.SUBSCRIBE);
accessor.setDestination("/user/queue/foo"); accessor.setDestination("/user/queue/foo");
Message<?> message = MessageBuilder.createMessage(new byte[0], accessor.getMessageHeaders()); Message<?> message = MessageBuilder.createMessage(new byte[0], accessor.getMessageHeaders());

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -36,7 +36,7 @@ import static org.mockito.Mockito.verify;
* @author Rossen Stoyanchev * @author Rossen Stoyanchev
* @since 4.1 * @since 4.1
*/ */
public class SimpSessionScopeTests { class SimpSessionScopeTests {
private SimpSessionScope scope = new SimpSessionScope(); private SimpSessionScope scope = new SimpSessionScope();
@ -47,17 +47,17 @@ public class SimpSessionScopeTests {
@BeforeEach @BeforeEach
public void setUp() { void setUp() {
SimpAttributesContextHolder.setAttributes(this.simpAttributes); SimpAttributesContextHolder.setAttributes(this.simpAttributes);
} }
@AfterEach @AfterEach
public void tearDown() { void tearDown() {
SimpAttributesContextHolder.resetAttributes(); SimpAttributesContextHolder.resetAttributes();
} }
@Test @Test
public void get() { void get() {
this.simpAttributes.setAttribute("name", "value"); this.simpAttributes.setAttribute("name", "value");
Object actual = this.scope.get("name", this.objectFactory); Object actual = this.scope.get("name", this.objectFactory);
@ -65,7 +65,7 @@ public class SimpSessionScopeTests {
} }
@Test @Test
public void getWithObjectFactory() { void getWithObjectFactory() {
given(this.objectFactory.getObject()).willReturn("value"); given(this.objectFactory.getObject()).willReturn("value");
Object actual = this.scope.get("name", this.objectFactory); Object actual = this.scope.get("name", this.objectFactory);
@ -74,7 +74,7 @@ public class SimpSessionScopeTests {
} }
@Test @Test
public void remove() { void remove() {
this.simpAttributes.setAttribute("name", "value"); this.simpAttributes.setAttribute("name", "value");
Object removed = this.scope.remove("name"); Object removed = this.scope.remove("name");
@ -86,7 +86,7 @@ public class SimpSessionScopeTests {
} }
@Test @Test
public void registerDestructionCallback() { void registerDestructionCallback() {
Runnable runnable = mock(); Runnable runnable = mock();
this.scope.registerDestructionCallback("name", runnable); this.scope.registerDestructionCallback("name", runnable);
@ -95,7 +95,7 @@ public class SimpSessionScopeTests {
} }
@Test @Test
public void getSessionId() { void getSessionId() {
assertThat(this.scope.getConversationId()).isEqualTo("session1"); assertThat(this.scope.getConversationId()).isEqualTo("session1");
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2019 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -36,7 +36,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Rossen Stoyanchev * @author Rossen Stoyanchev
* @author Johnny Lim * @author Johnny Lim
*/ */
public class PrincipalMethodArgumentResolverTests { class PrincipalMethodArgumentResolverTests {
private final PrincipalMethodArgumentResolver resolver = new PrincipalMethodArgumentResolver(); private final PrincipalMethodArgumentResolver resolver = new PrincipalMethodArgumentResolver();
@ -44,14 +44,14 @@ public class PrincipalMethodArgumentResolverTests {
@Test @Test
public void supportsParameter() { void supportsParameter() {
assertThat(this.resolver.supportsParameter(this.testMethod.arg(Principal.class))).isTrue(); assertThat(this.resolver.supportsParameter(this.testMethod.arg(Principal.class))).isTrue();
assertThat(this.resolver.supportsParameter(this.testMethod.arg(Optional.class, Principal.class))).isTrue(); assertThat(this.resolver.supportsParameter(this.testMethod.arg(Optional.class, Principal.class))).isTrue();
} }
@Test @Test
public void resolverArgument() { void resolverArgument() {
Principal user = () -> "Joe"; Principal user = () -> "Joe";
Message<String> message = new GenericMessage<>("Hello, world!", Message<String> message = new GenericMessage<>("Hello, world!",
Collections.singletonMap(SimpMessageHeaderAccessor.USER_HEADER, user)); Collections.singletonMap(SimpMessageHeaderAccessor.USER_HEADER, user));

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -122,7 +122,7 @@ public class SendToMethodReturnValueHandlerTests {
@BeforeEach @BeforeEach
public void setup() throws Exception { void setup() {
SimpMessagingTemplate messagingTemplate = new SimpMessagingTemplate(this.messageChannel); SimpMessagingTemplate messagingTemplate = new SimpMessagingTemplate(this.messageChannel);
messagingTemplate.setMessageConverter(new StringMessageConverter()); messagingTemplate.setMessageConverter(new StringMessageConverter());
this.handler = new SendToMethodReturnValueHandler(messagingTemplate, true); this.handler = new SendToMethodReturnValueHandler(messagingTemplate, true);
@ -134,7 +134,7 @@ public class SendToMethodReturnValueHandlerTests {
} }
@Test @Test
public void supportsReturnType() throws Exception { void supportsReturnType() {
assertThat(this.handler.supportsReturnType(this.sendToReturnType)).isTrue(); assertThat(this.handler.supportsReturnType(this.sendToReturnType)).isTrue();
assertThat(this.handler.supportsReturnType(this.sendToUserReturnType)).isTrue(); assertThat(this.handler.supportsReturnType(this.sendToUserReturnType)).isTrue();
assertThat(this.handler.supportsReturnType(this.noAnnotationsReturnType)).isFalse(); assertThat(this.handler.supportsReturnType(this.noAnnotationsReturnType)).isFalse();
@ -150,7 +150,7 @@ public class SendToMethodReturnValueHandlerTests {
} }
@Test @Test
public void sendToNoAnnotations() throws Exception { void sendToNoAnnotations() throws Exception {
given(this.messageChannel.send(any(Message.class))).willReturn(true); given(this.messageChannel.send(any(Message.class))).willReturn(true);
String sessionId = "sess1"; String sessionId = "sess1";
@ -162,7 +162,7 @@ public class SendToMethodReturnValueHandlerTests {
} }
@Test @Test
public void sendTo() throws Exception { void sendTo() throws Exception {
given(this.messageChannel.send(any(Message.class))).willReturn(true); given(this.messageChannel.send(any(Message.class))).willReturn(true);
String sessionId = "sess1"; String sessionId = "sess1";
@ -175,7 +175,7 @@ public class SendToMethodReturnValueHandlerTests {
} }
@Test @Test
public void sendToDefaultDestination() throws Exception { void sendToDefaultDestination() throws Exception {
given(this.messageChannel.send(any(Message.class))).willReturn(true); given(this.messageChannel.send(any(Message.class))).willReturn(true);
String sessionId = "sess1"; String sessionId = "sess1";
@ -187,7 +187,7 @@ public class SendToMethodReturnValueHandlerTests {
} }
@Test @Test
public void sendToClassDefaultNoAnnotation() throws Exception { void sendToClassDefaultNoAnnotation() throws Exception {
given(this.messageChannel.send(any(Message.class))).willReturn(true); given(this.messageChannel.send(any(Message.class))).willReturn(true);
String sessionId = "sess1"; String sessionId = "sess1";
@ -199,7 +199,7 @@ public class SendToMethodReturnValueHandlerTests {
} }
@Test @Test
public void sendToClassDefaultEmptyAnnotation() throws Exception { void sendToClassDefaultEmptyAnnotation() throws Exception {
given(this.messageChannel.send(any(Message.class))).willReturn(true); given(this.messageChannel.send(any(Message.class))).willReturn(true);
String sessionId = "sess1"; String sessionId = "sess1";
@ -211,7 +211,7 @@ public class SendToMethodReturnValueHandlerTests {
} }
@Test @Test
public void sendToClassDefaultOverride() throws Exception { void sendToClassDefaultOverride() throws Exception {
given(this.messageChannel.send(any(Message.class))).willReturn(true); given(this.messageChannel.send(any(Message.class))).willReturn(true);
String sessionId = "sess1"; String sessionId = "sess1";
@ -224,7 +224,7 @@ public class SendToMethodReturnValueHandlerTests {
} }
@Test @Test
public void sendToUserClassDefaultNoAnnotation() throws Exception { void sendToUserClassDefaultNoAnnotation() throws Exception {
given(this.messageChannel.send(any(Message.class))).willReturn(true); given(this.messageChannel.send(any(Message.class))).willReturn(true);
String sessionId = "sess1"; String sessionId = "sess1";
@ -236,7 +236,7 @@ public class SendToMethodReturnValueHandlerTests {
} }
@Test @Test
public void sendToUserClassDefaultEmptyAnnotation() throws Exception { void sendToUserClassDefaultEmptyAnnotation() throws Exception {
given(this.messageChannel.send(any(Message.class))).willReturn(true); given(this.messageChannel.send(any(Message.class))).willReturn(true);
String sessionId = "sess1"; String sessionId = "sess1";
@ -248,7 +248,7 @@ public class SendToMethodReturnValueHandlerTests {
} }
@Test @Test
public void sendToUserClassDefaultOverride() throws Exception { void sendToUserClassDefaultOverride() throws Exception {
given(this.messageChannel.send(any(Message.class))).willReturn(true); given(this.messageChannel.send(any(Message.class))).willReturn(true);
String sessionId = "sess1"; String sessionId = "sess1";
@ -306,7 +306,7 @@ public class SendToMethodReturnValueHandlerTests {
} }
@Test @Test
public void sendToDefaultDestinationWhenUsingDotPathSeparator() throws Exception { void sendToDefaultDestinationWhenUsingDotPathSeparator() throws Exception {
given(this.messageChannel.send(any(Message.class))).willReturn(true); given(this.messageChannel.send(any(Message.class))).willReturn(true);
Message<?> inputMessage = createMessage("sess1", "sub1", "/app/", "dest.foo.bar", null); Message<?> inputMessage = createMessage("sess1", "sub1", "/app/", "dest.foo.bar", null);
@ -319,7 +319,7 @@ public class SendToMethodReturnValueHandlerTests {
} }
@Test @Test
public void testHeadersToSend() throws Exception { void testHeadersToSend() throws Exception {
Message<?> message = createMessage("sess1", "sub1", "/app", "/dest", null); Message<?> message = createMessage("sess1", "sub1", "/app", "/dest", null);
SimpMessageSendingOperations messagingTemplate = mock(); SimpMessageSendingOperations messagingTemplate = mock();
@ -341,7 +341,7 @@ public class SendToMethodReturnValueHandlerTests {
} }
@Test @Test
public void sendToUser() throws Exception { void sendToUser() throws Exception {
given(this.messageChannel.send(any(Message.class))).willReturn(true); given(this.messageChannel.send(any(Message.class))).willReturn(true);
String sessionId = "sess1"; String sessionId = "sess1";
@ -363,7 +363,7 @@ public class SendToMethodReturnValueHandlerTests {
} }
@Test @Test
public void sendToAndSendToUser() throws Exception { void sendToAndSendToUser() throws Exception {
given(this.messageChannel.send(any(Message.class))).willReturn(true); given(this.messageChannel.send(any(Message.class))).willReturn(true);
String sessionId = "sess1"; String sessionId = "sess1";
@ -417,7 +417,7 @@ public class SendToMethodReturnValueHandlerTests {
} }
@Test @Test
public void sendToUserSingleSession() throws Exception { void sendToUserSingleSession() throws Exception {
given(this.messageChannel.send(any(Message.class))).willReturn(true); given(this.messageChannel.send(any(Message.class))).willReturn(true);
String sessionId = "sess1"; String sessionId = "sess1";
@ -443,7 +443,7 @@ public class SendToMethodReturnValueHandlerTests {
} }
@Test @Test
public void sendToUserWithUserNameProvider() throws Exception { void sendToUserWithUserNameProvider() throws Exception {
given(this.messageChannel.send(any(Message.class))).willReturn(true); given(this.messageChannel.send(any(Message.class))).willReturn(true);
String sessionId = "sess1"; String sessionId = "sess1";
@ -461,7 +461,7 @@ public class SendToMethodReturnValueHandlerTests {
} }
@Test @Test
public void sendToUserDefaultDestination() throws Exception { void sendToUserDefaultDestination() throws Exception {
given(this.messageChannel.send(any(Message.class))).willReturn(true); given(this.messageChannel.send(any(Message.class))).willReturn(true);
String sessionId = "sess1"; String sessionId = "sess1";
@ -478,7 +478,7 @@ public class SendToMethodReturnValueHandlerTests {
} }
@Test @Test
public void sendToUserDefaultDestinationWhenUsingDotPathSeparator() throws Exception { void sendToUserDefaultDestinationWhenUsingDotPathSeparator() throws Exception {
given(this.messageChannel.send(any(Message.class))).willReturn(true); given(this.messageChannel.send(any(Message.class))).willReturn(true);
TestUser user = new TestUser(); TestUser user = new TestUser();
@ -492,7 +492,7 @@ public class SendToMethodReturnValueHandlerTests {
} }
@Test @Test
public void sendToUserDefaultDestinationSingleSession() throws Exception { void sendToUserDefaultDestinationSingleSession() throws Exception {
given(this.messageChannel.send(any(Message.class))).willReturn(true); given(this.messageChannel.send(any(Message.class))).willReturn(true);
String sessionId = "sess1"; String sessionId = "sess1";
@ -511,7 +511,7 @@ public class SendToMethodReturnValueHandlerTests {
} }
@Test @Test
public void sendToUserSessionWithoutUserName() throws Exception { void sendToUserSessionWithoutUserName() throws Exception {
given(this.messageChannel.send(any(Message.class))).willReturn(true); given(this.messageChannel.send(any(Message.class))).willReturn(true);
String sessionId = "sess1"; String sessionId = "sess1";
@ -530,7 +530,7 @@ public class SendToMethodReturnValueHandlerTests {
} }
@Test @Test
public void jsonView() throws Exception { void jsonView() throws Exception {
given(this.messageChannel.send(any(Message.class))).willReturn(true); given(this.messageChannel.send(any(Message.class))).willReturn(true);
String sessionId = "sess1"; String sessionId = "sess1";

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -99,7 +99,7 @@ public class SimpAnnotationMethodMessageHandlerTests {
@BeforeEach @BeforeEach
public void setup() { void setup() {
SimpMessagingTemplate brokerTemplate = new SimpMessagingTemplate(this.channel); SimpMessagingTemplate brokerTemplate = new SimpMessagingTemplate(this.channel);
brokerTemplate.setMessageConverter(this.converter); brokerTemplate.setMessageConverter(this.converter);
@ -124,7 +124,7 @@ public class SimpAnnotationMethodMessageHandlerTests {
} }
@Test @Test
public void optionalHeaderArgumentResolutionWhenPresent() { void optionalHeaderArgumentResolutionWhenPresent() {
Map<String, Object> headers = Collections.singletonMap("foo", "bar"); Map<String, Object> headers = Collections.singletonMap("foo", "bar");
Message<?> message = createMessage("/pre/optionalHeaders", headers); Message<?> message = createMessage("/pre/optionalHeaders", headers);
this.messageHandler.registerHandler(this.testController); this.messageHandler.registerHandler(this.testController);
@ -136,7 +136,7 @@ public class SimpAnnotationMethodMessageHandlerTests {
} }
@Test @Test
public void optionalHeaderArgumentResolutionWhenNotPresent() { void optionalHeaderArgumentResolutionWhenNotPresent() {
Message<?> message = createMessage("/pre/optionalHeaders"); Message<?> message = createMessage("/pre/optionalHeaders");
this.messageHandler.registerHandler(this.testController); this.messageHandler.registerHandler(this.testController);
this.messageHandler.handleMessage(message); this.messageHandler.handleMessage(message);
@ -147,7 +147,7 @@ public class SimpAnnotationMethodMessageHandlerTests {
} }
@Test @Test
public void messageMappingDestinationVariableResolution() { void messageMappingDestinationVariableResolution() {
Message<?> message = createMessage("/pre/message/bar/value"); Message<?> message = createMessage("/pre/message/bar/value");
this.messageHandler.registerHandler(this.testController); this.messageHandler.registerHandler(this.testController);
this.messageHandler.handleMessage(message); this.messageHandler.handleMessage(message);
@ -158,7 +158,7 @@ public class SimpAnnotationMethodMessageHandlerTests {
} }
@Test @Test
public void subscribeEventDestinationVariableResolution() { void subscribeEventDestinationVariableResolution() {
Message<?> message = createMessage(SimpMessageType.SUBSCRIBE, "/pre/sub/bar/value", null); Message<?> message = createMessage(SimpMessageType.SUBSCRIBE, "/pre/sub/bar/value", null);
this.messageHandler.registerHandler(this.testController); this.messageHandler.registerHandler(this.testController);
this.messageHandler.handleMessage(message); this.messageHandler.handleMessage(message);
@ -169,7 +169,7 @@ public class SimpAnnotationMethodMessageHandlerTests {
} }
@Test @Test
public void simpleBinding() { void simpleBinding() {
Message<?> message = createMessage("/pre/binding/id/12"); Message<?> message = createMessage("/pre/binding/id/12");
this.messageHandler.registerHandler(this.testController); this.messageHandler.registerHandler(this.testController);
this.messageHandler.handleMessage(message); this.messageHandler.handleMessage(message);
@ -180,7 +180,7 @@ public class SimpAnnotationMethodMessageHandlerTests {
} }
@Test @Test
public void validationError() { void validationError() {
Message<?> message = createMessage("/pre/validation/payload"); Message<?> message = createMessage("/pre/validation/payload");
this.messageHandler.registerHandler(this.testController); this.messageHandler.registerHandler(this.testController);
this.messageHandler.handleMessage(message); this.messageHandler.handleMessage(message);
@ -189,7 +189,7 @@ public class SimpAnnotationMethodMessageHandlerTests {
} }
@Test @Test
public void exceptionWithHandlerMethodArg() { void exceptionWithHandlerMethodArg() {
Message<?> message = createMessage("/pre/illegalState"); Message<?> message = createMessage("/pre/illegalState");
this.messageHandler.registerHandler(this.testController); this.messageHandler.registerHandler(this.testController);
this.messageHandler.handleMessage(message); this.messageHandler.handleMessage(message);
@ -201,7 +201,7 @@ public class SimpAnnotationMethodMessageHandlerTests {
} }
@Test @Test
public void exceptionAsCause() { void exceptionAsCause() {
Message<?> message = createMessage("/pre/illegalStateCause"); Message<?> message = createMessage("/pre/illegalStateCause");
this.messageHandler.registerHandler(this.testController); this.messageHandler.registerHandler(this.testController);
this.messageHandler.handleMessage(message); this.messageHandler.handleMessage(message);
@ -213,7 +213,7 @@ public class SimpAnnotationMethodMessageHandlerTests {
} }
@Test @Test
public void errorAsMessageHandlingException() { void errorAsMessageHandlingException() {
Message<?> message = createMessage("/pre/error"); Message<?> message = createMessage("/pre/error");
this.messageHandler.registerHandler(this.testController); this.messageHandler.registerHandler(this.testController);
this.messageHandler.handleMessage(message); this.messageHandler.handleMessage(message);
@ -225,7 +225,7 @@ public class SimpAnnotationMethodMessageHandlerTests {
} }
@Test @Test
public void simpScope() { void simpScope() {
Map<String, Object> sessionAttributes = new ConcurrentHashMap<>(); Map<String, Object> sessionAttributes = new ConcurrentHashMap<>();
sessionAttributes.put("name", "value"); sessionAttributes.put("name", "value");
@ -241,7 +241,7 @@ public class SimpAnnotationMethodMessageHandlerTests {
} }
@Test @Test
public void interfaceBasedController() { void interfaceBasedController() {
InterfaceBasedController controller = new InterfaceBasedController(); InterfaceBasedController controller = new InterfaceBasedController();
Message<?> message = createMessage("/pre/binding/id/12"); Message<?> message = createMessage("/pre/binding/id/12");
@ -254,7 +254,7 @@ public class SimpAnnotationMethodMessageHandlerTests {
} }
@Test @Test
public void dotPathSeparator() { void dotPathSeparator() {
DotPathSeparatorController controller = new DotPathSeparatorController(); DotPathSeparatorController controller = new DotPathSeparatorController();
this.messageHandler.setPathMatcher(new AntPathMatcher(".")); this.messageHandler.setPathMatcher(new AntPathMatcher("."));
@ -294,7 +294,7 @@ public class SimpAnnotationMethodMessageHandlerTests {
} }
@Test @Test
public void listenableFutureFailure() { void listenableFutureFailure() {
ListenableFutureController controller = new ListenableFutureController(); ListenableFutureController controller = new ListenableFutureController();
this.messageHandler.registerHandler(controller); this.messageHandler.registerHandler(controller);
this.messageHandler.setDestinationPrefixes(Arrays.asList("/app1", "/app2/")); this.messageHandler.setDestinationPrefixes(Arrays.asList("/app1", "/app2/"));
@ -327,7 +327,7 @@ public class SimpAnnotationMethodMessageHandlerTests {
} }
@Test @Test
public void completableFutureFailure() { void completableFutureFailure() {
CompletableFutureController controller = new CompletableFutureController(); CompletableFutureController controller = new CompletableFutureController();
this.messageHandler.registerHandler(controller); this.messageHandler.registerHandler(controller);
this.messageHandler.setDestinationPrefixes(Arrays.asList("/app1", "/app2/")); this.messageHandler.setDestinationPrefixes(Arrays.asList("/app1", "/app2/"));
@ -360,7 +360,7 @@ public class SimpAnnotationMethodMessageHandlerTests {
} }
@Test @Test
public void monoFailure() { void monoFailure() {
ReactiveController controller = new ReactiveController(); ReactiveController controller = new ReactiveController();
this.messageHandler.registerHandler(controller); this.messageHandler.registerHandler(controller);
this.messageHandler.setDestinationPrefixes(Arrays.asList("/app1", "/app2/")); this.messageHandler.setDestinationPrefixes(Arrays.asList("/app1", "/app2/"));
@ -373,7 +373,7 @@ public class SimpAnnotationMethodMessageHandlerTests {
} }
@Test @Test
public void fluxNotHandled() { void fluxNotHandled() {
ReactiveController controller = new ReactiveController(); ReactiveController controller = new ReactiveController();
this.messageHandler.registerHandler(controller); this.messageHandler.registerHandler(controller);
this.messageHandler.setDestinationPrefixes(Arrays.asList("/app1", "/app2/")); this.messageHandler.setDestinationPrefixes(Arrays.asList("/app1", "/app2/"));
@ -388,7 +388,7 @@ public class SimpAnnotationMethodMessageHandlerTests {
} }
@Test @Test
public void placeholder() { void placeholder() {
Message<?> message = createMessage("/pre/myValue"); Message<?> message = createMessage("/pre/myValue");
this.messageHandler.setEmbeddedValueResolver(value -> ("/${myProperty}".equals(value) ? "/myValue" : value)); this.messageHandler.setEmbeddedValueResolver(value -> ("/${myProperty}".equals(value) ? "/myValue" : value));
this.messageHandler.registerHandler(this.testController); this.messageHandler.registerHandler(this.testController);
@ -453,7 +453,7 @@ public class SimpAnnotationMethodMessageHandlerTests {
public void optionalHeaders(@Header(name="foo", required=false) String foo1, @Header("foo") Optional<String> foo2) { public void optionalHeaders(@Header(name="foo", required=false) String foo1, @Header("foo") Optional<String> foo2) {
this.method = "optionalHeaders"; this.method = "optionalHeaders";
this.arguments.put("foo1", foo1); this.arguments.put("foo1", foo1);
this.arguments.put("foo2", (foo2.isPresent() ? foo2.get() : null)); this.arguments.put("foo2", (foo2.orElse(null)));
} }
@MessageMapping("/message/{foo}/{name}") @MessageMapping("/message/{foo}/{name}")

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -86,7 +86,7 @@ public class SubscriptionMethodReturnValueHandlerTests {
@BeforeEach @BeforeEach
public void setup() throws Exception { void setup() throws Exception {
SimpMessagingTemplate messagingTemplate = new SimpMessagingTemplate(this.messageChannel); SimpMessagingTemplate messagingTemplate = new SimpMessagingTemplate(this.messageChannel);
messagingTemplate.setMessageConverter(new StringMessageConverter()); messagingTemplate.setMessageConverter(new StringMessageConverter());
this.handler = new SubscriptionMethodReturnValueHandler(messagingTemplate); this.handler = new SubscriptionMethodReturnValueHandler(messagingTemplate);
@ -110,14 +110,14 @@ public class SubscriptionMethodReturnValueHandlerTests {
@Test @Test
public void supportsReturnType() throws Exception { void supportsReturnType() {
assertThat(this.handler.supportsReturnType(this.subscribeEventReturnType)).isTrue(); assertThat(this.handler.supportsReturnType(this.subscribeEventReturnType)).isTrue();
assertThat(this.handler.supportsReturnType(this.subscribeEventSendToReturnType)).isFalse(); assertThat(this.handler.supportsReturnType(this.subscribeEventSendToReturnType)).isFalse();
assertThat(this.handler.supportsReturnType(this.messageMappingReturnType)).isFalse(); assertThat(this.handler.supportsReturnType(this.messageMappingReturnType)).isFalse();
} }
@Test @Test
public void testMessageSentToChannel() throws Exception { void testMessageSentToChannel() throws Exception {
given(this.messageChannel.send(any(Message.class))).willReturn(true); given(this.messageChannel.send(any(Message.class))).willReturn(true);
String sessionId = "sess1"; String sessionId = "sess1";
@ -169,7 +169,7 @@ public class SubscriptionMethodReturnValueHandlerTests {
} }
@Test @Test
public void testJsonView() throws Exception { void testJsonView() throws Exception {
given(this.messageChannel.send(any(Message.class))).willReturn(true); given(this.messageChannel.send(any(Message.class))).willReturn(true);
String sessionId = "sess1"; String sessionId = "sess1";

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -39,20 +39,20 @@ import static org.mockito.Mockito.mock;
* *
* @author Rossen Stoyanchev * @author Rossen Stoyanchev
*/ */
public class BrokerMessageHandlerTests { class BrokerMessageHandlerTests {
private final TestBrokerMessageHandler handler = new TestBrokerMessageHandler(); private final TestBrokerMessageHandler handler = new TestBrokerMessageHandler();
@Test @Test
public void startShouldUpdateIsRunning() { void startShouldUpdateIsRunning() {
assertThat(this.handler.isRunning()).isFalse(); assertThat(this.handler.isRunning()).isFalse();
this.handler.start(); this.handler.start();
assertThat(this.handler.isRunning()).isTrue(); assertThat(this.handler.isRunning()).isTrue();
} }
@Test @Test
public void stopShouldUpdateIsRunning() { void stopShouldUpdateIsRunning() {
this.handler.start(); this.handler.start();
assertThat(this.handler.isRunning()).isTrue(); assertThat(this.handler.isRunning()).isTrue();
@ -61,20 +61,20 @@ public class BrokerMessageHandlerTests {
} }
@Test @Test
public void startAndStopShouldNotPublishBrokerAvailabilityEvents() { void startAndStopShouldNotPublishBrokerAvailabilityEvents() {
this.handler.start(); this.handler.start();
this.handler.stop(); this.handler.stop();
assertThat(this.handler.availabilityEvents).isEqualTo(Collections.emptyList()); assertThat(this.handler.availabilityEvents).isEqualTo(Collections.emptyList());
} }
@Test @Test
public void handleMessageWhenBrokerNotRunning() { void handleMessageWhenBrokerNotRunning() {
this.handler.handleMessage(new GenericMessage<Object>("payload")); this.handler.handleMessage(new GenericMessage<Object>("payload"));
assertThat(this.handler.messages).isEqualTo(Collections.emptyList()); assertThat(this.handler.messages).isEqualTo(Collections.emptyList());
} }
@Test @Test
public void publishBrokerAvailableEvent() { void publishBrokerAvailableEvent() {
assertThat(this.handler.isBrokerAvailable()).isFalse(); assertThat(this.handler.isBrokerAvailable()).isFalse();
assertThat(this.handler.availabilityEvents).isEqualTo(Collections.emptyList()); assertThat(this.handler.availabilityEvents).isEqualTo(Collections.emptyList());
@ -85,7 +85,7 @@ public class BrokerMessageHandlerTests {
} }
@Test @Test
public void publishBrokerAvailableEventWhenAlreadyAvailable() { void publishBrokerAvailableEventWhenAlreadyAvailable() {
this.handler.publishBrokerAvailableEvent(); this.handler.publishBrokerAvailableEvent();
this.handler.publishBrokerAvailableEvent(); this.handler.publishBrokerAvailableEvent();
@ -93,7 +93,7 @@ public class BrokerMessageHandlerTests {
} }
@Test @Test
public void publishBrokerUnavailableEvent() { void publishBrokerUnavailableEvent() {
this.handler.publishBrokerAvailableEvent(); this.handler.publishBrokerAvailableEvent();
assertThat(this.handler.isBrokerAvailable()).isTrue(); assertThat(this.handler.isBrokerAvailable()).isTrue();
@ -104,7 +104,7 @@ public class BrokerMessageHandlerTests {
} }
@Test @Test
public void publishBrokerUnavailableEventWhenAlreadyUnavailable() { void publishBrokerUnavailableEventWhenAlreadyUnavailable() {
this.handler.publishBrokerAvailableEvent(); this.handler.publishBrokerAvailableEvent();
this.handler.publishBrokerUnavailableEvent(); this.handler.publishBrokerUnavailableEvent();
this.handler.publishBrokerUnavailableEvent(); this.handler.publishBrokerUnavailableEvent();
@ -113,7 +113,7 @@ public class BrokerMessageHandlerTests {
} }
@Test @Test
public void checkDestination() { void checkDestination() {
TestBrokerMessageHandler theHandler = new TestBrokerMessageHandler("/topic"); TestBrokerMessageHandler theHandler = new TestBrokerMessageHandler("/topic");
theHandler.start(); theHandler.start();
@ -136,7 +136,7 @@ public class BrokerMessageHandlerTests {
} }
@Test @Test
public void checkDestinationWithoutConfiguredPrefixes() { void checkDestinationWithoutConfiguredPrefixes() {
this.handler.setUserDestinationPredicate(destination -> destination.startsWith("/user/")); this.handler.setUserDestinationPredicate(destination -> destination.startsWith("/user/"));
this.handler.start(); this.handler.start();

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -420,7 +420,7 @@ class DefaultSubscriptionRegistryTests {
} }
@Test // SPR-12665 @Test // SPR-12665
void findSubscriptionsReturnsMapSafeToIterate() throws Exception { void findSubscriptionsReturnsMapSafeToIterate() {
this.registry.registerSubscription(subscribeMessage("sess1", "1", "/foo")); this.registry.registerSubscription(subscribeMessage("sess1", "1", "/foo"));
this.registry.registerSubscription(subscribeMessage("sess2", "1", "/foo")); this.registry.registerSubscription(subscribeMessage("sess2", "1", "/foo"));
@ -437,7 +437,7 @@ class DefaultSubscriptionRegistryTests {
} }
@Test // SPR-13185 @Test // SPR-13185
void findSubscriptionsReturnsMapSafeToIterateIncludingValues() throws Exception { void findSubscriptionsReturnsMapSafeToIterateIncludingValues() {
this.registry.registerSubscription(subscribeMessage("sess1", "1", "/foo")); this.registry.registerSubscription(subscribeMessage("sess1", "1", "/foo"));
this.registry.registerSubscription(subscribeMessage("sess1", "2", "/foo")); this.registry.registerSubscription(subscribeMessage("sess1", "2", "/foo"));
@ -454,7 +454,7 @@ class DefaultSubscriptionRegistryTests {
} }
@Test // SPR-13555 @Test // SPR-13555
void cacheLimitExceeded() throws Exception { void cacheLimitExceeded() {
this.registry.setCacheLimit(1); this.registry.setCacheLimit(1);
this.registry.registerSubscription(subscribeMessage("sess1", "1", "/foo")); this.registry.registerSubscription(subscribeMessage("sess1", "1", "/foo"));
this.registry.registerSubscription(subscribeMessage("sess1", "2", "/bar")); this.registry.registerSubscription(subscribeMessage("sess1", "2", "/bar"));

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -43,7 +43,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Rossen Stoyanchev * @author Rossen Stoyanchev
* @see org.springframework.web.socket.messaging.OrderedMessageSendingIntegrationTests * @see org.springframework.web.socket.messaging.OrderedMessageSendingIntegrationTests
*/ */
public class OrderedMessageChannelDecoratorTests { class OrderedMessageChannelDecoratorTests {
private static final Log logger = LogFactory.getLog(OrderedMessageChannelDecoratorTests.class); private static final Log logger = LogFactory.getLog(OrderedMessageChannelDecoratorTests.class);
@ -52,7 +52,7 @@ public class OrderedMessageChannelDecoratorTests {
@BeforeEach @BeforeEach
public void setup() { void setup() {
this.executor = new ThreadPoolTaskExecutor(); this.executor = new ThreadPoolTaskExecutor();
this.executor.setCorePoolSize(Runtime.getRuntime().availableProcessors() * 2); this.executor.setCorePoolSize(Runtime.getRuntime().availableProcessors() * 2);
this.executor.setAllowCoreThreadTimeOut(true); this.executor.setAllowCoreThreadTimeOut(true);
@ -60,13 +60,13 @@ public class OrderedMessageChannelDecoratorTests {
} }
@AfterEach @AfterEach
public void tearDown() { void tearDown() {
this.executor.shutdown(); this.executor.shutdown();
} }
@Test @Test
public void test() throws InterruptedException { void test() throws InterruptedException {
int start = 1; int start = 1;
int end = 1000; int end = 1000;

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -82,14 +82,14 @@ public class SimpleBrokerMessageHandlerTests {
@BeforeEach @BeforeEach
public void setup() { void setup() {
this.messageHandler = new SimpleBrokerMessageHandler( this.messageHandler = new SimpleBrokerMessageHandler(
this.clientInChannel, this.clientOutChannel, this.brokerChannel, Collections.emptyList()); this.clientInChannel, this.clientOutChannel, this.brokerChannel, Collections.emptyList());
} }
@Test @Test
public void subscribePublish() { void subscribePublish() {
startSession("sess1"); startSession("sess1");
startSession("sess2"); startSession("sess2");
@ -114,7 +114,7 @@ public class SimpleBrokerMessageHandlerTests {
} }
@Test @Test
public void subscribeDisconnectPublish() { void subscribeDisconnectPublish() {
String sess1 = "sess1"; String sess1 = "sess1";
String sess2 = "sess2"; String sess2 = "sess2";
@ -152,7 +152,7 @@ public class SimpleBrokerMessageHandlerTests {
} }
@Test @Test
public void connect() { void connect() {
String id = "sess1"; String id = "sess1";
Message<String> connectMessage = startSession(id); Message<String> connectMessage = startSession(id);
@ -166,7 +166,7 @@ public class SimpleBrokerMessageHandlerTests {
} }
@Test @Test
public void heartbeatValueWithAndWithoutTaskScheduler() { void heartbeatValueWithAndWithoutTaskScheduler() {
assertThat(this.messageHandler.getHeartbeatValue()).isNull(); assertThat(this.messageHandler.getHeartbeatValue()).isNull();
this.messageHandler.setTaskScheduler(this.taskScheduler); this.messageHandler.setTaskScheduler(this.taskScheduler);
@ -175,7 +175,7 @@ public class SimpleBrokerMessageHandlerTests {
} }
@Test @Test
public void startWithHeartbeatValueWithoutTaskScheduler() { void startWithHeartbeatValueWithoutTaskScheduler() {
this.messageHandler.setHeartbeatValue(new long[] {10000, 10000}); this.messageHandler.setHeartbeatValue(new long[] {10000, 10000});
assertThatIllegalArgumentException().isThrownBy( assertThatIllegalArgumentException().isThrownBy(
this.messageHandler::start); this.messageHandler::start);
@ -201,7 +201,7 @@ public class SimpleBrokerMessageHandlerTests {
} }
@Test @Test
public void startWithOneZeroHeartbeatValue() { void startWithOneZeroHeartbeatValue() {
this.messageHandler.setTaskScheduler(this.taskScheduler); this.messageHandler.setTaskScheduler(this.taskScheduler);
this.messageHandler.setHeartbeatValue(new long[] {0, 10000}); this.messageHandler.setHeartbeatValue(new long[] {0, 10000});
this.messageHandler.start(); this.messageHandler.start();
@ -210,7 +210,7 @@ public class SimpleBrokerMessageHandlerTests {
} }
@Test @Test
public void readInactivity() throws Exception { void readInactivity() throws Exception {
this.messageHandler.setHeartbeatValue(new long[] {0, 1}); this.messageHandler.setHeartbeatValue(new long[] {0, 1});
this.messageHandler.setTaskScheduler(this.taskScheduler); this.messageHandler.setTaskScheduler(this.taskScheduler);
this.messageHandler.start(); this.messageHandler.start();
@ -241,7 +241,7 @@ public class SimpleBrokerMessageHandlerTests {
} }
@Test @Test
public void writeInactivity() throws Exception { void writeInactivity() throws Exception {
this.messageHandler.setHeartbeatValue(new long[] {1, 0}); this.messageHandler.setHeartbeatValue(new long[] {1, 0});
this.messageHandler.setTaskScheduler(this.taskScheduler); this.messageHandler.setTaskScheduler(this.taskScheduler);
this.messageHandler.start(); this.messageHandler.start();
@ -272,7 +272,7 @@ public class SimpleBrokerMessageHandlerTests {
} }
@Test @Test
public void readWriteIntervalCalculation() throws Exception { void readWriteIntervalCalculation() throws Exception {
this.messageHandler.setHeartbeatValue(new long[] {1, 1}); this.messageHandler.setHeartbeatValue(new long[] {1, 1});
this.messageHandler.setTaskScheduler(this.taskScheduler); this.messageHandler.setTaskScheduler(this.taskScheduler);
this.messageHandler.start(); this.messageHandler.start();

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -92,10 +92,10 @@ import static org.mockito.Mockito.mock;
* @author Brian Clozel * @author Brian Clozel
* @author Sebastien Deleuze * @author Sebastien Deleuze
*/ */
public class MessageBrokerConfigurationTests { class MessageBrokerConfigurationTests {
@Test @Test
public void clientInboundChannel() { void clientInboundChannel() {
ApplicationContext context = loadConfig(SimpleBrokerConfig.class); ApplicationContext context = loadConfig(SimpleBrokerConfig.class);
TestChannel channel = context.getBean("clientInboundChannel", TestChannel.class); TestChannel channel = context.getBean("clientInboundChannel", TestChannel.class);
@ -108,7 +108,7 @@ public class MessageBrokerConfigurationTests {
} }
@Test @Test
public void clientInboundChannelWithBrokerRelay() { void clientInboundChannelWithBrokerRelay() {
ApplicationContext context = loadConfig(BrokerRelayConfig.class); ApplicationContext context = loadConfig(BrokerRelayConfig.class);
TestChannel channel = context.getBean("clientInboundChannel", TestChannel.class); TestChannel channel = context.getBean("clientInboundChannel", TestChannel.class);
@ -121,7 +121,7 @@ public class MessageBrokerConfigurationTests {
} }
@Test @Test
public void clientInboundChannelCustomized() { void clientInboundChannelCustomized() {
ApplicationContext context = loadConfig(CustomConfig.class); ApplicationContext context = loadConfig(CustomConfig.class);
AbstractSubscribableChannel channel = context.getBean( AbstractSubscribableChannel channel = context.getBean(
@ -136,7 +136,7 @@ public class MessageBrokerConfigurationTests {
} }
@Test @Test
public void clientOutboundChannelUsedByAnnotatedMethod() { void clientOutboundChannelUsedByAnnotatedMethod() {
ApplicationContext context = loadConfig(SimpleBrokerConfig.class); ApplicationContext context = loadConfig(SimpleBrokerConfig.class);
TestChannel channel = context.getBean("clientOutboundChannel", TestChannel.class); TestChannel channel = context.getBean("clientOutboundChannel", TestChannel.class);
@ -161,7 +161,7 @@ public class MessageBrokerConfigurationTests {
} }
@Test @Test
public void clientOutboundChannelUsedBySimpleBroker() { void clientOutboundChannelUsedBySimpleBroker() {
ApplicationContext context = loadConfig(SimpleBrokerConfig.class); ApplicationContext context = loadConfig(SimpleBrokerConfig.class);
TestChannel outboundChannel = context.getBean("clientOutboundChannel", TestChannel.class); TestChannel outboundChannel = context.getBean("clientOutboundChannel", TestChannel.class);
@ -194,7 +194,7 @@ public class MessageBrokerConfigurationTests {
} }
@Test @Test
public void clientOutboundChannelCustomized() { void clientOutboundChannelCustomized() {
ApplicationContext context = loadConfig(CustomConfig.class); ApplicationContext context = loadConfig(CustomConfig.class);
AbstractSubscribableChannel channel = context.getBean( AbstractSubscribableChannel channel = context.getBean(
@ -215,7 +215,7 @@ public class MessageBrokerConfigurationTests {
} }
@Test @Test
public void brokerChannel() { void brokerChannel() {
ApplicationContext context = loadConfig(SimpleBrokerConfig.class); ApplicationContext context = loadConfig(SimpleBrokerConfig.class);
TestChannel channel = context.getBean("brokerChannel", TestChannel.class); TestChannel channel = context.getBean("brokerChannel", TestChannel.class);
@ -229,7 +229,7 @@ public class MessageBrokerConfigurationTests {
} }
@Test @Test
public void brokerChannelWithBrokerRelay() { void brokerChannelWithBrokerRelay() {
ApplicationContext context = loadConfig(BrokerRelayConfig.class); ApplicationContext context = loadConfig(BrokerRelayConfig.class);
TestChannel channel = context.getBean("brokerChannel", TestChannel.class); TestChannel channel = context.getBean("brokerChannel", TestChannel.class);
@ -241,7 +241,7 @@ public class MessageBrokerConfigurationTests {
} }
@Test @Test
public void brokerChannelUsedByAnnotatedMethod() { void brokerChannelUsedByAnnotatedMethod() {
ApplicationContext context = loadConfig(SimpleBrokerConfig.class); ApplicationContext context = loadConfig(SimpleBrokerConfig.class);
TestChannel channel = context.getBean("brokerChannel", TestChannel.class); TestChannel channel = context.getBean("brokerChannel", TestChannel.class);
@ -265,7 +265,7 @@ public class MessageBrokerConfigurationTests {
} }
@Test @Test
public void brokerChannelCustomized() { void brokerChannelCustomized() {
ApplicationContext context = loadConfig(CustomConfig.class); ApplicationContext context = loadConfig(CustomConfig.class);
AbstractSubscribableChannel channel = context.getBean( AbstractSubscribableChannel channel = context.getBean(
@ -282,7 +282,7 @@ public class MessageBrokerConfigurationTests {
} }
@Test @Test
public void configureMessageConvertersDefault() { void configureMessageConvertersDefault() {
AbstractMessageBrokerConfiguration config = new BaseTestMessageBrokerConfig(); AbstractMessageBrokerConfiguration config = new BaseTestMessageBrokerConfig();
CompositeMessageConverter compositeConverter = config.brokerMessageConverter(); CompositeMessageConverter compositeConverter = config.brokerMessageConverter();
@ -298,7 +298,7 @@ public class MessageBrokerConfigurationTests {
} }
@Test @Test
public void threadPoolSizeDefault() { void threadPoolSizeDefault() {
ApplicationContext context = loadConfig(DefaultConfig.class); ApplicationContext context = loadConfig(DefaultConfig.class);
String name = "clientInboundChannelExecutor"; String name = "clientInboundChannelExecutor";
@ -317,7 +317,7 @@ public class MessageBrokerConfigurationTests {
} }
@Test @Test
public void configureMessageConvertersCustom() { void configureMessageConvertersCustom() {
final MessageConverter testConverter = mock(); final MessageConverter testConverter = mock();
AbstractMessageBrokerConfiguration config = new BaseTestMessageBrokerConfig() { AbstractMessageBrokerConfiguration config = new BaseTestMessageBrokerConfig() {
@Override @Override
@ -334,7 +334,7 @@ public class MessageBrokerConfigurationTests {
} }
@Test @Test
public void configureMessageConvertersCustomAndDefault() { void configureMessageConvertersCustomAndDefault() {
final MessageConverter testConverter = mock(); final MessageConverter testConverter = mock();
AbstractMessageBrokerConfiguration config = new BaseTestMessageBrokerConfig() { AbstractMessageBrokerConfiguration config = new BaseTestMessageBrokerConfig() {
@ -356,7 +356,7 @@ public class MessageBrokerConfigurationTests {
} }
@Test @Test
public void customArgumentAndReturnValueTypes() { void customArgumentAndReturnValueTypes() {
ApplicationContext context = loadConfig(CustomConfig.class); ApplicationContext context = loadConfig(CustomConfig.class);
SimpAnnotationMethodMessageHandler handler = SimpAnnotationMethodMessageHandler handler =
@ -372,7 +372,7 @@ public class MessageBrokerConfigurationTests {
} }
@Test @Test
public void simpValidatorDefault() { void simpValidatorDefault() {
AbstractMessageBrokerConfiguration config = new BaseTestMessageBrokerConfig() {}; AbstractMessageBrokerConfiguration config = new BaseTestMessageBrokerConfig() {};
config.setApplicationContext(new StaticApplicationContext()); config.setApplicationContext(new StaticApplicationContext());
@ -381,7 +381,7 @@ public class MessageBrokerConfigurationTests {
} }
@Test @Test
public void simpValidatorCustom() { void simpValidatorCustom() {
final Validator validator = mock(); final Validator validator = mock();
AbstractMessageBrokerConfiguration config = new BaseTestMessageBrokerConfig() { AbstractMessageBrokerConfiguration config = new BaseTestMessageBrokerConfig() {
@Override @Override
@ -394,7 +394,7 @@ public class MessageBrokerConfigurationTests {
} }
@Test @Test
public void simpValidatorMvc() { void simpValidatorMvc() {
StaticApplicationContext appCxt = new StaticApplicationContext(); StaticApplicationContext appCxt = new StaticApplicationContext();
appCxt.registerSingleton("mvcValidator", TestValidator.class); appCxt.registerSingleton("mvcValidator", TestValidator.class);
AbstractMessageBrokerConfiguration config = new BaseTestMessageBrokerConfig() {}; AbstractMessageBrokerConfiguration config = new BaseTestMessageBrokerConfig() {};
@ -405,7 +405,7 @@ public class MessageBrokerConfigurationTests {
} }
@Test @Test
public void simpValidatorInjected() { void simpValidatorInjected() {
ApplicationContext context = loadConfig(SimpleBrokerConfig.class); ApplicationContext context = loadConfig(SimpleBrokerConfig.class);
SimpAnnotationMethodMessageHandler messageHandler = SimpAnnotationMethodMessageHandler messageHandler =
@ -415,7 +415,7 @@ public class MessageBrokerConfigurationTests {
} }
@Test @Test
public void customPathMatcher() { void customPathMatcher() {
ApplicationContext context = loadConfig(CustomConfig.class); ApplicationContext context = loadConfig(CustomConfig.class);
SimpleBrokerMessageHandler broker = context.getBean(SimpleBrokerMessageHandler.class); SimpleBrokerMessageHandler broker = context.getBean(SimpleBrokerMessageHandler.class);
@ -433,7 +433,7 @@ public class MessageBrokerConfigurationTests {
} }
@Test @Test
public void customCacheLimit() { void customCacheLimit() {
ApplicationContext context = loadConfig(CustomConfig.class); ApplicationContext context = loadConfig(CustomConfig.class);
SimpleBrokerMessageHandler broker = context.getBean(SimpleBrokerMessageHandler.class); SimpleBrokerMessageHandler broker = context.getBean(SimpleBrokerMessageHandler.class);
@ -442,7 +442,7 @@ public class MessageBrokerConfigurationTests {
} }
@Test @Test
public void customUserRegistryOrder() { void customUserRegistryOrder() {
ApplicationContext context = loadConfig(CustomConfig.class); ApplicationContext context = loadConfig(CustomConfig.class);
SimpUserRegistry registry = context.getBean(SimpUserRegistry.class); SimpUserRegistry registry = context.getBean(SimpUserRegistry.class);
@ -451,7 +451,7 @@ public class MessageBrokerConfigurationTests {
} }
@Test @Test
public void userBroadcasts() { void userBroadcasts() {
ApplicationContext context = loadConfig(BrokerRelayConfig.class); ApplicationContext context = loadConfig(BrokerRelayConfig.class);
SimpUserRegistry userRegistry = context.getBean(SimpUserRegistry.class); SimpUserRegistry userRegistry = context.getBean(SimpUserRegistry.class);
@ -471,7 +471,7 @@ public class MessageBrokerConfigurationTests {
} }
@Test @Test
public void userBroadcastsDisabledWithSimpleBroker() { void userBroadcastsDisabledWithSimpleBroker() {
ApplicationContext context = loadConfig(SimpleBrokerConfig.class); ApplicationContext context = loadConfig(SimpleBrokerConfig.class);
SimpUserRegistry registry = context.getBean(SimpUserRegistry.class); SimpUserRegistry registry = context.getBean(SimpUserRegistry.class);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2019 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -32,10 +32,10 @@ import static org.assertj.core.api.Assertions.assertThat;
* *
* @author Rossen Stoyanchev * @author Rossen Stoyanchev
*/ */
public class StompBrokerRelayRegistrationTests { class StompBrokerRelayRegistrationTests {
@Test @Test
public void test() { void test() {
SubscribableChannel inChannel = new StubMessageChannel(); SubscribableChannel inChannel = new StubMessageChannel();
MessageChannel outChannel = new StubMessageChannel(); MessageChannel outChannel = new StubMessageChannel();

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -77,7 +77,7 @@ public abstract class AbstractStompBrokerRelayIntegrationTests {
@BeforeEach @BeforeEach
public void setup(TestInfo testInfo) throws Exception { void setup(TestInfo testInfo) throws Exception {
logger.debug("Setting up before '" + testInfo.getTestMethod().get().getName() + "'"); logger.debug("Setting up before '" + testInfo.getTestMethod().get().getName() + "'");
this.responseChannel = new ExecutorSubscribableChannel(); this.responseChannel = new ExecutorSubscribableChannel();
@ -130,7 +130,7 @@ public abstract class AbstractStompBrokerRelayIntegrationTests {
protected abstract TcpOperations<byte[]> initTcpClient(int port); protected abstract TcpOperations<byte[]> initTcpClient(int port);
@AfterEach @AfterEach
public void stop() throws Exception { void stop() throws Exception {
try { try {
logger.debug("STOMP broker relay stats: " + this.relay.getStatsInfo()); logger.debug("STOMP broker relay stats: " + this.relay.getStatsInfo());
this.relay.stop(); this.relay.stop();
@ -155,7 +155,7 @@ public abstract class AbstractStompBrokerRelayIntegrationTests {
@Test @Test
public void publishSubscribe() throws Exception { void publishSubscribe() throws Exception {
logger.debug("Starting test publishSubscribe()"); logger.debug("Starting test publishSubscribe()");
String sess1 = "sess1"; String sess1 = "sess1";
@ -179,7 +179,7 @@ public abstract class AbstractStompBrokerRelayIntegrationTests {
} }
@Test @Test
public void messageDeliveryExceptionIfSystemSessionForwardFails() throws Exception { void messageDeliveryExceptionIfSystemSessionForwardFails() throws Exception {
logger.debug("Starting test messageDeliveryExceptionIfSystemSessionForwardFails()"); logger.debug("Starting test messageDeliveryExceptionIfSystemSessionForwardFails()");
stopActiveMqBrokerAndAwait(); stopActiveMqBrokerAndAwait();
@ -191,7 +191,7 @@ public abstract class AbstractStompBrokerRelayIntegrationTests {
} }
@Test @Test
public void brokerBecomingUnavailableTriggersErrorFrame() throws Exception { void brokerBecomingUnavailableTriggersErrorFrame() throws Exception {
logger.debug("Starting test brokerBecomingUnavailableTriggersErrorFrame()"); logger.debug("Starting test brokerBecomingUnavailableTriggersErrorFrame()");
String sess1 = "sess1"; String sess1 = "sess1";
@ -206,7 +206,7 @@ public abstract class AbstractStompBrokerRelayIntegrationTests {
} }
@Test @Test
public void brokerAvailabilityEventWhenStopped() throws Exception { void brokerAvailabilityEventWhenStopped() throws Exception {
logger.debug("Starting test brokerAvailabilityEventWhenStopped()"); logger.debug("Starting test brokerAvailabilityEventWhenStopped()");
stopActiveMqBrokerAndAwait(); stopActiveMqBrokerAndAwait();
@ -214,7 +214,7 @@ public abstract class AbstractStompBrokerRelayIntegrationTests {
} }
@Test @Test
public void relayReconnectsIfBrokerComesBackUp() throws Exception { void relayReconnectsIfBrokerComesBackUp() throws Exception {
logger.debug("Starting test relayReconnectsIfBrokerComesBackUp()"); logger.debug("Starting test relayReconnectsIfBrokerComesBackUp()");
String sess1 = "sess1"; String sess1 = "sess1";
@ -240,7 +240,7 @@ public abstract class AbstractStompBrokerRelayIntegrationTests {
} }
@Test @Test
public void disconnectWithReceipt() throws Exception { void disconnectWithReceipt() throws Exception {
logger.debug("Starting test disconnectWithReceipt()"); logger.debug("Starting test disconnectWithReceipt()");
MessageExchange connect = MessageExchangeBuilder.connect("sess1").build(); MessageExchange connect = MessageExchangeBuilder.connect("sess1").build();
@ -443,7 +443,7 @@ public abstract class AbstractStompBrokerRelayIntegrationTests {
} }
public MessageExchange build() { public MessageExchange build() {
return new MessageExchange(this.message, this.expected.toArray(new MessageMatcher[this.expected.size()])); return new MessageExchange(this.message, this.expected.toArray(new MessageMatcher[0]));
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -34,13 +34,13 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
* @author Rossen Stoyanchev * @author Rossen Stoyanchev
* @since 4.0.3 * @since 4.0.3
*/ */
public class BufferingStompDecoderTests { class BufferingStompDecoderTests {
private final StompDecoder STOMP_DECODER = new StompDecoder(); private static final StompDecoder STOMP_DECODER = new StompDecoder();
@Test @Test
public void basic() throws InterruptedException { void basic() {
BufferingStompDecoder stompDecoder = new BufferingStompDecoder(STOMP_DECODER, 128); BufferingStompDecoder stompDecoder = new BufferingStompDecoder(STOMP_DECODER, 128);
String chunk = "SEND\na:alpha\n\nMessage body\0"; String chunk = "SEND\na:alpha\n\nMessage body\0";
@ -53,7 +53,7 @@ public class BufferingStompDecoderTests {
} }
@Test @Test
public void oneMessageInTwoChunks() throws InterruptedException { void oneMessageInTwoChunks() {
BufferingStompDecoder stompDecoder = new BufferingStompDecoder(STOMP_DECODER, 128); BufferingStompDecoder stompDecoder = new BufferingStompDecoder(STOMP_DECODER, 128);
String chunk1 = "SEND\na:alpha\n\nMessage"; String chunk1 = "SEND\na:alpha\n\nMessage";
String chunk2 = " body\0"; String chunk2 = " body\0";
@ -70,7 +70,7 @@ public class BufferingStompDecoderTests {
} }
@Test @Test
public void twoMessagesInOneChunk() throws InterruptedException { void twoMessagesInOneChunk() {
BufferingStompDecoder stompDecoder = new BufferingStompDecoder(STOMP_DECODER, 128); BufferingStompDecoder stompDecoder = new BufferingStompDecoder(STOMP_DECODER, 128);
String chunk = """ String chunk = """
SEND SEND
@ -91,7 +91,7 @@ public class BufferingStompDecoderTests {
} }
@Test @Test
public void oneFullAndOneSplitMessageContentLength() throws InterruptedException { void oneFullAndOneSplitMessageContentLength() {
BufferingStompDecoder stompDecoder = new BufferingStompDecoder(STOMP_DECODER, 128); BufferingStompDecoder stompDecoder = new BufferingStompDecoder(STOMP_DECODER, 128);
int contentLength = "Payload2a-Payload2b".getBytes().length; int contentLength = "Payload2a-Payload2b".getBytes().length;
String chunk1 = "SEND\na:alpha\n\nPayload1\0SEND\ncontent-length:" + contentLength + "\n"; String chunk1 = "SEND\na:alpha\n\nPayload1\0SEND\ncontent-length:" + contentLength + "\n";
@ -120,7 +120,7 @@ public class BufferingStompDecoderTests {
} }
@Test @Test
public void oneFullAndOneSplitMessageNoContentLength() throws InterruptedException { void oneFullAndOneSplitMessageNoContentLength() {
BufferingStompDecoder stompDecoder = new BufferingStompDecoder(STOMP_DECODER, 128); BufferingStompDecoder stompDecoder = new BufferingStompDecoder(STOMP_DECODER, 128);
String chunk1 = "SEND\na:alpha\n\nPayload1\0SEND\na:alpha\n"; String chunk1 = "SEND\na:alpha\n\nPayload1\0SEND\na:alpha\n";
List<Message<byte[]>> messages = stompDecoder.decode(toByteBuffer(chunk1)); List<Message<byte[]>> messages = stompDecoder.decode(toByteBuffer(chunk1));
@ -148,7 +148,7 @@ public class BufferingStompDecoderTests {
} }
@Test @Test
public void oneFullAndOneSplitWithContentLengthExceedingBufferSize() throws InterruptedException { void oneFullAndOneSplitWithContentLengthExceedingBufferSize() {
BufferingStompDecoder stompDecoder = new BufferingStompDecoder(STOMP_DECODER, 128); BufferingStompDecoder stompDecoder = new BufferingStompDecoder(STOMP_DECODER, 128);
String chunk1 = "SEND\na:alpha\n\nPayload1\0SEND\ncontent-length:129\n"; String chunk1 = "SEND\na:alpha\n\nPayload1\0SEND\ncontent-length:129\n";
List<Message<byte[]>> messages = stompDecoder.decode(toByteBuffer(chunk1)); List<Message<byte[]>> messages = stompDecoder.decode(toByteBuffer(chunk1));
@ -165,7 +165,7 @@ public class BufferingStompDecoderTests {
} }
@Test @Test
public void bufferSizeLimit() { void bufferSizeLimit() {
BufferingStompDecoder stompDecoder = new BufferingStompDecoder(STOMP_DECODER, 10); BufferingStompDecoder stompDecoder = new BufferingStompDecoder(STOMP_DECODER, 10);
String payload = "SEND\na:alpha\n\nMessage body"; String payload = "SEND\na:alpha\n\nMessage body";
assertThatExceptionOfType(StompConversionException.class).isThrownBy(() -> assertThatExceptionOfType(StompConversionException.class).isThrownBy(() ->
@ -173,7 +173,7 @@ public class BufferingStompDecoderTests {
} }
@Test @Test
public void incompleteCommand() { void incompleteCommand() {
BufferingStompDecoder stompDecoder = new BufferingStompDecoder(STOMP_DECODER, 128); BufferingStompDecoder stompDecoder = new BufferingStompDecoder(STOMP_DECODER, 128);
String chunk = "MESSAG"; String chunk = "MESSAG";
@ -184,7 +184,7 @@ public class BufferingStompDecoderTests {
// SPR-13416 // SPR-13416
@Test @Test
public void incompleteHeaderWithPartialEscapeSequence() throws Exception { void incompleteHeaderWithPartialEscapeSequence() {
BufferingStompDecoder stompDecoder = new BufferingStompDecoder(STOMP_DECODER, 128); BufferingStompDecoder stompDecoder = new BufferingStompDecoder(STOMP_DECODER, 128);
String chunk = "SEND\na:long\\"; String chunk = "SEND\na:long\\";
@ -193,7 +193,7 @@ public class BufferingStompDecoderTests {
} }
@Test @Test
public void invalidEscapeSequence() { void invalidEscapeSequence() {
BufferingStompDecoder stompDecoder = new BufferingStompDecoder(STOMP_DECODER, 128); BufferingStompDecoder stompDecoder = new BufferingStompDecoder(STOMP_DECODER, 128);
String payload = "SEND\na:alpha\\x\\n\nMessage body\0"; String payload = "SEND\na:alpha\\x\\n\nMessage body\0";
assertThatExceptionOfType(StompConversionException.class).isThrownBy(() -> assertThatExceptionOfType(StompConversionException.class).isThrownBy(() ->
@ -201,7 +201,7 @@ public class BufferingStompDecoderTests {
} }
@Test @Test
public void invalidEscapeSequenceWithSingleSlashAtEndOfHeaderValue() { void invalidEscapeSequenceWithSingleSlashAtEndOfHeaderValue() {
BufferingStompDecoder stompDecoder = new BufferingStompDecoder(STOMP_DECODER, 128); BufferingStompDecoder stompDecoder = new BufferingStompDecoder(STOMP_DECODER, 128);
String payload = "SEND\na:alpha\\\n\nMessage body\0"; String payload = "SEND\na:alpha\\\n\nMessage body\0";
assertThatExceptionOfType(StompConversionException.class).isThrownBy(() -> assertThatExceptionOfType(StompConversionException.class).isThrownBy(() ->

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -83,7 +83,7 @@ public class DefaultStompSessionTests {
@BeforeEach @BeforeEach
public void setUp() { void setUp() {
this.connectHeaders = new StompHeaders(); this.connectHeaders = new StompHeaders();
this.session = new DefaultStompSession(this.sessionHandler, this.connectHeaders); this.session = new DefaultStompSession(this.sessionHandler, this.connectHeaders);
this.session.setMessageConverter( this.session.setMessageConverter(
@ -97,7 +97,7 @@ public class DefaultStompSessionTests {
@Test @Test
public void afterConnected() { void afterConnected() {
assertThat(this.session.isConnected()).isFalse(); assertThat(this.session.isConnected()).isFalse();
this.connectHeaders.setHost("my-host"); this.connectHeaders.setHost("my-host");
this.connectHeaders.setHeartbeat(new long[] {11, 12}); this.connectHeaders.setHeartbeat(new long[] {11, 12});
@ -127,7 +127,7 @@ public class DefaultStompSessionTests {
} }
@Test @Test
public void afterConnectFailure() { void afterConnectFailure() {
IllegalStateException exception = new IllegalStateException("simulated exception"); IllegalStateException exception = new IllegalStateException("simulated exception");
this.session.afterConnectFailure(exception); this.session.afterConnectFailure(exception);
verify(this.sessionHandler).handleTransportError(this.session, exception); verify(this.sessionHandler).handleTransportError(this.session, exception);
@ -135,7 +135,7 @@ public class DefaultStompSessionTests {
} }
@Test @Test
public void handleConnectedFrame() { void handleConnectedFrame() {
this.session.afterConnected(this.connection); this.session.afterConnected(this.connection);
assertThat(this.session.isConnected()).isTrue(); assertThat(this.session.isConnected()).isTrue();
@ -153,7 +153,7 @@ public class DefaultStompSessionTests {
} }
@Test @Test
public void heartbeatValues() { void heartbeatValues() {
this.session.afterConnected(this.connection); this.session.afterConnected(this.connection);
assertThat(this.session.isConnected()).isTrue(); assertThat(this.session.isConnected()).isTrue();
@ -175,7 +175,7 @@ public class DefaultStompSessionTests {
} }
@Test @Test
public void heartbeatNotSupportedByServer() { void heartbeatNotSupportedByServer() {
this.session.afterConnected(this.connection); this.session.afterConnected(this.connection);
verify(this.connection).sendAsync(any()); verify(this.connection).sendAsync(any());
@ -191,7 +191,7 @@ public class DefaultStompSessionTests {
} }
@Test @Test
public void heartbeatTasks() { void heartbeatTasks() {
this.session.afterConnected(this.connection); this.session.afterConnected(this.connection);
verify(this.connection).sendAsync(any()); verify(this.connection).sendAsync(any());
@ -226,7 +226,7 @@ public class DefaultStompSessionTests {
} }
@Test @Test
public void handleErrorFrame() { void handleErrorFrame() {
StompHeaderAccessor accessor = StompHeaderAccessor.create(StompCommand.ERROR); StompHeaderAccessor accessor = StompHeaderAccessor.create(StompCommand.ERROR);
accessor.setContentType(new MimeType("text", "plain", StandardCharsets.UTF_8)); accessor.setContentType(new MimeType("text", "plain", StandardCharsets.UTF_8));
accessor.addNativeHeader("foo", "bar"); accessor.addNativeHeader("foo", "bar");
@ -245,7 +245,7 @@ public class DefaultStompSessionTests {
} }
@Test @Test
public void handleErrorFrameWithEmptyPayload() { void handleErrorFrameWithEmptyPayload() {
StompHeaderAccessor accessor = StompHeaderAccessor.create(StompCommand.ERROR); StompHeaderAccessor accessor = StompHeaderAccessor.create(StompCommand.ERROR);
accessor.addNativeHeader("foo", "bar"); accessor.addNativeHeader("foo", "bar");
accessor.setLeaveMutable(true); accessor.setLeaveMutable(true);
@ -257,7 +257,7 @@ public class DefaultStompSessionTests {
} }
@Test @Test
public void handleErrorFrameWithConversionException() { void handleErrorFrameWithConversionException() {
StompHeaderAccessor accessor = StompHeaderAccessor.create(StompCommand.ERROR); StompHeaderAccessor accessor = StompHeaderAccessor.create(StompCommand.ERROR);
accessor.setContentType(MimeTypeUtils.APPLICATION_JSON); accessor.setContentType(MimeTypeUtils.APPLICATION_JSON);
accessor.addNativeHeader("foo", "bar"); accessor.addNativeHeader("foo", "bar");
@ -276,7 +276,7 @@ public class DefaultStompSessionTests {
} }
@Test @Test
public void handleMessageFrame() { void handleMessageFrame() {
this.session.afterConnected(this.connection); this.session.afterConnected(this.connection);
StompFrameHandler frameHandler = mock(); StompFrameHandler frameHandler = mock();
@ -303,7 +303,7 @@ public class DefaultStompSessionTests {
} }
@Test @Test
public void handleMessageFrameWithConversionException() { void handleMessageFrameWithConversionException() {
this.session.afterConnected(this.connection); this.session.afterConnected(this.connection);
assertThat(this.session.isConnected()).isTrue(); assertThat(this.session.isConnected()).isTrue();
@ -333,7 +333,7 @@ public class DefaultStompSessionTests {
} }
@Test @Test
public void handleFailure() { void handleFailure() {
IllegalStateException exception = new IllegalStateException("simulated exception"); IllegalStateException exception = new IllegalStateException("simulated exception");
this.session.handleFailure(exception); this.session.handleFailure(exception);
@ -342,7 +342,7 @@ public class DefaultStompSessionTests {
} }
@Test @Test
public void afterConnectionClosed() { void afterConnectionClosed() {
this.session.afterConnectionClosed(); this.session.afterConnectionClosed();
verify(this.sessionHandler).handleTransportError(same(this.session), any(ConnectionLostException.class)); verify(this.sessionHandler).handleTransportError(same(this.session), any(ConnectionLostException.class));
@ -350,7 +350,7 @@ public class DefaultStompSessionTests {
} }
@Test @Test
public void send() { void send() {
this.session.afterConnected(this.connection); this.session.afterConnected(this.connection);
assertThat(this.session.isConnected()).isTrue(); assertThat(this.session.isConnected()).isTrue();
@ -373,7 +373,7 @@ public class DefaultStompSessionTests {
} }
@Test @Test
public void sendWithReceipt() { void sendWithReceipt() {
this.session.afterConnected(this.connection); this.session.afterConnected(this.connection);
assertThat(this.session.isConnected()).isTrue(); assertThat(this.session.isConnected()).isTrue();
@ -416,7 +416,7 @@ public class DefaultStompSessionTests {
} }
@Test @Test
public void sendWithConversionException() { void sendWithConversionException() {
this.session.afterConnected(this.connection); this.session.afterConnected(this.connection);
assertThat(this.session.isConnected()).isTrue(); assertThat(this.session.isConnected()).isTrue();
@ -430,7 +430,7 @@ public class DefaultStompSessionTests {
} }
@Test @Test
public void sendWithExecutionException() { void sendWithExecutionException() {
this.session.afterConnected(this.connection); this.session.afterConnected(this.connection);
assertThat(this.session.isConnected()).isTrue(); assertThat(this.session.isConnected()).isTrue();
@ -444,7 +444,7 @@ public class DefaultStompSessionTests {
} }
@Test @Test
public void subscribe() { void subscribe() {
this.session.afterConnected(this.connection); this.session.afterConnected(this.connection);
assertThat(this.session.isConnected()).isTrue(); assertThat(this.session.isConnected()).isTrue();
@ -463,7 +463,7 @@ public class DefaultStompSessionTests {
} }
@Test @Test
public void subscribeWithHeaders() { void subscribeWithHeaders() {
this.session.afterConnected(this.connection); this.session.afterConnected(this.connection);
assertThat(this.session.isConnected()).isTrue(); assertThat(this.session.isConnected()).isTrue();
@ -489,7 +489,7 @@ public class DefaultStompSessionTests {
} }
@Test @Test
public void unsubscribe() { void unsubscribe() {
this.session.afterConnected(this.connection); this.session.afterConnected(this.connection);
assertThat(this.session.isConnected()).isTrue(); assertThat(this.session.isConnected()).isTrue();
@ -536,7 +536,7 @@ public class DefaultStompSessionTests {
} }
@Test @Test
public void ack() { void ack() {
this.session.afterConnected(this.connection); this.session.afterConnected(this.connection);
assertThat(this.session.isConnected()).isTrue(); assertThat(this.session.isConnected()).isTrue();
@ -553,7 +553,7 @@ public class DefaultStompSessionTests {
} }
@Test @Test
public void nack() { void nack() {
this.session.afterConnected(this.connection); this.session.afterConnected(this.connection);
assertThat(this.session.isConnected()).isTrue(); assertThat(this.session.isConnected()).isTrue();
@ -570,7 +570,7 @@ public class DefaultStompSessionTests {
} }
@Test @Test
public void receiptReceived() { void receiptReceived() {
this.session.afterConnected(this.connection); this.session.afterConnected(this.connection);
this.session.setTaskScheduler(mock()); this.session.setTaskScheduler(mock());
@ -597,12 +597,11 @@ public class DefaultStompSessionTests {
assertThat(received.get()).isNotNull(); assertThat(received.get()).isNotNull();
assertThat(received.get()).isTrue(); assertThat(received.get()).isTrue();
assertThat(receivedHeaders.get()).isNotNull(); assertThat(receivedHeaders.get()).isNotNull();
assertThat(receivedHeaders.get().get("foo")).hasSize(1); assertThat(receivedHeaders.get().get("foo")).containsExactly("bar");
assertThat(receivedHeaders.get().get("foo")).element(0).isEqualTo("bar");
} }
@Test @Test
public void receiptReceivedBeforeTaskAdded() { void receiptReceivedBeforeTaskAdded() {
this.session.afterConnected(this.connection); this.session.afterConnected(this.connection);
this.session.setTaskScheduler(mock()); this.session.setTaskScheduler(mock());
@ -628,8 +627,7 @@ public class DefaultStompSessionTests {
assertThat(received.get()).isNotNull(); assertThat(received.get()).isNotNull();
assertThat(received.get()).isTrue(); assertThat(received.get()).isTrue();
assertThat(receivedHeaders.get()).isNotNull(); assertThat(receivedHeaders.get()).isNotNull();
assertThat(receivedHeaders.get().get("foo")).hasSize(1); assertThat(receivedHeaders.get().get("foo")).containsExactly("bar");
assertThat(receivedHeaders.get().get("foo")).element(0).isEqualTo("bar");
} }
@Test @Test
@ -665,7 +663,7 @@ public class DefaultStompSessionTests {
} }
@Test @Test
public void disconnect() { void disconnect() {
this.session.afterConnected(this.connection); this.session.afterConnected(this.connection);
assertThat(this.session.isConnected()).isTrue(); assertThat(this.session.isConnected()).isTrue();
@ -675,7 +673,7 @@ public class DefaultStompSessionTests {
} }
@Test @Test
public void disconnectWithHeaders() { void disconnectWithHeaders() {
this.session.afterConnected(this.connection); this.session.afterConnected(this.connection);
assertThat(this.session.isConnected()).isTrue(); assertThat(this.session.isConnected()).isTrue();
@ -688,8 +686,7 @@ public class DefaultStompSessionTests {
StompHeaderAccessor accessor = MessageHeaderAccessor.getAccessor(message, StompHeaderAccessor.class); StompHeaderAccessor accessor = MessageHeaderAccessor.getAccessor(message, StompHeaderAccessor.class);
headers = StompHeaders.readOnlyStompHeaders(accessor.getNativeHeaders()); headers = StompHeaders.readOnlyStompHeaders(accessor.getNativeHeaders());
assertThat(headers).as(headers.toString()).hasSize(1); assertThat(headers).as(headers.toString()).hasSize(1);
assertThat(headers.get("foo")).hasSize(1); assertThat(headers.get("foo")).containsExactly("bar");
assertThat(headers.get("foo")).element(0).isEqualTo("bar");
assertThat(this.session.isConnected()).isFalse(); assertThat(this.session.isConnected()).isFalse();
verifyNoMoreInteractions(this.sessionHandler); verifyNoMoreInteractions(this.sessionHandler);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2022 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -25,7 +25,7 @@ import org.springframework.messaging.tcp.reactor.ReactorNettyTcpClient;
* *
* @author Rossen Stoyanchev * @author Rossen Stoyanchev
*/ */
public class ReactorNettyStompBrokerRelayIntegrationTests extends AbstractStompBrokerRelayIntegrationTests { class ReactorNettyStompBrokerRelayIntegrationTests extends AbstractStompBrokerRelayIntegrationTests {
@Override @Override
protected TcpOperations<byte[]> initTcpClient(int port) { protected TcpOperations<byte[]> initTcpClient(int port) {

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2022 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -49,7 +49,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Rossen Stoyanchev * @author Rossen Stoyanchev
* @author Sam Brannen * @author Sam Brannen
*/ */
public class ReactorNettyTcpStompClientTests { class ReactorNettyTcpStompClientTests {
private static final Log logger = LogFactory.getLog(ReactorNettyTcpStompClientTests.class); private static final Log logger = LogFactory.getLog(ReactorNettyTcpStompClientTests.class);
@ -62,7 +62,7 @@ public class ReactorNettyTcpStompClientTests {
@BeforeEach @BeforeEach
public void setup(TestInfo testInfo) throws Exception { void setup(TestInfo testInfo) throws Exception {
logger.debug("Setting up before '" + testInfo.getTestMethod().get().getName() + "'"); logger.debug("Setting up before '" + testInfo.getTestMethod().get().getName() + "'");
TransportConnector stompConnector = createStompConnector(); TransportConnector stompConnector = createStompConnector();
@ -97,7 +97,7 @@ public class ReactorNettyTcpStompClientTests {
} }
@AfterEach @AfterEach
public void shutdown() throws Exception { void shutdown() throws Exception {
try { try {
this.client.shutdown(); this.client.shutdown();
this.client2.shutdown(); this.client2.shutdown();
@ -116,12 +116,12 @@ public class ReactorNettyTcpStompClientTests {
@Test @Test
public void publishSubscribeOnReactorNetty() throws Exception { void publishSubscribeOnReactorNetty() throws Exception {
testPublishSubscribe(this.client); testPublishSubscribe(this.client);
} }
@Test @Test
public void publishSubscribeOnReactorNetty2() throws Exception { void publishSubscribeOnReactorNetty2() throws Exception {
testPublishSubscribe(this.client2); testPublishSubscribe(this.client2);
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2019 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -26,13 +26,13 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException
* *
* @author Rossen Stoyanchev * @author Rossen Stoyanchev
*/ */
public class StompClientSupportTests { class StompClientSupportTests {
private final StompClientSupport stompClient = new StompClientSupport() {}; private final StompClientSupport stompClient = new StompClientSupport() {};
@Test @Test
public void defaultHeartbeatValidation() throws Exception { void defaultHeartbeatValidation() {
trySetDefaultHeartbeat(new long[] {-1, 0}); trySetDefaultHeartbeat(new long[] {-1, 0});
trySetDefaultHeartbeat(new long[] {0, -1}); trySetDefaultHeartbeat(new long[] {0, -1});
} }
@ -43,12 +43,12 @@ public class StompClientSupportTests {
} }
@Test @Test
public void defaultHeartbeatValue() throws Exception { void defaultHeartbeatValue() {
assertThat(this.stompClient.getDefaultHeartbeat()).isEqualTo(new long[] {10000, 10000}); assertThat(this.stompClient.getDefaultHeartbeat()).isEqualTo(new long[] {10000, 10000});
} }
@Test @Test
public void isDefaultHeartbeatEnabled() throws Exception { void isDefaultHeartbeatEnabled() {
assertThat(this.stompClient.getDefaultHeartbeat()).isEqualTo(new long[] {10000, 10000}); assertThat(this.stompClient.getDefaultHeartbeat()).isEqualTo(new long[] {10000, 10000});
assertThat(this.stompClient.isDefaultHeartbeatEnabled()).isTrue(); assertThat(this.stompClient.isDefaultHeartbeatEnabled()).isTrue();
@ -57,7 +57,7 @@ public class StompClientSupportTests {
} }
@Test @Test
public void processConnectHeadersDefault() throws Exception { void processConnectHeadersDefault() {
StompHeaders connectHeaders = this.stompClient.processConnectHeaders(null); StompHeaders connectHeaders = this.stompClient.processConnectHeaders(null);
assertThat(connectHeaders).isNotNull(); assertThat(connectHeaders).isNotNull();
@ -65,7 +65,7 @@ public class StompClientSupportTests {
} }
@Test @Test
public void processConnectHeadersWithExplicitHeartbeat() throws Exception { void processConnectHeadersWithExplicitHeartbeat() {
StompHeaders connectHeaders = new StompHeaders(); StompHeaders connectHeaders = new StompHeaders();
connectHeaders.setHeartbeat(new long[] {15000, 15000}); connectHeaders.setHeartbeat(new long[] {15000, 15000});

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2019 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -30,7 +30,7 @@ import static org.assertj.core.api.Assertions.assertThat;
/** /**
* @author Juergen Hoeller * @author Juergen Hoeller
*/ */
public class StompCommandTests { class StompCommandTests {
private static final Collection<StompCommand> destinationRequired = private static final Collection<StompCommand> destinationRequired =
Arrays.asList(StompCommand.SEND, StompCommand.SUBSCRIBE, StompCommand.MESSAGE); Arrays.asList(StompCommand.SEND, StompCommand.SUBSCRIBE, StompCommand.MESSAGE);
@ -59,7 +59,7 @@ public class StompCommandTests {
@Test @Test
public void getMessageType() throws Exception { void getMessageType() {
for (StompCommand stompCommand : StompCommand.values()) { for (StompCommand stompCommand : StompCommand.values()) {
SimpMessageType simp = messageTypes.get(stompCommand); SimpMessageType simp = messageTypes.get(stompCommand);
if (simp == null) { if (simp == null) {
@ -70,28 +70,28 @@ public class StompCommandTests {
} }
@Test @Test
public void requiresDestination() throws Exception { void requiresDestination() {
for (StompCommand stompCommand : StompCommand.values()) { for (StompCommand stompCommand : StompCommand.values()) {
assertThat(stompCommand.requiresDestination()).isEqualTo(destinationRequired.contains(stompCommand)); assertThat(stompCommand.requiresDestination()).isEqualTo(destinationRequired.contains(stompCommand));
} }
} }
@Test @Test
public void requiresSubscriptionId() throws Exception { void requiresSubscriptionId() {
for (StompCommand stompCommand : StompCommand.values()) { for (StompCommand stompCommand : StompCommand.values()) {
assertThat(stompCommand.requiresSubscriptionId()).isEqualTo(subscriptionIdRequired.contains(stompCommand)); assertThat(stompCommand.requiresSubscriptionId()).isEqualTo(subscriptionIdRequired.contains(stompCommand));
} }
} }
@Test @Test
public void requiresContentLength() throws Exception { void requiresContentLength() {
for (StompCommand stompCommand : StompCommand.values()) { for (StompCommand stompCommand : StompCommand.values()) {
assertThat(stompCommand.requiresContentLength()).isEqualTo(contentLengthRequired.contains(stompCommand)); assertThat(stompCommand.requiresContentLength()).isEqualTo(contentLengthRequired.contains(stompCommand));
} }
} }
@Test @Test
public void isBodyAllowed() throws Exception { void isBodyAllowed() {
for (StompCommand stompCommand : StompCommand.values()) { for (StompCommand stompCommand : StompCommand.values()) {
assertThat(stompCommand.isBodyAllowed()).isEqualTo(bodyAllowed.contains(stompCommand)); assertThat(stompCommand.isBodyAllowed()).isEqualTo(bodyAllowed.contains(stompCommand));
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -34,13 +34,13 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
* @author Andy Wilkinson * @author Andy Wilkinson
* @author Stephane Maldini * @author Stephane Maldini
*/ */
public class StompDecoderTests { class StompDecoderTests {
private final StompDecoder decoder = new StompDecoder(); private final StompDecoder decoder = new StompDecoder();
@Test @Test
public void decodeFrameWithCrLfEols() { void decodeFrameWithCrLfEols() {
Message<byte[]> frame = decode("DISCONNECT\r\n\r\n\0"); Message<byte[]> frame = decode("DISCONNECT\r\n\r\n\0");
StompHeaderAccessor headers = StompHeaderAccessor.wrap(frame); StompHeaderAccessor headers = StompHeaderAccessor.wrap(frame);
@ -50,7 +50,7 @@ public class StompDecoderTests {
} }
@Test @Test
public void decodeFrameWithNoHeadersAndNoBody() { void decodeFrameWithNoHeadersAndNoBody() {
Message<byte[]> frame = decode("DISCONNECT\n\n\0"); Message<byte[]> frame = decode("DISCONNECT\n\n\0");
StompHeaderAccessor headers = StompHeaderAccessor.wrap(frame); StompHeaderAccessor headers = StompHeaderAccessor.wrap(frame);
@ -60,7 +60,7 @@ public class StompDecoderTests {
} }
@Test @Test
public void decodeFrameWithNoBody() { void decodeFrameWithNoBody() {
String accept = "accept-version:1.1\n"; String accept = "accept-version:1.1\n";
String host = "host:github.org\n"; String host = "host:github.org\n";
@ -77,7 +77,7 @@ public class StompDecoderTests {
} }
@Test @Test
public void decodeFrame() { void decodeFrame() {
Message<byte[]> frame = decode("SEND\ndestination:test\n\nThe body of the message\0"); Message<byte[]> frame = decode("SEND\ndestination:test\n\nThe body of the message\0");
StompHeaderAccessor headers = StompHeaderAccessor.wrap(frame); StompHeaderAccessor headers = StompHeaderAccessor.wrap(frame);
@ -91,7 +91,7 @@ public class StompDecoderTests {
} }
@Test @Test
public void decodeFrameWithContentLength() { void decodeFrameWithContentLength() {
Message<byte[]> message = decode("SEND\ncontent-length:23\n\nThe body of the message\0"); Message<byte[]> message = decode("SEND\ncontent-length:23\n\nThe body of the message\0");
StompHeaderAccessor headers = StompHeaderAccessor.wrap(message); StompHeaderAccessor headers = StompHeaderAccessor.wrap(message);
@ -107,7 +107,7 @@ public class StompDecoderTests {
// SPR-11528 // SPR-11528
@Test @Test
public void decodeFrameWithInvalidContentLength() { void decodeFrameWithInvalidContentLength() {
Message<byte[]> message = decode("SEND\ncontent-length:-1\n\nThe body of the message\0"); Message<byte[]> message = decode("SEND\ncontent-length:-1\n\nThe body of the message\0");
StompHeaderAccessor headers = StompHeaderAccessor.wrap(message); StompHeaderAccessor headers = StompHeaderAccessor.wrap(message);
@ -121,7 +121,7 @@ public class StompDecoderTests {
} }
@Test @Test
public void decodeFrameWithContentLengthZero() { void decodeFrameWithContentLengthZero() {
Message<byte[]> frame = decode("SEND\ncontent-length:0\n\n\0"); Message<byte[]> frame = decode("SEND\ncontent-length:0\n\n\0");
StompHeaderAccessor headers = StompHeaderAccessor.wrap(frame); StompHeaderAccessor headers = StompHeaderAccessor.wrap(frame);
@ -135,7 +135,7 @@ public class StompDecoderTests {
} }
@Test @Test
public void decodeFrameWithNullOctectsInTheBody() { void decodeFrameWithNullOctectsInTheBody() {
Message<byte[]> frame = decode("SEND\ncontent-length:23\n\nThe b\0dy \0f the message\0"); Message<byte[]> frame = decode("SEND\ncontent-length:23\n\nThe b\0dy \0f the message\0");
StompHeaderAccessor headers = StompHeaderAccessor.wrap(frame); StompHeaderAccessor headers = StompHeaderAccessor.wrap(frame);
@ -149,7 +149,7 @@ public class StompDecoderTests {
} }
@Test @Test
public void decodeFrameWithEscapedHeaders() { void decodeFrameWithEscapedHeaders() {
Message<byte[]> frame = decode("DISCONNECT\na\\c\\r\\n\\\\b:alpha\\cbravo\\r\\n\\\\\n\n\0"); Message<byte[]> frame = decode("DISCONNECT\na\\c\\r\\n\\\\b:alpha\\cbravo\\r\\n\\\\\n\n\0");
StompHeaderAccessor headers = StompHeaderAccessor.wrap(frame); StompHeaderAccessor headers = StompHeaderAccessor.wrap(frame);
@ -177,7 +177,7 @@ public class StompDecoderTests {
} }
@Test @Test
public void decodeFrameBodyNotAllowed() { void decodeFrameBodyNotAllowed() {
assertThatExceptionOfType(StompConversionException.class).isThrownBy(() -> assertThatExceptionOfType(StompConversionException.class).isThrownBy(() ->
decode("CONNECT\naccept-version:1.2\n\nThe body of the message\0")); decode("CONNECT\naccept-version:1.2\n\nThe body of the message\0"));
} }
@ -194,7 +194,7 @@ public class StompDecoderTests {
} }
@Test @Test
public void decodeMultipleFramesFromSameBuffer() { void decodeMultipleFramesFromSameBuffer() {
String frame1 = "SEND\ndestination:test\n\nThe body of the message\0"; String frame1 = "SEND\ndestination:test\n\nThe body of the message\0";
String frame2 = "DISCONNECT\n\n\0"; String frame2 = "DISCONNECT\n\n\0";
ByteBuffer buffer = ByteBuffer.wrap((frame1 + frame2).getBytes()); ByteBuffer buffer = ByteBuffer.wrap((frame1 + frame2).getBytes());
@ -224,48 +224,48 @@ public class StompDecoderTests {
} }
@Test @Test
public void decodeFrameWithIncompleteCommand() { void decodeFrameWithIncompleteCommand() {
assertIncompleteDecode("MESSAG"); assertIncompleteDecode("MESSAG");
} }
@Test @Test
public void decodeFrameWithIncompleteHeader() { void decodeFrameWithIncompleteHeader() {
assertIncompleteDecode("SEND\ndestination"); assertIncompleteDecode("SEND\ndestination");
assertIncompleteDecode("SEND\ndestination:"); assertIncompleteDecode("SEND\ndestination:");
assertIncompleteDecode("SEND\ndestination:test"); assertIncompleteDecode("SEND\ndestination:test");
} }
@Test @Test
public void decodeFrameWithoutNullOctetTerminator() { void decodeFrameWithoutNullOctetTerminator() {
assertIncompleteDecode("SEND\ndestination:test\n"); assertIncompleteDecode("SEND\ndestination:test\n");
assertIncompleteDecode("SEND\ndestination:test\n\n"); assertIncompleteDecode("SEND\ndestination:test\n\n");
assertIncompleteDecode("SEND\ndestination:test\n\nThe body"); assertIncompleteDecode("SEND\ndestination:test\n\nThe body");
} }
@Test @Test
public void decodeFrameWithInsufficientContent() { void decodeFrameWithInsufficientContent() {
assertIncompleteDecode("SEND\ncontent-length:23\n\nThe body of the mess"); assertIncompleteDecode("SEND\ncontent-length:23\n\nThe body of the mess");
} }
@Test @Test
public void decodeFrameWithIncompleteContentType() { void decodeFrameWithIncompleteContentType() {
assertIncompleteDecode("SEND\ncontent-type:text/plain;charset=U"); assertIncompleteDecode("SEND\ncontent-type:text/plain;charset=U");
} }
@Test @Test
public void decodeFrameWithInvalidContentType() { void decodeFrameWithInvalidContentType() {
assertThatExceptionOfType(InvalidMimeTypeException.class).isThrownBy(() -> assertThatExceptionOfType(InvalidMimeTypeException.class).isThrownBy(() ->
assertIncompleteDecode("SEND\ncontent-type:text/plain;charset=U\n\nThe body\0")); assertIncompleteDecode("SEND\ncontent-type:text/plain;charset=U\n\nThe body\0"));
} }
@Test @Test
public void decodeFrameWithIncorrectTerminator() { void decodeFrameWithIncorrectTerminator() {
assertThatExceptionOfType(StompConversionException.class).isThrownBy(() -> assertThatExceptionOfType(StompConversionException.class).isThrownBy(() ->
decode("SEND\ncontent-length:23\n\nThe body of the message*")); decode("SEND\ncontent-length:23\n\nThe body of the message*"));
} }
@Test @Test
public void decodeHeartbeat() { void decodeHeartbeat() {
String frame = "\n"; String frame = "\n";
ByteBuffer buffer = ByteBuffer.wrap(frame.getBytes()); ByteBuffer buffer = ByteBuffer.wrap(frame.getBytes());

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -29,13 +29,13 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Andy Wilkinson * @author Andy Wilkinson
* @author Stephane Maldini * @author Stephane Maldini
*/ */
public class StompEncoderTests { class StompEncoderTests {
private final StompEncoder encoder = new StompEncoder(); private final StompEncoder encoder = new StompEncoder();
@Test @Test
public void encodeFrameWithNoHeadersAndNoBody() { void encodeFrameWithNoHeadersAndNoBody() {
StompHeaderAccessor headers = StompHeaderAccessor.create(StompCommand.DISCONNECT); StompHeaderAccessor headers = StompHeaderAccessor.create(StompCommand.DISCONNECT);
Message<byte[]> frame = MessageBuilder.createMessage(new byte[0], headers.getMessageHeaders()); Message<byte[]> frame = MessageBuilder.createMessage(new byte[0], headers.getMessageHeaders());
@ -43,7 +43,7 @@ public class StompEncoderTests {
} }
@Test @Test
public void encodeFrameWithHeaders() { void encodeFrameWithHeaders() {
StompHeaderAccessor headers = StompHeaderAccessor.create(StompCommand.CONNECT); StompHeaderAccessor headers = StompHeaderAccessor.create(StompCommand.CONNECT);
headers.setAcceptVersion("1.2"); headers.setAcceptVersion("1.2");
headers.setHost("github.org"); headers.setHost("github.org");
@ -55,7 +55,7 @@ public class StompEncoderTests {
} }
@Test @Test
public void encodeFrameWithHeadersThatShouldBeEscaped() { void encodeFrameWithHeadersThatShouldBeEscaped() {
StompHeaderAccessor headers = StompHeaderAccessor.create(StompCommand.DISCONNECT); StompHeaderAccessor headers = StompHeaderAccessor.create(StompCommand.DISCONNECT);
headers.addNativeHeader("a:\r\n\\b", "alpha:bravo\r\n\\"); headers.addNativeHeader("a:\r\n\\b", "alpha:bravo\r\n\\");
Message<byte[]> frame = MessageBuilder.createMessage(new byte[0], headers.getMessageHeaders()); Message<byte[]> frame = MessageBuilder.createMessage(new byte[0], headers.getMessageHeaders());
@ -64,7 +64,7 @@ public class StompEncoderTests {
} }
@Test @Test
public void encodeFrameWithHeadersBody() { void encodeFrameWithHeadersBody() {
StompHeaderAccessor headers = StompHeaderAccessor.create(StompCommand.SEND); StompHeaderAccessor headers = StompHeaderAccessor.create(StompCommand.SEND);
headers.addNativeHeader("a", "alpha"); headers.addNativeHeader("a", "alpha");
Message<byte[]> frame = MessageBuilder.createMessage( Message<byte[]> frame = MessageBuilder.createMessage(
@ -74,7 +74,7 @@ public class StompEncoderTests {
} }
@Test @Test
public void encodeFrameWithContentLengthPresent() { void encodeFrameWithContentLengthPresent() {
StompHeaderAccessor headers = StompHeaderAccessor.create(StompCommand.SEND); StompHeaderAccessor headers = StompHeaderAccessor.create(StompCommand.SEND);
headers.setContentLength(12); headers.setContentLength(12);
Message<byte[]> frame = MessageBuilder.createMessage( Message<byte[]> frame = MessageBuilder.createMessage(

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -16,7 +16,6 @@
package org.springframework.messaging.simp.stomp; package org.springframework.messaging.simp.stomp;
import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -44,10 +43,10 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Rossen Stoyanchev * @author Rossen Stoyanchev
* @since 4.0 * @since 4.0
*/ */
public class StompHeaderAccessorTests { class StompHeaderAccessorTests {
@Test @Test
public void createWithCommand() { void createWithCommand() {
StompHeaderAccessor accessor = StompHeaderAccessor.create(StompCommand.CONNECTED); StompHeaderAccessor accessor = StompHeaderAccessor.create(StompCommand.CONNECTED);
assertThat(accessor.getCommand()).isEqualTo(StompCommand.CONNECTED); assertThat(accessor.getCommand()).isEqualTo(StompCommand.CONNECTED);
@ -56,7 +55,7 @@ public class StompHeaderAccessorTests {
} }
@Test @Test
public void createWithSubscribeNativeHeaders() { void createWithSubscribeNativeHeaders() {
MultiValueMap<String, String> extHeaders = new LinkedMultiValueMap<>(); MultiValueMap<String, String> extHeaders = new LinkedMultiValueMap<>();
extHeaders.add(StompHeaderAccessor.STOMP_ID_HEADER, "s1"); extHeaders.add(StompHeaderAccessor.STOMP_ID_HEADER, "s1");
extHeaders.add(StompHeaderAccessor.STOMP_DESTINATION_HEADER, "/d"); extHeaders.add(StompHeaderAccessor.STOMP_DESTINATION_HEADER, "/d");
@ -70,7 +69,7 @@ public class StompHeaderAccessorTests {
} }
@Test @Test
public void createWithUnsubscribeNativeHeaders() { void createWithUnsubscribeNativeHeaders() {
MultiValueMap<String, String> extHeaders = new LinkedMultiValueMap<>(); MultiValueMap<String, String> extHeaders = new LinkedMultiValueMap<>();
extHeaders.add(StompHeaderAccessor.STOMP_ID_HEADER, "s1"); extHeaders.add(StompHeaderAccessor.STOMP_ID_HEADER, "s1");
@ -82,7 +81,7 @@ public class StompHeaderAccessorTests {
} }
@Test @Test
public void createWithMessageFrameNativeHeaders() { void createWithMessageFrameNativeHeaders() {
MultiValueMap<String, String> extHeaders = new LinkedMultiValueMap<>(); MultiValueMap<String, String> extHeaders = new LinkedMultiValueMap<>();
extHeaders.add(StompHeaderAccessor.DESTINATION_HEADER, "/d"); extHeaders.add(StompHeaderAccessor.DESTINATION_HEADER, "/d");
extHeaders.add(StompHeaderAccessor.STOMP_SUBSCRIPTION_HEADER, "s1"); extHeaders.add(StompHeaderAccessor.STOMP_SUBSCRIPTION_HEADER, "s1");
@ -96,7 +95,7 @@ public class StompHeaderAccessorTests {
} }
@Test @Test
public void createWithConnectNativeHeaders() { void createWithConnectNativeHeaders() {
MultiValueMap<String, String> extHeaders = new LinkedMultiValueMap<>(); MultiValueMap<String, String> extHeaders = new LinkedMultiValueMap<>();
extHeaders.add(StompHeaderAccessor.STOMP_LOGIN_HEADER, "joe"); extHeaders.add(StompHeaderAccessor.STOMP_LOGIN_HEADER, "joe");
extHeaders.add(StompHeaderAccessor.STOMP_PASSCODE_HEADER, "joe123"); extHeaders.add(StompHeaderAccessor.STOMP_PASSCODE_HEADER, "joe123");
@ -111,12 +110,12 @@ public class StompHeaderAccessorTests {
assertThat(headerAccessor.toString()).contains("passcode=[PROTECTED]"); assertThat(headerAccessor.toString()).contains("passcode=[PROTECTED]");
Map<String, List<String>> output = headerAccessor.toNativeHeaderMap(); Map<String, List<String>> output = headerAccessor.toNativeHeaderMap();
assertThat(output.get(StompHeaderAccessor.STOMP_LOGIN_HEADER)).element(0).isEqualTo("joe"); assertThat(output.get(StompHeaderAccessor.STOMP_LOGIN_HEADER)).containsExactly("joe");
assertThat(output.get(StompHeaderAccessor.STOMP_PASSCODE_HEADER)).element(0).isEqualTo("PROTECTED"); assertThat(output.get(StompHeaderAccessor.STOMP_PASSCODE_HEADER)).containsExactly("PROTECTED");
} }
@Test @Test
public void toNativeHeadersSubscribe() { void toNativeHeadersSubscribe() {
StompHeaderAccessor headers = StompHeaderAccessor.create(StompCommand.SUBSCRIBE); StompHeaderAccessor headers = StompHeaderAccessor.create(StompCommand.SUBSCRIBE);
headers.setSubscriptionId("s1"); headers.setSubscriptionId("s1");
headers.setDestination("/d"); headers.setDestination("/d");
@ -124,23 +123,23 @@ public class StompHeaderAccessorTests {
Map<String, List<String>> actual = headers.toNativeHeaderMap(); Map<String, List<String>> actual = headers.toNativeHeaderMap();
assertThat(actual).hasSize(2); assertThat(actual).hasSize(2);
assertThat(actual.get(StompHeaderAccessor.STOMP_ID_HEADER)).element(0).isEqualTo("s1"); assertThat(actual.get(StompHeaderAccessor.STOMP_ID_HEADER)).containsExactly("s1");
assertThat(actual.get(StompHeaderAccessor.STOMP_DESTINATION_HEADER)).element(0).isEqualTo("/d"); assertThat(actual.get(StompHeaderAccessor.STOMP_DESTINATION_HEADER)).containsExactly("/d");
} }
@Test @Test
public void toNativeHeadersUnsubscribe() { void toNativeHeadersUnsubscribe() {
StompHeaderAccessor headers = StompHeaderAccessor.create(StompCommand.UNSUBSCRIBE); StompHeaderAccessor headers = StompHeaderAccessor.create(StompCommand.UNSUBSCRIBE);
headers.setSubscriptionId("s1"); headers.setSubscriptionId("s1");
Map<String, List<String>> actual = headers.toNativeHeaderMap(); Map<String, List<String>> actual = headers.toNativeHeaderMap();
assertThat(actual).hasSize(1); assertThat(actual).hasSize(1);
assertThat(actual.get(StompHeaderAccessor.STOMP_ID_HEADER)).element(0).isEqualTo("s1"); assertThat(actual.get(StompHeaderAccessor.STOMP_ID_HEADER)).containsExactly("s1");
} }
@Test @Test
public void toNativeHeadersMessageFrame() { void toNativeHeadersMessageFrame() {
StompHeaderAccessor headers = StompHeaderAccessor.create(StompCommand.MESSAGE); StompHeaderAccessor headers = StompHeaderAccessor.create(StompCommand.MESSAGE);
headers.setSubscriptionId("s1"); headers.setSubscriptionId("s1");
headers.setDestination("/d"); headers.setDestination("/d");
@ -150,14 +149,14 @@ public class StompHeaderAccessorTests {
Map<String, List<String>> actual = headers.toNativeHeaderMap(); Map<String, List<String>> actual = headers.toNativeHeaderMap();
assertThat(actual.size()).as(actual.toString()).isEqualTo(4); assertThat(actual.size()).as(actual.toString()).isEqualTo(4);
assertThat(actual.get(StompHeaderAccessor.STOMP_SUBSCRIPTION_HEADER)).element(0).isEqualTo("s1"); assertThat(actual.get(StompHeaderAccessor.STOMP_SUBSCRIPTION_HEADER)).containsExactly("s1");
assertThat(actual.get(StompHeaderAccessor.STOMP_DESTINATION_HEADER)).element(0).isEqualTo("/d"); assertThat(actual.get(StompHeaderAccessor.STOMP_DESTINATION_HEADER)).containsExactly("/d");
assertThat(actual.get(StompHeaderAccessor.STOMP_CONTENT_TYPE_HEADER)).element(0).isEqualTo("application/json"); assertThat(actual.get(StompHeaderAccessor.STOMP_CONTENT_TYPE_HEADER)).containsExactly("application/json");
assertThat(actual.get(StompHeaderAccessor.STOMP_MESSAGE_ID_HEADER)).element(0).as("message-id was not created").isNotNull(); assertThat(actual.get(StompHeaderAccessor.STOMP_MESSAGE_ID_HEADER)).singleElement().as("message-id was not created").isNotNull();
} }
@Test @Test
public void toNativeHeadersContentType() { void toNativeHeadersContentType() {
SimpMessageHeaderAccessor simpHeaderAccessor = SimpMessageHeaderAccessor.create(); SimpMessageHeaderAccessor simpHeaderAccessor = SimpMessageHeaderAccessor.create();
simpHeaderAccessor.setContentType(MimeType.valueOf("application/atom+xml")); simpHeaderAccessor.setContentType(MimeType.valueOf("application/atom+xml"));
Message<byte[]> message = MessageBuilder.createMessage(new byte[0], simpHeaderAccessor.getMessageHeaders()); Message<byte[]> message = MessageBuilder.createMessage(new byte[0], simpHeaderAccessor.getMessageHeaders());
@ -165,11 +164,11 @@ public class StompHeaderAccessorTests {
StompHeaderAccessor stompHeaderAccessor = StompHeaderAccessor.wrap(message); StompHeaderAccessor stompHeaderAccessor = StompHeaderAccessor.wrap(message);
Map<String, List<String>> map = stompHeaderAccessor.toNativeHeaderMap(); Map<String, List<String>> map = stompHeaderAccessor.toNativeHeaderMap();
assertThat(map.get(StompHeaderAccessor.STOMP_CONTENT_TYPE_HEADER)).element(0).isEqualTo("application/atom+xml"); assertThat(map.get(StompHeaderAccessor.STOMP_CONTENT_TYPE_HEADER)).containsExactly("application/atom+xml");
} }
@Test @Test
public void encodeConnectWithLoginAndPasscode() throws UnsupportedEncodingException { void encodeConnectWithLoginAndPasscode() {
MultiValueMap<String, String> extHeaders = new LinkedMultiValueMap<>(); MultiValueMap<String, String> extHeaders = new LinkedMultiValueMap<>();
extHeaders.add(StompHeaderAccessor.STOMP_LOGIN_HEADER, "joe"); extHeaders.add(StompHeaderAccessor.STOMP_LOGIN_HEADER, "joe");
extHeaders.add(StompHeaderAccessor.STOMP_PASSCODE_HEADER, "joe123"); extHeaders.add(StompHeaderAccessor.STOMP_PASSCODE_HEADER, "joe123");
@ -178,11 +177,11 @@ public class StompHeaderAccessorTests {
Message<byte[]> message = MessageBuilder.createMessage(new byte[0], headerAccessor.getMessageHeaders()); Message<byte[]> message = MessageBuilder.createMessage(new byte[0], headerAccessor.getMessageHeaders());
byte[] bytes = new StompEncoder().encode(message); byte[] bytes = new StompEncoder().encode(message);
assertThat(new String(bytes, "UTF-8")).isEqualTo("CONNECT\nlogin:joe\npasscode:joe123\n\n\0"); assertThat(new String(bytes, StandardCharsets.UTF_8)).isEqualTo("CONNECT\nlogin:joe\npasscode:joe123\n\n\0");
} }
@Test @Test
public void modifyCustomNativeHeader() { void modifyCustomNativeHeader() {
MultiValueMap<String, String> extHeaders = new LinkedMultiValueMap<>(); MultiValueMap<String, String> extHeaders = new LinkedMultiValueMap<>();
extHeaders.add(StompHeaderAccessor.STOMP_ID_HEADER, "s1"); extHeaders.add(StompHeaderAccessor.STOMP_ID_HEADER, "s1");
extHeaders.add(StompHeaderAccessor.STOMP_DESTINATION_HEADER, "/d"); extHeaders.add(StompHeaderAccessor.STOMP_DESTINATION_HEADER, "/d");
@ -195,13 +194,13 @@ public class StompHeaderAccessorTests {
Map<String, List<String>> actual = headers.toNativeHeaderMap(); Map<String, List<String>> actual = headers.toNativeHeaderMap();
assertThat(actual).hasSize(3); assertThat(actual).hasSize(3);
assertThat(actual.get(StompHeaderAccessor.STOMP_ID_HEADER)).element(0).isEqualTo("s1"); assertThat(actual.get(StompHeaderAccessor.STOMP_ID_HEADER)).containsExactly("s1");
assertThat(actual.get(StompHeaderAccessor.STOMP_DESTINATION_HEADER)).element(0).isEqualTo("/d"); assertThat(actual.get(StompHeaderAccessor.STOMP_DESTINATION_HEADER)).containsExactly("/d");
assertThat(actual.get("accountId")).element(0).as("abc123").isNotNull(); assertThat(actual.get("accountId")).element(0).as("abc123").isNotNull();
} }
@Test @Test
public void messageIdAndTimestampDefaultBehavior() { void messageIdAndTimestampDefaultBehavior() {
StompHeaderAccessor headerAccessor = StompHeaderAccessor.create(StompCommand.SEND); StompHeaderAccessor headerAccessor = StompHeaderAccessor.create(StompCommand.SEND);
MessageHeaders headers = headerAccessor.getMessageHeaders(); MessageHeaders headers = headerAccessor.getMessageHeaders();
@ -210,7 +209,7 @@ public class StompHeaderAccessorTests {
} }
@Test @Test
public void messageIdAndTimestampEnabled() { void messageIdAndTimestampEnabled() {
IdTimestampMessageHeaderInitializer headerInitializer = new IdTimestampMessageHeaderInitializer(); IdTimestampMessageHeaderInitializer headerInitializer = new IdTimestampMessageHeaderInitializer();
headerInitializer.setIdGenerator(new AlternativeJdkIdGenerator()); headerInitializer.setIdGenerator(new AlternativeJdkIdGenerator());
headerInitializer.setEnableTimestamp(true); headerInitializer.setEnableTimestamp(true);
@ -223,7 +222,7 @@ public class StompHeaderAccessorTests {
} }
@Test @Test
public void getAccessor() { void getAccessor() {
StompHeaderAccessor headerAccessor = StompHeaderAccessor.create(StompCommand.CONNECT); StompHeaderAccessor headerAccessor = StompHeaderAccessor.create(StompCommand.CONNECT);
Message<byte[]> message = MessageBuilder.createMessage(new byte[0], headerAccessor.getMessageHeaders()); Message<byte[]> message = MessageBuilder.createMessage(new byte[0], headerAccessor.getMessageHeaders());
@ -231,7 +230,7 @@ public class StompHeaderAccessorTests {
} }
@Test @Test
public void getShortLogMessage() { void getShortLogMessage() {
StompHeaderAccessor accessor = StompHeaderAccessor.create(StompCommand.SEND); StompHeaderAccessor accessor = StompHeaderAccessor.create(StompCommand.SEND);
accessor.setDestination("/foo"); accessor.setDestination("/foo");
accessor.setContentType(MimeTypeUtils.APPLICATION_JSON); accessor.setContentType(MimeTypeUtils.APPLICATION_JSON);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -38,7 +38,7 @@ import static org.mockito.Mockito.mock;
* *
* @author Rossen Stoyanchev * @author Rossen Stoyanchev
*/ */
public class DefaultUserDestinationResolverTests { class DefaultUserDestinationResolverTests {
private SimpUserRegistry registry = mock(); private SimpUserRegistry registry = mock();
@ -46,7 +46,7 @@ public class DefaultUserDestinationResolverTests {
@BeforeEach @BeforeEach
public void setup() { void setup() {
TestSimpUser simpUser = new TestSimpUser("joe"); TestSimpUser simpUser = new TestSimpUser("joe");
simpUser.addSessions(new TestSimpSession("123")); simpUser.addSessions(new TestSimpSession("123"));
@ -54,7 +54,7 @@ public class DefaultUserDestinationResolverTests {
} }
@Test @Test
public void handleSubscribe() { void handleSubscribe() {
TestPrincipal user = new TestPrincipal("joe"); TestPrincipal user = new TestPrincipal("joe");
String sourceDestination = "/user/queue/foo"; String sourceDestination = "/user/queue/foo";
@ -62,8 +62,7 @@ public class DefaultUserDestinationResolverTests {
UserDestinationResult actual = this.resolver.resolveDestination(message); UserDestinationResult actual = this.resolver.resolveDestination(message);
assertThat(actual.getSourceDestination()).isEqualTo(sourceDestination); assertThat(actual.getSourceDestination()).isEqualTo(sourceDestination);
assertThat(actual.getTargetDestinations()).hasSize(1); assertThat(actual.getTargetDestinations()).containsExactly("/queue/foo-user123");
assertThat(actual.getTargetDestinations()).element(0).isEqualTo("/queue/foo-user123");
assertThat(actual.getSubscribeDestination()).isEqualTo(sourceDestination); assertThat(actual.getSubscribeDestination()).isEqualTo(sourceDestination);
assertThat(actual.getUser()).isEqualTo(user.getName()); assertThat(actual.getUser()).isEqualTo(user.getName());
} }
@ -77,8 +76,7 @@ public class DefaultUserDestinationResolverTests {
Message<?> message = createMessage(SimpMessageType.SUBSCRIBE, user, "123", destination); Message<?> message = createMessage(SimpMessageType.SUBSCRIBE, user, "123", destination);
UserDestinationResult actual = this.resolver.resolveDestination(message); UserDestinationResult actual = this.resolver.resolveDestination(message);
assertThat(actual.getTargetDestinations()).hasSize(1); assertThat(actual.getTargetDestinations()).containsExactly("jms.queue.call-user123");
assertThat(actual.getTargetDestinations()).element(0).isEqualTo("jms.queue.call-user123");
assertThat(actual.getSubscribeDestination()).isEqualTo(destination); assertThat(actual.getSubscribeDestination()).isEqualTo(destination);
} }
@ -93,19 +91,17 @@ public class DefaultUserDestinationResolverTests {
Message<?> message = createMessage(SimpMessageType.SUBSCRIBE, user, "456", "/user/queue/foo"); Message<?> message = createMessage(SimpMessageType.SUBSCRIBE, user, "456", "/user/queue/foo");
UserDestinationResult actual = this.resolver.resolveDestination(message); UserDestinationResult actual = this.resolver.resolveDestination(message);
assertThat(actual.getTargetDestinations()).hasSize(1); assertThat(actual.getTargetDestinations()).containsExactly("/queue/foo-user456");
assertThat(actual.getTargetDestinations()).element(0).isEqualTo("/queue/foo-user456");
} }
@Test @Test
public void handleSubscribeNoUser() { void handleSubscribeNoUser() {
String sourceDestination = "/user/queue/foo"; String sourceDestination = "/user/queue/foo";
Message<?> message = createMessage(SimpMessageType.SUBSCRIBE, null, "123", sourceDestination); Message<?> message = createMessage(SimpMessageType.SUBSCRIBE, null, "123", sourceDestination);
UserDestinationResult actual = this.resolver.resolveDestination(message); UserDestinationResult actual = this.resolver.resolveDestination(message);
assertThat(actual.getSourceDestination()).isEqualTo(sourceDestination); assertThat(actual.getSourceDestination()).isEqualTo(sourceDestination);
assertThat(actual.getTargetDestinations()).hasSize(1); assertThat(actual.getTargetDestinations()).containsExactly("/queue/foo-user" + "123");
assertThat(actual.getTargetDestinations()).element(0).isEqualTo(("/queue/foo-user" + "123"));
assertThat(actual.getSubscribeDestination()).isEqualTo(sourceDestination); assertThat(actual.getSubscribeDestination()).isEqualTo(sourceDestination);
assertThat(actual.getUser()).isNull(); assertThat(actual.getUser()).isNull();
} }
@ -120,25 +116,23 @@ public class DefaultUserDestinationResolverTests {
} }
@Test @Test
public void handleUnsubscribe() { void handleUnsubscribe() {
TestPrincipal user = new TestPrincipal("joe"); TestPrincipal user = new TestPrincipal("joe");
Message<?> message = createMessage(SimpMessageType.UNSUBSCRIBE, user, "123", "/user/queue/foo"); Message<?> message = createMessage(SimpMessageType.UNSUBSCRIBE, user, "123", "/user/queue/foo");
UserDestinationResult actual = this.resolver.resolveDestination(message); UserDestinationResult actual = this.resolver.resolveDestination(message);
assertThat(actual.getTargetDestinations()).hasSize(1); assertThat(actual.getTargetDestinations()).containsExactly("/queue/foo-user123");
assertThat(actual.getTargetDestinations()).element(0).isEqualTo("/queue/foo-user123");
} }
@Test @Test
public void handleMessage() { void handleMessage() {
TestPrincipal user = new TestPrincipal("joe"); TestPrincipal user = new TestPrincipal("joe");
String sourceDestination = "/user/joe/queue/foo"; String sourceDestination = "/user/joe/queue/foo";
Message<?> message = createMessage(SimpMessageType.MESSAGE, user, "123", sourceDestination); Message<?> message = createMessage(SimpMessageType.MESSAGE, user, "123", sourceDestination);
UserDestinationResult actual = this.resolver.resolveDestination(message); UserDestinationResult actual = this.resolver.resolveDestination(message);
assertThat(actual.getSourceDestination()).isEqualTo(sourceDestination); assertThat(actual.getSourceDestination()).isEqualTo(sourceDestination);
assertThat(actual.getTargetDestinations()).hasSize(1); assertThat(actual.getTargetDestinations()).containsExactly("/queue/foo-user123");
assertThat(actual.getTargetDestinations()).element(0).isEqualTo("/queue/foo-user123");
assertThat(actual.getSubscribeDestination()).isEqualTo("/user/queue/foo"); assertThat(actual.getSubscribeDestination()).isEqualTo("/user/queue/foo");
assertThat(actual.getUser()).isEqualTo(user.getName()); assertThat(actual.getUser()).isEqualTo(user.getName());
} }
@ -152,8 +146,7 @@ public class DefaultUserDestinationResolverTests {
Message<?> message = createMessage(SimpMessageType.MESSAGE, user, "123", destination); Message<?> message = createMessage(SimpMessageType.MESSAGE, user, "123", destination);
UserDestinationResult actual = this.resolver.resolveDestination(message); UserDestinationResult actual = this.resolver.resolveDestination(message);
assertThat(actual.getTargetDestinations()).hasSize(1); assertThat(actual.getTargetDestinations()).containsExactly("jms.queue.call-user123");
assertThat(actual.getTargetDestinations()).element(0).isEqualTo("jms.queue.call-user123");
assertThat(actual.getSubscribeDestination()).isEqualTo("/user/jms.queue.call"); assertThat(actual.getSubscribeDestination()).isEqualTo("/user/jms.queue.call");
} }
@ -172,14 +165,13 @@ public class DefaultUserDestinationResolverTests {
UserDestinationResult actual = this.resolver.resolveDestination(message); UserDestinationResult actual = this.resolver.resolveDestination(message);
assertThat(actual.getSourceDestination()).isEqualTo(sourceDestination); assertThat(actual.getSourceDestination()).isEqualTo(sourceDestination);
assertThat(actual.getTargetDestinations()).hasSize(1); assertThat(actual.getTargetDestinations()).containsExactly("/queue/foo-user456");
assertThat(actual.getTargetDestinations()).element(0).isEqualTo("/queue/foo-user456");
assertThat(actual.getSubscribeDestination()).isEqualTo("/user/queue/foo"); assertThat(actual.getSubscribeDestination()).isEqualTo("/user/queue/foo");
assertThat(actual.getUser()).isEqualTo(otherUser.getName()); assertThat(actual.getUser()).isEqualTo(otherUser.getName());
} }
@Test @Test
public void handleMessageEncodedUserName() { void handleMessageEncodedUserName() {
String userName = "https://joe.openid.example.org/"; String userName = "https://joe.openid.example.org/";
TestSimpUser simpUser = new TestSimpUser(userName); TestSimpUser simpUser = new TestSimpUser(userName);
@ -191,25 +183,23 @@ public class DefaultUserDestinationResolverTests {
Message<?> message = createMessage(SimpMessageType.MESSAGE, new TestPrincipal("joe"), null, destination); Message<?> message = createMessage(SimpMessageType.MESSAGE, new TestPrincipal("joe"), null, destination);
UserDestinationResult actual = this.resolver.resolveDestination(message); UserDestinationResult actual = this.resolver.resolveDestination(message);
assertThat(actual.getTargetDestinations()).hasSize(1); assertThat(actual.getTargetDestinations()).containsExactly("/queue/foo-useropenid123");
assertThat(actual.getTargetDestinations()).element(0).isEqualTo("/queue/foo-useropenid123");
} }
@Test @Test
public void handleMessageWithNoUser() { void handleMessageWithNoUser() {
String sourceDestination = "/user/" + "123" + "/queue/foo"; String sourceDestination = "/user/" + "123" + "/queue/foo";
Message<?> message = createMessage(SimpMessageType.MESSAGE, null, "123", sourceDestination); Message<?> message = createMessage(SimpMessageType.MESSAGE, null, "123", sourceDestination);
UserDestinationResult actual = this.resolver.resolveDestination(message); UserDestinationResult actual = this.resolver.resolveDestination(message);
assertThat(actual.getSourceDestination()).isEqualTo(sourceDestination); assertThat(actual.getSourceDestination()).isEqualTo(sourceDestination);
assertThat(actual.getTargetDestinations()).hasSize(1); assertThat(actual.getTargetDestinations()).containsExactly("/queue/foo-user123");
assertThat(actual.getTargetDestinations()).element(0).isEqualTo("/queue/foo-user123");
assertThat(actual.getSubscribeDestination()).isEqualTo("/user/queue/foo"); assertThat(actual.getSubscribeDestination()).isEqualTo("/user/queue/foo");
assertThat(actual.getUser()).isNull(); assertThat(actual.getUser()).isNull();
} }
@Test @Test
public void ignoreMessage() { void ignoreMessage() {
// no destination // no destination
TestPrincipal user = new TestPrincipal("joe"); TestPrincipal user = new TestPrincipal("joe");

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -65,7 +65,7 @@ class UserRegistryMessageHandlerTests {
@BeforeEach @BeforeEach
void setUp() throws Exception { void setUp() {
SimpMessagingTemplate brokerTemplate = new SimpMessagingTemplate(this.brokerChannel); SimpMessagingTemplate brokerTemplate = new SimpMessagingTemplate(this.brokerChannel);
brokerTemplate.setMessageConverter(this.converter); brokerTemplate.setMessageConverter(this.converter);
@ -74,14 +74,14 @@ class UserRegistryMessageHandlerTests {
} }
@Test @Test
void brokerAvailableEvent() throws Exception { void brokerAvailableEvent() {
Runnable runnable = getUserRegistryTask(); Runnable runnable = getUserRegistryTask();
assertThat(runnable).isNotNull(); assertThat(runnable).isNotNull();
} }
@Test @Test
@SuppressWarnings({ "unchecked", "rawtypes" }) @SuppressWarnings({ "unchecked", "rawtypes" })
void brokerUnavailableEvent() throws Exception { void brokerUnavailableEvent() {
ScheduledFuture future = mock(); ScheduledFuture future = mock();
given(this.taskScheduler.scheduleWithFixedDelay(any(Runnable.class), any(Duration.class))).willReturn(future); given(this.taskScheduler.scheduleWithFixedDelay(any(Runnable.class), any(Duration.class))).willReturn(future);
@ -96,7 +96,7 @@ class UserRegistryMessageHandlerTests {
@Test @Test
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
void broadcastRegistry() throws Exception { void broadcastRegistry() {
given(this.brokerChannel.send(any())).willReturn(true); given(this.brokerChannel.send(any())).willReturn(true);
TestSimpUser simpUser1 = new TestSimpUser("joe"); TestSimpUser simpUser1 = new TestSimpUser("joe");
@ -126,7 +126,7 @@ class UserRegistryMessageHandlerTests {
} }
@Test @Test
void handleMessage() throws Exception { void handleMessage() {
TestSimpUser simpUser1 = new TestSimpUser("joe"); TestSimpUser simpUser1 = new TestSimpUser("joe");
TestSimpUser simpUser2 = new TestSimpUser("jane"); TestSimpUser simpUser2 = new TestSimpUser("jane");
@ -149,7 +149,7 @@ class UserRegistryMessageHandlerTests {
} }
@Test @Test
void handleMessageFromOwnBroadcast() throws Exception { void handleMessageFromOwnBroadcast() {
TestSimpUser simpUser = new TestSimpUser("joe"); TestSimpUser simpUser = new TestSimpUser("joe");
simpUser.addSessions(new TestSimpSession("123")); simpUser.addSessions(new TestSimpSession("123"));
given(this.localRegistry.getUserCount()).willReturn(1); given(this.localRegistry.getUserCount()).willReturn(1);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -37,7 +37,7 @@ import static org.mockito.Mockito.mock;
* *
* @author Rossen Stoyanchev * @author Rossen Stoyanchev
*/ */
public class ChannelInterceptorTests { class ChannelInterceptorTests {
private ExecutorSubscribableChannel channel; private ExecutorSubscribableChannel channel;
@ -45,7 +45,7 @@ public class ChannelInterceptorTests {
@BeforeEach @BeforeEach
public void setup() { void setup() {
this.channel = new ExecutorSubscribableChannel(); this.channel = new ExecutorSubscribableChannel();
this.messageHandler = new TestMessageHandler(); this.messageHandler = new TestMessageHandler();
this.channel.subscribe(this.messageHandler); this.channel.subscribe(this.messageHandler);
@ -53,7 +53,7 @@ public class ChannelInterceptorTests {
@Test @Test
public void preSendInterceptorReturningModifiedMessage() { void preSendInterceptorReturningModifiedMessage() {
Message<?> expected = mock(); Message<?> expected = mock();
PreSendInterceptor interceptor = new PreSendInterceptor(); PreSendInterceptor interceptor = new PreSendInterceptor();
interceptor.setMessageToReturn(expected); interceptor.setMessageToReturn(expected);
@ -69,7 +69,7 @@ public class ChannelInterceptorTests {
} }
@Test @Test
public void preSendInterceptorReturningNull() { void preSendInterceptorReturningNull() {
PreSendInterceptor interceptor1 = new PreSendInterceptor(); PreSendInterceptor interceptor1 = new PreSendInterceptor();
NullReturningPreSendInterceptor interceptor2 = new NullReturningPreSendInterceptor(); NullReturningPreSendInterceptor interceptor2 = new NullReturningPreSendInterceptor();
this.channel.addInterceptor(interceptor1); this.channel.addInterceptor(interceptor1);
@ -85,7 +85,7 @@ public class ChannelInterceptorTests {
} }
@Test @Test
public void postSendInterceptorMessageWasSent() { void postSendInterceptorMessageWasSent() {
final AtomicBoolean preSendInvoked = new AtomicBoolean(); final AtomicBoolean preSendInvoked = new AtomicBoolean();
final AtomicBoolean completionInvoked = new AtomicBoolean(); final AtomicBoolean completionInvoked = new AtomicBoolean();
this.channel.addInterceptor(new ChannelInterceptor() { this.channel.addInterceptor(new ChannelInterceptor() {
@ -112,7 +112,7 @@ public class ChannelInterceptorTests {
} }
@Test @Test
public void postSendInterceptorMessageWasNotSent() { void postSendInterceptorMessageWasNotSent() {
final AbstractMessageChannel testChannel = new AbstractMessageChannel() { final AbstractMessageChannel testChannel = new AbstractMessageChannel() {
@Override @Override
protected boolean sendInternal(Message<?> message, long timeout) { protected boolean sendInternal(Message<?> message, long timeout) {
@ -145,7 +145,7 @@ public class ChannelInterceptorTests {
} }
@Test @Test
public void afterCompletionWithSendException() { void afterCompletionWithSendException() {
final AbstractMessageChannel testChannel = new AbstractMessageChannel() { final AbstractMessageChannel testChannel = new AbstractMessageChannel() {
@Override @Override
protected boolean sendInternal(Message<?> message, long timeout) { protected boolean sendInternal(Message<?> message, long timeout) {
@ -167,7 +167,7 @@ public class ChannelInterceptorTests {
} }
@Test @Test
public void afterCompletionWithPreSendException() { void afterCompletionWithPreSendException() {
PreSendInterceptor interceptor1 = new PreSendInterceptor(); PreSendInterceptor interceptor1 = new PreSendInterceptor();
PreSendInterceptor interceptor2 = new PreSendInterceptor(); PreSendInterceptor interceptor2 = new PreSendInterceptor();
interceptor2.setExceptionToRaise(new RuntimeException("Simulated exception")); interceptor2.setExceptionToRaise(new RuntimeException("Simulated exception"));

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2019 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -25,10 +25,10 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Gary Russell * @author Gary Russell
* @since 5.0 * @since 5.0
*/ */
public class ErrorMessageTests { class ErrorMessageTests {
@Test @Test
public void testToString() { void testToString() {
ErrorMessage em = new ErrorMessage(new RuntimeException("foo")); ErrorMessage em = new ErrorMessage(new RuntimeException("foo"));
String emString = em.toString(); String emString = em.toString();
assertThat(emString).doesNotContain("original"); assertThat(emString).doesNotContain("original");

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -63,14 +63,14 @@ public class ExecutorSubscribableChannelTests {
@Test @Test
public void messageMustNotBeNull() { void messageMustNotBeNull() {
assertThatIllegalArgumentException().isThrownBy(() -> assertThatIllegalArgumentException().isThrownBy(() ->
this.channel.send(null)) this.channel.send(null))
.withMessageContaining("Message must not be null"); .withMessageContaining("Message must not be null");
} }
@Test @Test
public void sendWithoutExecutor() { void sendWithoutExecutor() {
BeforeHandleInterceptor interceptor = new BeforeHandleInterceptor(); BeforeHandleInterceptor interceptor = new BeforeHandleInterceptor();
this.channel.addInterceptor(interceptor); this.channel.addInterceptor(interceptor);
this.channel.subscribe(this.handler); this.channel.subscribe(this.handler);
@ -81,7 +81,7 @@ public class ExecutorSubscribableChannelTests {
} }
@Test @Test
public void sendWithExecutor() { void sendWithExecutor() {
BeforeHandleInterceptor interceptor = new BeforeHandleInterceptor(); BeforeHandleInterceptor interceptor = new BeforeHandleInterceptor();
TaskExecutor executor = mock(); TaskExecutor executor = mock();
ExecutorSubscribableChannel testChannel = new ExecutorSubscribableChannel(executor); ExecutorSubscribableChannel testChannel = new ExecutorSubscribableChannel(executor);
@ -97,7 +97,7 @@ public class ExecutorSubscribableChannelTests {
} }
@Test @Test
public void subscribeTwice() { void subscribeTwice() {
assertThat(this.channel.subscribe(this.handler)).isTrue(); assertThat(this.channel.subscribe(this.handler)).isTrue();
assertThat(this.channel.subscribe(this.handler)).isFalse(); assertThat(this.channel.subscribe(this.handler)).isFalse();
this.channel.send(this.message); this.channel.send(this.message);
@ -105,7 +105,7 @@ public class ExecutorSubscribableChannelTests {
} }
@Test @Test
public void unsubscribeTwice() { void unsubscribeTwice() {
this.channel.subscribe(this.handler); this.channel.subscribe(this.handler);
assertThat(this.channel.unsubscribe(this.handler)).isTrue(); assertThat(this.channel.unsubscribe(this.handler)).isTrue();
assertThat(this.channel.unsubscribe(this.handler)).isFalse(); assertThat(this.channel.unsubscribe(this.handler)).isFalse();
@ -114,7 +114,7 @@ public class ExecutorSubscribableChannelTests {
} }
@Test @Test
public void failurePropagates() { void failurePropagates() {
RuntimeException ex = new RuntimeException(); RuntimeException ex = new RuntimeException();
willThrow(ex).given(this.handler).handleMessage(this.message); willThrow(ex).given(this.handler).handleMessage(this.message);
MessageHandler secondHandler = mock(); MessageHandler secondHandler = mock();
@ -130,7 +130,7 @@ public class ExecutorSubscribableChannelTests {
} }
@Test @Test
public void concurrentModification() { void concurrentModification() {
this.channel.subscribe(message1 -> channel.unsubscribe(handler)); this.channel.subscribe(message1 -> channel.unsubscribe(handler));
this.channel.subscribe(this.handler); this.channel.subscribe(this.handler);
this.channel.send(this.message); this.channel.send(this.message);
@ -138,7 +138,7 @@ public class ExecutorSubscribableChannelTests {
} }
@Test @Test
public void interceptorWithModifiedMessage() { void interceptorWithModifiedMessage() {
Message<?> expected = mock(); Message<?> expected = mock();
BeforeHandleInterceptor interceptor = new BeforeHandleInterceptor(); BeforeHandleInterceptor interceptor = new BeforeHandleInterceptor();
interceptor.setMessageToReturn(expected); interceptor.setMessageToReturn(expected);
@ -151,7 +151,7 @@ public class ExecutorSubscribableChannelTests {
} }
@Test @Test
public void interceptorWithNull() { void interceptorWithNull() {
BeforeHandleInterceptor interceptor1 = new BeforeHandleInterceptor(); BeforeHandleInterceptor interceptor1 = new BeforeHandleInterceptor();
NullReturningBeforeHandleInterceptor interceptor2 = new NullReturningBeforeHandleInterceptor(); NullReturningBeforeHandleInterceptor interceptor2 = new NullReturningBeforeHandleInterceptor();
this.channel.addInterceptor(interceptor1); this.channel.addInterceptor(interceptor1);
@ -165,7 +165,7 @@ public class ExecutorSubscribableChannelTests {
} }
@Test @Test
public void interceptorWithException() { void interceptorWithException() {
IllegalStateException expected = new IllegalStateException("Fake exception"); IllegalStateException expected = new IllegalStateException("Fake exception");
willThrow(expected).given(this.handler).handleMessage(this.message); willThrow(expected).given(this.handler).handleMessage(this.message);
BeforeHandleInterceptor interceptor = new BeforeHandleInterceptor(); BeforeHandleInterceptor interceptor = new BeforeHandleInterceptor();

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2020 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -150,28 +150,28 @@ class MessageBuilderTests {
} }
@Test @Test
void notModifiedSameMessage() throws Exception { void notModifiedSameMessage() {
Message<?> original = MessageBuilder.withPayload("foo").build(); Message<?> original = MessageBuilder.withPayload("foo").build();
Message<?> result = MessageBuilder.fromMessage(original).build(); Message<?> result = MessageBuilder.fromMessage(original).build();
assertThat(result).isEqualTo(original); assertThat(result).isEqualTo(original);
} }
@Test @Test
void containsHeaderNotModifiedSameMessage() throws Exception { void containsHeaderNotModifiedSameMessage() {
Message<?> original = MessageBuilder.withPayload("foo").setHeader("bar", 42).build(); Message<?> original = MessageBuilder.withPayload("foo").setHeader("bar", 42).build();
Message<?> result = MessageBuilder.fromMessage(original).build(); Message<?> result = MessageBuilder.fromMessage(original).build();
assertThat(result).isEqualTo(original); assertThat(result).isEqualTo(original);
} }
@Test @Test
void sameHeaderValueAddedNotModifiedSameMessage() throws Exception { void sameHeaderValueAddedNotModifiedSameMessage() {
Message<?> original = MessageBuilder.withPayload("foo").setHeader("bar", 42).build(); Message<?> original = MessageBuilder.withPayload("foo").setHeader("bar", 42).build();
Message<?> result = MessageBuilder.fromMessage(original).setHeader("bar", 42).build(); Message<?> result = MessageBuilder.fromMessage(original).setHeader("bar", 42).build();
assertThat(result).isEqualTo(original); assertThat(result).isEqualTo(original);
} }
@Test @Test
void copySameHeaderValuesNotModifiedSameMessage() throws Exception { void copySameHeaderValuesNotModifiedSameMessage() {
Date current = new Date(); Date current = new Date();
Map<String, Object> originalHeaders = new HashMap<>(); Map<String, Object> originalHeaders = new HashMap<>();
originalHeaders.put("b", "xyz"); originalHeaders.put("b", "xyz");

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -39,16 +39,16 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
* @author Sebastien Deleuze * @author Sebastien Deleuze
* @author Juergen Hoeller * @author Juergen Hoeller
*/ */
public class MessageHeaderAccessorTests { class MessageHeaderAccessorTests {
@Test @Test
public void newEmptyHeaders() { void newEmptyHeaders() {
MessageHeaderAccessor accessor = new MessageHeaderAccessor(); MessageHeaderAccessor accessor = new MessageHeaderAccessor();
assertThat(accessor.toMap()).isEmpty(); assertThat(accessor.toMap()).isEmpty();
} }
@Test @Test
public void existingHeaders() throws InterruptedException { void existingHeaders() {
Map<String, Object> map = new HashMap<>(); Map<String, Object> map = new HashMap<>();
map.put("foo", "bar"); map.put("foo", "bar");
map.put("bar", "baz"); map.put("bar", "baz");
@ -63,7 +63,7 @@ public class MessageHeaderAccessorTests {
} }
@Test @Test
public void existingHeadersModification() throws InterruptedException { void existingHeadersModification() throws InterruptedException {
Map<String, Object> map = new HashMap<>(); Map<String, Object> map = new HashMap<>();
map.put("foo", "bar"); map.put("foo", "bar");
map.put("bar", "baz"); map.put("bar", "baz");
@ -82,7 +82,7 @@ public class MessageHeaderAccessorTests {
} }
@Test @Test
public void testRemoveHeader() { void testRemoveHeader() {
Message<?> message = new GenericMessage<>("payload", Collections.singletonMap("foo", "bar")); Message<?> message = new GenericMessage<>("payload", Collections.singletonMap("foo", "bar"));
MessageHeaderAccessor accessor = new MessageHeaderAccessor(message); MessageHeaderAccessor accessor = new MessageHeaderAccessor(message);
accessor.removeHeader("foo"); accessor.removeHeader("foo");
@ -91,7 +91,7 @@ public class MessageHeaderAccessorTests {
} }
@Test @Test
public void testRemoveHeaderEvenIfNull() { void testRemoveHeaderEvenIfNull() {
Message<?> message = new GenericMessage<>("payload", Collections.singletonMap("foo", null)); Message<?> message = new GenericMessage<>("payload", Collections.singletonMap("foo", null));
MessageHeaderAccessor accessor = new MessageHeaderAccessor(message); MessageHeaderAccessor accessor = new MessageHeaderAccessor(message);
accessor.removeHeader("foo"); accessor.removeHeader("foo");
@ -100,7 +100,7 @@ public class MessageHeaderAccessorTests {
} }
@Test @Test
public void removeHeaders() { void removeHeaders() {
Map<String, Object> map = new HashMap<>(); Map<String, Object> map = new HashMap<>();
map.put("foo", "bar"); map.put("foo", "bar");
map.put("bar", "baz"); map.put("bar", "baz");
@ -116,7 +116,7 @@ public class MessageHeaderAccessorTests {
} }
@Test @Test
public void copyHeaders() { void copyHeaders() {
Map<String, Object> map1 = new HashMap<>(); Map<String, Object> map1 = new HashMap<>();
map1.put("foo", "bar"); map1.put("foo", "bar");
GenericMessage<String> message = new GenericMessage<>("payload", map1); GenericMessage<String> message = new GenericMessage<>("payload", map1);
@ -134,7 +134,7 @@ public class MessageHeaderAccessorTests {
} }
@Test @Test
public void copyHeadersIfAbsent() { void copyHeadersIfAbsent() {
Map<String, Object> map1 = new HashMap<>(); Map<String, Object> map1 = new HashMap<>();
map1.put("foo", "bar"); map1.put("foo", "bar");
GenericMessage<String> message = new GenericMessage<>("payload", map1); GenericMessage<String> message = new GenericMessage<>("payload", map1);
@ -152,7 +152,7 @@ public class MessageHeaderAccessorTests {
} }
@Test @Test
public void copyHeadersFromNullMap() { void copyHeadersFromNullMap() {
MessageHeaderAccessor headers = new MessageHeaderAccessor(); MessageHeaderAccessor headers = new MessageHeaderAccessor();
headers.copyHeaders(null); headers.copyHeaders(null);
headers.copyHeadersIfAbsent(null); headers.copyHeadersIfAbsent(null);
@ -161,7 +161,7 @@ public class MessageHeaderAccessorTests {
} }
@Test @Test
public void toMap() { void toMap() {
MessageHeaderAccessor accessor = new MessageHeaderAccessor(); MessageHeaderAccessor accessor = new MessageHeaderAccessor();
accessor.setHeader("foo", "bar1"); accessor.setHeader("foo", "bar1");
@ -183,7 +183,7 @@ public class MessageHeaderAccessorTests {
} }
@Test @Test
public void leaveMutable() { void leaveMutable() {
MessageHeaderAccessor accessor = new MessageHeaderAccessor(); MessageHeaderAccessor accessor = new MessageHeaderAccessor();
accessor.setHeader("foo", "bar"); accessor.setHeader("foo", "bar");
accessor.setLeaveMutable(true); accessor.setLeaveMutable(true);
@ -197,7 +197,7 @@ public class MessageHeaderAccessorTests {
} }
@Test @Test
public void leaveMutableDefaultBehavior() { void leaveMutableDefaultBehavior() {
MessageHeaderAccessor accessor = new MessageHeaderAccessor(); MessageHeaderAccessor accessor = new MessageHeaderAccessor();
accessor.setHeader("foo", "bar"); accessor.setHeader("foo", "bar");
MessageHeaders headers = accessor.getMessageHeaders(); MessageHeaders headers = accessor.getMessageHeaders();
@ -216,14 +216,14 @@ public class MessageHeaderAccessorTests {
} }
@Test @Test
public void getAccessor() { void getAccessor() {
MessageHeaderAccessor expected = new MessageHeaderAccessor(); MessageHeaderAccessor expected = new MessageHeaderAccessor();
Message<?> message = MessageBuilder.createMessage("payload", expected.getMessageHeaders()); Message<?> message = MessageBuilder.createMessage("payload", expected.getMessageHeaders());
assertThat(MessageHeaderAccessor.getAccessor(message, MessageHeaderAccessor.class)).isSameAs(expected); assertThat(MessageHeaderAccessor.getAccessor(message, MessageHeaderAccessor.class)).isSameAs(expected);
} }
@Test @Test
public void getMutableAccessorSameInstance() { void getMutableAccessorSameInstance() {
TestMessageHeaderAccessor expected = new TestMessageHeaderAccessor(); TestMessageHeaderAccessor expected = new TestMessageHeaderAccessor();
expected.setLeaveMutable(true); expected.setLeaveMutable(true);
Message<?> message = MessageBuilder.createMessage("payload", expected.getMessageHeaders()); Message<?> message = MessageBuilder.createMessage("payload", expected.getMessageHeaders());
@ -235,7 +235,7 @@ public class MessageHeaderAccessorTests {
} }
@Test @Test
public void getMutableAccessorNewInstance() { void getMutableAccessorNewInstance() {
Message<?> message = MessageBuilder.withPayload("payload").build(); Message<?> message = MessageBuilder.withPayload("payload").build();
MessageHeaderAccessor actual = MessageHeaderAccessor.getMutableAccessor(message); MessageHeaderAccessor actual = MessageHeaderAccessor.getMutableAccessor(message);
@ -244,7 +244,7 @@ public class MessageHeaderAccessorTests {
} }
@Test @Test
public void getMutableAccessorNewInstanceMatchingType() { void getMutableAccessorNewInstanceMatchingType() {
TestMessageHeaderAccessor expected = new TestMessageHeaderAccessor(); TestMessageHeaderAccessor expected = new TestMessageHeaderAccessor();
Message<?> message = MessageBuilder.createMessage("payload", expected.getMessageHeaders()); Message<?> message = MessageBuilder.createMessage("payload", expected.getMessageHeaders());
@ -255,20 +255,20 @@ public class MessageHeaderAccessorTests {
} }
@Test @Test
public void timestampEnabled() { void timestampEnabled() {
MessageHeaderAccessor accessor = new MessageHeaderAccessor(); MessageHeaderAccessor accessor = new MessageHeaderAccessor();
accessor.setEnableTimestamp(true); accessor.setEnableTimestamp(true);
assertThat(accessor.getMessageHeaders().getTimestamp()).isNotNull(); assertThat(accessor.getMessageHeaders().getTimestamp()).isNotNull();
} }
@Test @Test
public void timestampDefaultBehavior() { void timestampDefaultBehavior() {
MessageHeaderAccessor accessor = new MessageHeaderAccessor(); MessageHeaderAccessor accessor = new MessageHeaderAccessor();
assertThat(accessor.getMessageHeaders().getTimestamp()).isNull(); assertThat(accessor.getMessageHeaders().getTimestamp()).isNull();
} }
@Test @Test
public void idGeneratorCustom() { void idGeneratorCustom() {
final UUID id = new UUID(0L, 23L); final UUID id = new UUID(0L, 23L);
MessageHeaderAccessor accessor = new MessageHeaderAccessor(); MessageHeaderAccessor accessor = new MessageHeaderAccessor();
accessor.setIdGenerator(() -> id); accessor.setIdGenerator(() -> id);
@ -276,14 +276,14 @@ public class MessageHeaderAccessorTests {
} }
@Test @Test
public void idGeneratorDefaultBehavior() { void idGeneratorDefaultBehavior() {
MessageHeaderAccessor accessor = new MessageHeaderAccessor(); MessageHeaderAccessor accessor = new MessageHeaderAccessor();
assertThat(accessor.getMessageHeaders().getId()).isNotNull(); assertThat(accessor.getMessageHeaders().getId()).isNotNull();
} }
@Test @Test
public void idTimestampWithMutableHeaders() { void idTimestampWithMutableHeaders() {
MessageHeaderAccessor accessor = new MessageHeaderAccessor(); MessageHeaderAccessor accessor = new MessageHeaderAccessor();
accessor.setIdGenerator(() -> MessageHeaders.ID_VALUE_NONE); accessor.setIdGenerator(() -> MessageHeaders.ID_VALUE_NONE);
accessor.setEnableTimestamp(false); accessor.setEnableTimestamp(false);
@ -303,7 +303,7 @@ public class MessageHeaderAccessorTests {
} }
@Test @Test
public void getShortLogMessagePayload() { void getShortLogMessagePayload() {
MessageHeaderAccessor accessor = new MessageHeaderAccessor(); MessageHeaderAccessor accessor = new MessageHeaderAccessor();
accessor.setContentType(MimeTypeUtils.TEXT_PLAIN); accessor.setContentType(MimeTypeUtils.TEXT_PLAIN);
@ -319,7 +319,7 @@ public class MessageHeaderAccessorTests {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append("a".repeat(80)); sb.append("a".repeat(80));
final String payload = sb.toString() + " > 80"; final String payload = sb + " > 80";
String actual = accessor.getShortLogMessage(payload); String actual = accessor.getShortLogMessage(payload);
assertThat(actual).isEqualTo("headers={contentType=text/plain} payload=" + sb + "...(truncated)"); assertThat(actual).isEqualTo("headers={contentType=text/plain} payload=" + sb + "...(truncated)");
@ -337,7 +337,7 @@ public class MessageHeaderAccessorTests {
} }
@Test @Test
public void getDetailedLogMessagePayload() { void getDetailedLogMessagePayload() {
MessageHeaderAccessor accessor = new MessageHeaderAccessor(); MessageHeaderAccessor accessor = new MessageHeaderAccessor();
accessor.setContentType(MimeTypeUtils.TEXT_PLAIN); accessor.setContentType(MimeTypeUtils.TEXT_PLAIN);
@ -371,7 +371,7 @@ public class MessageHeaderAccessorTests {
} }
@Test @Test
public void serializeMutableHeaders() throws Exception { void serializeMutableHeaders() throws Exception {
Map<String, Object> headers = new HashMap<>(); Map<String, Object> headers = new HashMap<>();
headers.put("foo", "bar"); headers.put("foo", "bar");
Message<String> message = new GenericMessage<>("test", headers); Message<String> message = new GenericMessage<>("test", headers);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -36,10 +36,10 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
* *
* @author Rossen Stoyanchev * @author Rossen Stoyanchev
*/ */
public class NativeMessageHeaderAccessorTests { class NativeMessageHeaderAccessorTests {
@Test @Test
public void createFromNativeHeaderMap() { void createFromNativeHeaderMap() {
MultiValueMap<String, String> inputNativeHeaders = new LinkedMultiValueMap<>(); MultiValueMap<String, String> inputNativeHeaders = new LinkedMultiValueMap<>();
inputNativeHeaders.add("foo", "bar"); inputNativeHeaders.add("foo", "bar");
inputNativeHeaders.add("bar", "baz"); inputNativeHeaders.add("bar", "baz");
@ -54,7 +54,7 @@ public class NativeMessageHeaderAccessorTests {
} }
@Test @Test
public void createFromMessage() { void createFromMessage() {
MultiValueMap<String, String> inputNativeHeaders = new LinkedMultiValueMap<>(); MultiValueMap<String, String> inputNativeHeaders = new LinkedMultiValueMap<>();
inputNativeHeaders.add("foo", "bar"); inputNativeHeaders.add("foo", "bar");
inputNativeHeaders.add("bar", "baz"); inputNativeHeaders.add("bar", "baz");
@ -75,7 +75,7 @@ public class NativeMessageHeaderAccessorTests {
} }
@Test @Test
public void createFromMessageNull() { void createFromMessageNull() {
NativeMessageHeaderAccessor headerAccessor = new NativeMessageHeaderAccessor((Message<?>) null); NativeMessageHeaderAccessor headerAccessor = new NativeMessageHeaderAccessor((Message<?>) null);
Map<String, Object> actual = headerAccessor.toMap(); Map<String, Object> actual = headerAccessor.toMap();
@ -86,7 +86,7 @@ public class NativeMessageHeaderAccessorTests {
} }
@Test @Test
public void createFromMessageAndModify() { void createFromMessageAndModify() {
MultiValueMap<String, String> inputNativeHeaders = new LinkedMultiValueMap<>(); MultiValueMap<String, String> inputNativeHeaders = new LinkedMultiValueMap<>();
inputNativeHeaders.add("foo", "bar"); inputNativeHeaders.add("foo", "bar");
@ -117,7 +117,7 @@ public class NativeMessageHeaderAccessorTests {
} }
@Test @Test
public void setNativeHeader() { void setNativeHeader() {
MultiValueMap<String, String> nativeHeaders = new LinkedMultiValueMap<>(); MultiValueMap<String, String> nativeHeaders = new LinkedMultiValueMap<>();
nativeHeaders.add("foo", "bar"); nativeHeaders.add("foo", "bar");
@ -128,7 +128,7 @@ public class NativeMessageHeaderAccessorTests {
} }
@Test @Test
public void setNativeHeaderNullValue() { void setNativeHeaderNullValue() {
MultiValueMap<String, String> nativeHeaders = new LinkedMultiValueMap<>(); MultiValueMap<String, String> nativeHeaders = new LinkedMultiValueMap<>();
nativeHeaders.add("foo", "bar"); nativeHeaders.add("foo", "bar");
@ -139,7 +139,7 @@ public class NativeMessageHeaderAccessorTests {
} }
@Test @Test
public void setNativeHeaderLazyInit() { void setNativeHeaderLazyInit() {
NativeMessageHeaderAccessor headerAccessor = new NativeMessageHeaderAccessor(); NativeMessageHeaderAccessor headerAccessor = new NativeMessageHeaderAccessor();
headerAccessor.setNativeHeader("foo", "baz"); headerAccessor.setNativeHeader("foo", "baz");
@ -147,7 +147,7 @@ public class NativeMessageHeaderAccessorTests {
} }
@Test @Test
public void setNativeHeaderLazyInitNullValue() { void setNativeHeaderLazyInitNullValue() {
NativeMessageHeaderAccessor headerAccessor = new NativeMessageHeaderAccessor(); NativeMessageHeaderAccessor headerAccessor = new NativeMessageHeaderAccessor();
headerAccessor.setNativeHeader("foo", null); headerAccessor.setNativeHeader("foo", null);
@ -156,7 +156,7 @@ public class NativeMessageHeaderAccessorTests {
} }
@Test @Test
public void setNativeHeaderImmutable() { void setNativeHeaderImmutable() {
NativeMessageHeaderAccessor headerAccessor = new NativeMessageHeaderAccessor(); NativeMessageHeaderAccessor headerAccessor = new NativeMessageHeaderAccessor();
headerAccessor.setNativeHeader("foo", "bar"); headerAccessor.setNativeHeader("foo", "bar");
headerAccessor.setImmutable(); headerAccessor.setImmutable();
@ -167,7 +167,7 @@ public class NativeMessageHeaderAccessorTests {
} }
@Test @Test
public void addNativeHeader() { void addNativeHeader() {
MultiValueMap<String, String> nativeHeaders = new LinkedMultiValueMap<>(); MultiValueMap<String, String> nativeHeaders = new LinkedMultiValueMap<>();
nativeHeaders.add("foo", "bar"); nativeHeaders.add("foo", "bar");
@ -178,7 +178,7 @@ public class NativeMessageHeaderAccessorTests {
} }
@Test @Test
public void addNativeHeaderNullValue() { void addNativeHeaderNullValue() {
MultiValueMap<String, String> nativeHeaders = new LinkedMultiValueMap<>(); MultiValueMap<String, String> nativeHeaders = new LinkedMultiValueMap<>();
nativeHeaders.add("foo", "bar"); nativeHeaders.add("foo", "bar");
@ -189,7 +189,7 @@ public class NativeMessageHeaderAccessorTests {
} }
@Test @Test
public void addNativeHeaderLazyInit() { void addNativeHeaderLazyInit() {
NativeMessageHeaderAccessor headerAccessor = new NativeMessageHeaderAccessor(); NativeMessageHeaderAccessor headerAccessor = new NativeMessageHeaderAccessor();
headerAccessor.addNativeHeader("foo", "bar"); headerAccessor.addNativeHeader("foo", "bar");
@ -197,7 +197,7 @@ public class NativeMessageHeaderAccessorTests {
} }
@Test @Test
public void addNativeHeaderLazyInitNullValue() { void addNativeHeaderLazyInitNullValue() {
NativeMessageHeaderAccessor headerAccessor = new NativeMessageHeaderAccessor(); NativeMessageHeaderAccessor headerAccessor = new NativeMessageHeaderAccessor();
headerAccessor.addNativeHeader("foo", null); headerAccessor.addNativeHeader("foo", null);
@ -206,7 +206,7 @@ public class NativeMessageHeaderAccessorTests {
} }
@Test @Test
public void addNativeHeaderImmutable() { void addNativeHeaderImmutable() {
NativeMessageHeaderAccessor headerAccessor = new NativeMessageHeaderAccessor(); NativeMessageHeaderAccessor headerAccessor = new NativeMessageHeaderAccessor();
headerAccessor.addNativeHeader("foo", "bar"); headerAccessor.addNativeHeader("foo", "bar");
headerAccessor.setImmutable(); headerAccessor.setImmutable();
@ -217,7 +217,7 @@ public class NativeMessageHeaderAccessorTests {
} }
@Test @Test
public void setImmutableIdempotent() { void setImmutableIdempotent() {
NativeMessageHeaderAccessor headerAccessor = new NativeMessageHeaderAccessor(); NativeMessageHeaderAccessor headerAccessor = new NativeMessageHeaderAccessor();
headerAccessor.addNativeHeader("foo", "bar"); headerAccessor.addNativeHeader("foo", "bar");
headerAccessor.setImmutable(); headerAccessor.setImmutable();