Polishing
This commit is contained in:
@@ -154,7 +154,7 @@ public abstract class AbstractEncoderMethodReturnValueHandler implements Handler
|
||||
}
|
||||
|
||||
Encoder<?> encoder = getEncoder(elementType, mimeType);
|
||||
return Flux.from((Publisher) publisher).map(value ->
|
||||
return Flux.from(publisher).map(value ->
|
||||
encodeValue(value, elementType, encoder, bufferFactory, mimeType, hints));
|
||||
}
|
||||
|
||||
|
||||
@@ -566,14 +566,6 @@ public abstract class AbstractMethodMessageHandler<T>
|
||||
this.handlerMethod = handlerMethod;
|
||||
}
|
||||
|
||||
public T getMapping() {
|
||||
return this.mapping;
|
||||
}
|
||||
|
||||
public HandlerMethod getHandlerMethod() {
|
||||
return this.handlerMethod;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.mapping.toString();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -541,6 +541,7 @@ public class DefaultSubscriptionRegistry extends AbstractSubscriptionRegistry {
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("rawtypes")
|
||||
public TypedValue read(EvaluationContext context, @Nullable Object target, String name) {
|
||||
Object value;
|
||||
if (target instanceof Message) {
|
||||
|
||||
@@ -215,6 +215,7 @@ public class MultiServerUserRegistry implements SimpUserRegistry, SmartApplicati
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
@@ -223,6 +224,7 @@ public class MultiServerUserRegistry implements SimpUserRegistry, SmartApplicati
|
||||
return this.id;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public void setUserMap(Map<String, TransferSimpUser> users) {
|
||||
this.users = users;
|
||||
}
|
||||
@@ -297,6 +299,7 @@ public class MultiServerUserRegistry implements SimpUserRegistry, SmartApplicati
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
@@ -328,6 +331,7 @@ public class MultiServerUserRegistry implements SimpUserRegistry, SmartApplicati
|
||||
return null;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public void setSessions(Set<TransferSimpSession> sessions) {
|
||||
this.sessions.addAll(sessions);
|
||||
}
|
||||
@@ -407,6 +411,7 @@ public class MultiServerUserRegistry implements SimpUserRegistry, SmartApplicati
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
@@ -425,6 +430,7 @@ public class MultiServerUserRegistry implements SimpUserRegistry, SmartApplicati
|
||||
return this.user;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public void setSubscriptions(Set<TransferSimpSubscription> subscriptions) {
|
||||
this.subscriptions.addAll(subscriptions);
|
||||
}
|
||||
@@ -487,6 +493,7 @@ public class MultiServerUserRegistry implements SimpUserRegistry, SmartApplicati
|
||||
this.destination = subscription.getDestination();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
@@ -505,6 +512,7 @@ public class MultiServerUserRegistry implements SimpUserRegistry, SmartApplicati
|
||||
return this.session;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public void setDestination(String destination) {
|
||||
this.destination = destination;
|
||||
}
|
||||
|
||||
@@ -51,6 +51,7 @@ public class HeaderMethodArgumentResolverTests {
|
||||
|
||||
|
||||
@BeforeEach
|
||||
@SuppressWarnings("resource")
|
||||
public void setup() {
|
||||
GenericApplicationContext context = new GenericApplicationContext();
|
||||
context.refresh();
|
||||
|
||||
@@ -53,6 +53,7 @@ public class HeaderMethodArgumentResolverTests {
|
||||
|
||||
|
||||
@BeforeEach
|
||||
@SuppressWarnings("resource")
|
||||
public void setup() {
|
||||
GenericApplicationContext context = new GenericApplicationContext();
|
||||
context.refresh();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -64,7 +64,6 @@ public class StubArgumentResolver implements HandlerMethodArgumentResolver {
|
||||
return parameter.getParameterType().equals(this.valueType);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public Mono<Object> resolveArgument(MethodParameter parameter, Message<?> message) {
|
||||
this.resolvedParameters.add(parameter);
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.messaging.handler.invocation.reactive;
|
||||
|
||||
import org.reactivestreams.Publisher;
|
||||
@@ -44,7 +45,7 @@ public class TestReturnValueHandler implements HandlerMethodReturnValueHandler {
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
public Mono<Void> handleReturnValue(@Nullable Object value, MethodParameter returnType, Message<?> message) {
|
||||
return value instanceof Publisher ?
|
||||
new ChannelSendOperator((Publisher) value, this::saveValue) :
|
||||
|
||||
@@ -237,6 +237,7 @@ public class SubscriptionMethodReturnValueHandlerTests {
|
||||
|
||||
private String withoutView;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public String getWithView1() {
|
||||
return withView1;
|
||||
}
|
||||
@@ -245,6 +246,7 @@ public class SubscriptionMethodReturnValueHandlerTests {
|
||||
this.withView1 = withView1;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public String getWithView2() {
|
||||
return withView2;
|
||||
}
|
||||
@@ -253,6 +255,7 @@ public class SubscriptionMethodReturnValueHandlerTests {
|
||||
this.withView2 = withView2;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public String getWithoutView() {
|
||||
return withoutView;
|
||||
}
|
||||
|
||||
@@ -180,8 +180,8 @@ public class SimpleBrokerMessageHandlerTests {
|
||||
this.messageHandler::start);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
@SuppressWarnings("rawtypes")
|
||||
public void startAndStopWithHeartbeatValue() {
|
||||
ScheduledFuture future = mock(ScheduledFuture.class);
|
||||
given(this.taskScheduler.scheduleWithFixedDelay(any(Runnable.class), eq(15000L))).willReturn(future);
|
||||
@@ -199,7 +199,6 @@ public class SimpleBrokerMessageHandlerTests {
|
||||
verifyNoMoreInteractions(future);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void startWithOneZeroHeartbeatValue() {
|
||||
this.messageHandler.setTaskScheduler(this.taskScheduler);
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.messaging.simp.stomp;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -46,11 +47,11 @@ import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
/**
|
||||
* Unit tests for StompBrokerRelayMessageHandler.
|
||||
* Unit tests for {@link StompBrokerRelayMessageHandler}.
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
*/
|
||||
public class StompBrokerRelayMessageHandlerTests {
|
||||
class StompBrokerRelayMessageHandlerTests {
|
||||
|
||||
private StompBrokerRelayMessageHandler brokerRelay;
|
||||
|
||||
@@ -60,7 +61,7 @@ public class StompBrokerRelayMessageHandlerTests {
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
void setup() {
|
||||
|
||||
this.outboundChannel = new StubMessageChannel();
|
||||
|
||||
@@ -80,7 +81,7 @@ public class StompBrokerRelayMessageHandlerTests {
|
||||
|
||||
|
||||
@Test
|
||||
public void virtualHost() throws Exception {
|
||||
void virtualHost() {
|
||||
|
||||
this.brokerRelay.setVirtualHost("ABC");
|
||||
|
||||
@@ -101,7 +102,7 @@ public class StompBrokerRelayMessageHandlerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void loginAndPasscode() throws Exception {
|
||||
void loginAndPasscode() {
|
||||
|
||||
this.brokerRelay.setSystemLogin("syslogin");
|
||||
this.brokerRelay.setSystemPasscode("syspasscode");
|
||||
@@ -125,7 +126,7 @@ public class StompBrokerRelayMessageHandlerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void destinationExcluded() throws Exception {
|
||||
void destinationExcluded() {
|
||||
|
||||
this.brokerRelay.start();
|
||||
|
||||
@@ -141,7 +142,7 @@ public class StompBrokerRelayMessageHandlerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void messageFromBrokerIsEnriched() throws Exception {
|
||||
void messageFromBrokerIsEnriched() {
|
||||
|
||||
this.brokerRelay.start();
|
||||
this.brokerRelay.handleMessage(connectMessage("sess1", "joe"));
|
||||
@@ -161,7 +162,7 @@ public class StompBrokerRelayMessageHandlerTests {
|
||||
// SPR-12820
|
||||
|
||||
@Test
|
||||
public void connectWhenBrokerNotAvailable() throws Exception {
|
||||
void connectWhenBrokerNotAvailable() {
|
||||
|
||||
this.brokerRelay.start();
|
||||
this.brokerRelay.stopInternal();
|
||||
@@ -176,7 +177,7 @@ public class StompBrokerRelayMessageHandlerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sendAfterBrokerUnavailable() throws Exception {
|
||||
void sendAfterBrokerUnavailable() {
|
||||
|
||||
this.brokerRelay.start();
|
||||
assertThat(this.brokerRelay.getConnectionCount()).isEqualTo(1);
|
||||
@@ -197,7 +198,8 @@ public class StompBrokerRelayMessageHandlerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void systemSubscription() throws Exception {
|
||||
@SuppressWarnings("rawtypes")
|
||||
void systemSubscription() {
|
||||
|
||||
MessageHandler handler = mock(MessageHandler.class);
|
||||
this.brokerRelay.setSystemSubscriptions(Collections.singletonMap("/topic/foo", handler));
|
||||
@@ -247,18 +249,7 @@ public class StompBrokerRelayMessageHandlerTests {
|
||||
private static ListenableFutureTask<Void> getVoidFuture() {
|
||||
ListenableFutureTask<Void> futureTask = new ListenableFutureTask<>(new Callable<Void>() {
|
||||
@Override
|
||||
public Void call() throws Exception {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
futureTask.run();
|
||||
return futureTask;
|
||||
}
|
||||
|
||||
private static ListenableFutureTask<Boolean> getBooleanFuture() {
|
||||
ListenableFutureTask<Boolean> futureTask = new ListenableFutureTask<>(new Callable<Boolean>() {
|
||||
@Override
|
||||
public Boolean call() throws Exception {
|
||||
public Void call() {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
@@ -22,7 +22,6 @@ import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
@@ -39,25 +38,17 @@ import static org.mockito.Mockito.mock;
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
*/
|
||||
public class MultiServerUserRegistryTests {
|
||||
class MultiServerUserRegistryTests {
|
||||
|
||||
private SimpUserRegistry localRegistry;
|
||||
private final SimpUserRegistry localRegistry = Mockito.mock(SimpUserRegistry.class);
|
||||
|
||||
private MultiServerUserRegistry registry;
|
||||
private final MultiServerUserRegistry registry = new MultiServerUserRegistry(this.localRegistry);
|
||||
|
||||
private MessageConverter converter;
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup() throws Exception {
|
||||
this.localRegistry = Mockito.mock(SimpUserRegistry.class);
|
||||
this.registry = new MultiServerUserRegistry(this.localRegistry);
|
||||
this.converter = new MappingJackson2MessageConverter();
|
||||
}
|
||||
private final MessageConverter converter = new MappingJackson2MessageConverter();
|
||||
|
||||
|
||||
@Test
|
||||
public void getUserFromLocalRegistry() throws Exception {
|
||||
void getUserFromLocalRegistry() {
|
||||
SimpUser user = Mockito.mock(SimpUser.class);
|
||||
Set<SimpUser> users = Collections.singleton(user);
|
||||
given(this.localRegistry.getUsers()).willReturn(users);
|
||||
@@ -69,7 +60,7 @@ public class MultiServerUserRegistryTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getUserFromRemoteRegistry() throws Exception {
|
||||
void getUserFromRemoteRegistry() {
|
||||
// Prepare broadcast message from remote server
|
||||
TestSimpUser testUser = new TestSimpUser("joe");
|
||||
TestSimpSession testSession = new TestSimpSession("remote-sess");
|
||||
@@ -100,7 +91,7 @@ public class MultiServerUserRegistryTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findSubscriptionsFromRemoteRegistry() throws Exception {
|
||||
void findSubscriptionsFromRemoteRegistry() {
|
||||
// Prepare broadcast message from remote server
|
||||
TestSimpUser user1 = new TestSimpUser("joe");
|
||||
TestSimpUser user2 = new TestSimpUser("jane");
|
||||
@@ -133,7 +124,7 @@ public class MultiServerUserRegistryTests {
|
||||
}
|
||||
|
||||
@Test // SPR-13800
|
||||
public void getSessionsWhenUserIsConnectedToMultipleServers() throws Exception {
|
||||
void getSessionsWhenUserIsConnectedToMultipleServers() {
|
||||
// Add user to local registry
|
||||
TestSimpUser localUser = new TestSimpUser("joe");
|
||||
TestSimpSession localSession = new TestSimpSession("sess123");
|
||||
@@ -169,7 +160,7 @@ public class MultiServerUserRegistryTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void purgeExpiredRegistries() throws Exception {
|
||||
void purgeExpiredRegistries() {
|
||||
// Prepare broadcast message from remote server
|
||||
TestSimpUser testUser = new TestSimpUser("joe");
|
||||
testUser.addSessions(new TestSimpSession("remote-sub"));
|
||||
|
||||
@@ -18,7 +18,6 @@ package org.springframework.messaging.simp.user;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Mockito;
|
||||
@@ -41,31 +40,22 @@ import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
import static org.springframework.messaging.simp.SimpMessageHeaderAccessor.ORIGINAL_DESTINATION;
|
||||
|
||||
/**
|
||||
* Unit tests for
|
||||
* {@link org.springframework.messaging.simp.user.UserDestinationMessageHandler}.
|
||||
* Unit tests for {@link UserDestinationMessageHandler}.
|
||||
*/
|
||||
public class UserDestinationMessageHandlerTests {
|
||||
class UserDestinationMessageHandlerTests {
|
||||
|
||||
private static final String SESSION_ID = "123";
|
||||
|
||||
private UserDestinationMessageHandler handler;
|
||||
private final SimpUserRegistry registry = mock(SimpUserRegistry.class);
|
||||
|
||||
private SimpUserRegistry registry;
|
||||
private final SubscribableChannel brokerChannel = mock(SubscribableChannel.class);
|
||||
|
||||
private SubscribableChannel brokerChannel;
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
this.registry = mock(SimpUserRegistry.class);
|
||||
this.brokerChannel = mock(SubscribableChannel.class);
|
||||
UserDestinationResolver resolver = new DefaultUserDestinationResolver(this.registry);
|
||||
this.handler = new UserDestinationMessageHandler(new StubMessageChannel(), this.brokerChannel, resolver);
|
||||
}
|
||||
private final UserDestinationMessageHandler handler = new UserDestinationMessageHandler(new StubMessageChannel(), this.brokerChannel, new DefaultUserDestinationResolver(this.registry));
|
||||
|
||||
|
||||
@Test
|
||||
public void handleSubscribe() {
|
||||
@SuppressWarnings("rawtypes")
|
||||
void handleSubscribe() {
|
||||
given(this.brokerChannel.send(Mockito.any(Message.class))).willReturn(true);
|
||||
this.handler.handleMessage(createWith(SimpMessageType.SUBSCRIBE, "joe", SESSION_ID, "/user/queue/foo"));
|
||||
|
||||
@@ -77,7 +67,8 @@ public class UserDestinationMessageHandlerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void handleUnsubscribe() {
|
||||
@SuppressWarnings("rawtypes")
|
||||
void handleUnsubscribe() {
|
||||
given(this.brokerChannel.send(Mockito.any(Message.class))).willReturn(true);
|
||||
this.handler.handleMessage(createWith(SimpMessageType.UNSUBSCRIBE, "joe", "123", "/user/queue/foo"));
|
||||
|
||||
@@ -89,7 +80,8 @@ public class UserDestinationMessageHandlerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void handleMessage() {
|
||||
@SuppressWarnings("rawtypes")
|
||||
void handleMessage() {
|
||||
TestSimpUser simpUser = new TestSimpUser("joe");
|
||||
simpUser.addSessions(new TestSimpSession("123"));
|
||||
given(this.registry.getUser("joe")).willReturn(simpUser);
|
||||
@@ -105,7 +97,8 @@ public class UserDestinationMessageHandlerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void handleMessageWithoutActiveSession() {
|
||||
@SuppressWarnings("rawtypes")
|
||||
void handleMessageWithoutActiveSession() {
|
||||
this.handler.setBroadcastDestination("/topic/unresolved");
|
||||
given(this.brokerChannel.send(Mockito.any(Message.class))).willReturn(true);
|
||||
this.handler.handleMessage(createWith(SimpMessageType.MESSAGE, "joe", "123", "/user/joe/queue/foo"));
|
||||
@@ -125,7 +118,8 @@ public class UserDestinationMessageHandlerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void handleMessageFromBrokerWithActiveSession() {
|
||||
@SuppressWarnings("rawtypes")
|
||||
void handleMessageFromBrokerWithActiveSession() {
|
||||
TestSimpUser simpUser = new TestSimpUser("joe");
|
||||
simpUser.addSessions(new TestSimpSession("123"));
|
||||
given(this.registry.getUser("joe")).willReturn(simpUser);
|
||||
@@ -153,7 +147,7 @@ public class UserDestinationMessageHandlerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void handleMessageFromBrokerWithoutActiveSession() {
|
||||
void handleMessageFromBrokerWithoutActiveSession() {
|
||||
this.handler.setBroadcastDestination("/topic/unresolved");
|
||||
given(this.brokerChannel.send(Mockito.any(Message.class))).willReturn(true);
|
||||
|
||||
@@ -170,7 +164,7 @@ public class UserDestinationMessageHandlerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ignoreMessage() {
|
||||
void ignoreMessage() {
|
||||
|
||||
// no destination
|
||||
this.handler.handleMessage(createWith(SimpMessageType.MESSAGE, "joe", "123", null));
|
||||
|
||||
@@ -89,8 +89,8 @@ public class UserRegistryMessageHandlerTests {
|
||||
assertThat(runnable).isNotNull();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
public void brokerUnavailableEvent() throws Exception {
|
||||
|
||||
ScheduledFuture future = mock(ScheduledFuture.class);
|
||||
@@ -106,6 +106,7 @@ public class UserRegistryMessageHandlerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("rawtypes")
|
||||
public void broadcastRegistry() throws Exception {
|
||||
given(this.brokerChannel.send(any())).willReturn(true);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user