Polishing
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2016 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.
|
||||
@@ -199,6 +199,20 @@ public class MappingJackson2MessageConverterTests {
|
||||
}
|
||||
|
||||
|
||||
|
||||
@JsonView(MyJacksonView1.class)
|
||||
public JacksonViewBean jsonViewResponse() {
|
||||
JacksonViewBean bean = new JacksonViewBean();
|
||||
bean.setWithView1("with");
|
||||
bean.setWithView2("with");
|
||||
bean.setWithoutView("with");
|
||||
return bean;
|
||||
}
|
||||
|
||||
public void jsonViewPayload(@JsonView(MyJacksonView2.class) JacksonViewBean payload) {
|
||||
}
|
||||
|
||||
|
||||
public static class MyBean {
|
||||
|
||||
private String string;
|
||||
@@ -262,9 +276,12 @@ public class MappingJackson2MessageConverterTests {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public interface MyJacksonView1 {};
|
||||
|
||||
public interface MyJacksonView2 {};
|
||||
|
||||
|
||||
public static class JacksonViewBean {
|
||||
|
||||
@JsonView(MyJacksonView1.class)
|
||||
@@ -300,16 +317,4 @@ public class MappingJackson2MessageConverterTests {
|
||||
}
|
||||
}
|
||||
|
||||
@JsonView(MyJacksonView1.class)
|
||||
public JacksonViewBean jsonViewResponse() {
|
||||
JacksonViewBean bean = new JacksonViewBean();
|
||||
bean.setWithView1("with");
|
||||
bean.setWithView2("with");
|
||||
bean.setWithoutView("with");
|
||||
return bean;
|
||||
}
|
||||
|
||||
public void jsonViewPayload(@JsonView(MyJacksonView2.class) JacksonViewBean payload) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-2016 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.
|
||||
@@ -66,7 +66,6 @@ public class GenericMessagingTemplateTests {
|
||||
|
||||
@Test
|
||||
public void sendAndReceive() {
|
||||
|
||||
SubscribableChannel channel = new ExecutorSubscribableChannel(this.executor);
|
||||
channel.subscribe(new MessageHandler() {
|
||||
@Override
|
||||
@@ -82,7 +81,6 @@ public class GenericMessagingTemplateTests {
|
||||
|
||||
@Test
|
||||
public void sendAndReceiveTimeout() throws InterruptedException {
|
||||
|
||||
final AtomicReference<Throwable> failure = new AtomicReference<Throwable>();
|
||||
final CountDownLatch latch = new CountDownLatch(1);
|
||||
|
||||
@@ -118,8 +116,9 @@ public class GenericMessagingTemplateTests {
|
||||
assertNull(this.template.convertSendAndReceive(channel, "request", String.class));
|
||||
assertTrue(latch.await(1000, TimeUnit.MILLISECONDS));
|
||||
|
||||
if (failure.get() != null) {
|
||||
throw new AssertionError(failure.get());
|
||||
Throwable ex = failure.get();
|
||||
if (ex != null) {
|
||||
throw new AssertionError(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -138,6 +137,7 @@ public class GenericMessagingTemplateTests {
|
||||
assertFalse(accessor.isMutable());
|
||||
}
|
||||
|
||||
|
||||
private class TestDestinationResolver implements DestinationResolver<MessageChannel> {
|
||||
|
||||
@Override
|
||||
@@ -145,4 +145,5 @@ public class GenericMessagingTemplateTests {
|
||||
return messageChannel;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2016 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.
|
||||
@@ -123,28 +123,21 @@ public class ObjectToStringHttpMessageConverterTests {
|
||||
@Test
|
||||
public void read() throws IOException {
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
|
||||
request.setContentType(MediaType.TEXT_PLAIN_VALUE);
|
||||
|
||||
Short shortValue = Short.valueOf((short) 781);
|
||||
|
||||
request.setContent(shortValue.toString().getBytes(
|
||||
StringHttpMessageConverter.DEFAULT_CHARSET));
|
||||
|
||||
assertEquals(shortValue, this.converter.read(Short.class, new ServletServerHttpRequest(request)));
|
||||
|
||||
Float floatValue = Float.valueOf(123);
|
||||
|
||||
request.setCharacterEncoding("UTF-16");
|
||||
request.setContent(floatValue.toString().getBytes("UTF-16"));
|
||||
|
||||
assertEquals(floatValue, this.converter.read(Float.class, new ServletServerHttpRequest(request)));
|
||||
|
||||
Long longValue = Long.valueOf(55819182821331L);
|
||||
|
||||
request.setCharacterEncoding("UTF-8");
|
||||
request.setContent(longValue.toString().getBytes("UTF-8"));
|
||||
|
||||
assertEquals(longValue, this.converter.read(Long.class, new ServletServerHttpRequest(request)));
|
||||
}
|
||||
|
||||
|
||||
@@ -50,14 +50,7 @@ import org.springframework.util.MultiValueMap;
|
||||
import org.springframework.util.concurrent.ListenableFuture;
|
||||
import org.springframework.util.concurrent.ListenableFutureCallback;
|
||||
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* @author Arjen Poutsma
|
||||
@@ -185,7 +178,7 @@ public class AsyncRestTemplateIntegrationTests extends AbstractJettyServerTestCa
|
||||
@Test
|
||||
public void postForLocation() throws Exception {
|
||||
HttpHeaders entityHeaders = new HttpHeaders();
|
||||
entityHeaders.setContentType(new MediaType("text", "plain", Charset.forName("ISO-8859-15")));
|
||||
entityHeaders.setContentType(new MediaType("text", "plain", Charset.forName("ISO-8859-1")));
|
||||
HttpEntity<String> entity = new HttpEntity<>(helloWorld, entityHeaders);
|
||||
Future<URI> locationFuture = template.postForLocation(baseUrl + "/{method}", entity, "post");
|
||||
URI location = locationFuture.get();
|
||||
@@ -195,7 +188,7 @@ public class AsyncRestTemplateIntegrationTests extends AbstractJettyServerTestCa
|
||||
@Test
|
||||
public void postForLocationCallback() throws Exception {
|
||||
HttpHeaders entityHeaders = new HttpHeaders();
|
||||
entityHeaders.setContentType(new MediaType("text", "plain", Charset.forName("ISO-8859-15")));
|
||||
entityHeaders.setContentType(new MediaType("text", "plain", Charset.forName("ISO-8859-1")));
|
||||
HttpEntity<String> entity = new HttpEntity<>(helloWorld, entityHeaders);
|
||||
final URI expected = new URI(baseUrl + "/post/1");
|
||||
ListenableFuture<URI> locationFuture = template.postForLocation(baseUrl + "/{method}", entity, "post");
|
||||
@@ -215,7 +208,7 @@ public class AsyncRestTemplateIntegrationTests extends AbstractJettyServerTestCa
|
||||
@Test
|
||||
public void postForLocationCallbackWithLambdas() throws Exception {
|
||||
HttpHeaders entityHeaders = new HttpHeaders();
|
||||
entityHeaders.setContentType(new MediaType("text", "plain", Charset.forName("ISO-8859-15")));
|
||||
entityHeaders.setContentType(new MediaType("text", "plain", Charset.forName("ISO-8859-1")));
|
||||
HttpEntity<String> entity = new HttpEntity<>(helloWorld, entityHeaders);
|
||||
final URI expected = new URI(baseUrl + "/post/1");
|
||||
ListenableFuture<URI> locationFuture = template.postForLocation(baseUrl + "/{method}", entity, "post");
|
||||
|
||||
@@ -27,6 +27,7 @@ import java.util.Set;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonTypeInfo;
|
||||
import com.fasterxml.jackson.annotation.JsonTypeName;
|
||||
import com.fasterxml.jackson.annotation.JsonView;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.core.ParameterizedTypeReference;
|
||||
@@ -44,8 +45,6 @@ import org.springframework.http.converter.json.MappingJacksonValue;
|
||||
import org.springframework.util.LinkedMultiValueMap;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonView;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
@@ -264,9 +263,12 @@ public class RestTemplateIntegrationTests extends AbstractJettyServerTestCase {
|
||||
assertTrue(content.contains("\"type\":\"bar\""));
|
||||
}
|
||||
|
||||
|
||||
public interface MyJacksonView1 {};
|
||||
|
||||
public interface MyJacksonView2 {};
|
||||
|
||||
|
||||
public static class MySampleBean {
|
||||
|
||||
@JsonView(MyJacksonView1.class)
|
||||
@@ -311,6 +313,7 @@ public class RestTemplateIntegrationTests extends AbstractJettyServerTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type")
|
||||
public static class ParentClass {
|
||||
|
||||
@@ -332,6 +335,7 @@ public class RestTemplateIntegrationTests extends AbstractJettyServerTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@JsonTypeName("foo")
|
||||
public static class Foo extends ParentClass {
|
||||
|
||||
@@ -343,6 +347,7 @@ public class RestTemplateIntegrationTests extends AbstractJettyServerTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@JsonTypeName("bar")
|
||||
public static class Bar extends ParentClass {
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2016 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.
|
||||
@@ -18,7 +18,6 @@ package org.springframework.web.multipart.support;
|
||||
|
||||
import java.net.URI;
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletRequestWrapper;
|
||||
|
||||
@@ -33,9 +32,7 @@ import org.springframework.mock.web.test.MockMultipartHttpServletRequest;
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* @author Rossen Stoyanchev
|
||||
@@ -89,9 +86,7 @@ public class RequestPartServletServerHttpRequestTests {
|
||||
assertArrayEquals(bytes, result);
|
||||
}
|
||||
|
||||
// SPR-13317
|
||||
|
||||
@Test
|
||||
@Test // SPR-13317
|
||||
public void getBodyWithWrappedRequest() throws Exception {
|
||||
byte[] bytes = "content".getBytes("UTF-8");
|
||||
MultipartFile part = new MockMultipartFile("part", "", "application/json", bytes);
|
||||
@@ -103,12 +98,9 @@ public class RequestPartServletServerHttpRequestTests {
|
||||
assertArrayEquals(bytes, result);
|
||||
}
|
||||
|
||||
// SPR-13096
|
||||
|
||||
@Test
|
||||
@Test // SPR-13096
|
||||
public void getBodyViaRequestParameter() throws Exception {
|
||||
MockMultipartHttpServletRequest mockRequest = new MockMultipartHttpServletRequest() {
|
||||
|
||||
@Override
|
||||
public HttpHeaders getMultipartHeaders(String paramOrFileName) {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
@@ -116,10 +108,10 @@ public class RequestPartServletServerHttpRequestTests {
|
||||
return headers;
|
||||
}
|
||||
};
|
||||
byte[] bytes = {(byte) 0xC4};
|
||||
mockRequest.setParameter("part", new String(bytes, Charset.forName("iso-8859-1")));
|
||||
ServerHttpRequest request = new RequestPartServletServerHttpRequest(mockRequest, "part");
|
||||
|
||||
byte[] bytes = {(byte) 0xC4};
|
||||
mockRequest.setParameter("part", new String(bytes, Charset.forName("ISO-8859-1")));
|
||||
ServerHttpRequest request = new RequestPartServletServerHttpRequest(mockRequest, "part");
|
||||
byte[] result = FileCopyUtils.copyToByteArray(request.getBody());
|
||||
assertArrayEquals(bytes, result);
|
||||
}
|
||||
@@ -127,7 +119,6 @@ public class RequestPartServletServerHttpRequestTests {
|
||||
@Test
|
||||
public void getBodyViaRequestParameterWithRequestEncoding() throws Exception {
|
||||
MockMultipartHttpServletRequest mockRequest = new MockMultipartHttpServletRequest() {
|
||||
|
||||
@Override
|
||||
public HttpHeaders getMultipartHeaders(String paramOrFileName) {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
@@ -135,11 +126,11 @@ public class RequestPartServletServerHttpRequestTests {
|
||||
return headers;
|
||||
}
|
||||
};
|
||||
|
||||
byte[] bytes = {(byte) 0xC4};
|
||||
mockRequest.setParameter("part", new String(bytes, Charset.forName("iso-8859-1")));
|
||||
mockRequest.setParameter("part", new String(bytes, Charset.forName("ISO-8859-1")));
|
||||
mockRequest.setCharacterEncoding("iso-8859-1");
|
||||
ServerHttpRequest request = new RequestPartServletServerHttpRequest(mockRequest, "part");
|
||||
|
||||
byte[] result = FileCopyUtils.copyToByteArray(request.getBody());
|
||||
assertArrayEquals(bytes, result);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2016 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.
|
||||
@@ -30,7 +30,6 @@ import org.eclipse.jetty.server.NetworkConnector;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.servlet.ServletContextHandler;
|
||||
import org.eclipse.jetty.servlet.ServletHolder;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
@@ -116,6 +115,13 @@ public class RequestPartIntegrationTests {
|
||||
baseUrl = "http://localhost:" + connector.getLocalPort();
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void stopServer() throws Exception {
|
||||
if (server != null) {
|
||||
server.stop();
|
||||
}
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
ByteArrayHttpMessageConverter emptyBodyConverter = new ByteArrayHttpMessageConverter();
|
||||
@@ -134,13 +140,6 @@ public class RequestPartIntegrationTests {
|
||||
restTemplate.setMessageConverters(Collections.singletonList(converter));
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void stopServer() throws Exception {
|
||||
if (server != null) {
|
||||
server.stop();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void commonsMultipartResolver() throws Exception {
|
||||
@@ -172,7 +171,7 @@ public class RequestPartIntegrationTests {
|
||||
RequestEntity<byte[]> requestEntity =
|
||||
RequestEntity.post(new URI(baseUrl + "/standard-resolver/spr13319"))
|
||||
.contentType(new MediaType(MediaType.MULTIPART_FORM_DATA, params))
|
||||
.body(content.getBytes(Charset.forName("us-ascii")));
|
||||
.body(content.getBytes(Charset.forName("US-ASCII")));
|
||||
|
||||
ByteArrayHttpMessageConverter converter = new ByteArrayHttpMessageConverter();
|
||||
converter.setSupportedMediaTypes(Collections.singletonList(MediaType.MULTIPART_FORM_DATA));
|
||||
|
||||
Reference in New Issue
Block a user