diff options
author | Emmanuel Bourg <ebourg@apache.org> | 2017-09-18 19:25:58 +0200 |
---|---|---|
committer | Emmanuel Bourg <ebourg@apache.org> | 2017-09-18 19:25:58 +0200 |
commit | 0ffebdadce315ab1d00dd5de08d285bbf54a851e (patch) | |
tree | 5097ac63ba7ebbabd2388a49de7ba306d9f88cb1 /spring-web/src/test/java/org/springframework/web | |
parent | 2062ec42e5d3b880b5120118adcbb279204d7353 (diff) |
New upstream version 4.3.11
Diffstat (limited to 'spring-web/src/test/java/org/springframework/web')
4 files changed, 83 insertions, 11 deletions
diff --git a/spring-web/src/test/java/org/springframework/web/client/RestTemplateTests.java b/spring-web/src/test/java/org/springframework/web/client/RestTemplateTests.java index f7083358..6e3236d3 100644 --- a/spring-web/src/test/java/org/springframework/web/client/RestTemplateTests.java +++ b/spring-web/src/test/java/org/springframework/web/client/RestTemplateTests.java @@ -44,8 +44,18 @@ import org.springframework.http.converter.GenericHttpMessageConverter; import org.springframework.http.converter.HttpMessageConverter; import org.springframework.web.util.DefaultUriTemplateHandler; -import static org.junit.Assert.*; -import static org.mockito.BDDMockito.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.fail; +import static org.mockito.BDDMockito.any; +import static org.mockito.BDDMockito.eq; +import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.mock; +import static org.mockito.BDDMockito.verify; +import static org.mockito.BDDMockito.willThrow; +import static org.springframework.http.MediaType.parseMediaType; /** * @author Arjen Poutsma @@ -701,9 +711,7 @@ public class RestTemplateTests { verify(response).close(); } - // Issue: SPR-9325, SPR-13860 - - @Test + @Test // Issue: SPR-9325, SPR-13860 public void ioException() throws Exception { String url = "http://example.com/resource?access_token=123"; @@ -725,6 +733,29 @@ public class RestTemplateTests { } } + @Test // SPR-15900 + public void ioExceptionWithEmptyQueryString() throws Exception { + + // http://example.com/resource? + URI uri = new URI("http", "example.com", "/resource", "", null); + + given(converter.canRead(String.class, null)).willReturn(true); + given(converter.getSupportedMediaTypes()).willReturn(Collections.singletonList(parseMediaType("foo/bar"))); + given(requestFactory.createRequest(uri, HttpMethod.GET)).willReturn(request); + given(request.getHeaders()).willReturn(new HttpHeaders()); + given(request.execute()).willThrow(new IOException("Socket failure")); + + try { + template.getForObject(uri, String.class); + fail("RestClientException expected"); + } + catch (ResourceAccessException ex) { + assertEquals("I/O error on GET request for \"http://example.com/resource\": " + + "Socket failure; nested exception is java.io.IOException: Socket failure", + ex.getMessage()); + } + } + @Test public void exchange() throws Exception { given(converter.canRead(Integer.class, null)).willReturn(true); diff --git a/spring-web/src/test/java/org/springframework/web/context/request/async/WebAsyncManagerTimeoutTests.java b/spring-web/src/test/java/org/springframework/web/context/request/async/WebAsyncManagerTimeoutTests.java index d8ecfe83..268f5fce 100644 --- a/spring-web/src/test/java/org/springframework/web/context/request/async/WebAsyncManagerTimeoutTests.java +++ b/spring-web/src/test/java/org/springframework/web/context/request/async/WebAsyncManagerTimeoutTests.java @@ -17,6 +17,7 @@ package org.springframework.web.context.request.async; import java.util.concurrent.Callable; +import java.util.concurrent.Future; import javax.servlet.AsyncEvent; import org.junit.Before; @@ -28,9 +29,15 @@ import org.springframework.mock.web.test.MockHttpServletRequest; import org.springframework.mock.web.test.MockHttpServletResponse; import org.springframework.web.context.request.NativeWebRequest; -import static org.junit.Assert.*; -import static org.mockito.BDDMockito.*; -import static org.springframework.web.context.request.async.CallableProcessingInterceptor.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.mockito.BDDMockito.any; +import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.mock; +import static org.mockito.BDDMockito.verify; +import static org.mockito.BDDMockito.verifyNoMoreInteractions; +import static org.mockito.BDDMockito.when; +import static org.springframework.web.context.request.async.CallableProcessingInterceptor.RESULT_NONE; /** * {@link WebAsyncManager} tests where container-triggered timeout/completion @@ -148,6 +155,27 @@ public class WebAsyncManagerTimeoutTests { verify(interceptor).beforeConcurrentHandling(this.asyncWebRequest, callable); } + @SuppressWarnings("unchecked") + @Test + public void startCallableProcessingTimeoutAndCheckThreadInterrupted() throws Exception { + + StubCallable callable = new StubCallable(); + Future future = mock(Future.class); + + AsyncTaskExecutor executor = mock(AsyncTaskExecutor.class); + when(executor.submit(any(Runnable.class))).thenReturn(future); + + this.asyncManager.setTaskExecutor(executor); + this.asyncManager.startCallableProcessing(callable); + + this.asyncWebRequest.onTimeout(ASYNC_EVENT); + + assertTrue(this.asyncManager.hasConcurrentResult()); + + verify(future).cancel(true); + verifyNoMoreInteractions(future); + } + @Test public void startDeferredResultProcessingTimeoutAndComplete() throws Exception { diff --git a/spring-web/src/test/java/org/springframework/web/filter/HttpPutFormContentFilterTests.java b/spring-web/src/test/java/org/springframework/web/filter/HttpPutFormContentFilterTests.java index 6a5de837..07758e96 100644 --- a/spring-web/src/test/java/org/springframework/web/filter/HttpPutFormContentFilterTests.java +++ b/spring-web/src/test/java/org/springframework/web/filter/HttpPutFormContentFilterTests.java @@ -58,7 +58,7 @@ public class HttpPutFormContentFilterTests { @Test public void wrapPutAndPatchOnly() throws Exception { - request.setContent("".getBytes("ISO-8859-1")); + request.setContent("foo=bar".getBytes("ISO-8859-1")); for (HttpMethod method : HttpMethod.values()) { request.setMethod(method.name()); filterChain = new MockFilterChain(); @@ -204,4 +204,13 @@ public class HttpPutFormContentFilterTests { assertArrayEquals(new String[] {"value4"}, parameters.get("name4")); } + @Test // SPR-15835 + public void hiddenHttpMethodFilterFollowedByHttpPutFormContentFilter() throws Exception { + request.addParameter("_method", "PUT"); + request.addParameter("hiddenField", "testHidden"); + filter.doFilter(request, response, filterChain); + + assertArrayEquals(new String[]{"testHidden"}, filterChain.getRequest().getParameterValues("hiddenField")); + } + } diff --git a/spring-web/src/test/java/org/springframework/web/method/annotation/ExceptionHandlerMethodResolverTests.java b/spring-web/src/test/java/org/springframework/web/method/annotation/ExceptionHandlerMethodResolverTests.java index 999178f6..98032176 100644 --- a/spring-web/src/test/java/org/springframework/web/method/annotation/ExceptionHandlerMethodResolverTests.java +++ b/spring-web/src/test/java/org/springframework/web/method/annotation/ExceptionHandlerMethodResolverTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 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. @@ -88,11 +88,12 @@ public class ExceptionHandlerMethodResolverTests { new ExceptionHandlerMethodResolver(AmbiguousController.class); } - @Test(expected = IllegalArgumentException.class) + @Test(expected = IllegalStateException.class) public void noExceptionMapping() { new ExceptionHandlerMethodResolver(NoExceptionController.class); } + @Controller static class ExceptionController { @@ -111,6 +112,7 @@ public class ExceptionHandlerMethodResolverTests { } } + @Controller static class InheritedController extends ExceptionController { @@ -119,6 +121,7 @@ public class ExceptionHandlerMethodResolverTests { } } + @Controller static class AmbiguousController { @@ -136,6 +139,7 @@ public class ExceptionHandlerMethodResolverTests { } } + @Controller static class NoExceptionController { |