Fixes for ignored tests after last week's nullability commit

Issue: SPR-15540
This commit is contained in:
Juergen Hoeller 2017-06-13 11:37:58 +02:00
parent 58242f2249
commit 7dd8dc62a5
9 changed files with 30 additions and 53 deletions

View File

@ -179,8 +179,8 @@ public class SendToMethodReturnValueHandler implements HandlerMethodReturnValueH
}
}
}
else if (annotation instanceof SendTo) {
SendTo sendTo = (SendTo) annotation;
else {
SendTo sendTo = (SendTo) annotation; // possibly null
String[] destinations = getTargetDestinations(sendTo, message, this.defaultDestinationPrefix);
for (String destination : destinations) {
destination = this.placeholderHelper.replacePlaceholders(destination, varResolver);

View File

@ -27,7 +27,6 @@ import javax.security.auth.Subject;
import com.fasterxml.jackson.annotation.JsonView;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
@ -176,7 +175,6 @@ public class SendToMethodReturnValueHandlerTests {
}
@Test
@Ignore // TODO: NULLABLE
public void sendToNoAnnotations() throws Exception {
given(this.messageChannel.send(any(Message.class))).willReturn(true);
@ -346,7 +344,6 @@ public class SendToMethodReturnValueHandlerTests {
}
@Test
@Ignore // TODO: NULLABLE
public void testHeadersToSend() throws Exception {
Message<?> message = createMessage("sess1", "sub1", "/app", "/dest", null);
@ -530,7 +527,6 @@ public class SendToMethodReturnValueHandlerTests {
}
@Test
@Ignore // TODO: NULLABLE
public void jsonView() throws Exception {
given(this.messageChannel.send(any(Message.class))).willReturn(true);

View File

@ -26,7 +26,6 @@ import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
@ -238,7 +237,6 @@ public class SimpAnnotationMethodMessageHandlerTests {
}
@Test
@Ignore // TODO: NULLABLE
@SuppressWarnings("unchecked")
public void listenableFutureSuccess() {
Message emptyMessage = (Message) MessageBuilder.withPayload(new byte[0]).build();
@ -277,7 +275,6 @@ public class SimpAnnotationMethodMessageHandlerTests {
}
@Test
@Ignore // TODO: NULLABLE
@SuppressWarnings("unchecked")
public void completableFutureSuccess() {
Message emptyMessage = (Message) MessageBuilder.withPayload(new byte[0]).build();

View File

@ -19,7 +19,6 @@ package org.springframework.messaging.simp.user;
import java.nio.charset.StandardCharsets;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Mockito;
@ -123,7 +122,6 @@ public class UserDestinationMessageHandlerTests {
}
@Test
@Ignore // TODO: NULLABLE
public void handleMessageFromBrokerWithActiveSession() {
TestSimpUser simpUser = new TestSimpUser("joe");
simpUser.addSessions(new TestSimpSession("123"));

View File

@ -200,11 +200,11 @@ public abstract class AbstractMessageConverterMethodArgumentResolver implements
logger.debug("Read [" + targetType + "] as \"" + contentType + "\" with [" + converter + "]");
}
if (message.hasBody()) {
HttpInputMessage inputMessageToUse =
HttpInputMessage msgToUse =
getAdvice().beforeBodyRead(message, parameter, targetType, converterType);
body = (genericConverter != null ? genericConverter.read(targetType, contextClass, message) :
((HttpMessageConverter<T>) converter).read(targetClass, message));
body = getAdvice().afterBodyRead(body, inputMessageToUse, parameter, targetType, converterType);
body = (genericConverter != null ? genericConverter.read(targetType, contextClass, msgToUse) :
((HttpMessageConverter<T>) converter).read(targetClass, msgToUse));
body = getAdvice().afterBodyRead(body, msgToUse, parameter, targetType, converterType);
}
else {
body = getAdvice().handleEmptyBody(null, message, parameter, targetType, converterType);

View File

@ -117,6 +117,7 @@ public abstract class AbstractMessageConverterMethodProcessor extends AbstractMe
@Nullable ContentNegotiationManager manager, @Nullable List<Object> requestResponseBodyAdvice) {
super(converters, requestResponseBodyAdvice);
this.contentNegotiationManager = (manager != null ? manager : new ContentNegotiationManager());
this.pathStrategy = initPathStrategy(this.contentNegotiationManager);
this.safeExtensions.addAll(this.contentNegotiationManager.getAllFileExtensions());
@ -163,7 +164,7 @@ public abstract class AbstractMessageConverterMethodProcessor extends AbstractMe
* @throws HttpMediaTypeNotAcceptableException thrown when the conditions indicated
* by the {@code Accept} header on the request cannot be met by the message converters
*/
@SuppressWarnings("unchecked")
@SuppressWarnings({"rawtypes", "unchecked"})
protected <T> void writeWithMessageConverters(@Nullable T value, MethodParameter returnType,
ServletServerHttpRequest inputMessage, ServletServerHttpResponse outputMessage)
throws IOException, HttpMediaTypeNotAcceptableException, HttpMessageNotWritableException {
@ -223,35 +224,26 @@ public abstract class AbstractMessageConverterMethodProcessor extends AbstractMe
if (selectedMediaType != null) {
selectedMediaType = selectedMediaType.removeQualityValue();
for (HttpMessageConverter<?> messageConverter : this.messageConverters) {
if (messageConverter instanceof GenericHttpMessageConverter) {
if (((GenericHttpMessageConverter) messageConverter).canWrite(
declaredType, valueType, selectedMediaType)) {
outputValue = (T) getAdvice().beforeBodyWrite(outputValue, returnType, selectedMediaType,
(Class<? extends HttpMessageConverter<?>>) messageConverter.getClass(),
inputMessage, outputMessage);
if (outputValue != null) {
addContentDispositionHeader(inputMessage, outputMessage);
((GenericHttpMessageConverter) messageConverter).write(
outputValue, declaredType, selectedMediaType, outputMessage);
if (logger.isDebugEnabled()) {
logger.debug("Written [" + outputValue + "] as \"" + selectedMediaType +
"\" using [" + messageConverter + "]");
}
}
return;
}
}
else if (messageConverter.canWrite(valueType, selectedMediaType)) {
for (HttpMessageConverter<?> converter : this.messageConverters) {
GenericHttpMessageConverter genericConverter =
(converter instanceof GenericHttpMessageConverter ? (GenericHttpMessageConverter<?>) converter : null);
if (genericConverter != null ?
((GenericHttpMessageConverter) converter).canWrite(declaredType, valueType, selectedMediaType) :
converter.canWrite(valueType, selectedMediaType)) {
outputValue = (T) getAdvice().beforeBodyWrite(outputValue, returnType, selectedMediaType,
(Class<? extends HttpMessageConverter<?>>) messageConverter.getClass(),
(Class<? extends HttpMessageConverter<?>>) converter.getClass(),
inputMessage, outputMessage);
if (outputValue != null) {
addContentDispositionHeader(inputMessage, outputMessage);
((HttpMessageConverter) messageConverter).write(outputValue, selectedMediaType, outputMessage);
if (genericConverter != null) {
genericConverter.write(outputValue, declaredType, selectedMediaType, outputMessage);
}
else {
((HttpMessageConverter) converter).write(outputValue, selectedMediaType, outputMessage);
}
if (logger.isDebugEnabled()) {
logger.debug("Written [" + outputValue + "] as \"" + selectedMediaType +
"\" using [" + messageConverter + "]");
"\" using [" + converter + "]");
}
}
return;
@ -305,7 +297,9 @@ public abstract class AbstractMessageConverterMethodProcessor extends AbstractMe
* @since 4.2
*/
@SuppressWarnings("unchecked")
protected List<MediaType> getProducibleMediaTypes(HttpServletRequest request, Class<?> valueClass, @Nullable Type declaredType) {
protected List<MediaType> getProducibleMediaTypes(HttpServletRequest request, Class<?> valueClass,
@Nullable Type declaredType) {
Set<MediaType> mediaTypes = (Set<MediaType>) request.getAttribute(HandlerMapping.PRODUCIBLE_MEDIA_TYPES_ATTRIBUTE);
if (!CollectionUtils.isEmpty(mediaTypes)) {
return new ArrayList<>(mediaTypes);

View File

@ -89,7 +89,7 @@ public class RequestResponseBodyMethodProcessor extends AbstractMessageConverter
* @since 4.2
*/
public RequestResponseBodyMethodProcessor(List<HttpMessageConverter<?>> converters,
List<Object> requestResponseBodyAdvice) {
@Nullable List<Object> requestResponseBodyAdvice) {
super(converters, null, requestResponseBodyAdvice);
}
@ -99,7 +99,7 @@ public class RequestResponseBodyMethodProcessor extends AbstractMessageConverter
* {@code @ResponseBody}.
*/
public RequestResponseBodyMethodProcessor(List<HttpMessageConverter<?>> converters,
ContentNegotiationManager manager, List<Object> requestResponseBodyAdvice) {
@Nullable ContentNegotiationManager manager, @Nullable List<Object> requestResponseBodyAdvice) {
super(converters, manager, requestResponseBodyAdvice);
}

View File

@ -507,7 +507,6 @@ public class RequestResponseBodyMethodProcessorTests {
}
@Test // SPR-12501
@Ignore // TODO: NULLABLE
public void resolveArgumentWithJacksonJsonView() throws Exception {
String content = "{\"withView1\" : \"with\", \"withView2\" : \"with\", \"withoutView\" : \"without\"}";
this.servletRequest.setContent(content.getBytes("UTF-8"));
@ -534,7 +533,6 @@ public class RequestResponseBodyMethodProcessorTests {
}
@Test // SPR-12501
@Ignore // TODO: NULLABLE
public void resolveHttpEntityArgumentWithJacksonJsonView() throws Exception {
String content = "{\"withView1\" : \"with\", \"withView2\" : \"with\", \"withoutView\" : \"without\"}";
this.servletRequest.setContent(content.getBytes("UTF-8"));
@ -562,7 +560,6 @@ public class RequestResponseBodyMethodProcessorTests {
}
@Test // SPR-12501
@Ignore // TODO: NULLABLE
public void resolveArgumentWithJacksonJsonViewAndXmlMessageConverter() throws Exception {
String content = "<root><withView1>with</withView1><withView2>with</withView2><withoutView>without</withoutView></root>";
this.servletRequest.setContent(content.getBytes("UTF-8"));
@ -589,7 +586,6 @@ public class RequestResponseBodyMethodProcessorTests {
}
@Test // SPR-12501
@Ignore // TODO: NULLABLE
public void resolveHttpEntityArgumentWithJacksonJsonViewAndXmlMessageConverter() throws Exception {
String content = "<root><withView1>with</withView1><withView2>with</withView2><withoutView>without</withoutView></root>";
this.servletRequest.setContent(content.getBytes("UTF-8"));

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2017 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.
@ -23,7 +23,6 @@ import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
@ -67,7 +66,6 @@ import static org.springframework.web.socket.messaging.StompTextMessageBuilder.*
* @author Rossen Stoyanchev
*/
@RunWith(Parameterized.class)
@Ignore // TODO: NULLABLE
public class StompWebSocketIntegrationTests extends AbstractWebSocketIntegrationTests {
private static final long TIMEOUT = 10;
@ -120,8 +118,7 @@ public class StompWebSocketIntegrationTests extends AbstractWebSocketIntegration
}
}
// SPR-10930
@Test
@Test // SPR-10930
public void sendMessageToBrokerAndReceiveReplyViaTopic() throws Exception {
TextMessage m1 = create(StompCommand.SUBSCRIBE).headers("id:subs1", "destination:/topic/foo").build();
TextMessage m2 = create(StompCommand.SEND).headers("destination:/topic/foo").body("5").build();
@ -140,8 +137,7 @@ public class StompWebSocketIntegrationTests extends AbstractWebSocketIntegration
}
}
// SPR-11648
@Test
@Test // SPR-11648
public void sendSubscribeToControllerAndReceiveReply() throws Exception {
String destHeader = "destination:/app/number";
TextMessage message = create(StompCommand.SUBSCRIBE).headers("id:subs1", destHeader).build();