Polishing

(cherry picked from commit e828be9)
This commit is contained in:
Juergen Hoeller
2016-08-26 17:29:16 +02:00
parent 2adbfb6d02
commit 5b0722ed28
8 changed files with 62 additions and 80 deletions

View File

@@ -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)));
}

View File

@@ -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.
@@ -49,14 +49,14 @@ import static org.junit.Assert.*;
*/
public class AsyncRestTemplateIntegrationTests extends AbstractJettyServerTestCase {
private final AsyncRestTemplate template = new AsyncRestTemplate(new HttpComponentsAsyncClientHttpRequestFactory());
private final AsyncRestTemplate template = new AsyncRestTemplate(
new HttpComponentsAsyncClientHttpRequestFactory());
@Test
public void getEntity() throws Exception {
Future<ResponseEntity<String>> futureEntity =
template.getForEntity(baseUrl + "/{method}", String.class, "get");
ResponseEntity<String> entity = futureEntity.get();
Future<ResponseEntity<String>> future = template.getForEntity(baseUrl + "/{method}", String.class, "get");
ResponseEntity<String> entity = future.get();
assertEquals("Invalid content", helloWorld, entity.getBody());
assertFalse("No headers", entity.getHeaders().isEmpty());
assertEquals("Invalid content-type", textContentType, entity.getHeaders().getContentType());
@@ -65,10 +65,9 @@ public class AsyncRestTemplateIntegrationTests extends AbstractJettyServerTestCa
@Test
public void multipleFutureGets() throws Exception {
Future<ResponseEntity<String>> futureEntity =
template.getForEntity(baseUrl + "/{method}", String.class, "get");
futureEntity.get();
futureEntity.get();
Future<ResponseEntity<String>> future = template.getForEntity(baseUrl + "/{method}", String.class, "get");
future.get();
future.get();
}
@Test

View File

@@ -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.
@@ -23,6 +23,7 @@ import java.nio.charset.Charset;
import java.util.EnumSet;
import java.util.Set;
import com.fasterxml.jackson.annotation.JsonView;
import org.junit.Test;
import org.springframework.core.io.ClassPathResource;
@@ -38,8 +39,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.*;
/**
@@ -235,17 +234,18 @@ public class RestTemplateIntegrationTests extends AbstractJettyServerTestCase {
assertFalse(s.contains("\"without\":\"without\""));
}
// SPR-12123
@Test
@Test // SPR-12123
public void serverPort() {
String s = template.getForObject("http://localhost:{port}/get", String.class, port);
assertEquals("Invalid content", helloWorld, s);
}
public interface MyJacksonView1 {};
public interface MyJacksonView2 {};
public static class MySampleBean {
@JsonView(MyJacksonView1.class)

View File

@@ -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);
}