Browse Source

Fix broken (Async)RestTemplate integration tests

Issue: SPR-13157
pull/826/head
Sam Brannen 11 years ago
parent
commit
75fe61843a
  1. 29
      spring-web/src/test/java/org/springframework/web/client/AbstractJettyServerTestCase.java
  2. 11
      spring-web/src/test/java/org/springframework/web/client/AsyncRestTemplateIntegrationTests.java
  3. 10
      spring-web/src/test/java/org/springframework/web/client/RestTemplateIntegrationTests.java

29
spring-web/src/test/java/org/springframework/web/client/AbstractJettyServerTestCase.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2015 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.
@ -50,27 +50,22 @@ import static org.junit.Assert.*; @@ -50,27 +50,22 @@ import static org.junit.Assert.*;
*/
public class AbstractJettyServerTestCase {
protected static String helloWorld = "H\u00e9llo W\u00f6rld";
protected static final String helloWorld = "H\u00e9llo W\u00f6rld";
protected static int port;
protected static String baseUrl;
protected static final int port = SocketUtils.findAvailableTcpPort();
protected static MediaType textContentType;
protected static MediaType jsonContentType;
protected static final String baseUrl = "http://localhost:" + port;
private static Server jettyServer;
protected static final MediaType textContentType = new MediaType("text", "plain", Collections.singletonMap("charset", "utf-8"));
protected static final MediaType jsonContentType = new MediaType("application", "json", Collections.singletonMap("charset", "utf-8"));
private static final Server jettyServer = new Server(port);
@BeforeClass
public static void startJettyServer() throws Exception {
port = SocketUtils.findAvailableTcpPort();
jettyServer = new Server(port);
baseUrl = "http://localhost:" + port;
ServletContextHandler handler = new ServletContextHandler();
byte[] bytes = helloWorld.getBytes("UTF-8");
textContentType = new MediaType("text", "plain", Collections
.singletonMap("charset", "UTF-8"));
jsonContentType = new MediaType("application", "json", Collections
.singletonMap("charset", "UTF-8"));
byte[] bytes = helloWorld.getBytes("utf-8");
handler.addServlet(new ServletHolder(new GetServlet(bytes, textContentType)), "/get");
handler.addServlet(new ServletHolder(new GetServlet(new byte[0], textContentType)), "/get/nothing");
handler.addServlet(new ServletHolder(new GetServlet(bytes, null)), "/get/nocontenttype");
@ -212,7 +207,7 @@ public class AbstractJettyServerTestCase { @@ -212,7 +207,7 @@ public class AbstractJettyServerTestCase {
response.setStatus(HttpServletResponse.SC_CREATED);
response.setHeader("Location", location);
response.setContentType(contentType.toString());
byte[] bytes = body.getBytes("UTF-8");
byte[] bytes = body.getBytes("utf-8");
response.setContentLength(bytes.length);;
FileCopyUtils.copy(bytes, response.getOutputStream());
}
@ -244,7 +239,7 @@ public class AbstractJettyServerTestCase { @@ -244,7 +239,7 @@ public class AbstractJettyServerTestCase {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
resp.setContentType("text/plain");
resp.setCharacterEncoding("UTF-8");
resp.setCharacterEncoding("utf-8");
resp.getWriter().write(req.getRequestURI());
}
}

11
spring-web/src/test/java/org/springframework/web/client/AsyncRestTemplateIntegrationTests.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2015 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.
@ -25,7 +25,6 @@ import java.util.concurrent.ExecutionException; @@ -25,7 +25,6 @@ import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import org.junit.Before;
import org.junit.Test;
import org.springframework.core.io.ClassPathResource;
@ -50,13 +49,7 @@ import static org.junit.Assert.*; @@ -50,13 +49,7 @@ import static org.junit.Assert.*;
*/
public class AsyncRestTemplateIntegrationTests extends AbstractJettyServerTestCase {
private AsyncRestTemplate template;
@Before
public void createTemplate() {
template = new AsyncRestTemplate(new HttpComponentsAsyncClientHttpRequestFactory());
}
private final AsyncRestTemplate template = new AsyncRestTemplate(new HttpComponentsAsyncClientHttpRequestFactory());
@Test

10
spring-web/src/test/java/org/springframework/web/client/RestTemplateIntegrationTests.java

@ -23,8 +23,6 @@ import java.nio.charset.Charset; @@ -23,8 +23,6 @@ import java.nio.charset.Charset;
import java.util.EnumSet;
import java.util.Set;
import com.fasterxml.jackson.annotation.JsonView;
import org.junit.Before;
import org.junit.Test;
import org.springframework.core.io.ClassPathResource;
@ -40,6 +38,8 @@ import org.springframework.http.converter.json.MappingJacksonValue; @@ -40,6 +38,8 @@ 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.*;
/**
@ -47,12 +47,8 @@ import static org.junit.Assert.*; @@ -47,12 +47,8 @@ import static org.junit.Assert.*;
*/
public class RestTemplateIntegrationTests extends AbstractJettyServerTestCase {
private RestTemplate template;
private final RestTemplate template = new RestTemplate(new HttpComponentsClientHttpRequestFactory());
@Before
public void createTemplate() {
template = new RestTemplate(new HttpComponentsClientHttpRequestFactory());
}
@Test
public void getString() {

Loading…
Cancel
Save