Clean up Mockito usage
This commit migrates to the MockitoJUnitRunner where sensible, which will later allow for an easier migration to Mockito's extension for JUnit Jupiter. In addition, this commit deletes unnecessary stubbing for various mocks and polishes test fixture setup in various test classes.
This commit is contained in:
parent
d495902a9c
commit
141ef9082f
|
|
@ -25,9 +25,11 @@ import java.sql.Types;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.ArgumentCaptor;
|
import org.mockito.ArgumentCaptor;
|
||||||
import org.mockito.Captor;
|
import org.mockito.Captor;
|
||||||
import org.mockito.MockitoAnnotations;
|
import org.mockito.Mock;
|
||||||
|
import org.mockito.junit.MockitoJUnitRunner;
|
||||||
|
|
||||||
import org.springframework.jdbc.support.lob.LobCreator;
|
import org.springframework.jdbc.support.lob.LobCreator;
|
||||||
import org.springframework.jdbc.support.lob.LobHandler;
|
import org.springframework.jdbc.support.lob.LobHandler;
|
||||||
|
|
@ -36,11 +38,10 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||||
import static org.mockito.ArgumentMatchers.eq;
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
import static org.mockito.BDDMockito.given;
|
import static org.mockito.BDDMockito.given;
|
||||||
import static org.mockito.Mockito.mock;
|
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test cases for the sql lob value:
|
* Test cases for the SQL LOB value:
|
||||||
*
|
*
|
||||||
* BLOB:
|
* BLOB:
|
||||||
* 1. Types.BLOB: setBlobAsBytes (byte[])
|
* 1. Types.BLOB: setBlobAsBytes (byte[])
|
||||||
|
|
@ -55,10 +56,16 @@ import static org.mockito.Mockito.verify;
|
||||||
*
|
*
|
||||||
* @author Alef Arendsen
|
* @author Alef Arendsen
|
||||||
*/
|
*/
|
||||||
|
@RunWith(MockitoJUnitRunner.class)
|
||||||
public class SqlLobValueTests {
|
public class SqlLobValueTests {
|
||||||
|
|
||||||
|
@Mock
|
||||||
private PreparedStatement preparedStatement;
|
private PreparedStatement preparedStatement;
|
||||||
|
|
||||||
|
@Mock
|
||||||
private LobHandler handler;
|
private LobHandler handler;
|
||||||
|
|
||||||
|
@Mock
|
||||||
private LobCreator creator;
|
private LobCreator creator;
|
||||||
|
|
||||||
@Captor
|
@Captor
|
||||||
|
|
@ -66,10 +73,6 @@ public class SqlLobValueTests {
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
MockitoAnnotations.initMocks(this);
|
|
||||||
preparedStatement = mock(PreparedStatement.class);
|
|
||||||
handler = mock(LobHandler.class);
|
|
||||||
creator = mock(LobCreator.class);
|
|
||||||
given(handler.getLobCreator()).willReturn(creator);
|
given(handler.getLobCreator()).willReturn(creator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -28,11 +28,11 @@ import javax.jms.TextMessage;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.ArgumentCaptor;
|
import org.mockito.ArgumentCaptor;
|
||||||
import org.mockito.BDDMockito;
|
|
||||||
import org.mockito.Captor;
|
import org.mockito.Captor;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.MockitoAnnotations;
|
import org.mockito.junit.MockitoJUnitRunner;
|
||||||
import org.mockito.stubbing.Answer;
|
import org.mockito.stubbing.Answer;
|
||||||
|
|
||||||
import org.springframework.beans.DirectFieldAccessor;
|
import org.springframework.beans.DirectFieldAccessor;
|
||||||
|
|
@ -65,6 +65,7 @@ import static org.mockito.Mockito.verify;
|
||||||
*
|
*
|
||||||
* @author Stephane Nicoll
|
* @author Stephane Nicoll
|
||||||
*/
|
*/
|
||||||
|
@RunWith(MockitoJUnitRunner.class)
|
||||||
public class JmsMessagingTemplateTests {
|
public class JmsMessagingTemplateTests {
|
||||||
|
|
||||||
@Captor
|
@Captor
|
||||||
|
|
@ -78,7 +79,6 @@ public class JmsMessagingTemplateTests {
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setup() {
|
public void setup() {
|
||||||
MockitoAnnotations.initMocks(this);
|
|
||||||
this.messagingTemplate = new JmsMessagingTemplate(this.jmsTemplate);
|
this.messagingTemplate = new JmsMessagingTemplate(this.jmsTemplate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -108,8 +108,6 @@ public class JmsMessagingTemplateTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void customConverterAlwaysTakesPrecedence() {
|
public void customConverterAlwaysTakesPrecedence() {
|
||||||
MessageConverter messageConverter = mock(MessageConverter.class);
|
|
||||||
given(this.jmsTemplate.getMessageConverter()).willReturn(messageConverter);
|
|
||||||
MessageConverter customMessageConverter = mock(MessageConverter.class);
|
MessageConverter customMessageConverter = mock(MessageConverter.class);
|
||||||
JmsMessagingTemplate messagingTemplate = new JmsMessagingTemplate();
|
JmsMessagingTemplate messagingTemplate = new JmsMessagingTemplate();
|
||||||
messagingTemplate.setJmsMessageConverter(
|
messagingTemplate.setJmsMessageConverter(
|
||||||
|
|
@ -648,11 +646,11 @@ public class JmsMessagingTemplateTests {
|
||||||
|
|
||||||
protected TextMessage createTextMessage(MessageCreator creator) throws JMSException {
|
protected TextMessage createTextMessage(MessageCreator creator) throws JMSException {
|
||||||
Session mock = mock(Session.class);
|
Session mock = mock(Session.class);
|
||||||
given(mock.createTextMessage(BDDMockito.any())).willAnswer(
|
given(mock.createTextMessage(any())).willAnswer(
|
||||||
(Answer<TextMessage>) invocation ->
|
(Answer<TextMessage>) invocation ->
|
||||||
new StubTextMessage((String) invocation.getArguments()[0]));
|
new StubTextMessage((String) invocation.getArguments()[0]));
|
||||||
javax.jms.Message message = creator.createMessage(mock);
|
javax.jms.Message message = creator.createMessage(mock);
|
||||||
verify(mock).createTextMessage(BDDMockito.any());
|
verify(mock).createTextMessage(any());
|
||||||
return TextMessage.class.cast(message);
|
return TextMessage.class.cast(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,34 +19,25 @@ package org.springframework.messaging.simp;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.mockito.Mockito;
|
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.times;
|
import static org.mockito.Mockito.times;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit tests for
|
* Unit tests for {@link SimpAttributes}.
|
||||||
* {@link org.springframework.messaging.simp.SimpAttributes}.
|
|
||||||
*
|
*
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
* @since 4.1
|
* @since 4.1
|
||||||
*/
|
*/
|
||||||
public class SimpAttributesTests {
|
public class SimpAttributesTests {
|
||||||
|
|
||||||
private SimpAttributes simpAttributes;
|
private final Map<String, Object> map = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
private Map<String, Object> map;
|
private final SimpAttributes simpAttributes = new SimpAttributes("session1", this.map);
|
||||||
|
|
||||||
|
|
||||||
@Before
|
|
||||||
public void setup() {
|
|
||||||
this.map = new ConcurrentHashMap<>();
|
|
||||||
this.simpAttributes = new SimpAttributes("session1", this.map);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
@ -69,7 +60,7 @@ public class SimpAttributesTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void registerDestructionCallback() {
|
public void registerDestructionCallback() {
|
||||||
Runnable callback = Mockito.mock(Runnable.class);
|
Runnable callback = mock(Runnable.class);
|
||||||
this.simpAttributes.registerDestructionCallback("name1", callback);
|
this.simpAttributes.registerDestructionCallback("name1", callback);
|
||||||
|
|
||||||
assertThat(this.simpAttributes.getAttribute(
|
assertThat(this.simpAttributes.getAttribute(
|
||||||
|
|
@ -80,14 +71,14 @@ public class SimpAttributesTests {
|
||||||
public void registerDestructionCallbackAfterSessionCompleted() {
|
public void registerDestructionCallbackAfterSessionCompleted() {
|
||||||
this.simpAttributes.sessionCompleted();
|
this.simpAttributes.sessionCompleted();
|
||||||
assertThatIllegalStateException().isThrownBy(() ->
|
assertThatIllegalStateException().isThrownBy(() ->
|
||||||
this.simpAttributes.registerDestructionCallback("name1", Mockito.mock(Runnable.class)))
|
this.simpAttributes.registerDestructionCallback("name1", mock(Runnable.class)))
|
||||||
.withMessageContaining("already completed");
|
.withMessageContaining("already completed");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void removeDestructionCallback() {
|
public void removeDestructionCallback() {
|
||||||
Runnable callback1 = Mockito.mock(Runnable.class);
|
Runnable callback1 = mock(Runnable.class);
|
||||||
Runnable callback2 = Mockito.mock(Runnable.class);
|
Runnable callback2 = mock(Runnable.class);
|
||||||
this.simpAttributes.registerDestructionCallback("name1", callback1);
|
this.simpAttributes.registerDestructionCallback("name1", callback1);
|
||||||
this.simpAttributes.registerDestructionCallback("name2", callback2);
|
this.simpAttributes.registerDestructionCallback("name2", callback2);
|
||||||
|
|
||||||
|
|
@ -109,8 +100,8 @@ public class SimpAttributesTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void sessionCompleted() {
|
public void sessionCompleted() {
|
||||||
Runnable callback1 = Mockito.mock(Runnable.class);
|
Runnable callback1 = mock(Runnable.class);
|
||||||
Runnable callback2 = Mockito.mock(Runnable.class);
|
Runnable callback2 = mock(Runnable.class);
|
||||||
this.simpAttributes.registerDestructionCallback("name1", callback1);
|
this.simpAttributes.registerDestructionCallback("name1", callback1);
|
||||||
this.simpAttributes.registerDestructionCallback("name2", callback2);
|
this.simpAttributes.registerDestructionCallback("name2", callback2);
|
||||||
|
|
||||||
|
|
@ -122,7 +113,7 @@ public class SimpAttributesTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void sessionCompletedIsIdempotent() {
|
public void sessionCompletedIsIdempotent() {
|
||||||
Runnable callback1 = Mockito.mock(Runnable.class);
|
Runnable callback1 = mock(Runnable.class);
|
||||||
this.simpAttributes.registerDestructionCallback("name1", callback1);
|
this.simpAttributes.registerDestructionCallback("name1", callback1);
|
||||||
|
|
||||||
this.simpAttributes.sessionCompleted();
|
this.simpAttributes.sessionCompleted();
|
||||||
|
|
|
||||||
|
|
@ -28,11 +28,11 @@ import javax.security.auth.Subject;
|
||||||
import com.fasterxml.jackson.annotation.JsonView;
|
import com.fasterxml.jackson.annotation.JsonView;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.ArgumentCaptor;
|
import org.mockito.ArgumentCaptor;
|
||||||
import org.mockito.Captor;
|
import org.mockito.Captor;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.Mockito;
|
import org.mockito.junit.MockitoJUnitRunner;
|
||||||
import org.mockito.MockitoAnnotations;
|
|
||||||
|
|
||||||
import org.springframework.core.MethodParameter;
|
import org.springframework.core.MethodParameter;
|
||||||
import org.springframework.core.annotation.AliasFor;
|
import org.springframework.core.annotation.AliasFor;
|
||||||
|
|
@ -58,6 +58,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.mockito.ArgumentMatchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.ArgumentMatchers.eq;
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
import static org.mockito.BDDMockito.given;
|
import static org.mockito.BDDMockito.given;
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.times;
|
import static org.mockito.Mockito.times;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
|
|
||||||
|
|
@ -68,6 +69,7 @@ import static org.mockito.Mockito.verify;
|
||||||
* @author Sebastien Deleuze
|
* @author Sebastien Deleuze
|
||||||
* @author Stephane Nicoll
|
* @author Stephane Nicoll
|
||||||
*/
|
*/
|
||||||
|
@RunWith(MockitoJUnitRunner.class)
|
||||||
public class SendToMethodReturnValueHandlerTests {
|
public class SendToMethodReturnValueHandlerTests {
|
||||||
|
|
||||||
private static final MimeType MIME_TYPE = new MimeType("text", "plain", StandardCharsets.UTF_8);
|
private static final MimeType MIME_TYPE = new MimeType("text", "plain", StandardCharsets.UTF_8);
|
||||||
|
|
@ -75,16 +77,18 @@ public class SendToMethodReturnValueHandlerTests {
|
||||||
private static final String PAYLOAD = "payload";
|
private static final String PAYLOAD = "payload";
|
||||||
|
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private MessageChannel messageChannel;
|
||||||
|
|
||||||
|
@Captor
|
||||||
|
private ArgumentCaptor<Message<?>> messageCaptor;
|
||||||
|
|
||||||
private SendToMethodReturnValueHandler handler;
|
private SendToMethodReturnValueHandler handler;
|
||||||
|
|
||||||
private SendToMethodReturnValueHandler handlerAnnotationNotRequired;
|
private SendToMethodReturnValueHandler handlerAnnotationNotRequired;
|
||||||
|
|
||||||
private SendToMethodReturnValueHandler jsonHandler;
|
private SendToMethodReturnValueHandler jsonHandler;
|
||||||
|
|
||||||
@Mock private MessageChannel messageChannel;
|
|
||||||
|
|
||||||
@Captor private ArgumentCaptor<Message<?>> messageCaptor;
|
|
||||||
|
|
||||||
private MethodParameter noAnnotationsReturnType = param("handleNoAnnotations");
|
private MethodParameter noAnnotationsReturnType = param("handleNoAnnotations");
|
||||||
private MethodParameter sendToReturnType = param("handleAndSendTo");
|
private MethodParameter sendToReturnType = param("handleAndSendTo");
|
||||||
private MethodParameter sendToDefaultDestReturnType = param("handleAndSendToDefaultDest");
|
private MethodParameter sendToDefaultDestReturnType = param("handleAndSendToDefaultDest");
|
||||||
|
|
@ -118,8 +122,6 @@ public class SendToMethodReturnValueHandlerTests {
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setup() throws Exception {
|
public void setup() throws Exception {
|
||||||
MockitoAnnotations.initMocks(this);
|
|
||||||
|
|
||||||
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);
|
||||||
|
|
@ -319,7 +321,7 @@ public class SendToMethodReturnValueHandlerTests {
|
||||||
public void testHeadersToSend() throws Exception {
|
public void testHeadersToSend() throws Exception {
|
||||||
Message<?> message = createMessage("sess1", "sub1", "/app", "/dest", null);
|
Message<?> message = createMessage("sess1", "sub1", "/app", "/dest", null);
|
||||||
|
|
||||||
SimpMessageSendingOperations messagingTemplate = Mockito.mock(SimpMessageSendingOperations.class);
|
SimpMessageSendingOperations messagingTemplate = mock(SimpMessageSendingOperations.class);
|
||||||
SendToMethodReturnValueHandler handler = new SendToMethodReturnValueHandler(messagingTemplate, false);
|
SendToMethodReturnValueHandler handler = new SendToMethodReturnValueHandler(messagingTemplate, false);
|
||||||
|
|
||||||
handler.handleReturnValue(PAYLOAD, this.noAnnotationsReturnType, message);
|
handler.handleReturnValue(PAYLOAD, this.noAnnotationsReturnType, message);
|
||||||
|
|
@ -630,10 +632,12 @@ public class SendToMethodReturnValueHandlerTests {
|
||||||
|
|
||||||
private static class TestUser implements Principal {
|
private static class TestUser implements Principal {
|
||||||
|
|
||||||
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return "joe";
|
return "joe";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean implies(Subject subject) {
|
public boolean implies(Subject subject) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -27,10 +27,11 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.ArgumentCaptor;
|
import org.mockito.ArgumentCaptor;
|
||||||
import org.mockito.Captor;
|
import org.mockito.Captor;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.MockitoAnnotations;
|
import org.mockito.junit.MockitoJUnitRunner;
|
||||||
import reactor.core.publisher.EmitterProcessor;
|
import reactor.core.publisher.EmitterProcessor;
|
||||||
import reactor.core.publisher.Flux;
|
import reactor.core.publisher.Flux;
|
||||||
import reactor.core.publisher.FluxProcessor;
|
import reactor.core.publisher.FluxProcessor;
|
||||||
|
|
@ -74,22 +75,18 @@ import static org.mockito.Mockito.never;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test fixture for
|
* Test fixture for {@link SimpAnnotationMethodMessageHandler}.
|
||||||
* {@link org.springframework.messaging.simp.annotation.support.SimpAnnotationMethodMessageHandler}.
|
|
||||||
*
|
*
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
* @author Brian Clozel
|
* @author Brian Clozel
|
||||||
* @author Sebastien Deleuze
|
* @author Sebastien Deleuze
|
||||||
*/
|
*/
|
||||||
|
@RunWith(MockitoJUnitRunner.class)
|
||||||
public class SimpAnnotationMethodMessageHandlerTests {
|
public class SimpAnnotationMethodMessageHandlerTests {
|
||||||
|
|
||||||
private static final String TEST_INVALID_VALUE = "invalidValue";
|
private static final String TEST_INVALID_VALUE = "invalidValue";
|
||||||
|
|
||||||
|
|
||||||
private TestSimpAnnotationMethodMessageHandler messageHandler;
|
|
||||||
|
|
||||||
private TestController testController;
|
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private SubscribableChannel channel;
|
private SubscribableChannel channel;
|
||||||
|
|
||||||
|
|
@ -99,11 +96,13 @@ public class SimpAnnotationMethodMessageHandlerTests {
|
||||||
@Captor
|
@Captor
|
||||||
private ArgumentCaptor<Object> payloadCaptor;
|
private ArgumentCaptor<Object> payloadCaptor;
|
||||||
|
|
||||||
|
private TestSimpAnnotationMethodMessageHandler messageHandler;
|
||||||
|
|
||||||
|
private TestController testController = new TestController();
|
||||||
|
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setup() {
|
public void setup() {
|
||||||
MockitoAnnotations.initMocks(this);
|
|
||||||
|
|
||||||
SimpMessagingTemplate brokerTemplate = new SimpMessagingTemplate(this.channel);
|
SimpMessagingTemplate brokerTemplate = new SimpMessagingTemplate(this.channel);
|
||||||
brokerTemplate.setMessageConverter(this.converter);
|
brokerTemplate.setMessageConverter(this.converter);
|
||||||
|
|
||||||
|
|
@ -111,8 +110,6 @@ public class SimpAnnotationMethodMessageHandlerTests {
|
||||||
this.messageHandler.setApplicationContext(new StaticApplicationContext());
|
this.messageHandler.setApplicationContext(new StaticApplicationContext());
|
||||||
this.messageHandler.setValidator(new StringTestValidator(TEST_INVALID_VALUE));
|
this.messageHandler.setValidator(new StringTestValidator(TEST_INVALID_VALUE));
|
||||||
this.messageHandler.afterPropertiesSet();
|
this.messageHandler.afterPropertiesSet();
|
||||||
|
|
||||||
this.testController = new TestController();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -287,12 +284,7 @@ public class SimpAnnotationMethodMessageHandlerTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
|
||||||
public void listenableFutureFailure() {
|
public void listenableFutureFailure() {
|
||||||
Message emptyMessage = MessageBuilder.withPayload(new byte[0]).build();
|
|
||||||
given(this.channel.send(any(Message.class))).willReturn(true);
|
|
||||||
given(this.converter.toMessage(any(), any(MessageHeaders.class))).willReturn(emptyMessage);
|
|
||||||
|
|
||||||
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/"));
|
||||||
|
|
@ -325,12 +317,7 @@ public class SimpAnnotationMethodMessageHandlerTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
|
||||||
public void completableFutureFailure() {
|
public void completableFutureFailure() {
|
||||||
Message emptyMessage = MessageBuilder.withPayload(new byte[0]).build();
|
|
||||||
given(this.channel.send(any(Message.class))).willReturn(true);
|
|
||||||
given(this.converter.toMessage(any(), any(MessageHeaders.class))).willReturn(emptyMessage);
|
|
||||||
|
|
||||||
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/"));
|
||||||
|
|
@ -363,12 +350,7 @@ public class SimpAnnotationMethodMessageHandlerTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
|
||||||
public void monoFailure() {
|
public void monoFailure() {
|
||||||
Message emptyMessage = MessageBuilder.withPayload(new byte[0]).build();
|
|
||||||
given(this.channel.send(any(Message.class))).willReturn(true);
|
|
||||||
given(this.converter.toMessage(any(), any(MessageHeaders.class))).willReturn(emptyMessage);
|
|
||||||
|
|
||||||
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/"));
|
||||||
|
|
@ -381,12 +363,7 @@ public class SimpAnnotationMethodMessageHandlerTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
|
||||||
public void fluxNotHandled() {
|
public void fluxNotHandled() {
|
||||||
Message emptyMessage = MessageBuilder.withPayload(new byte[0]).build();
|
|
||||||
given(this.channel.send(any(Message.class))).willReturn(true);
|
|
||||||
given(this.converter.toMessage(any(), any(MessageHeaders.class))).willReturn(emptyMessage);
|
|
||||||
|
|
||||||
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/"));
|
||||||
|
|
|
||||||
|
|
@ -23,11 +23,11 @@ import java.security.Principal;
|
||||||
import com.fasterxml.jackson.annotation.JsonView;
|
import com.fasterxml.jackson.annotation.JsonView;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.ArgumentCaptor;
|
import org.mockito.ArgumentCaptor;
|
||||||
import org.mockito.Captor;
|
import org.mockito.Captor;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.Mockito;
|
import org.mockito.junit.MockitoJUnitRunner;
|
||||||
import org.mockito.MockitoAnnotations;
|
|
||||||
|
|
||||||
import org.springframework.core.MethodParameter;
|
import org.springframework.core.MethodParameter;
|
||||||
import org.springframework.messaging.Message;
|
import org.springframework.messaging.Message;
|
||||||
|
|
@ -49,6 +49,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.mockito.ArgumentMatchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.ArgumentMatchers.eq;
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
import static org.mockito.BDDMockito.given;
|
import static org.mockito.BDDMockito.given;
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -57,6 +58,7 @@ import static org.mockito.Mockito.verify;
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
* @author Sebastien Deleuze
|
* @author Sebastien Deleuze
|
||||||
*/
|
*/
|
||||||
|
@RunWith(MockitoJUnitRunner.class)
|
||||||
public class SubscriptionMethodReturnValueHandlerTests {
|
public class SubscriptionMethodReturnValueHandlerTests {
|
||||||
|
|
||||||
public static final MimeType MIME_TYPE = new MimeType("text", "plain", StandardCharsets.UTF_8);
|
public static final MimeType MIME_TYPE = new MimeType("text", "plain", StandardCharsets.UTF_8);
|
||||||
|
|
@ -64,14 +66,16 @@ public class SubscriptionMethodReturnValueHandlerTests {
|
||||||
private static final String PAYLOAD = "payload";
|
private static final String PAYLOAD = "payload";
|
||||||
|
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private MessageChannel messageChannel;
|
||||||
|
|
||||||
|
@Captor
|
||||||
|
private ArgumentCaptor<Message<?>> messageCaptor;
|
||||||
|
|
||||||
private SubscriptionMethodReturnValueHandler handler;
|
private SubscriptionMethodReturnValueHandler handler;
|
||||||
|
|
||||||
private SubscriptionMethodReturnValueHandler jsonHandler;
|
private SubscriptionMethodReturnValueHandler jsonHandler;
|
||||||
|
|
||||||
@Mock private MessageChannel messageChannel;
|
|
||||||
|
|
||||||
@Captor private ArgumentCaptor<Message<?>> messageCaptor;
|
|
||||||
|
|
||||||
private MethodParameter subscribeEventReturnType;
|
private MethodParameter subscribeEventReturnType;
|
||||||
|
|
||||||
private MethodParameter subscribeEventSendToReturnType;
|
private MethodParameter subscribeEventSendToReturnType;
|
||||||
|
|
@ -83,8 +87,6 @@ public class SubscriptionMethodReturnValueHandlerTests {
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setup() throws Exception {
|
public void setup() throws Exception {
|
||||||
MockitoAnnotations.initMocks(this);
|
|
||||||
|
|
||||||
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);
|
||||||
|
|
@ -148,7 +150,7 @@ public class SubscriptionMethodReturnValueHandlerTests {
|
||||||
String destination = "/dest";
|
String destination = "/dest";
|
||||||
Message<?> inputMessage = createInputMessage(sessionId, subscriptionId, destination, null);
|
Message<?> inputMessage = createInputMessage(sessionId, subscriptionId, destination, null);
|
||||||
|
|
||||||
MessageSendingOperations messagingTemplate = Mockito.mock(MessageSendingOperations.class);
|
MessageSendingOperations messagingTemplate = mock(MessageSendingOperations.class);
|
||||||
SubscriptionMethodReturnValueHandler handler = new SubscriptionMethodReturnValueHandler(messagingTemplate);
|
SubscriptionMethodReturnValueHandler handler = new SubscriptionMethodReturnValueHandler(messagingTemplate);
|
||||||
|
|
||||||
handler.handleReturnValue(PAYLOAD, this.subscribeEventReturnType, inputMessage);
|
handler.handleReturnValue(PAYLOAD, this.subscribeEventReturnType, inputMessage);
|
||||||
|
|
|
||||||
|
|
@ -21,9 +21,7 @@ import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.mockito.MockitoAnnotations;
|
|
||||||
|
|
||||||
import org.springframework.context.ApplicationEvent;
|
import org.springframework.context.ApplicationEvent;
|
||||||
import org.springframework.context.ApplicationEventPublisher;
|
import org.springframework.context.ApplicationEventPublisher;
|
||||||
|
|
@ -42,14 +40,7 @@ import static org.mockito.Mockito.mock;
|
||||||
*/
|
*/
|
||||||
public class BrokerMessageHandlerTests {
|
public class BrokerMessageHandlerTests {
|
||||||
|
|
||||||
private TestBrokerMessageHandler handler;
|
private final TestBrokerMessageHandler handler = new TestBrokerMessageHandler();
|
||||||
|
|
||||||
|
|
||||||
@Before
|
|
||||||
public void setup() {
|
|
||||||
MockitoAnnotations.initMocks(this);
|
|
||||||
this.handler = new TestBrokerMessageHandler();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
@ -61,7 +52,6 @@ public class BrokerMessageHandlerTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void stopShouldUpdateIsRunning() {
|
public void stopShouldUpdateIsRunning() {
|
||||||
|
|
||||||
this.handler.start();
|
this.handler.start();
|
||||||
assertThat(this.handler.isRunning()).isTrue();
|
assertThat(this.handler.isRunning()).isTrue();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,10 +23,11 @@ import java.util.concurrent.ScheduledFuture;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.ArgumentCaptor;
|
import org.mockito.ArgumentCaptor;
|
||||||
import org.mockito.Captor;
|
import org.mockito.Captor;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.MockitoAnnotations;
|
import org.mockito.junit.MockitoJUnitRunner;
|
||||||
|
|
||||||
import org.springframework.messaging.Message;
|
import org.springframework.messaging.Message;
|
||||||
import org.springframework.messaging.MessageChannel;
|
import org.springframework.messaging.MessageChannel;
|
||||||
|
|
@ -56,11 +57,13 @@ import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
* @since 4.0
|
* @since 4.0
|
||||||
*/
|
*/
|
||||||
|
@RunWith(MockitoJUnitRunner.class)
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public class SimpleBrokerMessageHandlerTests {
|
public class SimpleBrokerMessageHandlerTests {
|
||||||
|
|
||||||
private SimpleBrokerMessageHandler messageHandler;
|
private SimpleBrokerMessageHandler messageHandler;
|
||||||
|
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private SubscribableChannel clientInChannel;
|
private SubscribableChannel clientInChannel;
|
||||||
|
|
||||||
|
|
@ -79,7 +82,6 @@ public class SimpleBrokerMessageHandlerTests {
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setup() {
|
public void setup() {
|
||||||
MockitoAnnotations.initMocks(this);
|
|
||||||
this.messageHandler = new SimpleBrokerMessageHandler(
|
this.messageHandler = new SimpleBrokerMessageHandler(
|
||||||
this.clientInChannel, this.clientOutChannel, this.brokerChannel, Collections.emptyList());
|
this.clientInChannel, this.clientOutChannel, this.brokerChannel, Collections.emptyList());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,10 +24,11 @@ import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.ArgumentCaptor;
|
import org.mockito.ArgumentCaptor;
|
||||||
import org.mockito.Captor;
|
import org.mockito.Captor;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.MockitoAnnotations;
|
import org.mockito.junit.MockitoJUnitRunner;
|
||||||
|
|
||||||
import org.springframework.messaging.Message;
|
import org.springframework.messaging.Message;
|
||||||
import org.springframework.messaging.MessageDeliveryException;
|
import org.springframework.messaging.MessageDeliveryException;
|
||||||
|
|
@ -60,15 +61,17 @@ import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||||
*
|
*
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
*/
|
*/
|
||||||
|
@RunWith(MockitoJUnitRunner.class)
|
||||||
public class DefaultStompSessionTests {
|
public class DefaultStompSessionTests {
|
||||||
|
|
||||||
private DefaultStompSession session;
|
private DefaultStompSession session;
|
||||||
|
|
||||||
|
private StompHeaders connectHeaders;
|
||||||
|
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private StompSessionHandler sessionHandler;
|
private StompSessionHandler sessionHandler;
|
||||||
|
|
||||||
private StompHeaders connectHeaders;
|
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private TcpConnection<byte[]> connection;
|
private TcpConnection<byte[]> connection;
|
||||||
|
|
||||||
|
|
@ -78,9 +81,6 @@ public class DefaultStompSessionTests {
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
MockitoAnnotations.initMocks(this);
|
|
||||||
|
|
||||||
this.sessionHandler = mock(StompSessionHandler.class);
|
|
||||||
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(new StringMessageConverter());
|
this.session.setMessageConverter(new StringMessageConverter());
|
||||||
|
|
|
||||||
|
|
@ -23,10 +23,10 @@ import java.util.concurrent.ScheduledFuture;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.ArgumentCaptor;
|
import org.mockito.ArgumentCaptor;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.Mockito;
|
import org.mockito.junit.MockitoJUnitRunner;
|
||||||
import org.mockito.MockitoAnnotations;
|
|
||||||
|
|
||||||
import org.springframework.messaging.Message;
|
import org.springframework.messaging.Message;
|
||||||
import org.springframework.messaging.MessageChannel;
|
import org.springframework.messaging.MessageChannel;
|
||||||
|
|
@ -50,6 +50,7 @@ import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||||
* User tests for {@link UserRegistryMessageHandler}.
|
* User tests for {@link UserRegistryMessageHandler}.
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
*/
|
*/
|
||||||
|
@RunWith(MockitoJUnitRunner.class)
|
||||||
public class UserRegistryMessageHandlerTests {
|
public class UserRegistryMessageHandlerTests {
|
||||||
|
|
||||||
private UserRegistryMessageHandler handler;
|
private UserRegistryMessageHandler handler;
|
||||||
|
|
@ -60,6 +61,7 @@ public class UserRegistryMessageHandlerTests {
|
||||||
|
|
||||||
private MessageConverter converter;
|
private MessageConverter converter;
|
||||||
|
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private MessageChannel brokerChannel;
|
private MessageChannel brokerChannel;
|
||||||
|
|
||||||
|
|
@ -69,9 +71,6 @@ public class UserRegistryMessageHandlerTests {
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
|
|
||||||
MockitoAnnotations.initMocks(this);
|
|
||||||
|
|
||||||
given(this.brokerChannel.send(any())).willReturn(true);
|
given(this.brokerChannel.send(any())).willReturn(true);
|
||||||
this.converter = new MappingJackson2MessageConverter();
|
this.converter = new MappingJackson2MessageConverter();
|
||||||
|
|
||||||
|
|
@ -95,7 +94,7 @@ public class UserRegistryMessageHandlerTests {
|
||||||
@Test
|
@Test
|
||||||
public void brokerUnavailableEvent() throws Exception {
|
public void brokerUnavailableEvent() throws Exception {
|
||||||
|
|
||||||
ScheduledFuture future = Mockito.mock(ScheduledFuture.class);
|
ScheduledFuture future = mock(ScheduledFuture.class);
|
||||||
given(this.taskScheduler.scheduleWithFixedDelay(any(Runnable.class), any(Long.class))).willReturn(future);
|
given(this.taskScheduler.scheduleWithFixedDelay(any(Runnable.class), any(Long.class))).willReturn(future);
|
||||||
|
|
||||||
BrokerAvailabilityEvent event = new BrokerAvailabilityEvent(true, this);
|
BrokerAvailabilityEvent event = new BrokerAvailabilityEvent(true, this);
|
||||||
|
|
|
||||||
|
|
@ -18,12 +18,12 @@ package org.springframework.messaging.support;
|
||||||
|
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.ArgumentCaptor;
|
import org.mockito.ArgumentCaptor;
|
||||||
import org.mockito.Captor;
|
import org.mockito.Captor;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.MockitoAnnotations;
|
import org.mockito.junit.MockitoJUnitRunner;
|
||||||
|
|
||||||
import org.springframework.core.task.TaskExecutor;
|
import org.springframework.core.task.TaskExecutor;
|
||||||
import org.springframework.messaging.Message;
|
import org.springframework.messaging.Message;
|
||||||
|
|
@ -46,6 +46,7 @@ import static org.mockito.Mockito.verifyZeroInteractions;
|
||||||
*
|
*
|
||||||
* @author Phillip Webb
|
* @author Phillip Webb
|
||||||
*/
|
*/
|
||||||
|
@RunWith(MockitoJUnitRunner.class)
|
||||||
public class ExecutorSubscribableChannelTests {
|
public class ExecutorSubscribableChannelTests {
|
||||||
|
|
||||||
private ExecutorSubscribableChannel channel = new ExecutorSubscribableChannel();
|
private ExecutorSubscribableChannel channel = new ExecutorSubscribableChannel();
|
||||||
|
|
@ -53,18 +54,12 @@ public class ExecutorSubscribableChannelTests {
|
||||||
@Mock
|
@Mock
|
||||||
private MessageHandler handler;
|
private MessageHandler handler;
|
||||||
|
|
||||||
private final Object payload = new Object();
|
|
||||||
|
|
||||||
private final Message<Object> message = MessageBuilder.withPayload(this.payload).build();
|
|
||||||
|
|
||||||
@Captor
|
@Captor
|
||||||
private ArgumentCaptor<Runnable> runnableCaptor;
|
private ArgumentCaptor<Runnable> runnableCaptor;
|
||||||
|
|
||||||
|
private final Object payload = new Object();
|
||||||
|
|
||||||
@Before
|
private final Message<Object> message = MessageBuilder.withPayload(this.payload).build();
|
||||||
public void setup() {
|
|
||||||
MockitoAnnotations.initMocks(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
||||||
|
|
@ -24,11 +24,11 @@ import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.ArgumentCaptor;
|
import org.mockito.ArgumentCaptor;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.MockitoAnnotations;
|
import org.mockito.junit.MockitoJUnitRunner;
|
||||||
import reactor.core.publisher.Flux;
|
import reactor.core.publisher.Flux;
|
||||||
import reactor.core.publisher.Mono;
|
import reactor.core.publisher.Mono;
|
||||||
import reactor.test.StepVerifier;
|
import reactor.test.StepVerifier;
|
||||||
|
|
@ -57,6 +57,7 @@ import static org.springframework.http.MediaType.TEXT_XML;
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
* @author Brian Clozel
|
* @author Brian Clozel
|
||||||
*/
|
*/
|
||||||
|
@RunWith(MockitoJUnitRunner.class)
|
||||||
public class EncoderHttpMessageWriterTests {
|
public class EncoderHttpMessageWriterTests {
|
||||||
|
|
||||||
private static final Map<String, Object> NO_HINTS = Collections.emptyMap();
|
private static final Map<String, Object> NO_HINTS = Collections.emptyMap();
|
||||||
|
|
@ -67,17 +68,9 @@ public class EncoderHttpMessageWriterTests {
|
||||||
@Mock
|
@Mock
|
||||||
private HttpMessageEncoder<String> encoder;
|
private HttpMessageEncoder<String> encoder;
|
||||||
|
|
||||||
private ArgumentCaptor<MediaType> mediaTypeCaptor;
|
private final ArgumentCaptor<MediaType> mediaTypeCaptor = ArgumentCaptor.forClass(MediaType.class);
|
||||||
|
|
||||||
private MockServerHttpResponse response;
|
private final MockServerHttpResponse response = new MockServerHttpResponse();
|
||||||
|
|
||||||
|
|
||||||
@Before
|
|
||||||
public void setUp() throws Exception {
|
|
||||||
MockitoAnnotations.initMocks(this);
|
|
||||||
this.mediaTypeCaptor = ArgumentCaptor.forClass(MediaType.class);
|
|
||||||
this.response = new MockServerHttpResponse();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
@ -116,9 +109,6 @@ public class EncoderHttpMessageWriterTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void testDefaultMediaType(MediaType negotiatedMediaType) {
|
private void testDefaultMediaType(MediaType negotiatedMediaType) {
|
||||||
|
|
||||||
this.mediaTypeCaptor = ArgumentCaptor.forClass(MediaType.class);
|
|
||||||
|
|
||||||
MimeType defaultContentType = MimeTypeUtils.TEXT_XML;
|
MimeType defaultContentType = MimeTypeUtils.TEXT_XML;
|
||||||
configureEncoder(defaultContentType);
|
configureEncoder(defaultContentType);
|
||||||
HttpMessageWriter<String> writer = new EncoderHttpMessageWriter<>(this.encoder);
|
HttpMessageWriter<String> writer = new EncoderHttpMessageWriter<>(this.encoder);
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.springframework.web.server.session;
|
package org.springframework.web.server.session;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
@ -49,10 +50,6 @@ import static org.mockito.Mockito.verify;
|
||||||
@RunWith(MockitoJUnitRunner.class)
|
@RunWith(MockitoJUnitRunner.class)
|
||||||
public class DefaultWebSessionManagerTests {
|
public class DefaultWebSessionManagerTests {
|
||||||
|
|
||||||
private DefaultWebSessionManager sessionManager;
|
|
||||||
|
|
||||||
private ServerWebExchange exchange;
|
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private WebSessionIdResolver sessionIdResolver;
|
private WebSessionIdResolver sessionIdResolver;
|
||||||
|
|
||||||
|
|
@ -65,10 +62,13 @@ public class DefaultWebSessionManagerTests {
|
||||||
@Mock
|
@Mock
|
||||||
private WebSession updateSession;
|
private WebSession updateSession;
|
||||||
|
|
||||||
|
private DefaultWebSessionManager sessionManager;
|
||||||
|
|
||||||
|
private ServerWebExchange exchange;
|
||||||
|
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
|
|
||||||
given(this.createSession.save()).willReturn(Mono.empty());
|
given(this.createSession.save()).willReturn(Mono.empty());
|
||||||
given(this.createSession.getId()).willReturn("create-session-id");
|
given(this.createSession.getId()).willReturn("create-session-id");
|
||||||
given(this.updateSession.getId()).willReturn("update-session-id");
|
given(this.updateSession.getId()).willReturn("update-session-id");
|
||||||
|
|
|
||||||
|
|
@ -21,10 +21,11 @@ import java.util.List;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.ArgumentCaptor;
|
import org.mockito.ArgumentCaptor;
|
||||||
import org.mockito.Captor;
|
import org.mockito.Captor;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.MockitoAnnotations;
|
import org.mockito.junit.MockitoJUnitRunner;
|
||||||
|
|
||||||
import org.springframework.context.support.StaticApplicationContext;
|
import org.springframework.context.support.StaticApplicationContext;
|
||||||
import org.springframework.core.ReactiveAdapterRegistry;
|
import org.springframework.core.ReactiveAdapterRegistry;
|
||||||
|
|
@ -48,10 +49,9 @@ import static org.mockito.Mockito.verify;
|
||||||
*
|
*
|
||||||
* @author Brian Clozel
|
* @author Brian Clozel
|
||||||
*/
|
*/
|
||||||
|
@RunWith(MockitoJUnitRunner.class)
|
||||||
public class DelegatingWebFluxConfigurationTests {
|
public class DelegatingWebFluxConfigurationTests {
|
||||||
|
|
||||||
private DelegatingWebFluxConfiguration delegatingConfig;
|
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private WebFluxConfigurer webFluxConfigurer;
|
private WebFluxConfigurer webFluxConfigurer;
|
||||||
|
|
||||||
|
|
@ -64,10 +64,11 @@ public class DelegatingWebFluxConfigurationTests {
|
||||||
@Captor
|
@Captor
|
||||||
private ArgumentCaptor<FormatterRegistry> formatterRegistry;
|
private ArgumentCaptor<FormatterRegistry> formatterRegistry;
|
||||||
|
|
||||||
|
private DelegatingWebFluxConfiguration delegatingConfig;
|
||||||
|
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setup() {
|
public void setup() {
|
||||||
MockitoAnnotations.initMocks(this);
|
|
||||||
delegatingConfig = new DelegatingWebFluxConfiguration();
|
delegatingConfig = new DelegatingWebFluxConfiguration();
|
||||||
delegatingConfig.setApplicationContext(new StaticApplicationContext());
|
delegatingConfig.setApplicationContext(new StaticApplicationContext());
|
||||||
given(webFluxConfigurer.getValidator()).willReturn(null);
|
given(webFluxConfigurer.getValidator()).willReturn(null);
|
||||||
|
|
|
||||||
|
|
@ -23,10 +23,11 @@ import java.util.Map;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.ArgumentCaptor;
|
import org.mockito.ArgumentCaptor;
|
||||||
import org.mockito.Captor;
|
import org.mockito.Captor;
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mock;
|
||||||
import org.mockito.MockitoAnnotations;
|
import org.mockito.junit.MockitoJUnitRunner;
|
||||||
import reactor.core.publisher.Mono;
|
import reactor.core.publisher.Mono;
|
||||||
import reactor.test.StepVerifier;
|
import reactor.test.StepVerifier;
|
||||||
|
|
||||||
|
|
@ -39,6 +40,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException
|
||||||
import static org.mockito.ArgumentMatchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.BDDMockito.given;
|
import static org.mockito.BDDMockito.given;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||||
import static org.mockito.Mockito.verifyZeroInteractions;
|
import static org.mockito.Mockito.verifyZeroInteractions;
|
||||||
|
|
||||||
|
|
@ -48,20 +50,20 @@ import static org.mockito.Mockito.verifyZeroInteractions;
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
* @author Brian Clozel
|
* @author Brian Clozel
|
||||||
*/
|
*/
|
||||||
|
@RunWith(MockitoJUnitRunner.class)
|
||||||
public class DefaultWebClientTests {
|
public class DefaultWebClientTests {
|
||||||
|
|
||||||
private WebClient.Builder builder;
|
@Mock
|
||||||
|
|
||||||
private ExchangeFunction exchangeFunction;
|
private ExchangeFunction exchangeFunction;
|
||||||
|
|
||||||
@Captor
|
@Captor
|
||||||
private ArgumentCaptor<ClientRequest> captor;
|
private ArgumentCaptor<ClientRequest> captor;
|
||||||
|
|
||||||
|
private WebClient.Builder builder;
|
||||||
|
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setup() {
|
public void setup() {
|
||||||
MockitoAnnotations.initMocks(this);
|
|
||||||
this.exchangeFunction = mock(ExchangeFunction.class);
|
|
||||||
ClientResponse mockResponse = mock(ClientResponse.class);
|
ClientResponse mockResponse = mock(ClientResponse.class);
|
||||||
given(this.exchangeFunction.exchange(this.captor.capture())).willReturn(Mono.just(mockResponse));
|
given(this.exchangeFunction.exchange(this.captor.capture())).willReturn(Mono.just(mockResponse));
|
||||||
this.builder = WebClient.builder().baseUrl("/base").exchangeFunction(this.exchangeFunction);
|
this.builder = WebClient.builder().baseUrl("/base").exchangeFunction(this.exchangeFunction);
|
||||||
|
|
@ -309,7 +311,7 @@ public class DefaultWebClientTests {
|
||||||
|
|
||||||
private ClientRequest verifyAndGetRequest() {
|
private ClientRequest verifyAndGetRequest() {
|
||||||
ClientRequest request = this.captor.getValue();
|
ClientRequest request = this.captor.getValue();
|
||||||
Mockito.verify(this.exchangeFunction).exchange(request);
|
verify(this.exchangeFunction).exchange(request);
|
||||||
verifyNoMoreInteractions(this.exchangeFunction);
|
verifyNoMoreInteractions(this.exchangeFunction);
|
||||||
return request;
|
return request;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,12 +20,12 @@ import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.ArgumentCaptor;
|
import org.mockito.ArgumentCaptor;
|
||||||
import org.mockito.Captor;
|
import org.mockito.Captor;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.MockitoAnnotations;
|
import org.mockito.junit.MockitoJUnitRunner;
|
||||||
|
|
||||||
import org.springframework.format.support.FormattingConversionService;
|
import org.springframework.format.support.FormattingConversionService;
|
||||||
import org.springframework.http.converter.HttpMessageConverter;
|
import org.springframework.http.converter.HttpMessageConverter;
|
||||||
|
|
@ -55,10 +55,9 @@ import static org.mockito.Mockito.verify;
|
||||||
*
|
*
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
*/
|
*/
|
||||||
|
@RunWith(MockitoJUnitRunner.class)
|
||||||
public class DelegatingWebMvcConfigurationTests {
|
public class DelegatingWebMvcConfigurationTests {
|
||||||
|
|
||||||
private DelegatingWebMvcConfiguration delegatingConfig;
|
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private WebMvcConfigurer webMvcConfigurer;
|
private WebMvcConfigurer webMvcConfigurer;
|
||||||
|
|
||||||
|
|
@ -83,12 +82,7 @@ public class DelegatingWebMvcConfigurationTests {
|
||||||
@Captor
|
@Captor
|
||||||
private ArgumentCaptor<List<HandlerExceptionResolver>> exceptionResolvers;
|
private ArgumentCaptor<List<HandlerExceptionResolver>> exceptionResolvers;
|
||||||
|
|
||||||
|
private final DelegatingWebMvcConfiguration delegatingConfig = new DelegatingWebMvcConfiguration();
|
||||||
@Before
|
|
||||||
public void setUp() {
|
|
||||||
MockitoAnnotations.initMocks(this);
|
|
||||||
delegatingConfig = new DelegatingWebMvcConfiguration();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
@ -134,7 +128,6 @@ public class DelegatingWebMvcConfigurationTests {
|
||||||
converters.add(0, customConverter);
|
converters.add(0, customConverter);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
delegatingConfig = new DelegatingWebMvcConfiguration();
|
|
||||||
delegatingConfig.setConfigurers(configurers);
|
delegatingConfig.setConfigurers(configurers);
|
||||||
|
|
||||||
RequestMappingHandlerAdapter adapter = delegatingConfig.requestMappingHandlerAdapter(
|
RequestMappingHandlerAdapter adapter = delegatingConfig.requestMappingHandlerAdapter(
|
||||||
|
|
|
||||||
|
|
@ -21,9 +21,7 @@ import javax.servlet.ServletException;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.mockito.Mockito;
|
|
||||||
|
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.mock.web.test.MockHttpServletRequest;
|
import org.springframework.mock.web.test.MockHttpServletRequest;
|
||||||
|
|
@ -34,34 +32,27 @@ import org.springframework.web.servlet.HandlerInterceptor;
|
||||||
import org.springframework.web.servlet.support.WebContentGenerator;
|
import org.springframework.web.servlet.support.WebContentGenerator;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit tests for
|
* Unit tests for {@link org.springframework.web.servlet.HandlerMapping}.
|
||||||
* {@link org.springframework.web.servlet.handler.HandlerMappingTests}.
|
|
||||||
* @author Brian Clozel
|
* @author Brian Clozel
|
||||||
*/
|
*/
|
||||||
public class HandlerMappingTests {
|
public class HandlerMappingTests {
|
||||||
|
|
||||||
private MockHttpServletRequest request;
|
private AbstractHandlerMapping handlerMapping = new TestHandlerMapping();
|
||||||
private AbstractHandlerMapping handlerMapping;
|
private StaticWebApplicationContext context = new StaticWebApplicationContext();
|
||||||
private StaticWebApplicationContext context;
|
private MockHttpServletRequest request = new MockHttpServletRequest();
|
||||||
|
|
||||||
@Before
|
|
||||||
public void setup() {
|
|
||||||
this.context = new StaticWebApplicationContext();
|
|
||||||
this.handlerMapping = new TestHandlerMapping();
|
|
||||||
this.request = new MockHttpServletRequest();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void orderedInterceptors() throws Exception {
|
public void orderedInterceptors() throws Exception {
|
||||||
HandlerInterceptor i1 = Mockito.mock(HandlerInterceptor.class);
|
HandlerInterceptor i1 = mock(HandlerInterceptor.class);
|
||||||
MappedInterceptor mappedInterceptor1 = new MappedInterceptor(new String[]{"/**"}, i1);
|
MappedInterceptor mappedInterceptor1 = new MappedInterceptor(new String[]{"/**"}, i1);
|
||||||
HandlerInterceptor i2 = Mockito.mock(HandlerInterceptor.class);
|
HandlerInterceptor i2 = mock(HandlerInterceptor.class);
|
||||||
HandlerInterceptor i3 = Mockito.mock(HandlerInterceptor.class);
|
HandlerInterceptor i3 = mock(HandlerInterceptor.class);
|
||||||
MappedInterceptor mappedInterceptor3 = new MappedInterceptor(new String[]{"/**"}, i3);
|
MappedInterceptor mappedInterceptor3 = new MappedInterceptor(new String[]{"/**"}, i3);
|
||||||
HandlerInterceptor i4 = Mockito.mock(HandlerInterceptor.class);
|
HandlerInterceptor i4 = mock(HandlerInterceptor.class);
|
||||||
|
|
||||||
this.handlerMapping.setInterceptors(mappedInterceptor1, i2, mappedInterceptor3, i4);
|
this.handlerMapping.setInterceptors(mappedInterceptor1, i2, mappedInterceptor3, i4);
|
||||||
this.handlerMapping.setApplicationContext(this.context);
|
this.handlerMapping.setApplicationContext(this.context);
|
||||||
|
|
|
||||||
|
|
@ -18,11 +18,11 @@ package org.springframework.web.servlet.mvc.method.annotation;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.ArgumentCaptor;
|
import org.mockito.ArgumentCaptor;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.MockitoAnnotations;
|
import org.mockito.junit.MockitoJUnitRunner;
|
||||||
|
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
|
|
||||||
|
|
@ -42,19 +42,13 @@ import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
* @author Tomasz Nurkiewicz
|
* @author Tomasz Nurkiewicz
|
||||||
*/
|
*/
|
||||||
|
@RunWith(MockitoJUnitRunner.class)
|
||||||
public class ResponseBodyEmitterTests {
|
public class ResponseBodyEmitterTests {
|
||||||
|
|
||||||
private ResponseBodyEmitter emitter;
|
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private ResponseBodyEmitter.Handler handler;
|
private ResponseBodyEmitter.Handler handler;
|
||||||
|
|
||||||
|
private final ResponseBodyEmitter emitter = new ResponseBodyEmitter();
|
||||||
@Before
|
|
||||||
public void setup() {
|
|
||||||
MockitoAnnotations.initMocks(this);
|
|
||||||
this.emitter = new ResponseBodyEmitter();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
||||||
|
|
@ -22,9 +22,7 @@ import java.util.EnumSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import javax.servlet.ServletException;
|
import javax.servlet.ServletException;
|
||||||
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.mockito.Mockito;
|
|
||||||
|
|
||||||
import org.springframework.beans.ConversionNotSupportedException;
|
import org.springframework.beans.ConversionNotSupportedException;
|
||||||
import org.springframework.beans.TypeMismatchException;
|
import org.springframework.beans.TypeMismatchException;
|
||||||
|
|
@ -62,6 +60,7 @@ import org.springframework.web.servlet.NoHandlerFoundException;
|
||||||
import org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver;
|
import org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test fixture for {@link ResponseEntityExceptionHandler}.
|
* Test fixture for {@link ResponseEntityExceptionHandler}.
|
||||||
|
|
@ -70,26 +69,15 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
*/
|
*/
|
||||||
public class ResponseEntityExceptionHandlerTests {
|
public class ResponseEntityExceptionHandlerTests {
|
||||||
|
|
||||||
private ResponseEntityExceptionHandler exceptionHandlerSupport;
|
private ResponseEntityExceptionHandler exceptionHandlerSupport = new ApplicationExceptionHandler();
|
||||||
|
|
||||||
private DefaultHandlerExceptionResolver defaultExceptionResolver;
|
private DefaultHandlerExceptionResolver defaultExceptionResolver = new DefaultHandlerExceptionResolver();
|
||||||
|
|
||||||
private WebRequest request;
|
private MockHttpServletRequest servletRequest = new MockHttpServletRequest("GET", "/");
|
||||||
|
|
||||||
private MockHttpServletRequest servletRequest;
|
private MockHttpServletResponse servletResponse = new MockHttpServletResponse();
|
||||||
|
|
||||||
private MockHttpServletResponse servletResponse;
|
private WebRequest request = new ServletWebRequest(this.servletRequest, this.servletResponse);
|
||||||
|
|
||||||
|
|
||||||
@Before
|
|
||||||
public void setup() {
|
|
||||||
this.servletRequest = new MockHttpServletRequest("GET", "/");
|
|
||||||
this.servletResponse = new MockHttpServletResponse();
|
|
||||||
this.request = new ServletWebRequest(this.servletRequest, this.servletResponse);
|
|
||||||
|
|
||||||
this.exceptionHandlerSupport = new ApplicationExceptionHandler();
|
|
||||||
this.defaultExceptionResolver = new DefaultHandlerExceptionResolver();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
@ -179,7 +167,7 @@ public class ResponseEntityExceptionHandlerTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void methodArgumentNotValid() {
|
public void methodArgumentNotValid() {
|
||||||
Exception ex = Mockito.mock(MethodArgumentNotValidException.class);
|
Exception ex = mock(MethodArgumentNotValidException.class);
|
||||||
testException(ex);
|
testException(ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,9 +19,7 @@ package org.springframework.web.socket.config.annotation;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.mockito.Mockito;
|
|
||||||
|
|
||||||
import org.springframework.scheduling.TaskScheduler;
|
import org.springframework.scheduling.TaskScheduler;
|
||||||
import org.springframework.web.socket.WebSocketHandler;
|
import org.springframework.web.socket.WebSocketHandler;
|
||||||
|
|
@ -37,26 +35,20 @@ import org.springframework.web.socket.sockjs.transport.handler.DefaultSockJsServ
|
||||||
import org.springframework.web.socket.sockjs.transport.handler.WebSocketTransportHandler;
|
import org.springframework.web.socket.sockjs.transport.handler.WebSocketTransportHandler;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test fixture for
|
* Test fixture for {@link AbstractWebSocketHandlerRegistration}.
|
||||||
* {@link org.springframework.web.socket.config.annotation.AbstractWebSocketHandlerRegistration}.
|
|
||||||
*
|
*
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
*/
|
*/
|
||||||
public class WebSocketHandlerRegistrationTests {
|
public class WebSocketHandlerRegistrationTests {
|
||||||
|
|
||||||
private TestWebSocketHandlerRegistration registration;
|
private TestWebSocketHandlerRegistration registration = new TestWebSocketHandlerRegistration();
|
||||||
|
|
||||||
private TaskScheduler taskScheduler;
|
private TaskScheduler taskScheduler = mock(TaskScheduler.class);
|
||||||
|
|
||||||
|
|
||||||
@Before
|
|
||||||
public void setup() {
|
|
||||||
this.taskScheduler = Mockito.mock(TaskScheduler.class);
|
|
||||||
this.registration = new TestWebSocketHandlerRegistration();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void minimal() {
|
public void minimal() {
|
||||||
WebSocketHandler handler = new TextWebSocketHandler();
|
WebSocketHandler handler = new TextWebSocketHandler();
|
||||||
|
|
|
||||||
|
|
@ -21,8 +21,9 @@ import java.util.Map;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.MockitoAnnotations;
|
import org.mockito.junit.MockitoJUnitRunner;
|
||||||
|
|
||||||
import org.springframework.beans.DirectFieldAccessor;
|
import org.springframework.beans.DirectFieldAccessor;
|
||||||
import org.springframework.messaging.MessageChannel;
|
import org.springframework.messaging.MessageChannel;
|
||||||
|
|
@ -46,12 +47,9 @@ import static org.mockito.Mockito.verify;
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
* @author Andy Wilkinson
|
* @author Andy Wilkinson
|
||||||
*/
|
*/
|
||||||
|
@RunWith(MockitoJUnitRunner.class)
|
||||||
public class SubProtocolWebSocketHandlerTests {
|
public class SubProtocolWebSocketHandlerTests {
|
||||||
|
|
||||||
private SubProtocolWebSocketHandler webSocketHandler;
|
|
||||||
|
|
||||||
private TestWebSocketSession session;
|
|
||||||
|
|
||||||
@Mock SubProtocolHandler stompHandler;
|
@Mock SubProtocolHandler stompHandler;
|
||||||
|
|
||||||
@Mock SubProtocolHandler mqttHandler;
|
@Mock SubProtocolHandler mqttHandler;
|
||||||
|
|
@ -63,10 +61,13 @@ public class SubProtocolWebSocketHandlerTests {
|
||||||
@Mock
|
@Mock
|
||||||
SubscribableChannel outClientChannel;
|
SubscribableChannel outClientChannel;
|
||||||
|
|
||||||
|
private SubProtocolWebSocketHandler webSocketHandler;
|
||||||
|
|
||||||
|
private TestWebSocketSession session;
|
||||||
|
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setup() {
|
public void setup() {
|
||||||
MockitoAnnotations.initMocks(this);
|
|
||||||
this.webSocketHandler = new SubProtocolWebSocketHandler(this.inClientChannel, this.outClientChannel);
|
this.webSocketHandler = new SubProtocolWebSocketHandler(this.inClientChannel, this.outClientChannel);
|
||||||
given(stompHandler.getSupportedProtocols()).willReturn(Arrays.asList("v10.stomp", "v11.stomp", "v12.stomp"));
|
given(stompHandler.getSupportedProtocols()).willReturn(Arrays.asList("v10.stomp", "v11.stomp", "v12.stomp"));
|
||||||
given(mqttHandler.getSupportedProtocols()).willReturn(Arrays.asList("MQTT"));
|
given(mqttHandler.getSupportedProtocols()).willReturn(Arrays.asList("MQTT"));
|
||||||
|
|
|
||||||
|
|
@ -22,9 +22,10 @@ import java.util.concurrent.ScheduledFuture;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.ArgumentCaptor;
|
import org.mockito.ArgumentCaptor;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.MockitoAnnotations;
|
import org.mockito.junit.MockitoJUnitRunner;
|
||||||
|
|
||||||
import org.springframework.messaging.Message;
|
import org.springframework.messaging.Message;
|
||||||
import org.springframework.messaging.simp.stomp.ConnectionHandlingStompSession;
|
import org.springframework.messaging.simp.stomp.ConnectionHandlingStompSession;
|
||||||
|
|
@ -63,6 +64,7 @@ import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||||
*
|
*
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
*/
|
*/
|
||||||
|
@RunWith(MockitoJUnitRunner.class)
|
||||||
public class WebSocketStompClientTests {
|
public class WebSocketStompClientTests {
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
|
|
@ -74,7 +76,6 @@ public class WebSocketStompClientTests {
|
||||||
@Mock
|
@Mock
|
||||||
private WebSocketSession webSocketSession;
|
private WebSocketSession webSocketSession;
|
||||||
|
|
||||||
|
|
||||||
private TestWebSocketStompClient stompClient;
|
private TestWebSocketStompClient stompClient;
|
||||||
|
|
||||||
private ArgumentCaptor<WebSocketHandler> webSocketHandlerCaptor;
|
private ArgumentCaptor<WebSocketHandler> webSocketHandlerCaptor;
|
||||||
|
|
@ -84,8 +85,6 @@ public class WebSocketStompClientTests {
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
MockitoAnnotations.initMocks(this);
|
|
||||||
|
|
||||||
WebSocketClient webSocketClient = mock(WebSocketClient.class);
|
WebSocketClient webSocketClient = mock(WebSocketClient.class);
|
||||||
this.stompClient = new TestWebSocketStompClient(webSocketClient);
|
this.stompClient = new TestWebSocketStompClient(webSocketClient);
|
||||||
this.stompClient.setTaskScheduler(this.taskScheduler);
|
this.stompClient.setTaskScheduler(this.taskScheduler);
|
||||||
|
|
|
||||||
|
|
@ -21,10 +21,7 @@ import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.mockito.Mock;
|
|
||||||
import org.mockito.MockitoAnnotations;
|
|
||||||
|
|
||||||
import org.springframework.web.socket.AbstractHttpRequestTests;
|
import org.springframework.web.socket.AbstractHttpRequestTests;
|
||||||
import org.springframework.web.socket.SubProtocolCapable;
|
import org.springframework.web.socket.SubProtocolCapable;
|
||||||
|
|
@ -35,6 +32,7 @@ import org.springframework.web.socket.handler.TextWebSocketHandler;
|
||||||
import org.springframework.web.socket.server.support.DefaultHandshakeHandler;
|
import org.springframework.web.socket.server.support.DefaultHandshakeHandler;
|
||||||
|
|
||||||
import static org.mockito.BDDMockito.given;
|
import static org.mockito.BDDMockito.given;
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -44,19 +42,9 @@ import static org.mockito.Mockito.verify;
|
||||||
*/
|
*/
|
||||||
public class DefaultHandshakeHandlerTests extends AbstractHttpRequestTests {
|
public class DefaultHandshakeHandlerTests extends AbstractHttpRequestTests {
|
||||||
|
|
||||||
private DefaultHandshakeHandler handshakeHandler;
|
private RequestUpgradeStrategy upgradeStrategy = mock(RequestUpgradeStrategy.class);
|
||||||
|
|
||||||
@Mock
|
private DefaultHandshakeHandler handshakeHandler = new DefaultHandshakeHandler(this.upgradeStrategy);
|
||||||
private RequestUpgradeStrategy upgradeStrategy;
|
|
||||||
|
|
||||||
|
|
||||||
@Before
|
|
||||||
public void setup() {
|
|
||||||
super.setup();
|
|
||||||
|
|
||||||
MockitoAnnotations.initMocks(this);
|
|
||||||
this.handshakeHandler = new DefaultHandshakeHandler(this.upgradeStrategy);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
||||||
|
|
@ -22,13 +22,13 @@ import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.mockito.Mockito;
|
|
||||||
|
|
||||||
import org.springframework.mock.web.test.MockHttpSession;
|
import org.springframework.mock.web.test.MockHttpSession;
|
||||||
import org.springframework.web.socket.AbstractHttpRequestTests;
|
import org.springframework.web.socket.AbstractHttpRequestTests;
|
||||||
import org.springframework.web.socket.WebSocketHandler;
|
import org.springframework.web.socket.WebSocketHandler;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test fixture for {@link HttpSessionHandshakeInterceptor}.
|
* Test fixture for {@link HttpSessionHandshakeInterceptor}.
|
||||||
|
|
@ -37,12 +37,12 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
*/
|
*/
|
||||||
public class HttpSessionHandshakeInterceptorTests extends AbstractHttpRequestTests {
|
public class HttpSessionHandshakeInterceptorTests extends AbstractHttpRequestTests {
|
||||||
|
|
||||||
|
private final Map<String, Object> attributes = new HashMap<>();
|
||||||
|
private final WebSocketHandler wsHandler = mock(WebSocketHandler.class);
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void defaultConstructor() throws Exception {
|
public void defaultConstructor() throws Exception {
|
||||||
Map<String, Object> attributes = new HashMap<>();
|
|
||||||
WebSocketHandler wsHandler = Mockito.mock(WebSocketHandler.class);
|
|
||||||
|
|
||||||
this.servletRequest.setSession(new MockHttpSession(null, "123"));
|
this.servletRequest.setSession(new MockHttpSession(null, "123"));
|
||||||
this.servletRequest.getSession().setAttribute("foo", "bar");
|
this.servletRequest.getSession().setAttribute("foo", "bar");
|
||||||
this.servletRequest.getSession().setAttribute("bar", "baz");
|
this.servletRequest.getSession().setAttribute("bar", "baz");
|
||||||
|
|
@ -58,9 +58,6 @@ public class HttpSessionHandshakeInterceptorTests extends AbstractHttpRequestTes
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void constructorWithAttributeNames() throws Exception {
|
public void constructorWithAttributeNames() throws Exception {
|
||||||
Map<String, Object> attributes = new HashMap<>();
|
|
||||||
WebSocketHandler wsHandler = Mockito.mock(WebSocketHandler.class);
|
|
||||||
|
|
||||||
this.servletRequest.setSession(new MockHttpSession(null, "123"));
|
this.servletRequest.setSession(new MockHttpSession(null, "123"));
|
||||||
this.servletRequest.getSession().setAttribute("foo", "bar");
|
this.servletRequest.getSession().setAttribute("foo", "bar");
|
||||||
this.servletRequest.getSession().setAttribute("bar", "baz");
|
this.servletRequest.getSession().setAttribute("bar", "baz");
|
||||||
|
|
@ -76,9 +73,6 @@ public class HttpSessionHandshakeInterceptorTests extends AbstractHttpRequestTes
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void doNotCopyHttpSessionId() throws Exception {
|
public void doNotCopyHttpSessionId() throws Exception {
|
||||||
Map<String, Object> attributes = new HashMap<>();
|
|
||||||
WebSocketHandler wsHandler = Mockito.mock(WebSocketHandler.class);
|
|
||||||
|
|
||||||
this.servletRequest.setSession(new MockHttpSession(null, "123"));
|
this.servletRequest.setSession(new MockHttpSession(null, "123"));
|
||||||
this.servletRequest.getSession().setAttribute("foo", "bar");
|
this.servletRequest.getSession().setAttribute("foo", "bar");
|
||||||
|
|
||||||
|
|
@ -93,9 +87,6 @@ public class HttpSessionHandshakeInterceptorTests extends AbstractHttpRequestTes
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void doNotCopyAttributes() throws Exception {
|
public void doNotCopyAttributes() throws Exception {
|
||||||
Map<String, Object> attributes = new HashMap<>();
|
|
||||||
WebSocketHandler wsHandler = Mockito.mock(WebSocketHandler.class);
|
|
||||||
|
|
||||||
this.servletRequest.setSession(new MockHttpSession(null, "123"));
|
this.servletRequest.setSession(new MockHttpSession(null, "123"));
|
||||||
this.servletRequest.getSession().setAttribute("foo", "bar");
|
this.servletRequest.getSession().setAttribute("foo", "bar");
|
||||||
|
|
||||||
|
|
@ -109,9 +100,6 @@ public class HttpSessionHandshakeInterceptorTests extends AbstractHttpRequestTes
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void doNotCauseSessionCreation() throws Exception {
|
public void doNotCauseSessionCreation() throws Exception {
|
||||||
Map<String, Object> attributes = new HashMap<>();
|
|
||||||
WebSocketHandler wsHandler = Mockito.mock(WebSocketHandler.class);
|
|
||||||
|
|
||||||
HttpSessionHandshakeInterceptor interceptor = new HttpSessionHandshakeInterceptor();
|
HttpSessionHandshakeInterceptor interceptor = new HttpSessionHandshakeInterceptor();
|
||||||
interceptor.beforeHandshake(this.request, this.response, wsHandler, attributes);
|
interceptor.beforeHandshake(this.request, this.response, wsHandler, attributes);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,6 @@ import java.util.Set;
|
||||||
import java.util.concurrent.ConcurrentSkipListSet;
|
import java.util.concurrent.ConcurrentSkipListSet;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.mockito.Mockito;
|
|
||||||
|
|
||||||
import org.springframework.http.HttpHeaders;
|
import org.springframework.http.HttpHeaders;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
|
|
@ -34,6 +33,7 @@ import org.springframework.web.socket.WebSocketHandler;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test fixture for {@link OriginHandshakeInterceptor}.
|
* Test fixture for {@link OriginHandshakeInterceptor}.
|
||||||
|
|
@ -42,16 +42,17 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException
|
||||||
*/
|
*/
|
||||||
public class OriginHandshakeInterceptorTests extends AbstractHttpRequestTests {
|
public class OriginHandshakeInterceptorTests extends AbstractHttpRequestTests {
|
||||||
|
|
||||||
|
private final Map<String, Object> attributes = new HashMap<>();
|
||||||
|
private final WebSocketHandler wsHandler = mock(WebSocketHandler.class);
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void invalidInput() {
|
public void invalidInput() {
|
||||||
assertThatIllegalArgumentException().isThrownBy(() ->
|
assertThatIllegalArgumentException().isThrownBy(() -> new OriginHandshakeInterceptor(null));
|
||||||
new OriginHandshakeInterceptor(null));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void originValueMatch() throws Exception {
|
public void originValueMatch() throws Exception {
|
||||||
Map<String, Object> attributes = new HashMap<>();
|
|
||||||
WebSocketHandler wsHandler = Mockito.mock(WebSocketHandler.class);
|
|
||||||
this.servletRequest.addHeader(HttpHeaders.ORIGIN, "https://mydomain1.com");
|
this.servletRequest.addHeader(HttpHeaders.ORIGIN, "https://mydomain1.com");
|
||||||
List<String> allowed = Collections.singletonList("https://mydomain1.com");
|
List<String> allowed = Collections.singletonList("https://mydomain1.com");
|
||||||
OriginHandshakeInterceptor interceptor = new OriginHandshakeInterceptor(allowed);
|
OriginHandshakeInterceptor interceptor = new OriginHandshakeInterceptor(allowed);
|
||||||
|
|
@ -61,8 +62,6 @@ public class OriginHandshakeInterceptorTests extends AbstractHttpRequestTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void originValueNoMatch() throws Exception {
|
public void originValueNoMatch() throws Exception {
|
||||||
Map<String, Object> attributes = new HashMap<>();
|
|
||||||
WebSocketHandler wsHandler = Mockito.mock(WebSocketHandler.class);
|
|
||||||
this.servletRequest.addHeader(HttpHeaders.ORIGIN, "https://mydomain1.com");
|
this.servletRequest.addHeader(HttpHeaders.ORIGIN, "https://mydomain1.com");
|
||||||
List<String> allowed = Collections.singletonList("https://mydomain2.com");
|
List<String> allowed = Collections.singletonList("https://mydomain2.com");
|
||||||
OriginHandshakeInterceptor interceptor = new OriginHandshakeInterceptor(allowed);
|
OriginHandshakeInterceptor interceptor = new OriginHandshakeInterceptor(allowed);
|
||||||
|
|
@ -72,8 +71,6 @@ public class OriginHandshakeInterceptorTests extends AbstractHttpRequestTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void originListMatch() throws Exception {
|
public void originListMatch() throws Exception {
|
||||||
Map<String, Object> attributes = new HashMap<>();
|
|
||||||
WebSocketHandler wsHandler = Mockito.mock(WebSocketHandler.class);
|
|
||||||
this.servletRequest.addHeader(HttpHeaders.ORIGIN, "https://mydomain2.com");
|
this.servletRequest.addHeader(HttpHeaders.ORIGIN, "https://mydomain2.com");
|
||||||
List<String> allowed = Arrays.asList("https://mydomain1.com", "https://mydomain2.com", "http://mydomain3.com");
|
List<String> allowed = Arrays.asList("https://mydomain1.com", "https://mydomain2.com", "http://mydomain3.com");
|
||||||
OriginHandshakeInterceptor interceptor = new OriginHandshakeInterceptor(allowed);
|
OriginHandshakeInterceptor interceptor = new OriginHandshakeInterceptor(allowed);
|
||||||
|
|
@ -83,8 +80,6 @@ public class OriginHandshakeInterceptorTests extends AbstractHttpRequestTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void originListNoMatch() throws Exception {
|
public void originListNoMatch() throws Exception {
|
||||||
Map<String, Object> attributes = new HashMap<>();
|
|
||||||
WebSocketHandler wsHandler = Mockito.mock(WebSocketHandler.class);
|
|
||||||
this.servletRequest.addHeader(HttpHeaders.ORIGIN, "http://www.mydomain4.com/");
|
this.servletRequest.addHeader(HttpHeaders.ORIGIN, "http://www.mydomain4.com/");
|
||||||
List<String> allowed = Arrays.asList("https://mydomain1.com", "https://mydomain2.com", "http://mydomain3.com");
|
List<String> allowed = Arrays.asList("https://mydomain1.com", "https://mydomain2.com", "http://mydomain3.com");
|
||||||
OriginHandshakeInterceptor interceptor = new OriginHandshakeInterceptor(allowed);
|
OriginHandshakeInterceptor interceptor = new OriginHandshakeInterceptor(allowed);
|
||||||
|
|
@ -94,8 +89,6 @@ public class OriginHandshakeInterceptorTests extends AbstractHttpRequestTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void originNoMatchWithNullHostileCollection() throws Exception {
|
public void originNoMatchWithNullHostileCollection() throws Exception {
|
||||||
Map<String, Object> attributes = new HashMap<>();
|
|
||||||
WebSocketHandler wsHandler = Mockito.mock(WebSocketHandler.class);
|
|
||||||
this.servletRequest.addHeader(HttpHeaders.ORIGIN, "http://www.mydomain4.com/");
|
this.servletRequest.addHeader(HttpHeaders.ORIGIN, "http://www.mydomain4.com/");
|
||||||
OriginHandshakeInterceptor interceptor = new OriginHandshakeInterceptor();
|
OriginHandshakeInterceptor interceptor = new OriginHandshakeInterceptor();
|
||||||
Set<String> allowedOrigins = new ConcurrentSkipListSet<>();
|
Set<String> allowedOrigins = new ConcurrentSkipListSet<>();
|
||||||
|
|
@ -107,8 +100,6 @@ public class OriginHandshakeInterceptorTests extends AbstractHttpRequestTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void originMatchAll() throws Exception {
|
public void originMatchAll() throws Exception {
|
||||||
Map<String, Object> attributes = new HashMap<>();
|
|
||||||
WebSocketHandler wsHandler = Mockito.mock(WebSocketHandler.class);
|
|
||||||
this.servletRequest.addHeader(HttpHeaders.ORIGIN, "https://mydomain1.com");
|
this.servletRequest.addHeader(HttpHeaders.ORIGIN, "https://mydomain1.com");
|
||||||
OriginHandshakeInterceptor interceptor = new OriginHandshakeInterceptor();
|
OriginHandshakeInterceptor interceptor = new OriginHandshakeInterceptor();
|
||||||
interceptor.setAllowedOrigins(Collections.singletonList("*"));
|
interceptor.setAllowedOrigins(Collections.singletonList("*"));
|
||||||
|
|
@ -118,8 +109,6 @@ public class OriginHandshakeInterceptorTests extends AbstractHttpRequestTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void sameOriginMatchWithEmptyAllowedOrigins() throws Exception {
|
public void sameOriginMatchWithEmptyAllowedOrigins() throws Exception {
|
||||||
Map<String, Object> attributes = new HashMap<>();
|
|
||||||
WebSocketHandler wsHandler = Mockito.mock(WebSocketHandler.class);
|
|
||||||
this.servletRequest.addHeader(HttpHeaders.ORIGIN, "http://mydomain2.com");
|
this.servletRequest.addHeader(HttpHeaders.ORIGIN, "http://mydomain2.com");
|
||||||
this.servletRequest.setServerName("mydomain2.com");
|
this.servletRequest.setServerName("mydomain2.com");
|
||||||
OriginHandshakeInterceptor interceptor = new OriginHandshakeInterceptor(Collections.emptyList());
|
OriginHandshakeInterceptor interceptor = new OriginHandshakeInterceptor(Collections.emptyList());
|
||||||
|
|
@ -129,8 +118,6 @@ public class OriginHandshakeInterceptorTests extends AbstractHttpRequestTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void sameOriginMatchWithAllowedOrigins() throws Exception {
|
public void sameOriginMatchWithAllowedOrigins() throws Exception {
|
||||||
Map<String, Object> attributes = new HashMap<>();
|
|
||||||
WebSocketHandler wsHandler = Mockito.mock(WebSocketHandler.class);
|
|
||||||
this.servletRequest.addHeader(HttpHeaders.ORIGIN, "http://mydomain2.com");
|
this.servletRequest.addHeader(HttpHeaders.ORIGIN, "http://mydomain2.com");
|
||||||
this.servletRequest.setServerName("mydomain2.com");
|
this.servletRequest.setServerName("mydomain2.com");
|
||||||
OriginHandshakeInterceptor interceptor = new OriginHandshakeInterceptor(Arrays.asList("http://mydomain1.com"));
|
OriginHandshakeInterceptor interceptor = new OriginHandshakeInterceptor(Arrays.asList("http://mydomain1.com"));
|
||||||
|
|
@ -140,8 +127,6 @@ public class OriginHandshakeInterceptorTests extends AbstractHttpRequestTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void sameOriginNoMatch() throws Exception {
|
public void sameOriginNoMatch() throws Exception {
|
||||||
Map<String, Object> attributes = new HashMap<>();
|
|
||||||
WebSocketHandler wsHandler = Mockito.mock(WebSocketHandler.class);
|
|
||||||
this.servletRequest.addHeader(HttpHeaders.ORIGIN, "http://mydomain3.com");
|
this.servletRequest.addHeader(HttpHeaders.ORIGIN, "http://mydomain3.com");
|
||||||
this.servletRequest.setServerName("mydomain2.com");
|
this.servletRequest.setServerName("mydomain2.com");
|
||||||
OriginHandshakeInterceptor interceptor = new OriginHandshakeInterceptor(Collections.emptyList());
|
OriginHandshakeInterceptor interceptor = new OriginHandshakeInterceptor(Collections.emptyList());
|
||||||
|
|
|
||||||
|
|
@ -23,8 +23,9 @@ import java.util.Map;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.MockitoAnnotations;
|
import org.mockito.junit.MockitoJUnitRunner;
|
||||||
|
|
||||||
import org.springframework.http.HttpHeaders;
|
import org.springframework.http.HttpHeaders;
|
||||||
import org.springframework.scheduling.TaskScheduler;
|
import org.springframework.scheduling.TaskScheduler;
|
||||||
|
|
@ -57,6 +58,7 @@ import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||||
* @author Sebastien Deleuze
|
* @author Sebastien Deleuze
|
||||||
* @author Ben Kiefer
|
* @author Ben Kiefer
|
||||||
*/
|
*/
|
||||||
|
@RunWith(MockitoJUnitRunner.class)
|
||||||
public class DefaultSockJsServiceTests extends AbstractHttpRequestTests {
|
public class DefaultSockJsServiceTests extends AbstractHttpRequestTests {
|
||||||
|
|
||||||
private static final String sockJsPrefix = "/mysockjs";
|
private static final String sockJsPrefix = "/mysockjs";
|
||||||
|
|
@ -66,25 +68,30 @@ public class DefaultSockJsServiceTests extends AbstractHttpRequestTests {
|
||||||
private static final String sessionUrlPrefix = "/server1/" + sessionId + "/";
|
private static final String sessionUrlPrefix = "/server1/" + sessionId + "/";
|
||||||
|
|
||||||
|
|
||||||
@Mock private SessionCreatingTransportHandler xhrHandler;
|
@Mock
|
||||||
|
private SessionCreatingTransportHandler xhrHandler;
|
||||||
|
|
||||||
@Mock private TransportHandler xhrSendHandler;
|
@Mock
|
||||||
|
private TransportHandler xhrSendHandler;
|
||||||
|
|
||||||
@Mock private HandshakeTransportHandler wsTransportHandler;
|
@Mock
|
||||||
|
private HandshakeTransportHandler wsTransportHandler;
|
||||||
|
|
||||||
@Mock private WebSocketHandler wsHandler;
|
@Mock
|
||||||
|
private WebSocketHandler wsHandler;
|
||||||
|
|
||||||
@Mock private TaskScheduler taskScheduler;
|
@Mock
|
||||||
|
private TaskScheduler taskScheduler;
|
||||||
|
|
||||||
private TestSockJsSession session;
|
private TestSockJsSession session;
|
||||||
|
|
||||||
private TransportHandlingSockJsService service;
|
private TransportHandlingSockJsService service;
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
@Before
|
@Before
|
||||||
public void setup() {
|
public void setup() {
|
||||||
super.setup();
|
super.setup();
|
||||||
MockitoAnnotations.initMocks(this);
|
|
||||||
|
|
||||||
Map<String, Object> attributes = Collections.emptyMap();
|
Map<String, Object> attributes = Collections.emptyMap();
|
||||||
this.session = new TestSockJsSession(sessionId, new StubSockJsServiceConfig(), this.wsHandler, attributes);
|
this.session = new TestSockJsSession(sessionId, new StubSockJsServiceConfig(), this.wsHandler, attributes);
|
||||||
|
|
|
||||||
|
|
@ -167,10 +167,10 @@
|
||||||
<property name="ignoreComments" value="true" />
|
<property name="ignoreComments" value="true" />
|
||||||
</module>
|
</module>
|
||||||
<module name="com.puppycrawl.tools.checkstyle.checks.regexp.RegexpSinglelineJavaCheck">
|
<module name="com.puppycrawl.tools.checkstyle.checks.regexp.RegexpSinglelineJavaCheck">
|
||||||
|
<property name="id" value="bddMockito"/>
|
||||||
<property name="maximum" value="0"/>
|
<property name="maximum" value="0"/>
|
||||||
<property name="format" value="org\.mockito\.Mockito\.(when|doThrow|doAnswer)" />
|
<property name="format" value="org\.mockito\.Mockito\.(when|doThrow|doAnswer)" />
|
||||||
<property name="message"
|
<property name="message" value="Please use BDDMockito." />
|
||||||
value="Please use BDDMockito imports." />
|
|
||||||
<property name="ignoreComments" value="true" />
|
<property name="ignoreComments" value="true" />
|
||||||
</module>
|
</module>
|
||||||
<module name="com.puppycrawl.tools.checkstyle.checks.regexp.RegexpSinglelineJavaCheck">
|
<module name="com.puppycrawl.tools.checkstyle.checks.regexp.RegexpSinglelineJavaCheck">
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue