Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
73493bc4
S
spring-framework
项目概览
爱吃血肠
/
spring-framework
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
spring-framework
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
73493bc4
编写于
2月 20, 2017
作者:
J
Juergen Hoeller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Revised imports in tests (org.jetbrains.annotations.NotNull etc)
上级
370e3d68
变更
84
隐藏空白更改
内联
并排
Showing
84 changed file
with
646 addition
and
861 deletion
+646
-861
spring-web/src/test/java/org/springframework/http/server/reactive/bootstrap/ReactorHttpServer.java
...ork/http/server/reactive/bootstrap/ReactorHttpServer.java
+4
-6
spring-web/src/test/java/org/springframework/http/server/reactive/bootstrap/RxNettyHttpServer.java
...ork/http/server/reactive/bootstrap/RxNettyHttpServer.java
+3
-8
spring-web/src/test/java/org/springframework/web/cors/reactive/DefaultCorsProcessorTests.java
...ramework/web/cors/reactive/DefaultCorsProcessorTests.java
+4
-10
spring-web/src/test/java/org/springframework/web/server/adapter/DefaultServerWebExchangeCheckNotModifiedTests.java
...dapter/DefaultServerWebExchangeCheckNotModifiedTests.java
+4
-9
spring-web/src/test/java/org/springframework/web/server/adapter/WebHttpHandlerBuilderTests.java
...mework/web/server/adapter/WebHttpHandlerBuilderTests.java
+8
-6
spring-web/src/test/java/org/springframework/web/server/handler/ResponseStatusExceptionHandlerTests.java
...b/server/handler/ResponseStatusExceptionHandlerTests.java
+4
-6
spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultWebClient.java
...mework/web/reactive/function/client/DefaultWebClient.java
+11
-27
spring-webflux/src/test/java/org/springframework/web/reactive/DispatcherHandlerErrorTests.java
...ngframework/web/reactive/DispatcherHandlerErrorTests.java
+8
-8
spring-webflux/src/test/java/org/springframework/web/reactive/config/CorsRegistryTests.java
...pringframework/web/reactive/config/CorsRegistryTests.java
+4
-9
spring-webflux/src/test/java/org/springframework/web/reactive/config/DelegatingWebFluxConfigurationTests.java
.../reactive/config/DelegatingWebFluxConfigurationTests.java
+1
-1
spring-webflux/src/test/java/org/springframework/web/reactive/config/ResourceHandlerRegistryTests.java
...ork/web/reactive/config/ResourceHandlerRegistryTests.java
+4
-8
spring-webflux/src/test/java/org/springframework/web/reactive/config/ViewResolverRegistryTests.java
...mework/web/reactive/config/ViewResolverRegistryTests.java
+3
-2
spring-webflux/src/test/java/org/springframework/web/reactive/config/WebFluxConfigurationSupportTests.java
...web/reactive/config/WebFluxConfigurationSupportTests.java
+10
-15
spring-webflux/src/test/java/org/springframework/web/reactive/function/client/DefaultWebClientTests.java
...k/web/reactive/function/client/DefaultWebClientTests.java
+1
-1
spring-webflux/src/test/java/org/springframework/web/reactive/function/client/WebClientIntegrationTests.java
...b/reactive/function/client/WebClientIntegrationTests.java
+1
-1
spring-webflux/src/test/java/org/springframework/web/reactive/resource/CachingResourceResolverTests.java
...k/web/reactive/resource/CachingResourceResolverTests.java
+3
-3
spring-webflux/src/test/java/org/springframework/web/reactive/resource/CssLinkResourceTransformerTests.java
...eb/reactive/resource/CssLinkResourceTransformerTests.java
+2
-3
spring-webflux/src/test/java/org/springframework/web/reactive/resource/GzipResourceResolverTests.java
...work/web/reactive/resource/GzipResourceResolverTests.java
+10
-12
spring-webflux/src/test/java/org/springframework/web/reactive/resource/ResourceTransformerSupportTests.java
...eb/reactive/resource/ResourceTransformerSupportTests.java
+5
-6
spring-webflux/src/test/java/org/springframework/web/reactive/resource/ResourceUrlProviderTests.java
...ework/web/reactive/resource/ResourceUrlProviderTests.java
+6
-10
spring-webflux/src/test/java/org/springframework/web/reactive/resource/ResourceWebHandlerTests.java
...mework/web/reactive/resource/ResourceWebHandlerTests.java
+6
-12
spring-webflux/src/test/java/org/springframework/web/reactive/result/HandlerResultHandlerTests.java
...mework/web/reactive/result/HandlerResultHandlerTests.java
+9
-14
spring-webflux/src/test/java/org/springframework/web/reactive/result/condition/CompositeRequestConditionTests.java
...tive/result/condition/CompositeRequestConditionTests.java
+3
-6
spring-webflux/src/test/java/org/springframework/web/reactive/result/condition/RequestConditionHolderTests.java
...eactive/result/condition/RequestConditionHolderTests.java
+1
-1
spring-webflux/src/test/java/org/springframework/web/reactive/result/condition/RequestMappingInfoTests.java
...eb/reactive/result/condition/RequestMappingInfoTests.java
+6
-10
spring-webflux/src/test/java/org/springframework/web/reactive/result/method/HandlerMethodMappingTests.java
...web/reactive/result/method/HandlerMethodMappingTests.java
+4
-5
spring-webflux/src/test/java/org/springframework/web/reactive/result/method/InvocableHandlerMethodTests.java
...b/reactive/result/method/InvocableHandlerMethodTests.java
+1
-1
spring-webflux/src/test/java/org/springframework/web/reactive/result/method/RequestMappingInfoHandlerMappingTests.java
.../result/method/RequestMappingInfoHandlerMappingTests.java
+17
-22
spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/BindingContextFactoryTests.java
.../result/method/annotation/BindingContextFactoryTests.java
+2
-2
spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/ContextPathIntegrationTests.java
...result/method/annotation/ContextPathIntegrationTests.java
+6
-6
spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/CookieValueMethodArgumentResolverTests.java
...od/annotation/CookieValueMethodArgumentResolverTests.java
+8
-10
spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/ErrorsArgumentResolverTests.java
...result/method/annotation/ErrorsArgumentResolverTests.java
+4
-8
spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/ExpressionValueMethodArgumentResolverTests.java
...nnotation/ExpressionValueMethodArgumentResolverTests.java
+3
-5
spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/HttpEntityArgumentResolverTests.java
...lt/method/annotation/HttpEntityArgumentResolverTests.java
+4
-18
spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/InitBinderBindingContextTests.java
...sult/method/annotation/InitBinderBindingContextTests.java
+6
-13
spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/MessageReaderArgumentResolverTests.java
...method/annotation/MessageReaderArgumentResolverTests.java
+4
-10
spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/MessageWriterResultHandlerTests.java
...lt/method/annotation/MessageWriterResultHandlerTests.java
+7
-3
spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/ModelAttributeMethodArgumentResolverTests.java
...annotation/ModelAttributeMethodArgumentResolverTests.java
+19
-22
spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/PathVariableMapMethodArgumentResolverTests.java
...nnotation/PathVariableMapMethodArgumentResolverTests.java
+2
-2
spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/PathVariableMethodArgumentResolverTests.java
...d/annotation/PathVariableMethodArgumentResolverTests.java
+2
-2
spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestAttributeMethodArgumentResolverTests.java
...notation/RequestAttributeMethodArgumentResolverTests.java
+3
-9
spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestBodyArgumentResolverTests.java
...t/method/annotation/RequestBodyArgumentResolverTests.java
+9
-15
spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestHeaderMapMethodArgumentResolverTests.java
...notation/RequestHeaderMapMethodArgumentResolverTests.java
+14
-19
spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestHeaderMethodArgumentResolverTests.java
.../annotation/RequestHeaderMethodArgumentResolverTests.java
+15
-20
spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestMappingHandlerMappingTests.java
.../method/annotation/RequestMappingHandlerMappingTests.java
+6
-10
spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestParamMapMethodArgumentResolverTests.java
...nnotation/RequestParamMapMethodArgumentResolverTests.java
+2
-3
spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestParamMethodArgumentResolverTests.java
...d/annotation/RequestParamMethodArgumentResolverTests.java
+4
-8
spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/ResponseBodyResultHandlerTests.java
...ult/method/annotation/ResponseBodyResultHandlerTests.java
+16
-43
spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/ResponseEntityResultHandlerTests.java
...t/method/annotation/ResponseEntityResultHandlerTests.java
+5
-10
spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/ServerWebExchangeArgumentResolverTests.java
...od/annotation/ServerWebExchangeArgumentResolverTests.java
+9
-9
spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/SessionAttributeMethodArgumentResolverTests.java
...notation/SessionAttributeMethodArgumentResolverTests.java
+6
-11
spring-webflux/src/test/java/org/springframework/web/reactive/result/view/RedirectViewTests.java
...framework/web/reactive/result/view/RedirectViewTests.java
+3
-4
spring-webflux/src/test/java/org/springframework/web/reactive/result/view/UrlBasedViewResolverTests.java
...k/web/reactive/result/view/UrlBasedViewResolverTests.java
+6
-4
spring-webflux/src/test/java/org/springframework/web/reactive/result/view/ViewResolutionResultHandlerTests.java
...eactive/result/view/ViewResolutionResultHandlerTests.java
+10
-10
spring-webflux/src/test/java/org/springframework/web/reactive/result/view/freemarker/FreeMarkerViewTests.java
.../reactive/result/view/freemarker/FreeMarkerViewTests.java
+3
-7
spring-webflux/src/test/java/org/springframework/web/reactive/socket/AbstractWebSocketIntegrationTests.java
...eb/reactive/socket/AbstractWebSocketIntegrationTests.java
+21
-18
spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/WebContentInterceptorTests.java
...framework/web/servlet/mvc/WebContentInterceptorTests.java
+11
-21
spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/RequestMappingInfoHandlerMappingTests.java
...let/mvc/method/RequestMappingInfoHandlerMappingTests.java
+2
-2
spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/AbstractRequestAttributesArgumentResolverTests.java
...ation/AbstractRequestAttributesArgumentResolverTests.java
+4
-2
spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/CrossOriginTests.java
...k/web/servlet/mvc/method/annotation/CrossOriginTests.java
+4
-2
spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/DeferredResultReturnValueHandlerTests.java
...hod/annotation/DeferredResultReturnValueHandlerTests.java
+3
-4
spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/HttpEntityMethodProcessorMockTests.java
...method/annotation/HttpEntityMethodProcessorMockTests.java
+13
-11
spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/HttpEntityMethodProcessorTests.java
...mvc/method/annotation/HttpEntityMethodProcessorTests.java
+12
-13
spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/MatrixVariablesMapMethodArgumentResolverTests.java
...tation/MatrixVariablesMapMethodArgumentResolverTests.java
+15
-15
spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/MatrixVariablesMethodArgumentResolverTests.java
...nnotation/MatrixVariablesMethodArgumentResolverTests.java
+12
-18
spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ModelAndViewMethodReturnValueHandlerTests.java
...annotation/ModelAndViewMethodReturnValueHandlerTests.java
+2
-2
spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ModelAndViewResolverMethodReturnValueHandlerTests.java
...on/ModelAndViewResolverMethodReturnValueHandlerTests.java
+3
-3
spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/MvcUriComponentsBuilderTests.java
...t/mvc/method/annotation/MvcUriComponentsBuilderTests.java
+25
-15
spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/PathVariableMapMethodArgumentResolverTests.java
...nnotation/PathVariableMapMethodArgumentResolverTests.java
+12
-13
spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/PathVariableMethodArgumentResolverTests.java
...d/annotation/PathVariableMethodArgumentResolverTests.java
+10
-14
spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/RequestPartIntegrationTests.java
...et/mvc/method/annotation/RequestPartIntegrationTests.java
+2
-2
spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/RequestPartMethodArgumentResolverTests.java
...od/annotation/RequestPartMethodArgumentResolverTests.java
+24
-25
spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/RequestResponseBodyMethodProcessorMockTests.java
...notation/RequestResponseBodyMethodProcessorMockTests.java
+19
-20
spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/RequestResponseBodyMethodProcessorTests.java
...d/annotation/RequestResponseBodyMethodProcessorTests.java
+19
-22
spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ResponseBodyEmitterReturnValueHandlerTests.java
...nnotation/ResponseBodyEmitterReturnValueHandlerTests.java
+10
-10
spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ServletCookieValueMethodArgumentResolverTests.java
...tation/ServletCookieValueMethodArgumentResolverTests.java
+7
-9
spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ServletModelAttributeMethodProcessorTests.java
...annotation/ServletModelAttributeMethodProcessorTests.java
+55
-71
spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ServletResponseMethodArgumentResolverTests.java
...nnotation/ServletResponseMethodArgumentResolverTests.java
+7
-6
spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/StreamingResponseBodyReturnValueHandlerTests.java
...otation/StreamingResponseBodyReturnValueHandlerTests.java
+1
-1
spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/UriComponentsBuilderMethodArgumentResolverTests.java
...tion/UriComponentsBuilderMethodArgumentResolverTests.java
+10
-9
spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ViewMethodReturnValueHandlerTests.java
.../method/annotation/ViewMethodReturnValueHandlerTests.java
+5
-2
spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ViewNameMethodReturnValueHandlerTests.java
...hod/annotation/ViewNameMethodReturnValueHandlerTests.java
+5
-3
spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/support/DefaultHandlerExceptionResolverTests.java
...let/mvc/support/DefaultHandlerExceptionResolverTests.java
+8
-10
spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/support/ParameterizableViewControllerTests.java
...rvlet/mvc/support/ParameterizableViewControllerTests.java
+4
-13
未找到文件。
spring-web/src/test/java/org/springframework/http/server/reactive/bootstrap/ReactorHttpServer.java
浏览文件 @
73493bc4
/*
* Copyright
(c) 2011-2016 Pivotal Software Inc, All Rights Reserved
.
* 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.
* You may obtain a copy of the License at
*
*
http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
...
...
@@ -18,7 +18,6 @@ package org.springframework.http.server.reactive.bootstrap;
import
java.util.concurrent.atomic.AtomicReference
;
import
org.jetbrains.annotations.NotNull
;
import
reactor.core.Loopback
;
import
reactor.ipc.netty.NettyContext
;
...
...
@@ -42,11 +41,10 @@ public class ReactorHttpServer extends AbstractHttpServer implements Loopback {
this
.
reactorServer
=
reactor
.
ipc
.
netty
.
http
.
server
.
HttpServer
.
create
(
getHost
(),
getPort
());
}
@NotNull
private
ReactorHttpHandlerAdapter
createHttpHandlerAdapter
()
{
return
getHttpHandlerMap
()
!=
null
?
return
(
getHttpHandlerMap
()
!=
null
?
new
ReactorHttpHandlerAdapter
(
getHttpHandlerMap
())
:
new
ReactorHttpHandlerAdapter
(
getHttpHandler
());
new
ReactorHttpHandlerAdapter
(
getHttpHandler
())
)
;
}
@Override
...
...
spring-web/src/test/java/org/springframework/http/server/reactive/bootstrap/RxNettyHttpServer.java
浏览文件 @
73493bc4
/*
* Copyright 2002-201
6
the original author or authors.
* Copyright 2002-201
7
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.
...
...
@@ -16,14 +16,10 @@
package
org.springframework.http.server.reactive.bootstrap
;
import
java.net.InetSocketAddress
;
import
io.netty.buffer.ByteBuf
;
import
org.jetbrains.annotations.NotNull
;
import
org.springframework.http.server.reactive.RxNettyHttpHandlerAdapter
;
/**
* @author Rossen Stoyanchev
*/
...
...
@@ -40,11 +36,10 @@ public class RxNettyHttpServer extends AbstractHttpServer {
this
.
rxNettyServer
=
io
.
reactivex
.
netty
.
protocol
.
http
.
server
.
HttpServer
.
newServer
(
getPort
());
}
@NotNull
private
RxNettyHttpHandlerAdapter
createHttpHandlerAdapter
()
{
return
getHttpHandlerMap
()
!=
null
?
return
(
getHttpHandlerMap
()
!=
null
?
new
RxNettyHttpHandlerAdapter
(
getHttpHandlerMap
())
:
new
RxNettyHttpHandlerAdapter
(
getHttpHandler
());
new
RxNettyHttpHandlerAdapter
(
getHttpHandler
())
)
;
}
...
...
spring-web/src/test/java/org/springframework/web/cors/reactive/DefaultCorsProcessorTests.java
浏览文件 @
73493bc4
/*
* Copyright 2002-201
6
the original author or authors.
* Copyright 2002-201
7
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.
...
...
@@ -16,7 +16,6 @@
package
org.springframework.web.cors.reactive
;
import
org.jetbrains.annotations.NotNull
;
import
org.junit.Before
;
import
org.junit.Test
;
...
...
@@ -28,13 +27,8 @@ import org.springframework.mock.http.server.reactive.test.MockServerHttpResponse
import
org.springframework.web.cors.CorsConfiguration
;
import
org.springframework.web.server.adapter.DefaultServerWebExchange
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertFalse
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
springframework
.
http
.
HttpHeaders
.
ACCESS_CONTROL_ALLOW_HEADERS
;
import
static
org
.
springframework
.
http
.
HttpHeaders
.
ACCESS_CONTROL_ALLOW_ORIGIN
;
import
static
org
.
springframework
.
http
.
HttpHeaders
.
ACCESS_CONTROL_REQUEST_HEADERS
;
import
static
org
.
springframework
.
http
.
HttpHeaders
.
ACCESS_CONTROL_REQUEST_METHOD
;
import
static
org
.
junit
.
Assert
.*;
import
static
org
.
springframework
.
http
.
HttpHeaders
.*;
/**
* {@link DefaultCorsProcessor} tests with simple or pre-flight CORS request.
...
...
@@ -329,6 +323,7 @@ public class DefaultCorsProcessorTests {
assertEquals
(
HttpStatus
.
FORBIDDEN
,
this
.
response
.
getStatusCode
());
}
private
MockServerHttpRequest
.
BaseBuilder
<?>
actualRequest
()
{
return
corsRequest
(
HttpMethod
.
GET
);
}
...
...
@@ -343,7 +338,6 @@ public class DefaultCorsProcessorTests {
.
header
(
HttpHeaders
.
ORIGIN
,
"http://domain2.com"
);
}
@NotNull
private
DefaultServerWebExchange
createExchange
()
{
return
new
DefaultServerWebExchange
(
this
.
request
,
this
.
response
);
}
...
...
spring-web/src/test/java/org/springframework/web/server/adapter/DefaultServerWebExchangeCheckNotModifiedTests.java
浏览文件 @
73493bc4
/*
* Copyright 2002-201
6
the original author or authors.
* Copyright 2002-201
7
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.
...
...
@@ -24,7 +24,6 @@ import java.util.Arrays;
import
java.util.Locale
;
import
java.util.TimeZone
;
import
org.jetbrains.annotations.NotNull
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
...
...
@@ -37,10 +36,7 @@ import org.springframework.http.HttpStatus;
import
org.springframework.mock.http.server.reactive.test.MockServerHttpRequest
;
import
org.springframework.mock.http.server.reactive.test.MockServerHttpResponse
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertFalse
;
import
static
org
.
junit
.
Assert
.
assertNull
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
junit
.
Assert
.*;
/**
* "checkNotModified" unit tests for {@link DefaultServerWebExchange}.
...
...
@@ -74,7 +70,7 @@ public class DefaultServerWebExchangeCheckNotModifiedTests {
@Before
public
void
set
U
p
()
throws
URISyntaxException
{
public
void
set
u
p
()
throws
URISyntaxException
{
this
.
currentDate
=
Instant
.
now
().
truncatedTo
(
ChronoUnit
.
SECONDS
);
this
.
dateFormat
=
new
SimpleDateFormat
(
"EEE, dd MMM yyyy HH:mm:ss z"
,
Locale
.
US
);
this
.
dateFormat
.
setTimeZone
(
TimeZone
.
getTimeZone
(
"GMT"
));
...
...
@@ -319,12 +315,11 @@ public class DefaultServerWebExchangeCheckNotModifiedTests {
assertEquals
(-
1
,
response
.
getHeaders
().
getLastModified
());
}
@NotNull
private
MockServerHttpRequest
.
BaseBuilder
<?>
request
()
{
return
MockServerHttpRequest
.
get
(
"http://example.org"
);
}
@NotNull
private
DefaultServerWebExchange
createExchange
()
{
return
new
DefaultServerWebExchange
(
this
.
request
,
this
.
response
);
}
...
...
spring-web/src/test/java/org/springframework/web/server/adapter/WebHttpHandlerBuilderTests.java
浏览文件 @
73493bc4
...
...
@@ -13,11 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.springframework.web.server.adapter
;
import
java.nio.charset.StandardCharsets
;
import
org.jetbrains.annotations.NotNull
;
import
org.junit.Test
;
import
reactor.core.publisher.Flux
;
import
reactor.core.publisher.Mono
;
...
...
@@ -36,16 +36,16 @@ import org.springframework.web.server.WebExceptionHandler;
import
org.springframework.web.server.WebFilter
;
import
org.springframework.web.server.WebHandler
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
*
;
/**
* Unit tests for {@link WebHttpHandlerBuilder}.
*
* @author Rossen Stoyanchev
*/
public
class
WebHttpHandlerBuilderTests
{
@Test
// SPR-15074
@Test
// SPR-15074
public
void
orderedWebFilterBeans
()
throws
Exception
{
AnnotationConfigApplicationContext
context
=
new
AnnotationConfigApplicationContext
();
context
.
register
(
OrderedWebFilterBeanConfig
.
class
);
...
...
@@ -60,7 +60,7 @@ public class WebHttpHandlerBuilderTests {
assertEquals
(
"FilterB::FilterA"
,
response
.
getBodyAsString
().
blockMillis
(
5000
));
}
@Test
// SPR-15074
@Test
// SPR-15074
public
void
orderedWebExceptionHandlerBeans
()
throws
Exception
{
AnnotationConfigApplicationContext
context
=
new
AnnotationConfigApplicationContext
();
context
.
register
(
OrderedExceptionHandlerBeanConfig
.
class
);
...
...
@@ -90,6 +90,7 @@ public class WebHttpHandlerBuilderTests {
assertEquals
(
"handled"
,
response
.
getBodyAsString
().
blockMillis
(
5000
));
}
private
static
Mono
<
Void
>
writeToResponse
(
ServerWebExchange
exchange
,
String
value
)
{
byte
[]
bytes
=
value
.
getBytes
(
StandardCharsets
.
UTF_8
);
DataBuffer
buffer
=
new
DefaultDataBufferFactory
().
wrap
(
bytes
);
...
...
@@ -113,7 +114,6 @@ public class WebHttpHandlerBuilderTests {
return
createFilter
(
"FilterB"
);
}
@NotNull
private
WebFilter
createFilter
(
String
name
)
{
return
(
exchange
,
chain
)
->
{
String
value
=
exchange
.
getAttribute
(
ATTRIBUTE
).
map
(
v
->
v
+
"::"
+
name
).
orElse
(
name
);
...
...
@@ -131,6 +131,7 @@ public class WebHttpHandlerBuilderTests {
}
}
@Configuration
@SuppressWarnings
(
"unused"
)
static
class
OrderedExceptionHandlerBeanConfig
{
...
...
@@ -153,6 +154,7 @@ public class WebHttpHandlerBuilderTests {
}
}
@Configuration
@SuppressWarnings
(
"unused"
)
static
class
NoFilterConfig
{
...
...
spring-web/src/test/java/org/springframework/web/server/handler/ResponseStatusExceptionHandlerTests.java
浏览文件 @
73493bc4
/*
* Copyright 2002-201
6
the original author or authors.
* Copyright 2002-201
7
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.server.handler;
import
java.time.Duration
;
import
org.jetbrains.annotations.NotNull
;
import
org.junit.Before
;
import
org.junit.Test
;
import
reactor.core.publisher.Mono
;
...
...
@@ -30,8 +29,7 @@ import org.springframework.mock.http.server.reactive.test.MockServerHttpResponse
import
org.springframework.web.server.ResponseStatusException
;
import
org.springframework.web.server.adapter.DefaultServerWebExchange
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertSame
;
import
static
org
.
junit
.
Assert
.*;
/**
* Unit tests for {@link ResponseStatusExceptionHandler}.
...
...
@@ -48,7 +46,7 @@ public class ResponseStatusExceptionHandlerTests {
@Before
public
void
set
U
p
()
throws
Exception
{
public
void
set
u
p
()
throws
Exception
{
this
.
handler
=
new
ResponseStatusExceptionHandler
();
this
.
request
=
MockServerHttpRequest
.
get
(
"/"
).
build
();
this
.
response
=
new
MockServerHttpResponse
();
...
...
@@ -69,7 +67,7 @@ public class ResponseStatusExceptionHandlerTests {
StepVerifier
.
create
(
mono
).
consumeErrorWith
(
actual
->
assertSame
(
expected
,
actual
)).
verify
();
}
@NotNull
private
DefaultServerWebExchange
createExchange
()
{
return
new
DefaultServerWebExchange
(
this
.
request
,
this
.
response
);
}
...
...
spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultWebClient.java
浏览文件 @
73493bc4
...
...
@@ -25,7 +25,6 @@ import java.util.Arrays;
import
java.util.Map
;
import
java.util.function.Function
;
import
org.jetbrains.annotations.NotNull
;
import
org.reactivestreams.Publisher
;
import
reactor.core.publisher.Mono
;
...
...
@@ -41,7 +40,6 @@ import org.springframework.web.util.DefaultUriBuilderFactory;
import
org.springframework.web.util.UriBuilder
;
import
org.springframework.web.util.UriBuilderFactory
;
/**
* Default implementation of {@link WebClient}.
*
...
...
@@ -64,21 +62,10 @@ class DefaultWebClient implements WebClient {
this
.
exchangeFunction
=
exchangeFunction
;
this
.
uriBuilderFactory
=
(
factory
!=
null
?
factory
:
new
DefaultUriBuilderFactory
());
this
.
defaultHeaders
=
defaultHeaders
!=
null
?
HttpHeaders
.
readOnlyHttpHeaders
(
defaultHeaders
)
:
null
;
this
.
defaultCookies
=
defaultCookies
!=
null
?
CollectionUtils
.
unmodifiableMultiValueMap
(
defaultCookies
)
:
null
;
}
private
ExchangeFunction
getExchangeFunction
()
{
return
this
.
exchangeFunction
;
}
private
UriBuilderFactory
getUriBuilderFactory
()
{
return
this
.
uriBuilderFactory
;
this
.
defaultHeaders
=
(
defaultHeaders
!=
null
?
HttpHeaders
.
readOnlyHttpHeaders
(
defaultHeaders
)
:
null
);
this
.
defaultCookies
=
(
defaultCookies
!=
null
?
CollectionUtils
.
unmodifiableMultiValueMap
(
defaultCookies
)
:
null
);
}
...
...
@@ -117,12 +104,10 @@ class DefaultWebClient implements WebClient {
return
method
(
HttpMethod
.
OPTIONS
);
}
@NotNull
private
UriSpec
method
(
HttpMethod
httpMethod
)
{
return
new
DefaultUriSpec
(
httpMethod
);
}
@Override
public
WebClient
filter
(
ExchangeFilterFunction
filterFunction
)
{
ExchangeFunction
filteredExchangeFunction
=
this
.
exchangeFunction
.
filter
(
filterFunction
);
...
...
@@ -142,17 +127,17 @@ class DefaultWebClient implements WebClient {
@Override
public
HeaderSpec
uri
(
String
uriTemplate
,
Object
...
uriVariables
)
{
return
uri
(
getUriBuilderFactory
()
.
expand
(
uriTemplate
,
uriVariables
));
return
uri
(
uriBuilderFactory
.
expand
(
uriTemplate
,
uriVariables
));
}
@Override
public
HeaderSpec
uri
(
String
uriTemplate
,
Map
<
String
,
?>
uriVariables
)
{
return
uri
(
getUriBuilderFactory
()
.
expand
(
uriTemplate
,
uriVariables
));
return
uri
(
uriBuilderFactory
.
expand
(
uriTemplate
,
uriVariables
));
}
@Override
public
HeaderSpec
uri
(
Function
<
UriBuilder
,
URI
>
uriFunction
)
{
return
uri
(
uriFunction
.
apply
(
getUriBuilderFactory
()
.
builder
()));
return
uri
(
uriFunction
.
apply
(
uriBuilderFactory
.
builder
()));
}
@Override
...
...
@@ -161,6 +146,7 @@ class DefaultWebClient implements WebClient {
}
}
private
class
DefaultHeaderSpec
implements
HeaderSpec
{
private
final
HttpMethod
httpMethod
;
...
...
@@ -171,13 +157,11 @@ class DefaultWebClient implements WebClient {
private
MultiValueMap
<
String
,
String
>
cookies
;
DefaultHeaderSpec
(
HttpMethod
httpMethod
,
URI
uri
)
{
this
.
httpMethod
=
httpMethod
;
this
.
uri
=
uri
;
}
private
HttpHeaders
getHeaders
()
{
if
(
this
.
headers
==
null
)
{
this
.
headers
=
new
HttpHeaders
();
...
...
@@ -263,19 +247,19 @@ class DefaultWebClient implements WebClient {
@Override
public
Mono
<
ClientResponse
>
exchange
()
{
ClientRequest
request
=
this
.
initRequestBuilder
().
build
();
return
getExchangeFunction
()
.
exchange
(
request
);
return
exchangeFunction
.
exchange
(
request
);
}
@Override
public
<
T
>
Mono
<
ClientResponse
>
exchange
(
BodyInserter
<
T
,
?
super
ClientHttpRequest
>
inserter
)
{
ClientRequest
request
=
this
.
initRequestBuilder
().
body
(
inserter
).
build
();
return
getExchangeFunction
()
.
exchange
(
request
);
return
exchangeFunction
.
exchange
(
request
);
}
@Override
public
<
T
,
S
extends
Publisher
<
T
>>
Mono
<
ClientResponse
>
exchange
(
S
publisher
,
Class
<
T
>
elementClass
)
{
ClientRequest
request
=
initRequestBuilder
().
headers
(
this
.
headers
).
body
(
publisher
,
elementClass
).
build
();
return
getExchangeFunction
()
.
exchange
(
request
);
return
exchangeFunction
.
exchange
(
request
);
}
private
ClientRequest
.
Builder
initRequestBuilder
()
{
...
...
spring-webflux/src/test/java/org/springframework/web/reactive/DispatcherHandlerErrorTests.java
浏览文件 @
73493bc4
/*
* Copyright 2002-201
6
the original author or authors.
* Copyright 2002-201
7
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.
...
...
@@ -19,7 +19,6 @@ package org.springframework.web.reactive;
import
java.time.Duration
;
import
java.util.Collections
;
import
org.jetbrains.annotations.NotNull
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.reactivestreams.Publisher
;
...
...
@@ -54,10 +53,8 @@ import org.springframework.web.server.handler.ExceptionHandlingWebHandler;
import
static
org
.
hamcrest
.
CoreMatchers
.
instanceOf
;
import
static
org
.
hamcrest
.
CoreMatchers
.
startsWith
;
import
static
org
.
hamcrest
.
Matchers
.
is
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertSame
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
springframework
.
http
.
MediaType
.
APPLICATION_JSON
;
import
static
org
.
junit
.
Assert
.*;
import
static
org
.
springframework
.
http
.
MediaType
.*;
/**
...
...
@@ -78,7 +75,7 @@ public class DispatcherHandlerErrorTests {
@Before
public
void
set
U
p
()
throws
Exception
{
public
void
set
u
p
()
throws
Exception
{
AnnotationConfigApplicationContext
appContext
=
new
AnnotationConfigApplicationContext
();
appContext
.
register
(
TestConfig
.
class
);
appContext
.
refresh
();
...
...
@@ -168,7 +165,7 @@ public class DispatcherHandlerErrorTests {
assertEquals
(
HttpStatus
.
INTERNAL_SERVER_ERROR
,
exchange
.
getResponse
().
getStatusCode
());
}
@NotNull
private
ServerWebExchange
createExchange
()
{
return
new
DefaultServerWebExchange
(
this
.
request
,
new
MockServerHttpResponse
());
}
...
...
@@ -201,6 +198,7 @@ public class DispatcherHandlerErrorTests {
}
}
@Controller
@SuppressWarnings
(
"unused"
)
private
static
class
TestController
{
...
...
@@ -228,9 +226,11 @@ public class DispatcherHandlerErrorTests {
}
}
private
static
class
Foo
{
}
private
static
class
ServerError500ExceptionHandler
implements
WebExceptionHandler
{
@Override
...
...
spring-webflux/src/test/java/org/springframework/web/reactive/config/CorsRegistryTests.java
浏览文件 @
73493bc4
/*
* Copyright 2002-201
5
the original author or authors.
* Copyright 2002-201
7
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.
...
...
@@ -19,13 +19,12 @@ package org.springframework.web.reactive.config;
import
java.util.Arrays
;
import
java.util.Map
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.springframework.web.cors.CorsConfiguration
;
import
static
org
.
junit
.
Assert
.*;
/**
* Test fixture with a {@link CorsRegistry}.
*
...
...
@@ -33,12 +32,8 @@ import org.springframework.web.cors.CorsConfiguration;
*/
public
class
CorsRegistryTests
{
private
CorsRegistry
registry
;
private
final
CorsRegistry
registry
=
new
CorsRegistry
()
;
@Before
public
void
setUp
()
{
this
.
registry
=
new
CorsRegistry
();
}
@Test
public
void
noMapping
()
{
...
...
spring-webflux/src/test/java/org/springframework/web/reactive/config/DelegatingWebFluxConfigurationTests.java
浏览文件 @
73493bc4
...
...
@@ -68,7 +68,7 @@ public class DelegatingWebFluxConfigurationTests {
@Before
public
void
set
U
p
()
{
public
void
set
u
p
()
{
MockitoAnnotations
.
initMocks
(
this
);
delegatingConfig
=
new
DelegatingWebFluxConfiguration
();
delegatingConfig
.
setApplicationContext
(
new
StaticApplicationContext
());
...
...
spring-webflux/src/test/java/org/springframework/web/reactive/config/ResourceHandlerRegistryTests.java
浏览文件 @
73493bc4
...
...
@@ -47,11 +47,7 @@ import org.springframework.web.reactive.resource.WebJarsResourceResolver;
import
org.springframework.web.server.ServerWebExchange
;
import
org.springframework.web.server.adapter.DefaultServerWebExchange
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertFalse
;
import
static
org
.
junit
.
Assert
.
assertNull
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
junit
.
Assert
.*;
/**
* Unit tests for {@link ResourceHandlerRegistry}.
...
...
@@ -70,7 +66,7 @@ public class ResourceHandlerRegistryTests {
@Before
public
void
set
U
p
()
{
public
void
set
u
p
()
{
this
.
registry
=
new
ResourceHandlerRegistry
(
new
GenericApplicationContext
());
this
.
registration
=
this
.
registry
.
addResourceHandler
(
"/resources/**"
);
this
.
registration
.
addResourceLocations
(
"classpath:org/springframework/web/reactive/config/"
);
...
...
@@ -104,8 +100,7 @@ public class ResourceHandlerRegistryTests {
@Test
public
void
cacheControl
()
{
assertThat
(
getHandler
(
"/resources/**"
).
getCacheControl
(),
Matchers
.
nullValue
());
assertThat
(
getHandler
(
"/resources/**"
).
getCacheControl
(),
Matchers
.
nullValue
());
this
.
registration
.
setCacheControl
(
CacheControl
.
noCache
().
cachePrivate
());
assertThat
(
getHandler
(
"/resources/**"
).
getCacheControl
().
getHeaderValue
(),
...
...
@@ -221,6 +216,7 @@ public class ResourceHandlerRegistryTests {
assertThat
(
transformers
.
get
(
2
),
Matchers
.
sameInstance
(
cssLinkTransformer
));
}
private
ResourceWebHandler
getHandler
(
String
pathPattern
)
{
SimpleUrlHandlerMapping
mapping
=
(
SimpleUrlHandlerMapping
)
this
.
registry
.
getHandlerMapping
();
return
(
ResourceWebHandler
)
mapping
.
getUrlMap
().
get
(
pathPattern
);
...
...
spring-webflux/src/test/java/org/springframework/web/reactive/config/ViewResolverRegistryTests.java
浏览文件 @
73493bc4
/*
* Copyright 2002-201
6
the original author or authors.
* Copyright 2002-201
7
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.
...
...
@@ -39,12 +39,13 @@ public class ViewResolverRegistryTests {
@Before
public
void
set
U
p
()
{
public
void
set
u
p
()
{
StaticWebApplicationContext
context
=
new
StaticWebApplicationContext
();
context
.
registerSingleton
(
"freeMarkerConfigurer"
,
FreeMarkerConfigurer
.
class
);
this
.
registry
=
new
ViewResolverRegistry
(
context
);
}
@Test
public
void
order
()
{
assertEquals
(
Ordered
.
LOWEST_PRECEDENCE
,
this
.
registry
.
getOrder
());
...
...
spring-webflux/src/test/java/org/springframework/web/reactive/config/WebFluxConfigurationSupportTests.java
浏览文件 @
73493bc4
...
...
@@ -21,7 +21,6 @@ import java.util.Collections;
import
java.util.List
;
import
javax.xml.bind.annotation.XmlRootElement
;
import
org.jetbrains.annotations.NotNull
;
import
org.junit.Before
;
import
org.junit.Test
;
...
...
@@ -66,16 +65,8 @@ import org.springframework.web.reactive.result.view.freemarker.FreeMarkerViewRes
import
org.springframework.web.server.WebHandler
;
import
org.springframework.web.server.adapter.DefaultServerWebExchange
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertFalse
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
junit
.
Assert
.
assertSame
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
springframework
.
http
.
MediaType
.
APPLICATION_JSON
;
import
static
org
.
springframework
.
http
.
MediaType
.
APPLICATION_OCTET_STREAM
;
import
static
org
.
springframework
.
http
.
MediaType
.
APPLICATION_XML
;
import
static
org
.
springframework
.
http
.
MediaType
.
IMAGE_PNG
;
import
static
org
.
springframework
.
http
.
MediaType
.
TEXT_PLAIN
;
import
static
org
.
junit
.
Assert
.*;
import
static
org
.
springframework
.
http
.
MediaType
.*;
/**
* Unit tests for {@link WebFluxConfigurationSupport}.
...
...
@@ -87,7 +78,7 @@ public class WebFluxConfigurationSupportTests {
@Before
public
void
set
U
p
()
throws
Exception
{
public
void
set
u
p
()
throws
Exception
{
this
.
request
=
MockServerHttpRequest
.
get
(
"/"
).
build
();
}
...
...
@@ -269,12 +260,11 @@ public class WebFluxConfigurationSupportTests {
assertNotNull
(
webHandler
);
}
@NotNull
private
DefaultServerWebExchange
createExchange
()
{
return
new
DefaultServerWebExchange
(
this
.
request
,
new
MockServerHttpResponse
());
}
private
void
assertHasMessageReader
(
List
<
HttpMessageReader
<?>>
readers
,
Class
<?>
clazz
,
MediaType
mediaType
)
{
ResolvableType
type
=
ResolvableType
.
forClass
(
clazz
);
assertTrue
(
readers
.
stream
()
...
...
@@ -298,10 +288,12 @@ public class WebFluxConfigurationSupportTests {
return
context
;
}
@EnableWebFlux
static
class
WebFluxConfig
{
}
@Configuration
static
class
CustomPatchMatchConfig
extends
WebFluxConfigurationSupport
{
...
...
@@ -312,6 +304,7 @@ public class WebFluxConfigurationSupportTests {
}
}
@Configuration
static
class
CustomMessageConverterConfig
extends
WebFluxConfigurationSupport
{
...
...
@@ -336,6 +329,7 @@ public class WebFluxConfigurationSupportTests {
}
}
@Configuration
@SuppressWarnings
(
"unused"
)
static
class
CustomViewResolverConfig
extends
WebFluxConfigurationSupport
{
...
...
@@ -350,9 +344,9 @@ public class WebFluxConfigurationSupportTests {
public
FreeMarkerConfigurer
freeMarkerConfig
()
{
return
new
FreeMarkerConfigurer
();
}
}
@Configuration
static
class
CustomResourceHandlingConfig
extends
WebFluxConfigurationSupport
{
...
...
@@ -366,4 +360,5 @@ public class WebFluxConfigurationSupportTests {
@XmlRootElement
static
class
TestBean
{
}
}
spring-webflux/src/test/java/org/springframework/web/reactive/function/client/DefaultWebClientTests.java
浏览文件 @
73493bc4
...
...
@@ -47,7 +47,7 @@ public class DefaultWebClientTests {
@Before
public
void
set
U
p
()
throws
Exception
{
public
void
set
u
p
()
throws
Exception
{
MockitoAnnotations
.
initMocks
(
this
);
this
.
exchangeFunction
=
mock
(
ExchangeFunction
.
class
);
when
(
this
.
exchangeFunction
.
exchange
(
captor
.
capture
())).
thenReturn
(
Mono
.
empty
());
...
...
spring-webflux/src/test/java/org/springframework/web/reactive/function/client/WebClientIntegrationTests.java
浏览文件 @
73493bc4
...
...
@@ -60,7 +60,7 @@ public class WebClientIntegrationTests {
}
@After
public
void
tearD
own
()
throws
Exception
{
public
void
shutd
own
()
throws
Exception
{
this
.
server
.
shutdown
();
}
...
...
spring-webflux/src/test/java/org/springframework/web/reactive/resource/CachingResourceResolverTests.java
浏览文件 @
73493bc4
/*
* Copyright 2002-201
6
the original author or authors.
* Copyright 2002-201
7
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.
...
...
@@ -19,7 +19,6 @@ package org.springframework.web.reactive.resource;
import
java.util.ArrayList
;
import
java.util.List
;
import
org.jetbrains.annotations.NotNull
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.mockito.Mockito
;
...
...
@@ -38,6 +37,7 @@ import static org.junit.Assert.assertSame;
/**
* Unit tests for {@link CachingResourceResolver}.
*
* @author Rossen Stoyanchev
*/
public
class
CachingResourceResolverTests
{
...
...
@@ -153,7 +153,7 @@ public class CachingResourceResolverTests {
assertSame
(
gzResource
,
this
.
chain
.
resolveResource
(
createExchange
(),
file
,
this
.
locations
).
blockMillis
(
5000
));
}
@NotNull
private
DefaultServerWebExchange
createExchange
()
{
return
new
DefaultServerWebExchange
(
this
.
request
,
new
MockServerHttpResponse
());
}
...
...
spring-webflux/src/test/java/org/springframework/web/reactive/resource/CssLinkResourceTransformerTests.java
浏览文件 @
73493bc4
...
...
@@ -40,8 +40,7 @@ import org.springframework.util.StringUtils;
import
org.springframework.web.server.ServerWebExchange
;
import
org.springframework.web.server.adapter.DefaultServerWebExchange
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertSame
;
import
static
org
.
junit
.
Assert
.*;
/**
* Unit tests for {@link CssLinkResourceTransformer}.
...
...
@@ -53,7 +52,7 @@ public class CssLinkResourceTransformerTests {
@Before
public
void
set
U
p
()
{
public
void
set
u
p
()
{
ClassPathResource
allowedLocation
=
new
ClassPathResource
(
"test/"
,
getClass
());
ResourceWebHandler
resourceHandler
=
new
ResourceWebHandler
();
...
...
spring-webflux/src/test/java/org/springframework/web/reactive/resource/GzipResourceResolverTests.java
浏览文件 @
73493bc4
/*
* Copyright 2002-201
6
the original author or authors.
* Copyright 2002-201
7
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.
...
...
@@ -28,7 +28,6 @@ import java.util.List;
import
java.util.Map
;
import
java.util.zip.GZIPOutputStream
;
import
org.jetbrains.annotations.NotNull
;
import
org.junit.Before
;
import
org.junit.BeforeClass
;
import
org.junit.Test
;
...
...
@@ -43,13 +42,12 @@ import org.springframework.mock.http.server.reactive.test.MockServerHttpResponse
import
org.springframework.util.FileCopyUtils
;
import
org.springframework.web.server.adapter.DefaultServerWebExchange
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertFalse
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
junit
.
Assert
.*;
/**
* Unit tests for {@link GzipResourceResolver}.
*
* @author Rossen Stoyanchev
*/
public
class
GzipResourceResolverTests
{
...
...
@@ -58,8 +56,6 @@ public class GzipResourceResolverTests {
private
List
<
Resource
>
locations
;
private
Cache
cache
;
private
MockServerHttpRequest
request
;
...
...
@@ -80,9 +76,10 @@ public class GzipResourceResolverTests {
gzFile
.
deleteOnExit
();
}
@Before
public
void
set
U
p
()
{
this
.
cache
=
new
ConcurrentMapCache
(
"resourceCache"
);
public
void
set
u
p
()
{
Cache
cache
=
new
ConcurrentMapCache
(
"resourceCache"
);
Map
<
String
,
VersionStrategy
>
versionStrategyMap
=
new
HashMap
<>();
versionStrategyMap
.
put
(
"/**"
,
new
ContentVersionStrategy
());
...
...
@@ -90,7 +87,7 @@ public class GzipResourceResolverTests {
versionResolver
.
setStrategyMap
(
versionStrategyMap
);
List
<
ResourceResolver
>
resolvers
=
new
ArrayList
<>();
resolvers
.
add
(
new
CachingResourceResolver
(
this
.
cache
));
resolvers
.
add
(
new
CachingResourceResolver
(
cache
));
resolvers
.
add
(
new
GzipResourceResolver
());
resolvers
.
add
(
versionResolver
);
resolvers
.
add
(
new
PathResourceResolver
());
...
...
@@ -160,7 +157,7 @@ public class GzipResourceResolverTests {
resolved
instanceof
HttpResource
);
}
@Test
// SPR-13149
@Test
// SPR-13149
public
void
resolveWithNullRequest
()
throws
IOException
{
String
file
=
"js/foo.js"
;
Resource
resolved
=
this
.
resolver
.
resolveResource
(
null
,
file
,
this
.
locations
).
blockMillis
(
5000
);
...
...
@@ -173,8 +170,9 @@ public class GzipResourceResolverTests {
resolved
instanceof
HttpResource
);
}
@NotNull
private
DefaultServerWebExchange
createExchange
()
{
return
new
DefaultServerWebExchange
(
this
.
request
,
new
MockServerHttpResponse
());
}
}
spring-webflux/src/test/java/org/springframework/web/reactive/resource/ResourceTransformerSupportTests.java
浏览文件 @
73493bc4
/*
* Copyright 2002-201
6
the original author or authors.
* Copyright 2002-201
7
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.
...
...
@@ -13,13 +13,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.springframework.web.reactive.resource
;
import
java.util.Arrays
;
import
java.util.Collections
;
import
java.util.List
;
import
org.jetbrains.annotations.NotNull
;
import
org.junit.Before
;
import
org.junit.Test
;
import
reactor.core.publisher.Mono
;
...
...
@@ -31,7 +31,7 @@ import org.springframework.mock.http.server.reactive.test.MockServerHttpResponse
import
org.springframework.web.server.ServerWebExchange
;
import
org.springframework.web.server.adapter.DefaultServerWebExchange
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
*
;
/**
* Unit tests for {@code ResourceTransformerSupport}.
...
...
@@ -49,7 +49,7 @@ public class ResourceTransformerSupportTests {
@Before
public
void
set
U
p
()
{
public
void
set
u
p
()
{
VersionResourceResolver
versionResolver
=
new
VersionResourceResolver
();
versionResolver
.
setStrategyMap
(
Collections
.
singletonMap
(
"/**"
,
new
ContentVersionStrategy
()));
PathResourceResolver
pathResolver
=
new
PathResourceResolver
();
...
...
@@ -63,7 +63,6 @@ public class ResourceTransformerSupportTests {
this
.
request
=
MockServerHttpRequest
.
get
(
""
).
build
();
}
private
ResourceUrlProvider
createResourceUrlProvider
(
List
<
ResourceResolver
>
resolvers
)
{
ResourceWebHandler
handler
=
new
ResourceWebHandler
();
handler
.
setLocations
(
Collections
.
singletonList
(
new
ClassPathResource
(
"test/"
,
getClass
())));
...
...
@@ -104,7 +103,7 @@ public class ResourceTransformerSupportTests {
assertEquals
(
"../bar-11e16cf79faee7ac698c805cf28248d2.css"
,
actual
);
}
@NotNull
private
DefaultServerWebExchange
createExchange
()
{
return
new
DefaultServerWebExchange
(
this
.
request
,
new
MockServerHttpResponse
());
}
...
...
spring-webflux/src/test/java/org/springframework/web/reactive/resource/ResourceUrlProviderTests.java
浏览文件 @
73493bc4
/*
* Copyright 2002-201
6
the original author or authors.
* Copyright 2002-201
7
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.
...
...
@@ -36,12 +36,8 @@ import org.springframework.web.context.support.AnnotationConfigWebApplicationCon
import
org.springframework.web.reactive.handler.SimpleUrlHandlerMapping
;
import
org.springframework.web.server.ServerWebExchange
;
import
org.springframework.web.server.adapter.DefaultServerWebExchange
;
import
org.springframework.web.server.session.DefaultWebSessionManager
;
import
org.springframework.web.server.session.WebSessionManager
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertFalse
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
junit
.
Assert
.*;
/**
...
...
@@ -61,7 +57,7 @@ public class ResourceUrlProviderTests {
@Before
public
void
set
U
p
()
throws
Exception
{
public
void
set
u
p
()
throws
Exception
{
this
.
locations
.
add
(
new
ClassPathResource
(
"test/"
,
getClass
()));
this
.
locations
.
add
(
new
ClassPathResource
(
"testalternatepath/"
,
getClass
()));
this
.
handler
.
setLocations
(
locations
);
...
...
@@ -77,7 +73,7 @@ public class ResourceUrlProviderTests {
assertEquals
(
"/resources/foo.css"
,
url
);
}
@Test
// SPR-13374
@Test
// SPR-13374
public
void
getStaticResourceUrlRequestWithQueryOrHash
()
{
MockServerHttpRequest
request
=
MockServerHttpRequest
.
get
(
"/"
).
build
();
MockServerHttpResponse
response
=
new
MockServerHttpResponse
();
...
...
@@ -108,7 +104,7 @@ public class ResourceUrlProviderTests {
assertEquals
(
"/resources/foo-e36d2e05253c6c7085a91522ce43a0b4.css"
,
url
);
}
@Test
// SPR-12647
@Test
// SPR-12647
public
void
bestPatternMatch
()
throws
Exception
{
ResourceWebHandler
otherHandler
=
new
ResourceWebHandler
();
otherHandler
.
setLocations
(
this
.
locations
);
...
...
@@ -129,7 +125,7 @@ public class ResourceUrlProviderTests {
assertEquals
(
"/resources/foo-e36d2e05253c6c7085a91522ce43a0b4.css"
,
url
);
}
@Test
// SPR-12592
@Test
// SPR-12592
public
void
initializeOnce
()
throws
Exception
{
AnnotationConfigWebApplicationContext
context
=
new
AnnotationConfigWebApplicationContext
();
context
.
setServletContext
(
new
MockServletContext
());
...
...
spring-webflux/src/test/java/org/springframework/web/reactive/resource/ResourceWebHandlerTests.java
浏览文件 @
73493bc4
/*
* Copyright 2002-201
6
the original author or authors.
* Copyright 2002-201
7
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.
...
...
@@ -24,7 +24,6 @@ import java.util.Collections;
import
java.util.List
;
import
java.util.concurrent.TimeUnit
;
import
org.jetbrains.annotations.NotNull
;
import
org.junit.Before
;
import
org.junit.Test
;
import
reactor.core.publisher.Flux
;
...
...
@@ -47,18 +46,14 @@ import org.springframework.http.MediaType;
import
org.springframework.mock.http.server.reactive.test.MockServerHttpRequest
;
import
org.springframework.mock.http.server.reactive.test.MockServerHttpResponse
;
import
org.springframework.util.StringUtils
;
import
org.springframework.web.reactive.HandlerMapping
;
import
org.springframework.web.reactive.accept.CompositeContentTypeResolver
;
import
org.springframework.web.reactive.accept.RequestedContentTypeResolverBuilder
;
import
org.springframework.web.server.MethodNotAllowedException
;
import
org.springframework.web.server.ServerWebExchange
;
import
org.springframework.web.server.adapter.DefaultServerWebExchange
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
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
.
springframework
.
web
.
reactive
.
HandlerMapping
.
PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE
;
import
static
org
.
junit
.
Assert
.*;
/**
* Unit tests for {@link ResourceWebHandler}.
...
...
@@ -77,7 +72,7 @@ public class ResourceWebHandlerTests {
@Before
public
void
set
U
p
()
throws
Exception
{
public
void
set
u
p
()
throws
Exception
{
List
<
Resource
>
paths
=
new
ArrayList
<>(
2
);
paths
.
add
(
new
ClassPathResource
(
"test/"
,
getClass
()));
paths
.
add
(
new
ClassPathResource
(
"testalternatepath/"
,
getClass
()));
...
...
@@ -579,14 +574,13 @@ public class ResourceWebHandlerTests {
assertEquals
(
"max-age=3600"
,
this
.
response
.
getHeaders
().
getCacheControl
());
}
@NotNull
private
ServerWebExchange
createExchange
(
String
path
)
{
ServerWebExchange
exchange
=
new
DefaultServerWebExchange
(
this
.
request
,
this
.
response
);
exchange
.
getAttributes
().
put
(
PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE
,
path
);
exchange
.
getAttributes
().
put
(
HandlerMapping
.
PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE
,
path
);
return
exchange
;
}
private
long
resourceLastModified
(
String
resourceName
)
throws
IOException
{
return
new
ClassPathResource
(
resourceName
,
getClass
()).
getFile
().
lastModified
();
}
...
...
spring-webflux/src/test/java/org/springframework/web/reactive/result/HandlerResultHandlerTests.java
浏览文件 @
73493bc4
/*
* Copyright 2002-201
6
the original author or authors.
* Copyright 2002-201
7
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.
...
...
@@ -13,34 +13,28 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.springframework.web.reactive.result
;
import
java.util.Arrays
;
import
java.util.Collections
;
import
java.util.List
;
import
org.jetbrains.annotations.NotNull
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.springframework.http.MediaType
;
import
org.springframework.mock.http.server.reactive.test.MockServerHttpRequest
;
import
org.springframework.mock.http.server.reactive.test.MockServerHttpResponse
;
import
org.springframework.web.reactive.HandlerMapping
;
import
org.springframework.web.reactive.accept.FixedContentTypeResolver
;
import
org.springframework.web.reactive.accept.HeaderContentTypeResolver
;
import
org.springframework.web.reactive.accept.RequestedContentTypeResolver
;
import
org.springframework.web.server.ServerWebExchange
;
import
org.springframework.web.server.adapter.DefaultServerWebExchange
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
springframework
.
http
.
MediaType
.
ALL
;
import
static
org
.
springframework
.
http
.
MediaType
.
APPLICATION_JSON_UTF8
;
import
static
org
.
springframework
.
http
.
MediaType
.
APPLICATION_OCTET_STREAM
;
import
static
org
.
springframework
.
http
.
MediaType
.
IMAGE_GIF
;
import
static
org
.
springframework
.
http
.
MediaType
.
IMAGE_JPEG
;
import
static
org
.
springframework
.
http
.
MediaType
.
IMAGE_PNG
;
import
static
org
.
springframework
.
http
.
MediaType
.
TEXT_PLAIN
;
import
static
org
.
springframework
.
web
.
reactive
.
HandlerMapping
.
PRODUCIBLE_MEDIA_TYPES_ATTRIBUTE
;
import
static
org
.
junit
.
Assert
.*;
import
static
org
.
springframework
.
http
.
MediaType
.*;
/**
* Unit tests for {@link AbstractHandlerResultHandler}.
...
...
@@ -54,7 +48,7 @@ public class HandlerResultHandlerTests {
@Before
public
void
set
U
p
()
throws
Exception
{
public
void
set
u
p
()
throws
Exception
{
this
.
resultHandler
=
new
TestResultHandler
();
this
.
request
=
MockServerHttpRequest
.
get
(
"/path"
).
build
();
}
...
...
@@ -72,7 +66,8 @@ public class HandlerResultHandlerTests {
@Test
public
void
producibleMediaTypesRequestAttribute
()
throws
Exception
{
ServerWebExchange
exchange
=
exchange
();
exchange
.
getAttributes
().
put
(
PRODUCIBLE_MEDIA_TYPES_ATTRIBUTE
,
Collections
.
singleton
(
IMAGE_GIF
));
exchange
.
getAttributes
().
put
(
HandlerMapping
.
PRODUCIBLE_MEDIA_TYPES_ATTRIBUTE
,
Collections
.
singleton
(
IMAGE_GIF
));
List
<
MediaType
>
mediaTypes
=
Arrays
.
asList
(
IMAGE_JPEG
,
IMAGE_GIF
,
IMAGE_PNG
);
MediaType
actual
=
resultHandler
.
selectMediaType
(
exchange
,
()
->
mediaTypes
);
...
...
@@ -110,7 +105,7 @@ public class HandlerResultHandlerTests {
assertEquals
(
APPLICATION_OCTET_STREAM
,
actual
);
}
@NotNull
private
DefaultServerWebExchange
exchange
()
{
return
new
DefaultServerWebExchange
(
this
.
request
,
new
MockServerHttpResponse
());
}
...
...
spring-webflux/src/test/java/org/springframework/web/reactive/result/condition/CompositeRequestConditionTests.java
浏览文件 @
73493bc4
/*
* Copyright 2002-201
6
the original author or authors.
* Copyright 2002-201
7
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.
...
...
@@ -16,7 +16,6 @@
package
org.springframework.web.reactive.result.condition
;
import
org.jetbrains.annotations.NotNull
;
import
org.junit.Before
;
import
org.junit.Test
;
...
...
@@ -27,9 +26,7 @@ import org.springframework.web.bind.annotation.RequestMethod;
import
org.springframework.web.server.ServerWebExchange
;
import
org.springframework.web.server.adapter.DefaultServerWebExchange
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertNull
;
import
static
org
.
junit
.
Assert
.
assertSame
;
import
static
org
.
junit
.
Assert
.*;
/**
* Unit tests for {@link CompositeRequestCondition}.
...
...
@@ -142,7 +139,7 @@ public class CompositeRequestConditionTests {
cond1
.
compareTo
(
cond2
,
createExchange
());
}
@NotNull
private
DefaultServerWebExchange
createExchange
()
{
return
new
DefaultServerWebExchange
(
this
.
request
,
new
MockServerHttpResponse
());
}
...
...
spring-webflux/src/test/java/org/springframework/web/reactive/result/condition/RequestConditionHolderTests.java
浏览文件 @
73493bc4
...
...
@@ -42,7 +42,7 @@ public class RequestConditionHolderTests {
@Before
public
void
set
U
p
()
throws
Exception
{
public
void
set
u
p
()
throws
Exception
{
ServerHttpRequest
request
=
MockServerHttpRequest
.
get
(
"/"
).
build
();
MockServerHttpResponse
response
=
new
MockServerHttpResponse
();
this
.
exchange
=
new
DefaultServerWebExchange
(
request
,
response
);
...
...
spring-webflux/src/test/java/org/springframework/web/reactive/result/condition/RequestMappingInfoTests.java
浏览文件 @
73493bc4
/*
* Copyright 2002-201
6
the original author or authors.
* Copyright 2002-201
7
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.
...
...
@@ -20,7 +20,6 @@ import java.util.Collections;
import
java.util.Comparator
;
import
java.util.List
;
import
org.jetbrains.annotations.NotNull
;
import
org.junit.Before
;
import
org.junit.Ignore
;
import
org.junit.Test
;
...
...
@@ -37,12 +36,8 @@ import org.springframework.web.server.adapter.DefaultServerWebExchange;
import
org.springframework.web.server.session.MockWebSessionManager
;
import
org.springframework.web.server.session.WebSessionManager
;
import
static
java
.
util
.
Arrays
.
asList
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertFalse
;
import
static
org
.
junit
.
Assert
.
assertNotEquals
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
junit
.
Assert
.
assertNull
;
import
static
java
.
util
.
Arrays
.*;
import
static
org
.
junit
.
Assert
.*;
/**
* Unit tests for {@link RequestMappingInfo}.
...
...
@@ -57,10 +52,11 @@ public class RequestMappingInfoTests {
// TODO: CORS pre-flight (see @Ignored)
@Before
public
void
set
U
p
()
throws
Exception
{
public
void
set
u
p
()
throws
Exception
{
this
.
request
=
MockServerHttpRequest
.
get
(
"/foo"
).
build
();
}
@Test
public
void
createEmpty
()
{
RequestMappingInfo
info
=
new
RequestMappingInfo
(
null
,
null
,
null
,
null
,
null
,
null
,
null
);
...
...
@@ -345,7 +341,7 @@ public class RequestMappingInfoTests {
assertNull
(
"Pre-flight should match the ACCESS_CONTROL_REQUEST_METHOD"
,
match
);
}
@NotNull
private
DefaultServerWebExchange
createExchange
()
{
return
new
DefaultServerWebExchange
(
this
.
request
,
new
MockServerHttpResponse
());
}
...
...
spring-webflux/src/test/java/org/springframework/web/reactive/result/method/HandlerMethodMappingTests.java
浏览文件 @
73493bc4
/*
* Copyright 2002-201
6
the original author or authors.
* Copyright 2002-201
7
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.
...
...
@@ -42,12 +42,11 @@ import org.springframework.web.server.session.MockWebSessionManager;
import
org.springframework.web.server.session.WebSessionManager
;
import
org.springframework.web.util.ParsingPathMatcher
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
junit
.
Assert
.
assertNull
;
import
static
org
.
junit
.
Assert
.*;
/**
* Unit tests for {@link AbstractHandlerMethodMapping}.
*
* @author Rossen Stoyanchev
*/
public
class
HandlerMethodMappingTests
{
...
...
@@ -62,7 +61,7 @@ public class HandlerMethodMappingTests {
@Before
public
void
set
U
p
()
throws
Exception
{
public
void
set
u
p
()
throws
Exception
{
this
.
mapping
=
new
MyHandlerMethodMapping
();
this
.
handler
=
new
MyHandler
();
this
.
method1
=
handler
.
getClass
().
getMethod
(
"handlerMethod1"
);
...
...
spring-webflux/src/test/java/org/springframework/web/reactive/result/method/InvocableHandlerMethodTests.java
浏览文件 @
73493bc4
...
...
@@ -54,7 +54,7 @@ public class InvocableHandlerMethodTests {
@Before
public
void
set
U
p
()
throws
Exception
{
public
void
set
u
p
()
throws
Exception
{
this
.
exchange
=
new
DefaultServerWebExchange
(
MockServerHttpRequest
.
get
(
"http://localhost:8080/path"
).
build
(),
new
MockServerHttpResponse
(),
...
...
spring-webflux/src/test/java/org/springframework/web/reactive/result/method/RequestMappingInfoHandlerMappingTests.java
浏览文件 @
73493bc4
/*
* Copyright 2002-201
6
the original author or authors.
* Copyright 2002-201
7
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.
...
...
@@ -51,7 +51,7 @@ import org.springframework.web.reactive.BindingContext;
import
org.springframework.web.reactive.HandlerMapping
;
import
org.springframework.web.reactive.HandlerResult
;
import
org.springframework.web.reactive.result.ResolvableMethod
;
import
org.springframework.web.reactive.result.method.RequestMappingInfo.
BuilderConfiguration
;
import
org.springframework.web.reactive.result.method.RequestMappingInfo.
*
;
import
org.springframework.web.server.MethodNotAllowedException
;
import
org.springframework.web.server.NotAcceptableStatusException
;
import
org.springframework.web.server.ServerWebExchange
;
...
...
@@ -60,19 +60,14 @@ import org.springframework.web.server.UnsupportedMediaTypeStatusException;
import
org.springframework.web.server.adapter.DefaultServerWebExchange
;
import
org.springframework.web.server.support.HttpRequestPathHelper
;
import
static
org
.
hamcrest
.
CoreMatchers
.
containsString
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
junit
.
Assert
.
assertNull
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
springframework
.
web
.
bind
.
annotation
.
RequestMethod
.
GET
;
import
static
org
.
springframework
.
web
.
bind
.
annotation
.
RequestMethod
.
HEAD
;
import
static
org
.
springframework
.
web
.
bind
.
annotation
.
RequestMethod
.
OPTIONS
;
import
static
org
.
springframework
.
web
.
reactive
.
result
.
method
.
RequestMappingInfo
.
paths
;
import
static
org
.
hamcrest
.
CoreMatchers
.*;
import
static
org
.
junit
.
Assert
.*;
import
static
org
.
springframework
.
web
.
bind
.
annotation
.
RequestMethod
.*;
import
static
org
.
springframework
.
web
.
reactive
.
result
.
method
.
RequestMappingInfo
.*;
/**
* Unit tests for {@link RequestMappingInfoHandlerMapping}.
*
* @author Rossen Stoyanchev
*/
public
class
RequestMappingInfoHandlerMappingTests
{
...
...
@@ -83,7 +78,7 @@ public class RequestMappingInfoHandlerMappingTests {
@Before
public
void
set
U
p
()
throws
Exception
{
public
void
set
u
p
()
throws
Exception
{
this
.
handlerMapping
=
new
TestRequestMappingInfoHandlerMapping
();
this
.
handlerMapping
.
registerHandler
(
new
TestController
());
}
...
...
@@ -157,7 +152,7 @@ public class RequestMappingInfoHandlerMappingTests {
ex
->
assertEquals
(
new
HashSet
<>(
Arrays
.
asList
(
"GET"
,
"HEAD"
)),
ex
.
getSupportedMethods
()));
}
@Test
// SPR-9603
@Test
// SPR-9603
public
void
getHandlerRequestMethodMatchFalsePositive
()
throws
Exception
{
this
.
request
=
MockServerHttpRequest
.
get
(
"/users"
).
accept
(
MediaType
.
APPLICATION_XML
).
build
();
this
.
handlerMapping
.
registerHandler
(
new
UserController
());
...
...
@@ -168,7 +163,7 @@ public class RequestMappingInfoHandlerMappingTests {
.
verify
();
}
@Test
// SPR-8462
@Test
// SPR-8462
public
void
getHandlerMediaTypeNotSupported
()
throws
Exception
{
testHttpMediaTypeNotSupportedException
(
"/person/1"
);
testHttpMediaTypeNotSupportedException
(
"/person/1/"
);
...
...
@@ -186,14 +181,14 @@ public class RequestMappingInfoHandlerMappingTests {
ex
.
getMessage
()));
}
@Test
// SPR-8462
@Test
// SPR-8462
public
void
getHandlerTestMediaTypeNotAcceptable
()
throws
Exception
{
testMediaTypeNotAcceptable
(
"/persons"
);
testMediaTypeNotAcceptable
(
"/persons/"
);
testMediaTypeNotAcceptable
(
"/persons.json"
);
}
@Test
// SPR-12854
@Test
// SPR-12854
public
void
getHandlerTestRequestParamMismatch
()
throws
Exception
{
this
.
request
=
MockServerHttpRequest
.
get
(
"/params"
).
build
();
Mono
<
Object
>
mono
=
this
.
handlerMapping
.
getHandler
(
createExchange
());
...
...
@@ -228,7 +223,8 @@ public class RequestMappingInfoHandlerMappingTests {
exchange
.
getAttributes
().
get
(
name
));
}
@Test
@SuppressWarnings
(
"unchecked"
)
@Test
@SuppressWarnings
(
"unchecked"
)
public
void
handleMatchUriTemplateVariables
()
throws
Exception
{
String
lookupPath
=
"/1/2"
;
this
.
request
=
MockServerHttpRequest
.
get
(
lookupPath
).
build
();
...
...
@@ -245,7 +241,7 @@ public class RequestMappingInfoHandlerMappingTests {
assertEquals
(
"2"
,
uriVariables
.
get
(
"path2"
));
}
@Test
// SPR-9098
@Test
// SPR-9098
public
void
handleMatchUriTemplateVariablesDecode
()
throws
Exception
{
RequestMappingInfo
key
=
paths
(
"/{group}/{identifier}"
).
build
();
this
.
request
=
MockServerHttpRequest
.
method
(
HttpMethod
.
GET
,
URI
.
create
(
"/group/a%2Fb"
)).
build
();
...
...
@@ -352,12 +348,10 @@ public class RequestMappingInfoHandlerMappingTests {
private
ServerWebExchange
createExchange
()
{
return
new
DefaultServerWebExchange
(
this
.
request
,
new
MockServerHttpResponse
());
}
@SuppressWarnings
(
"unchecked"
)
private
<
T
>
void
assertError
(
Mono
<
Object
>
mono
,
final
Class
<
T
>
exceptionClass
,
final
Consumer
<
T
>
consumer
)
{
StepVerifier
.
create
(
mono
)
.
consumeErrorWith
(
error
->
{
assertEquals
(
exceptionClass
,
error
.
getClass
());
...
...
@@ -367,7 +361,6 @@ public class RequestMappingInfoHandlerMappingTests {
.
verify
();
}
private
void
testHttpMediaTypeNotSupportedException
(
String
url
)
throws
Exception
{
this
.
request
=
MockServerHttpRequest
.
put
(
url
).
contentType
(
MediaType
.
APPLICATION_JSON
).
build
();
Mono
<
Object
>
mono
=
this
.
handlerMapping
.
getHandler
(
createExchange
());
...
...
@@ -504,6 +497,7 @@ public class RequestMappingInfoHandlerMappingTests {
}
}
@SuppressWarnings
(
"unused"
)
@Controller
private
static
class
UserController
{
...
...
@@ -517,6 +511,7 @@ public class RequestMappingInfoHandlerMappingTests {
}
}
private
static
class
TestRequestMappingInfoHandlerMapping
extends
RequestMappingInfoHandlerMapping
{
void
registerHandler
(
Object
handler
)
{
...
...
spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/BindingContextFactoryTests.java
浏览文件 @
73493bc4
/*
* Copyright 2002-201
6
the original author or authors.
* Copyright 2002-201
7
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.
...
...
@@ -57,7 +57,7 @@ public class BindingContextFactoryTests {
@Before
public
void
set
U
p
()
throws
Exception
{
public
void
set
u
p
()
throws
Exception
{
WebFluxConfigurationSupport
configurationSupport
=
new
WebFluxConfigurationSupport
();
configurationSupport
.
setApplicationContext
(
new
StaticApplicationContext
());
RequestMappingHandlerAdapter
adapter
=
configurationSupport
.
requestMappingHandlerAdapter
();
...
...
spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/ContextPathIntegrationTests.java
浏览文件 @
73493bc4
/*
* Copyright 2002-201
6
the original author or authors.
* Copyright 2002-201
7
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.
...
...
@@ -31,7 +31,7 @@ import org.springframework.web.client.RestTemplate;
import
org.springframework.web.reactive.DispatcherHandler
;
import
org.springframework.web.reactive.config.EnableWebFlux
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
*
;
/**
* Integration tests that demonstrate running multiple applications under
...
...
@@ -46,8 +46,7 @@ public class ContextPathIntegrationTests {
@Before
public
void
setUp
()
throws
Exception
{
public
void
setup
()
throws
Exception
{
AnnotationConfigApplicationContext
context1
=
new
AnnotationConfigApplicationContext
();
context1
.
register
(
WebApp1Config
.
class
);
context1
.
refresh
();
...
...
@@ -69,14 +68,13 @@ public class ContextPathIntegrationTests {
}
@After
public
void
tearD
own
()
throws
Exception
{
public
void
shutd
own
()
throws
Exception
{
this
.
server
.
stop
();
}
@Test
public
void
basic
()
throws
Exception
{
RestTemplate
restTemplate
=
new
RestTemplate
();
String
actual
;
...
...
@@ -102,6 +100,7 @@ public class ContextPathIntegrationTests {
}
}
@EnableWebFlux
@Configuration
static
class
WebApp2Config
{
...
...
@@ -112,6 +111,7 @@ public class ContextPathIntegrationTests {
}
}
@RestController
static
class
TestController
{
...
...
spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/CookieValueMethodArgumentResolverTests.java
浏览文件 @
73493bc4
/*
* Copyright 2002-201
6
the original author or authors.
* Copyright 2002-201
7
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.reactive.result.method.annotation;
import
java.lang.reflect.Method
;
import
org.jetbrains.annotations.NotNull
;
import
org.junit.Before
;
import
org.junit.Test
;
import
reactor.core.publisher.Mono
;
...
...
@@ -36,9 +35,7 @@ import org.springframework.web.reactive.BindingContext;
import
org.springframework.web.server.ServerWebInputException
;
import
org.springframework.web.server.adapter.DefaultServerWebExchange
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertFalse
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
junit
.
Assert
.*;
/**
* Test fixture with {@link CookieValueMethodArgumentResolver}.
...
...
@@ -51,20 +48,21 @@ public class CookieValueMethodArgumentResolverTests {
private
ServerHttpRequest
request
;
private
BindingContext
bindingContext
;
private
MethodParameter
cookieParameter
;
private
MethodParameter
cookieStringParameter
;
private
MethodParameter
stringParameter
;
private
BindingContext
bindingContext
=
new
BindingContext
();
@Before
public
void
set
U
p
()
throws
Exception
{
public
void
set
u
p
()
throws
Exception
{
AnnotationConfigApplicationContext
context
=
new
AnnotationConfigApplicationContext
();
context
.
refresh
();
this
.
resolver
=
new
CookieValueMethodArgumentResolver
(
context
.
getBeanFactory
());
this
.
resolver
=
new
CookieValueMethodArgumentResolver
(
context
.
getBeanFactory
());
this
.
request
=
MockServerHttpRequest
.
get
(
"/"
).
build
();
this
.
bindingContext
=
new
BindingContext
();
Method
method
=
getClass
().
getMethod
(
"params"
,
HttpCookie
.
class
,
String
.
class
,
String
.
class
);
this
.
cookieParameter
=
new
SynthesizingMethodParameter
(
method
,
0
);
...
...
@@ -120,7 +118,7 @@ public class CookieValueMethodArgumentResolverTests {
.
verify
();
}
@NotNull
private
DefaultServerWebExchange
createExchange
()
{
return
new
DefaultServerWebExchange
(
this
.
request
,
new
MockServerHttpResponse
());
}
...
...
spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/ErrorsArgumentResolverTests.java
浏览文件 @
73493bc4
/*
* Copyright 2002-201
6
the original author or authors.
* Copyright 2002-201
7
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.
...
...
@@ -35,11 +35,8 @@ import org.springframework.web.reactive.result.ResolvableMethod;
import
org.springframework.web.server.ServerWebExchange
;
import
org.springframework.web.server.adapter.DefaultServerWebExchange
;
import
static
junit
.
framework
.
TestCase
.
assertFalse
;
import
static
org
.
junit
.
Assert
.
assertSame
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
springframework
.
core
.
ResolvableType
.
forClass
;
import
static
org
.
springframework
.
core
.
ResolvableType
.
forClassWithGenerics
;
import
static
org
.
junit
.
Assert
.*;
import
static
org
.
springframework
.
core
.
ResolvableType
.*;
/**
* Unit tests for {@link ErrorsMethodArgumentResolver}.
...
...
@@ -60,7 +57,7 @@ public class ErrorsArgumentResolverTests {
@Before
public
void
set
U
p
()
throws
Exception
{
public
void
set
u
p
()
throws
Exception
{
this
.
resolver
=
new
ErrorsMethodArgumentResolver
(
new
ReactiveAdapterRegistry
());
MockServerHttpRequest
request
=
MockServerHttpRequest
.
post
(
"/path"
).
build
();
...
...
@@ -75,7 +72,6 @@ public class ErrorsArgumentResolverTests {
@Test
public
void
supports
()
throws
Exception
{
MethodParameter
parameter
=
parameter
(
forClass
(
Errors
.
class
));
assertTrue
(
this
.
resolver
.
supportsParameter
(
parameter
));
...
...
spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/ExpressionValueMethodArgumentResolverTests.java
浏览文件 @
73493bc4
/*
* Copyright 2002-201
6
the original author or authors.
* Copyright 2002-201
7
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.
...
...
@@ -32,9 +32,7 @@ import org.springframework.web.reactive.BindingContext;
import
org.springframework.web.server.ServerWebExchange
;
import
org.springframework.web.server.adapter.DefaultServerWebExchange
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertFalse
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
junit
.
Assert
.*;
/**
* Unit tests for {@link ExpressionValueMethodArgumentResolver}.
...
...
@@ -52,7 +50,7 @@ public class ExpressionValueMethodArgumentResolverTests {
@Before
public
void
set
U
p
()
throws
Exception
{
public
void
set
u
p
()
throws
Exception
{
AnnotationConfigApplicationContext
context
=
new
AnnotationConfigApplicationContext
();
context
.
refresh
();
this
.
resolver
=
new
ExpressionValueMethodArgumentResolver
(
context
.
getBeanFactory
());
...
...
spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/HttpEntityArgumentResolverTests.java
浏览文件 @
73493bc4
/*
* Copyright 2002-201
6
the original author or authors.
* Copyright 2002-201
7
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.
...
...
@@ -16,8 +16,6 @@
package
org.springframework.web.reactive.result.method.annotation
;
import
java.nio.ByteBuffer
;
import
java.nio.charset.StandardCharsets
;
import
java.time.Duration
;
import
java.util.ArrayList
;
import
java.util.List
;
...
...
@@ -38,8 +36,6 @@ import rx.Single;
import
org.springframework.core.MethodParameter
;
import
org.springframework.core.ResolvableType
;
import
org.springframework.core.codec.StringDecoder
;
import
org.springframework.core.io.buffer.DataBuffer
;
import
org.springframework.core.io.buffer.DefaultDataBufferFactory
;
import
org.springframework.http.HttpEntity
;
import
org.springframework.http.MediaType
;
import
org.springframework.http.RequestEntity
;
...
...
@@ -53,12 +49,8 @@ import org.springframework.web.server.ServerWebExchange;
import
org.springframework.web.server.ServerWebInputException
;
import
org.springframework.web.server.adapter.DefaultServerWebExchange
;
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
.
assertTrue
;
import
static
org
.
springframework
.
core
.
ResolvableType
.
forClassWithGenerics
;
import
static
org
.
junit
.
Assert
.*;
import
static
org
.
springframework
.
core
.
ResolvableType
.*;
/**
* Unit tests for {@link HttpEntityArgumentResolver}.When adding a test also
...
...
@@ -78,7 +70,7 @@ public class HttpEntityArgumentResolverTests {
@Before
public
void
set
U
p
()
throws
Exception
{
public
void
set
u
p
()
throws
Exception
{
this
.
request
=
MockServerHttpRequest
.
post
(
"/path"
).
build
();
}
...
...
@@ -344,12 +336,6 @@ public class HttpEntityArgumentResolverTests {
return
(
HttpEntity
<
T
>)
httpEntity
;
}
private
DataBuffer
dataBuffer
(
String
body
)
{
byte
[]
bytes
=
body
.
getBytes
(
StandardCharsets
.
UTF_8
);
ByteBuffer
byteBuffer
=
ByteBuffer
.
wrap
(
bytes
);
return
new
DefaultDataBufferFactory
().
wrap
(
byteBuffer
);
}
@SuppressWarnings
(
"unused"
)
void
handle
(
...
...
spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/InitBinderBindingContextTests.java
浏览文件 @
73493bc4
/*
* Copyright 2002-201
6
the original author or authors.
* Copyright 2002-201
7
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.
...
...
@@ -21,7 +21,6 @@ import java.util.ArrayList;
import
java.util.Collections
;
import
java.util.List
;
import
org.jetbrains.annotations.NotNull
;
import
org.junit.Before
;
import
org.junit.Test
;
...
...
@@ -39,10 +38,7 @@ import org.springframework.web.reactive.result.method.SyncHandlerMethodArgumentR
import
org.springframework.web.reactive.result.method.SyncInvocableHandlerMethod
;
import
org.springframework.web.server.adapter.DefaultServerWebExchange
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
junit
.
Assert
.
assertNull
;
import
static
org
.
junit
.
Assert
.
assertSame
;
import
static
org
.
junit
.
Assert
.*;
/**
* Unit tests for {@link InitBinderBindingContext}.
...
...
@@ -58,7 +54,7 @@ public class InitBinderBindingContextTests {
@Before
public
void
set
U
p
()
throws
Exception
{
public
void
set
u
p
()
throws
Exception
{
this
.
request
=
MockServerHttpRequest
.
get
(
"/"
).
build
();
}
...
...
@@ -125,14 +121,12 @@ public class InitBinderBindingContextTests {
assertEquals
(
"requestParam-22"
,
dataBinder
.
getDisallowedFields
()[
0
]);
}
@NotNull
private
DefaultServerWebExchange
createExchange
()
{
return
new
DefaultServerWebExchange
(
this
.
request
,
new
MockServerHttpResponse
());
}
private
BindingContext
createBindingContext
(
String
methodName
,
Class
<?>...
parameterTypes
)
throws
Exception
{
private
BindingContext
createBindingContext
(
String
methodName
,
Class
<?>...
parameterTypes
)
throws
Exception
{
Object
handler
=
new
InitBinderHandler
();
Method
method
=
handler
.
getClass
().
getMethod
(
methodName
,
parameterTypes
);
...
...
@@ -140,8 +134,7 @@ public class InitBinderBindingContextTests {
handlerMethod
.
setArgumentResolvers
(
new
ArrayList
<>(
this
.
argumentResolvers
));
handlerMethod
.
setParameterNameDiscoverer
(
new
LocalVariableTableParameterNameDiscoverer
());
return
new
InitBinderBindingContext
(
this
.
bindingInitializer
,
Collections
.
singletonList
(
handlerMethod
));
return
new
InitBinderBindingContext
(
this
.
bindingInitializer
,
Collections
.
singletonList
(
handlerMethod
));
}
...
...
spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/MessageReaderArgumentResolverTests.java
浏览文件 @
73493bc4
/*
* Copyright 2002-201
6
the original author or authors.
* Copyright 2002-201
7
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 javax.xml.bind.annotation.XmlRootElement;
import
io.reactivex.Flowable
;
import
io.reactivex.Maybe
;
import
org.jetbrains.annotations.NotNull
;
import
org.junit.Before
;
import
org.junit.Test
;
import
reactor.core.publisher.Flux
;
...
...
@@ -59,12 +58,8 @@ import org.springframework.web.server.ServerWebInputException;
import
org.springframework.web.server.UnsupportedMediaTypeStatusException
;
import
org.springframework.web.server.adapter.DefaultServerWebExchange
;
import
static
org
.
junit
.
Assert
.
assertArrayEquals
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
springframework
.
core
.
ResolvableType
.
forClass
;
import
static
org
.
springframework
.
core
.
ResolvableType
.
forClassWithGenerics
;
import
static
org
.
junit
.
Assert
.*;
import
static
org
.
springframework
.
core
.
ResolvableType
.*;
/**
* Unit tests for {@link AbstractMessageReaderArgumentResolver}.
...
...
@@ -83,7 +78,7 @@ public class MessageReaderArgumentResolverTests {
@Before
public
void
set
U
p
()
throws
Exception
{
public
void
set
u
p
()
throws
Exception
{
this
.
request
=
request
().
build
();
ConfigurableWebBindingInitializer
initializer
=
new
ConfigurableWebBindingInitializer
();
initializer
.
setValidator
(
new
TestBeanValidator
());
...
...
@@ -314,7 +309,6 @@ public class MessageReaderArgumentResolverTests {
return
MockServerHttpRequest
.
post
(
"/path"
);
}
@NotNull
private
DefaultServerWebExchange
exchange
()
{
return
new
DefaultServerWebExchange
(
this
.
request
,
new
MockServerHttpResponse
());
}
...
...
spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/MessageWriterResultHandlerTests.java
浏览文件 @
73493bc4
/*
* Copyright 2002-201
6
the original author or authors.
* Copyright 2002-201
7
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.
...
...
@@ -79,7 +79,7 @@ public class MessageWriterResultHandlerTests {
@Before
public
void
set
U
p
()
throws
Exception
{
public
void
set
u
p
()
throws
Exception
{
this
.
resultHandler
=
createResultHandler
();
ServerHttpRequest
request
=
MockServerHttpRequest
.
get
(
"/path"
).
build
();
this
.
exchange
=
new
DefaultServerWebExchange
(
request
,
this
.
response
);
...
...
@@ -222,6 +222,7 @@ public class MessageWriterResultHandlerTests {
}
}
@JsonTypeName
(
"foo"
)
private
static
class
Foo
extends
ParentClass
{
...
...
@@ -230,6 +231,7 @@ public class MessageWriterResultHandlerTests {
}
}
@JsonTypeName
(
"bar"
)
private
static
class
Bar
extends
ParentClass
{
...
...
@@ -238,12 +240,14 @@ public class MessageWriterResultHandlerTests {
}
}
private
interface
Identifiable
extends
Serializable
{
@SuppressWarnings
(
"unused"
)
Long
getId
();
}
@SuppressWarnings
({
"serial"
})
private
static
class
SimpleBean
implements
Identifiable
{
...
...
@@ -266,6 +270,7 @@ public class MessageWriterResultHandlerTests {
}
}
@SuppressWarnings
(
"unused"
)
private
static
class
TestController
{
...
...
@@ -296,7 +301,6 @@ public class MessageWriterResultHandlerTests {
Identifiable
identifiable
()
{
return
null
;
}
List
<
Identifiable
>
listIdentifiable
()
{
return
null
;
}
}
}
spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/ModelAttributeMethodArgumentResolverTests.java
浏览文件 @
73493bc4
...
...
@@ -60,7 +60,7 @@ public class ModelAttributeMethodArgumentResolverTests {
@Before
public
void
set
U
p
()
throws
Exception
{
public
void
set
u
p
()
throws
Exception
{
LocalValidatorFactoryBean
validator
=
new
LocalValidatorFactoryBean
();
validator
.
afterPropertiesSet
();
ConfigurableWebBindingInitializer
initializer
=
new
ConfigurableWebBindingInitializer
();
...
...
@@ -71,7 +71,6 @@ public class ModelAttributeMethodArgumentResolverTests {
@Test
public
void
supports
()
throws
Exception
{
ModelAttributeMethodArgumentResolver
resolver
=
new
ModelAttributeMethodArgumentResolver
(
new
ReactiveAdapterRegistry
(),
false
);
...
...
@@ -90,7 +89,6 @@ public class ModelAttributeMethodArgumentResolverTests {
@Test
public
void
supportsWithDefaultResolution
()
throws
Exception
{
ModelAttributeMethodArgumentResolver
resolver
=
new
ModelAttributeMethodArgumentResolver
(
new
ReactiveAdapterRegistry
(),
true
);
...
...
@@ -191,6 +189,24 @@ public class ModelAttributeMethodArgumentResolverTests {
});
}
private
void
testBindFoo
(
ResolvableType
type
,
Function
<
Object
,
Foo
>
valueExtractor
)
throws
Exception
{
Object
value
=
createResolver
()
.
resolveArgument
(
parameter
(
type
),
this
.
bindContext
,
exchange
(
"name=Robert&age=25"
))
.
blockMillis
(
0
);
Foo
foo
=
valueExtractor
.
apply
(
value
);
assertEquals
(
"Robert"
,
foo
.
getName
());
String
key
=
"foo"
;
String
bindingResultKey
=
BindingResult
.
MODEL_KEY_PREFIX
+
key
;
Map
<
String
,
Object
>
map
=
bindContext
.
getModel
().
asMap
();
assertEquals
(
map
.
toString
(),
2
,
map
.
size
());
assertSame
(
foo
,
map
.
get
(
key
));
assertNotNull
(
map
.
get
(
bindingResultKey
));
assertTrue
(
map
.
get
(
bindingResultKey
)
instanceof
BindingResult
);
}
@Test
public
void
validationError
()
throws
Exception
{
testValidationError
(
forClass
(
Foo
.
class
),
resolvedArgumentMono
->
resolvedArgumentMono
);
...
...
@@ -220,25 +236,6 @@ public class ModelAttributeMethodArgumentResolverTests {
});
}
private
void
testBindFoo
(
ResolvableType
type
,
Function
<
Object
,
Foo
>
valueExtractor
)
throws
Exception
{
Object
value
=
createResolver
()
.
resolveArgument
(
parameter
(
type
),
this
.
bindContext
,
exchange
(
"name=Robert&age=25"
))
.
blockMillis
(
0
);
Foo
foo
=
valueExtractor
.
apply
(
value
);
assertEquals
(
"Robert"
,
foo
.
getName
());
String
key
=
"foo"
;
String
bindingResultKey
=
BindingResult
.
MODEL_KEY_PREFIX
+
key
;
Map
<
String
,
Object
>
map
=
bindContext
.
getModel
().
asMap
();
assertEquals
(
map
.
toString
(),
2
,
map
.
size
());
assertSame
(
foo
,
map
.
get
(
key
));
assertNotNull
(
map
.
get
(
bindingResultKey
));
assertTrue
(
map
.
get
(
bindingResultKey
)
instanceof
BindingResult
);
}
private
void
testValidationError
(
ResolvableType
type
,
Function
<
Mono
<?>,
Mono
<?>>
valueMonoExtractor
)
throws
URISyntaxException
{
...
...
spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/PathVariableMapMethodArgumentResolverTests.java
浏览文件 @
73493bc4
/*
* Copyright 2002-201
6
the original author or authors.
* Copyright 2002-201
7
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.
...
...
@@ -56,7 +56,7 @@ public class PathVariableMapMethodArgumentResolverTests {
@Before
public
void
set
U
p
()
throws
Exception
{
public
void
set
u
p
()
throws
Exception
{
this
.
resolver
=
new
PathVariableMapMethodArgumentResolver
();
ServerHttpRequest
request
=
MockServerHttpRequest
.
get
(
"/"
).
build
();
...
...
spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/PathVariableMethodArgumentResolverTests.java
浏览文件 @
73493bc4
/*
* Copyright 2002-201
6
the original author or authors.
* Copyright 2002-201
7
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.
...
...
@@ -67,7 +67,7 @@ public class PathVariableMethodArgumentResolverTests {
@Before
public
void
set
U
p
()
throws
Exception
{
public
void
set
u
p
()
throws
Exception
{
this
.
resolver
=
new
PathVariableMethodArgumentResolver
(
null
);
ServerHttpRequest
request
=
MockServerHttpRequest
.
get
(
"/"
).
build
();
...
...
spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestAttributeMethodArgumentResolverTests.java
浏览文件 @
73493bc4
/*
* Copyright 2002-201
6
the original author or authors.
* Copyright 2002-201
7
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.
...
...
@@ -41,12 +41,7 @@ import org.springframework.web.server.ServerWebExchange;
import
org.springframework.web.server.ServerWebInputException
;
import
org.springframework.web.server.adapter.DefaultServerWebExchange
;
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
.*;
/**
* Unit tests for {@link RequestAttributeMethodArgumentResolver}.
...
...
@@ -63,8 +58,7 @@ public class RequestAttributeMethodArgumentResolverTests {
@Before
@SuppressWarnings
(
"ConfusingArgumentToVarargsMethod"
)
public
void
setUp
()
throws
Exception
{
public
void
setup
()
throws
Exception
{
AnnotationConfigApplicationContext
context
=
new
AnnotationConfigApplicationContext
();
context
.
refresh
();
this
.
resolver
=
new
RequestAttributeMethodArgumentResolver
(
context
.
getBeanFactory
());
...
...
spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestBodyArgumentResolverTests.java
浏览文件 @
73493bc4
/*
* Copyright 2002-201
6
the original author or authors.
* Copyright 2002-201
7
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.
...
...
@@ -46,13 +46,8 @@ import org.springframework.web.server.ServerWebExchange;
import
org.springframework.web.server.ServerWebInputException
;
import
org.springframework.web.server.adapter.DefaultServerWebExchange
;
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
.
assertTrue
;
import
static
org
.
springframework
.
core
.
ResolvableType
.
forClass
;
import
static
org
.
springframework
.
core
.
ResolvableType
.
forClassWithGenerics
;
import
static
org
.
junit
.
Assert
.*;
import
static
org
.
springframework
.
core
.
ResolvableType
.*;
/**
* Unit tests for {@link RequestBodyArgumentResolver}. When adding a test also
...
...
@@ -63,19 +58,18 @@ import static org.springframework.core.ResolvableType.forClassWithGenerics;
*/
public
class
RequestBodyArgumentResolverTests
{
private
RequestBodyArgumentResolver
resolver
=
resolver
()
;
private
RequestBodyArgumentResolver
resolver
;
private
ResolvableMethod
testMethod
=
ResolvableMethod
.
onClass
(
this
.
getClass
()).
name
(
"handle"
)
;
private
ResolvableMethod
testMethod
;
@Before
public
void
setUp
()
throws
Exception
{
}
private
RequestBodyArgumentResolver
resolver
()
{
public
void
setup
()
{
List
<
HttpMessageReader
<?>>
readers
=
new
ArrayList
<>();
readers
.
add
(
new
DecoderHttpMessageReader
<>(
new
StringDecoder
()));
return
new
RequestBodyArgumentResolver
(
readers
);
this
.
resolver
=
new
RequestBodyArgumentResolver
(
readers
);
this
.
testMethod
=
ResolvableMethod
.
onClass
(
getClass
()).
name
(
"handle"
);
}
...
...
spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestHeaderMapMethodArgumentResolverTests.java
浏览文件 @
73493bc4
/*
* Copyright 2002-201
6
the original author or authors.
* Copyright 2002-201
7
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.
...
...
@@ -20,7 +20,6 @@ import java.lang.reflect.Method;
import
java.util.Collections
;
import
java.util.Map
;
import
org.jetbrains.annotations.NotNull
;
import
org.junit.Before
;
import
org.junit.Test
;
import
reactor.core.publisher.Mono
;
...
...
@@ -34,12 +33,9 @@ import org.springframework.mock.http.server.reactive.test.MockServerHttpResponse
import
org.springframework.util.LinkedMultiValueMap
;
import
org.springframework.util.MultiValueMap
;
import
org.springframework.web.bind.annotation.RequestHeader
;
import
org.springframework.web.server.ServerWebExchange
;
import
org.springframework.web.server.adapter.DefaultServerWebExchange
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertFalse
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
junit
.
Assert
.*;
/**
* Unit tests for {@link RequestHeaderMapMethodArgumentResolver}.
...
...
@@ -50,25 +46,24 @@ public class RequestHeaderMapMethodArgumentResolverTests {
private
RequestHeaderMapMethodArgumentResolver
resolver
;
private
ServerHttpRequest
request
;
private
MethodParameter
paramMap
;
private
MethodParameter
paramMultiValueMap
;
private
MethodParameter
paramHttpHeaders
;
private
MethodParameter
paramUnsupported
;
private
ServerHttpRequest
request
;
@Before
public
void
set
U
p
()
throws
Exception
{
public
void
set
u
p
()
throws
Exception
{
resolver
=
new
RequestHeaderMapMethodArgumentResolver
();
request
=
MockServerHttpRequest
.
get
(
"/"
).
build
();
Method
method
=
getClass
().
getMethod
(
"params"
,
Map
.
class
,
MultiValueMap
.
class
,
HttpHeaders
.
class
,
Map
.
class
);
paramMap
=
new
SynthesizingMethodParameter
(
method
,
0
);
paramMultiValueMap
=
new
SynthesizingMethodParameter
(
method
,
1
);
paramHttpHeaders
=
new
SynthesizingMethodParameter
(
method
,
2
);
paramUnsupported
=
new
SynthesizingMethodParameter
(
method
,
3
);
this
.
request
=
MockServerHttpRequest
.
get
(
"/"
).
build
();
}
...
...
@@ -85,9 +80,9 @@ public class RequestHeaderMapMethodArgumentResolverTests {
String
name
=
"foo"
;
String
value
=
"bar"
;
Map
<
String
,
String
>
expected
=
Collections
.
singletonMap
(
name
,
value
);
this
.
request
=
MockServerHttpRequest
.
get
(
"/"
).
header
(
name
,
value
).
build
();
request
=
MockServerHttpRequest
.
get
(
"/"
).
header
(
name
,
value
).
build
();
Mono
<
Object
>
mono
=
this
.
resolver
.
resolveArgument
(
paramMap
,
null
,
createExchange
());
Mono
<
Object
>
mono
=
resolver
.
resolveArgument
(
paramMap
,
null
,
createExchange
());
Object
result
=
mono
.
block
();
assertTrue
(
result
instanceof
Map
);
...
...
@@ -99,13 +94,13 @@ public class RequestHeaderMapMethodArgumentResolverTests {
String
name
=
"foo"
;
String
value1
=
"bar"
;
String
value2
=
"baz"
;
this
.
request
=
MockServerHttpRequest
.
get
(
"/"
).
header
(
name
,
value1
,
value2
).
build
();
request
=
MockServerHttpRequest
.
get
(
"/"
).
header
(
name
,
value1
,
value2
).
build
();
MultiValueMap
<
String
,
String
>
expected
=
new
LinkedMultiValueMap
<>(
1
);
expected
.
add
(
name
,
value1
);
expected
.
add
(
name
,
value2
);
Mono
<
Object
>
mono
=
this
.
resolver
.
resolveArgument
(
paramMultiValueMap
,
null
,
createExchange
());
Mono
<
Object
>
mono
=
resolver
.
resolveArgument
(
paramMultiValueMap
,
null
,
createExchange
());
Object
result
=
mono
.
block
();
assertTrue
(
result
instanceof
MultiValueMap
);
...
...
@@ -117,22 +112,22 @@ public class RequestHeaderMapMethodArgumentResolverTests {
String
name
=
"foo"
;
String
value1
=
"bar"
;
String
value2
=
"baz"
;
this
.
request
=
MockServerHttpRequest
.
get
(
"/"
).
header
(
name
,
value1
,
value2
).
build
();
request
=
MockServerHttpRequest
.
get
(
"/"
).
header
(
name
,
value1
,
value2
).
build
();
HttpHeaders
expected
=
new
HttpHeaders
();
expected
.
add
(
name
,
value1
);
expected
.
add
(
name
,
value2
);
Mono
<
Object
>
mono
=
this
.
resolver
.
resolveArgument
(
paramHttpHeaders
,
null
,
createExchange
());
Mono
<
Object
>
mono
=
resolver
.
resolveArgument
(
paramHttpHeaders
,
null
,
createExchange
());
Object
result
=
mono
.
block
();
assertTrue
(
result
instanceof
HttpHeaders
);
assertEquals
(
"Invalid result"
,
expected
,
result
);
}
@NotNull
private
DefaultServerWebExchange
createExchange
()
{
return
new
DefaultServerWebExchange
(
this
.
request
,
new
MockServerHttpResponse
());
return
new
DefaultServerWebExchange
(
request
,
new
MockServerHttpResponse
());
}
...
...
spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestHeaderMethodArgumentResolverTests.java
浏览文件 @
73493bc4
/*
* Copyright 2002-201
6
the original author or authors.
* Copyright 2002-201
7
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.
...
...
@@ -22,7 +22,6 @@ import java.time.format.DateTimeFormatter;
import
java.util.Date
;
import
java.util.Map
;
import
org.jetbrains.annotations.NotNull
;
import
org.junit.Before
;
import
org.junit.Test
;
import
reactor.core.publisher.Mono
;
...
...
@@ -42,10 +41,7 @@ import org.springframework.web.reactive.BindingContext;
import
org.springframework.web.server.ServerWebInputException
;
import
org.springframework.web.server.adapter.DefaultServerWebExchange
;
import
static
org
.
junit
.
Assert
.
assertArrayEquals
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertFalse
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
junit
.
Assert
.*;
/**
* Unit tests for {@link RequestHeaderMethodArgumentResolver}.
...
...
@@ -56,6 +52,10 @@ public class RequestHeaderMethodArgumentResolverTests {
private
RequestHeaderMethodArgumentResolver
resolver
;
private
ServerHttpRequest
request
;
private
BindingContext
bindingContext
;
private
MethodParameter
paramNamedDefaultValueStringHeader
;
private
MethodParameter
paramNamedValueStringArray
;
private
MethodParameter
paramSystemProperty
;
...
...
@@ -65,18 +65,19 @@ public class RequestHeaderMethodArgumentResolverTests {
private
MethodParameter
paramDate
;
private
MethodParameter
paramInstant
;
private
ServerHttpRequest
request
;
private
BindingContext
bindingContext
;
@Before
public
void
set
U
p
()
throws
Exception
{
public
void
set
u
p
()
throws
Exception
{
AnnotationConfigApplicationContext
context
=
new
AnnotationConfigApplicationContext
();
context
.
refresh
();
this
.
resolver
=
new
RequestHeaderMethodArgumentResolver
(
context
.
getBeanFactory
());
@SuppressWarnings
(
"ConfusingArgumentToVarargsMethod"
)
this
.
request
=
MockServerHttpRequest
.
get
(
"/"
).
build
();
ConfigurableWebBindingInitializer
initializer
=
new
ConfigurableWebBindingInitializer
();
initializer
.
setConversionService
(
new
DefaultFormattingConversionService
());
this
.
bindingContext
=
new
BindingContext
(
initializer
);
Method
method
=
ReflectionUtils
.
findMethod
(
getClass
(),
"params"
,
(
Class
<?>[])
null
);
this
.
paramNamedDefaultValueStringHeader
=
new
SynthesizingMethodParameter
(
method
,
0
);
this
.
paramNamedValueStringArray
=
new
SynthesizingMethodParameter
(
method
,
1
);
...
...
@@ -86,12 +87,6 @@ public class RequestHeaderMethodArgumentResolverTests {
this
.
paramNamedValueMap
=
new
SynthesizingMethodParameter
(
method
,
5
);
this
.
paramDate
=
new
SynthesizingMethodParameter
(
method
,
6
);
this
.
paramInstant
=
new
SynthesizingMethodParameter
(
method
,
7
);
this
.
request
=
MockServerHttpRequest
.
get
(
"/"
).
build
();
ConfigurableWebBindingInitializer
initializer
=
new
ConfigurableWebBindingInitializer
();
initializer
.
setConversionService
(
new
DefaultFormattingConversionService
());
this
.
bindingContext
=
new
BindingContext
(
initializer
);
}
...
...
@@ -227,9 +222,9 @@ public class RequestHeaderMethodArgumentResolverTests {
assertEquals
(
Instant
.
from
(
DateTimeFormatter
.
RFC_1123_DATE_TIME
.
parse
(
rfc1123val
)),
result
);
}
@NotNull
private
DefaultServerWebExchange
createExchange
()
{
return
new
DefaultServerWebExchange
(
request
,
new
MockServerHttpResponse
());
return
new
DefaultServerWebExchange
(
this
.
request
,
new
MockServerHttpResponse
());
}
...
...
spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestMappingHandlerMappingTests.java
浏览文件 @
73493bc4
/*
* Copyright 2002-201
6
the original author or authors.
* Copyright 2002-201
7
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.
...
...
@@ -43,13 +43,8 @@ import org.springframework.web.context.support.StaticWebApplicationContext;
import
org.springframework.web.reactive.accept.MappingContentTypeResolver
;
import
org.springframework.web.reactive.result.method.RequestMappingInfo
;
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
.
assertTrue
;
import
static
org
.
mockito
.
Mockito
.
mock
;
import
static
org
.
mockito
.
Mockito
.
when
;
import
static
org
.
junit
.
Assert
.*;
import
static
org
.
mockito
.
Mockito
.*;
/**
* Unit tests for {@link RequestMappingHandlerMapping}.
...
...
@@ -64,7 +59,7 @@ public class RequestMappingHandlerMappingTests {
@Before
public
void
set
Up
()
throws
Exception
{
public
void
set
up
()
{
this
.
handlerMapping
.
setApplicationContext
(
wac
);
}
...
...
@@ -181,6 +176,7 @@ public class RequestMappingHandlerMappingTests {
assertComposedAnnotationMapping
(
RequestMethod
.
PATCH
);
}
private
RequestMappingInfo
assertComposedAnnotationMapping
(
RequestMethod
requestMethod
)
throws
Exception
{
String
methodName
=
requestMethod
.
name
().
toLowerCase
();
String
path
=
"/"
+
methodName
;
...
...
@@ -240,9 +236,9 @@ public class RequestMappingHandlerMappingTests {
@PatchMapping
(
"/patch"
)
public
void
patch
()
{
}
}
@RequestMapping
(
method
=
RequestMethod
.
POST
,
produces
=
MediaType
.
APPLICATION_JSON_VALUE
,
consumes
=
MediaType
.
APPLICATION_JSON_VALUE
)
...
...
spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestParamMapMethodArgumentResolverTests.java
浏览文件 @
73493bc4
/*
* Copyright 2002-201
6
the original author or authors.
* Copyright 2002-201
7
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.
...
...
@@ -53,9 +53,8 @@ public class RequestParamMapMethodArgumentResolverTests {
private
MethodParameter
paramMapWithoutAnnot
;
@Before
public
void
set
U
p
()
throws
Exception
{
public
void
set
u
p
()
throws
Exception
{
this
.
resolver
=
new
RequestParamMapMethodArgumentResolver
();
Method
method
=
getClass
().
getMethod
(
"params"
,
Map
.
class
,
MultiValueMap
.
class
,
Map
.
class
,
Map
.
class
);
...
...
spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestParamMethodArgumentResolverTests.java
浏览文件 @
73493bc4
/*
* Copyright 2002-201
6
the original author or authors.
* Copyright 2002-201
7
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.
...
...
@@ -42,11 +42,7 @@ import org.springframework.web.server.ServerWebExchange;
import
org.springframework.web.server.ServerWebInputException
;
import
org.springframework.web.server.adapter.DefaultServerWebExchange
;
import
static
org
.
junit
.
Assert
.
assertArrayEquals
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertFalse
;
import
static
org
.
junit
.
Assert
.
assertNull
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
junit
.
Assert
.*;
/**
* Unit tests for {@link RequestParamMethodArgumentResolver}.
...
...
@@ -69,8 +65,8 @@ public class RequestParamMethodArgumentResolverTests {
private
BindingContext
bindContext
;
@Before
@SuppressWarnings
(
"ConfusingArgumentToVarargsMethod"
)
public
void
set
U
p
()
throws
Exception
{
@Before
public
void
set
u
p
()
throws
Exception
{
this
.
resolver
=
new
RequestParamMethodArgumentResolver
(
null
,
true
);
ParameterNameDiscoverer
paramNameDiscoverer
=
new
LocalVariableTableParameterNameDiscoverer
();
...
...
spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/ResponseBodyResultHandlerTests.java
浏览文件 @
73493bc4
/*
* Copyright 2002-201
6
the original author or authors.
* Copyright 2002-201
7
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.
...
...
@@ -17,7 +17,6 @@
package
org.springframework.web.reactive.result.method.annotation
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.List
;
import
org.junit.Before
;
...
...
@@ -34,22 +33,15 @@ import org.springframework.http.codec.HttpMessageWriter;
import
org.springframework.http.codec.ResourceHttpMessageWriter
;
import
org.springframework.http.codec.json.Jackson2JsonEncoder
;
import
org.springframework.http.codec.xml.Jaxb2XmlEncoder
;
import
org.springframework.http.server.reactive.ServerHttpRequest
;
import
org.springframework.mock.http.server.reactive.test.MockServerHttpRequest
;
import
org.springframework.mock.http.server.reactive.test.MockServerHttpResponse
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.util.ObjectUtils
;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.method.HandlerMethod
;
import
org.springframework.web.reactive.HandlerResult
;
import
org.springframework.web.reactive.accept.RequestedContentTypeResolver
;
import
org.springframework.web.reactive.accept.RequestedContentTypeResolverBuilder
;
import
org.springframework.web.server.ServerWebExchange
;
import
org.springframework.web.server.adapter.DefaultServerWebExchange
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.*;
/**
* Unit tests for {@link ResponseBodyResultHandler}.When adding a test also
...
...
@@ -66,41 +58,20 @@ public class ResponseBodyResultHandlerTests {
private
ResponseBodyResultHandler
resultHandler
;
private
MockServerHttpResponse
response
;
private
ServerWebExchange
exchange
;
@Before
public
void
setUp
()
throws
Exception
{
this
.
resultHandler
=
createHandler
();
initExchange
();
}
private
void
initExchange
()
{
ServerHttpRequest
request
=
MockServerHttpRequest
.
get
(
"/"
).
build
();
this
.
response
=
new
MockServerHttpResponse
();
this
.
exchange
=
new
DefaultServerWebExchange
(
request
,
this
.
response
);
}
private
ResponseBodyResultHandler
createHandler
(
HttpMessageWriter
<?>...
writers
)
{
List
<
HttpMessageWriter
<?>>
writerList
;
if
(
ObjectUtils
.
isEmpty
(
writers
))
{
writerList
=
new
ArrayList
<>();
writerList
.
add
(
new
EncoderHttpMessageWriter
<>(
new
ByteBufferEncoder
()));
writerList
.
add
(
new
EncoderHttpMessageWriter
<>(
new
CharSequenceEncoder
()));
writerList
.
add
(
new
ResourceHttpMessageWriter
());
writerList
.
add
(
new
EncoderHttpMessageWriter
<>(
new
Jaxb2XmlEncoder
()));
writerList
.
add
(
new
EncoderHttpMessageWriter
<>(
new
Jackson2JsonEncoder
()));
}
else
{
writerList
=
Arrays
.
asList
(
writers
);
}
public
void
setup
()
throws
Exception
{
List
<
HttpMessageWriter
<?>>
writerList
=
new
ArrayList
<>(
5
);
writerList
.
add
(
new
EncoderHttpMessageWriter
<>(
new
ByteBufferEncoder
()));
writerList
.
add
(
new
EncoderHttpMessageWriter
<>(
new
CharSequenceEncoder
()));
writerList
.
add
(
new
ResourceHttpMessageWriter
());
writerList
.
add
(
new
EncoderHttpMessageWriter
<>(
new
Jaxb2XmlEncoder
()));
writerList
.
add
(
new
EncoderHttpMessageWriter
<>(
new
Jackson2JsonEncoder
()));
RequestedContentTypeResolver
resolver
=
new
RequestedContentTypeResolverBuilder
().
build
();
return
new
ResponseBodyResultHandler
(
writerList
,
resolver
);
this
.
resultHandler
=
new
ResponseBodyResultHandler
(
writerList
,
resolver
);
}
@Test
public
void
supports
()
throws
NoSuchMethodException
{
Object
controller
=
new
TestController
();
...
...
@@ -133,7 +104,8 @@ public class ResponseBodyResultHandlerTests {
}
@RestController
@SuppressWarnings
(
"unused"
)
@RestController
@SuppressWarnings
(
"unused"
)
private
static
class
TestRestController
{
public
Mono
<
Void
>
handleToMonoVoid
()
{
return
null
;}
...
...
@@ -163,7 +135,9 @@ public class ResponseBodyResultHandlerTests {
}
}
@Controller
@SuppressWarnings
(
"unused"
)
@Controller
@SuppressWarnings
(
"unused"
)
private
static
class
TestController
{
@ResponseBody
...
...
@@ -174,7 +148,6 @@ public class ResponseBodyResultHandlerTests {
public
String
doWork
()
{
return
null
;
}
}
}
spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/ResponseEntityResultHandlerTests.java
浏览文件 @
73493bc4
/*
* Copyright 2002-201
6
the original author or authors.
* Copyright 2002-201
7
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.
...
...
@@ -27,7 +27,6 @@ import java.util.Collections;
import
java.util.List
;
import
java.util.concurrent.CompletableFuture
;
import
org.jetbrains.annotations.NotNull
;
import
org.junit.Before
;
import
org.junit.Test
;
import
reactor.core.publisher.Mono
;
...
...
@@ -60,12 +59,9 @@ import org.springframework.web.reactive.result.ResolvableMethod;
import
org.springframework.web.server.ServerWebExchange
;
import
org.springframework.web.server.adapter.DefaultServerWebExchange
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertFalse
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
springframework
.
core
.
ResolvableType
.
forClassWithGenerics
;
import
static
org
.
springframework
.
http
.
ResponseEntity
.
notFound
;
import
static
org
.
springframework
.
http
.
ResponseEntity
.
ok
;
import
static
org
.
junit
.
Assert
.*;
import
static
org
.
springframework
.
core
.
ResolvableType
.*;
import
static
org
.
springframework
.
http
.
ResponseEntity
.*;
/**
* Unit tests for {@link ResponseEntityResultHandler}. When adding a test also
...
...
@@ -86,7 +82,7 @@ public class ResponseEntityResultHandlerTests {
@Before
public
void
set
U
p
()
throws
Exception
{
public
void
set
u
p
()
throws
Exception
{
this
.
resultHandler
=
createHandler
();
initExchange
();
}
...
...
@@ -325,7 +321,6 @@ public class ResponseEntityResultHandlerTests {
assertResponseBody
(
"abc"
);
}
@NotNull
private
DefaultServerWebExchange
createExchange
()
{
return
new
DefaultServerWebExchange
(
this
.
request
,
this
.
response
);
}
...
...
spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/ServerWebExchangeArgumentResolverTests.java
浏览文件 @
73493bc4
/*
* Copyright 2002-201
6
the original author or authors.
* Copyright 2002-201
7
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.
...
...
@@ -34,10 +34,8 @@ import org.springframework.web.server.adapter.DefaultServerWebExchange;
import
org.springframework.web.server.session.MockWebSessionManager
;
import
org.springframework.web.server.session.WebSessionManager
;
import
static
org
.
junit
.
Assert
.
assertFalse
;
import
static
org
.
junit
.
Assert
.
assertSame
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
mockito
.
Mockito
.
mock
;
import
static
org
.
junit
.
Assert
.*;
import
static
org
.
mockito
.
Mockito
.*;
/**
* Unit tests for {@link ServerWebExchangeArgumentResolver}.
...
...
@@ -45,15 +43,15 @@ import static org.mockito.Mockito.mock;
*/
public
class
ServerWebExchangeArgumentResolverTests
{
private
ServerWebExchangeArgumentResolver
resolver
=
new
ServerWebExchangeArgumentResolver
(
);
private
final
ResolvableMethod
testMethod
=
ResolvableMethod
.
onClass
(
getClass
()).
name
(
"handle"
);
private
ServerWebExchange
exchange
;
private
final
ServerWebExchangeArgumentResolver
resolver
=
new
ServerWebExchangeArgumentResolver
()
;
private
ResolvableMethod
testMethod
=
ResolvableMethod
.
onClass
(
getClass
()).
name
(
"handle"
)
;
private
ServerWebExchange
exchange
;
@Before
public
void
set
U
p
()
throws
Exception
{
public
void
set
u
p
()
throws
Exception
{
ServerHttpRequest
request
=
MockServerHttpRequest
.
get
(
"/path"
).
build
();
ServerHttpResponse
response
=
new
MockServerHttpResponse
();
...
...
@@ -61,6 +59,7 @@ public class ServerWebExchangeArgumentResolverTests {
this
.
exchange
=
new
DefaultServerWebExchange
(
request
,
response
,
sessionManager
);
}
@Test
public
void
supportsParameter
()
throws
Exception
{
assertTrue
(
this
.
resolver
.
supportsParameter
(
parameter
(
ServerWebExchange
.
class
)));
...
...
@@ -78,6 +77,7 @@ public class ServerWebExchangeArgumentResolverTests {
testResolveArgument
(
parameter
(
HttpMethod
.
class
),
HttpMethod
.
GET
);
}
private
void
testResolveArgument
(
MethodParameter
parameter
,
Object
expected
)
{
Mono
<
Object
>
mono
=
this
.
resolver
.
resolveArgument
(
parameter
,
new
BindingContext
(),
this
.
exchange
);
assertSame
(
expected
,
mono
.
block
());
...
...
spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/SessionAttributeMethodArgumentResolverTests.java
浏览文件 @
73493bc4
/*
* Copyright 2002-201
6
the original author or authors.
* Copyright 2002-201
7
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.
...
...
@@ -44,17 +44,12 @@ import org.springframework.web.server.adapter.DefaultServerWebExchange;
import
org.springframework.web.server.session.MockWebSessionManager
;
import
org.springframework.web.server.session.WebSessionManager
;
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
.
mockito
.
Mockito
.
mock
;
import
static
org
.
mockito
.
Mockito
.
when
;
import
static
org
.
junit
.
Assert
.*;
import
static
org
.
mockito
.
Mockito
.*;
/**
* Unit tests for {@link SessionAttributeMethodArgumentResolver}.
*
* @author Rossen Stoyanchev
*/
public
class
SessionAttributeMethodArgumentResolverTests
{
...
...
@@ -69,8 +64,7 @@ public class SessionAttributeMethodArgumentResolverTests {
@Before
@SuppressWarnings
(
"ConfusingArgumentToVarargsMethod"
)
public
void
setUp
()
throws
Exception
{
public
void
setup
()
throws
Exception
{
AnnotationConfigApplicationContext
context
=
new
AnnotationConfigApplicationContext
();
context
.
refresh
();
this
.
resolver
=
new
SessionAttributeMethodArgumentResolver
(
context
.
getBeanFactory
());
...
...
@@ -84,6 +78,7 @@ public class SessionAttributeMethodArgumentResolverTests {
this
.
handleMethod
=
ReflectionUtils
.
findMethod
(
getClass
(),
"handleWithSessionAttribute"
,
(
Class
<?>[])
null
);
}
@Test
public
void
supportsParameter
()
throws
Exception
{
assertTrue
(
this
.
resolver
.
supportsParameter
(
new
MethodParameter
(
this
.
handleMethod
,
0
)));
...
...
spring-webflux/src/test/java/org/springframework/web/reactive/result/view/RedirectViewTests.java
浏览文件 @
73493bc4
/*
* Copyright 2002-201
6
the original author or authors.
* Copyright 2002-201
7
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.
...
...
@@ -21,7 +21,6 @@ import java.util.Collections;
import
java.util.HashMap
;
import
java.util.Map
;
import
org.jetbrains.annotations.NotNull
;
import
org.junit.Before
;
import
org.junit.Test
;
...
...
@@ -50,7 +49,7 @@ public class RedirectViewTests {
@Before
public
void
set
U
p
()
{
public
void
set
u
p
()
{
this
.
request
=
MockServerHttpRequest
.
get
(
"/"
).
contextPath
(
"/context"
).
build
();
this
.
response
=
new
MockServerHttpResponse
();
}
...
...
@@ -142,7 +141,7 @@ public class RedirectViewTests {
this
.
response
.
getHeaders
().
getLocation
());
}
@NotNull
private
DefaultServerWebExchange
createExchange
()
{
return
new
DefaultServerWebExchange
(
this
.
request
,
this
.
response
);
}
...
...
spring-webflux/src/test/java/org/springframework/web/reactive/result/view/UrlBasedViewResolverTests.java
浏览文件 @
73493bc4
/*
* Copyright 2002-201
6
the original author or authors.
* Copyright 2002-201
7
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.
...
...
@@ -19,17 +19,17 @@ package org.springframework.web.reactive.result.view;
import
java.util.Locale
;
import
java.util.Map
;
import
static
org
.
junit
.
Assert
.*;
import
org.junit.Before
;
import
org.junit.Test
;
import
reactor.core.publisher.Mono
;
import
reactor.test.StepVerifier
;
import
org.springframework.context.support.StaticApplicationContext
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.MediaType
;
import
org.springframework.web.server.ServerWebExchange
;
import
reactor.test.StepVerifier
;
import
static
org
.
junit
.
Assert
.*
;
/**
* Unit tests for {@link UrlBasedViewResolver}.
...
...
@@ -42,13 +42,14 @@ public class UrlBasedViewResolverTests {
private
UrlBasedViewResolver
resolver
;
@Before
public
void
set
U
p
()
{
public
void
set
u
p
()
{
StaticApplicationContext
context
=
new
StaticApplicationContext
();
context
.
refresh
();
resolver
=
new
UrlBasedViewResolver
();
resolver
.
setApplicationContext
(
context
);
}
@Test
public
void
viewNames
()
throws
Exception
{
resolver
.
setViewClass
(
TestView
.
class
);
...
...
@@ -90,6 +91,7 @@ public class UrlBasedViewResolverTests {
.
expectComplete
();
}
private
static
class
TestView
extends
AbstractUrlBasedView
{
@Override
...
...
spring-webflux/src/test/java/org/springframework/web/reactive/result/view/ViewResolutionResultHandlerTests.java
浏览文件 @
73493bc4
/*
* Copyright 2002-201
6
the original author or authors.
* Copyright 2002-201
7
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.
...
...
@@ -41,6 +41,7 @@ import org.springframework.core.Ordered;
import
org.springframework.core.ResolvableType
;
import
org.springframework.core.io.buffer.DataBuffer
;
import
org.springframework.core.io.buffer.DefaultDataBufferFactory
;
import
org.springframework.core.io.buffer.support.DataBufferTestUtils
;
import
org.springframework.http.MediaType
;
import
org.springframework.http.server.reactive.ServerHttpResponse
;
import
org.springframework.mock.http.server.reactive.test.MockServerHttpRequest
;
...
...
@@ -57,13 +58,11 @@ import org.springframework.web.server.NotAcceptableStatusException;
import
org.springframework.web.server.ServerWebExchange
;
import
org.springframework.web.server.adapter.DefaultServerWebExchange
;
import
static
java
.
nio
.
charset
.
StandardCharsets
.
UTF_8
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
mockito
.
Mockito
.
mock
;
import
static
org
.
springframework
.
core
.
ResolvableType
.
forClass
;
import
static
org
.
springframework
.
core
.
ResolvableType
.
forClassWithGenerics
;
import
static
org
.
springframework
.
core
.
io
.
buffer
.
support
.
DataBufferTestUtils
.
dumpString
;
import
static
org
.
springframework
.
http
.
MediaType
.
APPLICATION_JSON
;
import
static
java
.
nio
.
charset
.
StandardCharsets
.*;
import
static
org
.
junit
.
Assert
.*;
import
static
org
.
mockito
.
Mockito
.*;
import
static
org
.
springframework
.
core
.
ResolvableType
.*;
import
static
org
.
springframework
.
http
.
MediaType
.*;
/**
* Unit tests for {@link ViewResolutionResultHandler}.
...
...
@@ -77,7 +76,7 @@ public class ViewResolutionResultHandlerTests {
@Before
public
void
set
U
p
()
throws
Exception
{
public
void
set
u
p
()
throws
Exception
{
this
.
request
=
MockServerHttpRequest
.
get
(
"/path"
).
build
();
}
...
...
@@ -288,6 +287,7 @@ public class ViewResolutionResultHandlerTests {
"}"
);
}
private
ServerWebExchange
createExchange
()
{
return
new
DefaultServerWebExchange
(
this
.
request
,
new
MockServerHttpResponse
());
}
...
...
@@ -336,7 +336,7 @@ public class ViewResolutionResultHandlerTests {
private
void
assertResponseBody
(
ServerWebExchange
exchange
,
String
responseBody
)
{
MockServerHttpResponse
response
=
(
MockServerHttpResponse
)
exchange
.
getResponse
();
StepVerifier
.
create
(
response
.
getBody
())
.
consumeNextWith
(
buf
->
assertEquals
(
responseBody
,
dumpString
(
buf
,
UTF_8
)))
.
consumeNextWith
(
buf
->
assertEquals
(
responseBody
,
DataBufferTestUtils
.
dumpString
(
buf
,
UTF_8
)))
.
expectComplete
()
.
verify
();
}
...
...
spring-webflux/src/test/java/org/springframework/web/reactive/result/view/freemarker/FreeMarkerViewTests.java
浏览文件 @
73493bc4
/*
* Copyright 2002-201
6
the original author or authors.
* Copyright 2002-201
7
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.
...
...
@@ -37,8 +37,7 @@ import org.springframework.ui.ModelMap;
import
org.springframework.web.server.ServerWebExchange
;
import
org.springframework.web.server.adapter.DefaultServerWebExchange
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
junit
.
Assert
.*;
/**
* @author Rossen Stoyanchev
...
...
@@ -61,7 +60,7 @@ public class FreeMarkerViewTests {
@Before
public
void
set
U
p
()
throws
Exception
{
public
void
set
u
p
()
throws
Exception
{
this
.
context
=
new
GenericApplicationContext
();
this
.
context
.
refresh
();
...
...
@@ -71,9 +70,6 @@ public class FreeMarkerViewTests {
configurer
.
setResourceLoader
(
this
.
context
);
this
.
freeMarkerConfig
=
configurer
.
createConfiguration
();
FreeMarkerView
fv
=
new
FreeMarkerView
();
fv
.
setApplicationContext
(
this
.
context
);
MockServerHttpRequest
request
=
MockServerHttpRequest
.
get
(
"/path"
).
build
();
this
.
response
=
new
MockServerHttpResponse
();
this
.
exchange
=
new
DefaultServerWebExchange
(
request
,
this
.
response
);
...
...
spring-webflux/src/test/java/org/springframework/web/reactive/socket/AbstractWebSocketIntegrationTests.java
浏览文件 @
73493bc4
/*
* Copyright 2002-201
6
the original author or authors.
* Copyright 2002-201
7
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.
...
...
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.springframework.web.reactive.socket
;
import
java.io.File
;
...
...
@@ -21,7 +22,6 @@ import java.net.URI;
import
java.net.URISyntaxException
;
import
org.apache.tomcat.websocket.server.WsContextListener
;
import
org.jetbrains.annotations.NotNull
;
import
org.junit.After
;
import
org.junit.Before
;
import
org.junit.runner.RunWith
;
...
...
@@ -61,7 +61,7 @@ import org.springframework.web.reactive.socket.server.upgrade.RxNettyRequestUpgr
import
org.springframework.web.reactive.socket.server.upgrade.TomcatRequestUpgradeStrategy
;
import
org.springframework.web.reactive.socket.server.upgrade.UndertowRequestUpgradeStrategy
;
import
static
org
.
junit
.
Assume
.
assumeFalse
;
import
static
org
.
junit
.
Assume
.
*
;
/**
* Base class for WebSocket integration tests. Sub-classes must implement
...
...
@@ -123,7 +123,6 @@ public abstract class AbstractWebSocketIntegrationTests {
@Before
public
void
setup
()
throws
Exception
{
// TODO
// Caused by: java.io.IOException: Upgrade responses cannot have a transfer coding
// at org.xnio.http.HttpUpgrade$HttpUpgradeState.handleUpgrade(HttpUpgrade.java:490)
...
...
@@ -146,6 +145,15 @@ public abstract class AbstractWebSocketIntegrationTests {
}
}
@After
public
void
stop
()
throws
Exception
{
if
(
this
.
client
instanceof
Lifecycle
)
{
((
Lifecycle
)
this
.
client
).
stop
();
}
this
.
server
.
stop
();
}
private
HttpHandler
createHttpHandler
()
{
AnnotationConfigApplicationContext
context
=
new
AnnotationConfigApplicationContext
();
context
.
register
(
DispatcherConfig
.
class
,
this
.
serverConfigClass
);
...
...
@@ -154,16 +162,12 @@ public abstract class AbstractWebSocketIntegrationTests {
return
DispatcherHandler
.
toHttpHandler
(
context
);
}
protected
abstract
Class
<?>
getWebConfigClass
();
@After
public
void
tearDown
()
throws
Exception
{
if
(
this
.
client
instanceof
Lifecycle
)
{
((
Lifecycle
)
this
.
client
).
stop
();
}
this
.
server
.
stop
();
protected
URI
getUrl
(
String
path
)
throws
URISyntaxException
{
return
new
URI
(
"ws://localhost:"
+
this
.
port
+
path
);
}
protected
abstract
Class
<?>
getWebConfigClass
();
@Configuration
static
class
DispatcherConfig
{
...
...
@@ -174,11 +178,6 @@ public abstract class AbstractWebSocketIntegrationTests {
}
}
@NotNull
protected
URI
getUrl
(
String
path
)
throws
URISyntaxException
{
return
new
URI
(
"ws://localhost:"
+
this
.
port
+
path
);
}
static
abstract
class
AbstractHandlerAdapterConfig
{
...
...
@@ -193,9 +192,9 @@ public abstract class AbstractWebSocketIntegrationTests {
}
protected
abstract
RequestUpgradeStrategy
getUpgradeStrategy
();
}
@Configuration
static
class
ReactorNettyConfig
extends
AbstractHandlerAdapterConfig
{
...
...
@@ -205,6 +204,7 @@ public abstract class AbstractWebSocketIntegrationTests {
}
}
@Configuration
static
class
RxNettyConfig
extends
AbstractHandlerAdapterConfig
{
...
...
@@ -214,6 +214,7 @@ public abstract class AbstractWebSocketIntegrationTests {
}
}
@Configuration
static
class
TomcatConfig
extends
AbstractHandlerAdapterConfig
{
...
...
@@ -223,6 +224,7 @@ public abstract class AbstractWebSocketIntegrationTests {
}
}
@Configuration
static
class
UndertowConfig
extends
AbstractHandlerAdapterConfig
{
...
...
@@ -232,6 +234,7 @@ public abstract class AbstractWebSocketIntegrationTests {
}
}
@Configuration
static
class
JettyConfig
extends
AbstractHandlerAdapterConfig
{
...
...
spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/WebContentInterceptorTests.java
浏览文件 @
73493bc4
/*
* Copyright 2002-201
5
the original author or authors.
* Copyright 2002-201
7
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.
...
...
@@ -16,18 +16,16 @@
package
org.springframework.web.servlet.mvc
;
import
static
org
.
hamcrest
.
Matchers
.
is
;
import
static
org
.
junit
.
Assert
.*;
import
java.util.Properties
;
import
org.hamcrest.Matchers
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.springframework.mock.web.test.MockHttpServletRequest
;
import
org.springframework.mock.web.test.MockHttpServletResponse
;
import
org.springframework.web.servlet.support.WebContentGenerator
;
import
static
org
.
hamcrest
.
Matchers
.*;
import
static
org
.
junit
.
Assert
.*;
/**
* @author Rick Evans
...
...
@@ -35,17 +33,9 @@ import org.springframework.web.servlet.support.WebContentGenerator;
*/
public
class
WebContentInterceptorTests
{
private
MockHttpServletRequest
request
;
private
MockHttpServletRequest
request
=
new
MockHttpServletRequest
(
"GET"
,
"/"
)
;
private
MockHttpServletResponse
response
;
@Before
public
void
setUp
()
throws
Exception
{
request
=
new
MockHttpServletRequest
();
request
.
setMethod
(
WebContentGenerator
.
METHOD_GET
);
response
=
new
MockHttpServletResponse
();
}
private
MockHttpServletResponse
response
=
new
MockHttpServletResponse
();
@Test
...
...
@@ -68,14 +58,14 @@ public class WebContentInterceptorTests {
interceptor
.
setCacheSeconds
(
10
);
interceptor
.
setCacheMappings
(
mappings
);
//
request.setRequestURI("http://localhost:7070/example/adminhandle.vm");
//
request.setRequestURI("http://localhost:7070/example/adminhandle.vm");
request
.
setRequestURI
(
"example/adminhandle.vm"
);
interceptor
.
preHandle
(
request
,
response
,
null
);
Iterable
<
String
>
cacheControlHeaders
=
response
.
getHeaders
(
"Cache-Control"
);
assertThat
(
cacheControlHeaders
,
Matchers
.
emptyIterable
());
//
request.setRequestURI("http://localhost:7070/example/bingo.html");
//
request.setRequestURI("http://localhost:7070/example/bingo.html");
request
.
setRequestURI
(
"example/bingo.html"
);
interceptor
.
preHandle
(
request
,
response
,
null
);
...
...
@@ -148,7 +138,7 @@ public class WebContentInterceptorTests {
mappings
.
setProperty
(
"*/*.cache.html"
,
"10"
);
// was **/*.cache.html
interceptor
.
setCacheMappings
(
mappings
);
//
request.setRequestURI("http://example.org/foo/page.html");
//
request.setRequestURI("http://example.org/foo/page.html");
request
.
setRequestURI
(
"foo/page.html"
);
interceptor
.
preHandle
(
request
,
response
,
null
);
...
...
@@ -159,9 +149,9 @@ public class WebContentInterceptorTests {
Iterable
<
String
>
pragmaHeaders
=
response
.
getHeaders
(
"Pragma"
);
assertThat
(
pragmaHeaders
,
Matchers
.
contains
(
"no-cache"
));
// request.setRequestURI("http://example.org/page.cache.html");
request
=
new
MockHttpServletRequest
(
"GET"
,
"foo/page.cache.html"
);
response
=
new
MockHttpServletResponse
();
// request.setRequestURI("http://example.org/page.cache.html");
request
.
setRequestURI
(
"foo/page.cache.html"
);
interceptor
.
preHandle
(
request
,
response
,
null
);
expiresHeaders
=
response
.
getHeaders
(
"Expires"
);
...
...
spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/RequestMappingInfoHandlerMappingTests.java
浏览文件 @
73493bc4
/*
* Copyright 2002-201
6
the original author or authors.
* Copyright 2002-201
7
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.
...
...
@@ -84,7 +84,7 @@ public class RequestMappingInfoHandlerMappingTests {
@Before
public
void
set
U
p
()
throws
Exception
{
public
void
set
u
p
()
throws
Exception
{
TestController
testController
=
new
TestController
();
this
.
fooMethod
=
new
HandlerMethod
(
testController
,
"foo"
);
...
...
spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/AbstractRequestAttributesArgumentResolverTests.java
浏览文件 @
73493bc4
/*
* Copyright 2002-201
6
the original author or authors.
* Copyright 2002-201
7
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.
...
...
@@ -62,11 +62,13 @@ public abstract class AbstractRequestAttributesArgumentResolverTests {
@Before
public
void
set
U
p
()
throws
Exception
{
public
void
set
u
p
()
throws
Exception
{
HttpServletRequest
request
=
new
MockHttpServletRequest
();
HttpServletResponse
response
=
new
MockHttpServletResponse
();
this
.
webRequest
=
new
ServletWebRequest
(
request
,
response
);
this
.
resolver
=
createResolver
();
this
.
handleMethod
=
AbstractRequestAttributesArgumentResolverTests
.
class
.
getDeclaredMethod
(
getHandleMethodName
(),
Foo
.
class
,
Foo
.
class
,
Foo
.
class
,
Optional
.
class
);
}
...
...
spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/CrossOriginTests.java
浏览文件 @
73493bc4
/*
* Copyright 2002-201
6
the original author or authors.
* Copyright 2002-201
7
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.
...
...
@@ -74,7 +74,7 @@ public class CrossOriginTests {
@Before
public
void
set
U
p
()
{
public
void
set
u
p
()
{
StaticWebApplicationContext
wac
=
new
StaticWebApplicationContext
();
Properties
props
=
new
Properties
();
props
.
setProperty
(
"myOrigin"
,
"http://example.com"
);
...
...
@@ -89,6 +89,7 @@ public class CrossOriginTests {
this
.
request
.
addHeader
(
HttpHeaders
.
ORIGIN
,
"http://domain.com/"
);
}
@Test
public
void
noAnnotationWithoutOrigin
()
throws
Exception
{
this
.
handlerMapping
.
registerHandler
(
new
MethodLevelController
());
...
...
@@ -288,6 +289,7 @@ public class CrossOriginTests {
assertNull
(
this
.
handlerMapping
.
getHandler
(
request
));
}
private
CorsConfiguration
getCorsConfiguration
(
HandlerExecutionChain
chain
,
boolean
isPreFlightRequest
)
{
if
(
isPreFlightRequest
)
{
Object
handler
=
chain
.
getHandler
();
...
...
spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/DeferredResultReturnValueHandlerTests.java
浏览文件 @
73493bc4
/*
* Copyright 2002-201
6
the original author or authors.
* Copyright 2002-201
7
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.
...
...
@@ -41,6 +41,7 @@ import static org.junit.Assert.assertTrue;
/**
* Unit tests for {@link DeferredResultMethodReturnValueHandler}.
*
* @author Rossen Stoyanchev
*/
public
class
DeferredResultReturnValueHandlerTests
{
...
...
@@ -53,7 +54,7 @@ public class DeferredResultReturnValueHandlerTests {
@Before
public
void
set
U
p
()
throws
Exception
{
public
void
set
u
p
()
throws
Exception
{
this
.
handler
=
new
DeferredResultMethodReturnValueHandler
();
this
.
request
=
new
MockHttpServletRequest
();
MockHttpServletResponse
response
=
new
MockHttpServletResponse
();
...
...
@@ -190,8 +191,6 @@ public class DeferredResultReturnValueHandlerTests {
private
CompletableFuture
<
String
>
handleCompletableFuture
()
{
return
null
;
}
}
}
spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/HttpEntityMethodProcessorMockTests.java
浏览文件 @
73493bc4
/*
* Copyright 2002-201
6
the original author or authors.
* Copyright 2002-201
7
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.
...
...
@@ -110,9 +110,9 @@ public class HttpEntityMethodProcessorMockTests {
private
ServletWebRequest
webRequest
;
@SuppressWarnings
(
"unchecked"
)
@Before
public
void
setUp
()
throws
Exception
{
@SuppressWarnings
(
"unchecked"
)
public
void
setup
()
throws
Exception
{
dateFormat
=
new
SimpleDateFormat
(
"EEE, dd MMM yyyy HH:mm:ss z"
,
Locale
.
US
);
dateFormat
.
setTimeZone
(
TimeZone
.
getTimeZone
(
"GMT"
));
...
...
@@ -259,8 +259,8 @@ public class HttpEntityMethodProcessorMockTests {
verify
(
stringHttpMessageConverter
).
write
(
eq
(
body
),
eq
(
MediaType
.
TEXT_HTML
),
isA
(
HttpOutputMessage
.
class
));
}
@SuppressWarnings
(
"unchecked"
)
@Test
@SuppressWarnings
(
"unchecked"
)
public
void
shouldHandleReturnValueWithResponseBodyAdvice
()
throws
Exception
{
servletRequest
.
addHeader
(
"Accept"
,
"text/*"
);
servletRequest
.
setAttribute
(
PRODUCIBLE_MEDIA_TYPES_ATTRIBUTE
,
Collections
.
singleton
(
MediaType
.
TEXT_HTML
));
...
...
@@ -310,7 +310,7 @@ public class HttpEntityMethodProcessorMockTests {
processor
.
handleReturnValue
(
returnValue
,
returnTypeResponseEntityProduces
,
mavContainer
,
webRequest
);
}
@Test
// SPR-9142
@Test
// SPR-9142
public
void
shouldFailHandlingWhenAcceptHeaderIllegal
()
throws
Exception
{
ResponseEntity
<
String
>
returnValue
=
new
ResponseEntity
<>(
"Body"
,
HttpStatus
.
ACCEPTED
);
servletRequest
.
addHeader
(
"Accept"
,
"01"
);
...
...
@@ -371,7 +371,7 @@ public class HttpEntityMethodProcessorMockTests {
assertConditionalResponse
(
HttpStatus
.
NOT_MODIFIED
,
null
,
etagValue
,
-
1
);
}
@Test
// SPR-14559
@Test
// SPR-14559
public
void
shouldHandleInvalidIfNoneMatchWithHttp200
()
throws
Exception
{
String
etagValue
=
"\"deadb33f8badf00d\""
;
servletRequest
.
addHeader
(
HttpHeaders
.
IF_NONE_MATCH
,
"unquoted"
);
...
...
@@ -429,7 +429,7 @@ public class HttpEntityMethodProcessorMockTests {
assertConditionalResponse
(
HttpStatus
.
OK
,
null
,
changedEtagValue
,
oneMinuteAgo
);
}
@Test
// SPR-13496
@Test
// SPR-13496
public
void
shouldHandleConditionalRequestIfNoneMatchWildcard
()
throws
Exception
{
String
wildcardValue
=
"*"
;
String
etagValue
=
"\"some-etag\""
;
...
...
@@ -443,7 +443,7 @@ public class HttpEntityMethodProcessorMockTests {
assertConditionalResponse
(
HttpStatus
.
OK
,
"body"
,
etagValue
,
-
1
);
}
@Test
// SPR-13626
@Test
// SPR-13626
public
void
shouldHandleGetIfNoneMatchWildcard
()
throws
Exception
{
String
wildcardValue
=
"*"
;
String
etagValue
=
"\"some-etag\""
;
...
...
@@ -456,7 +456,7 @@ public class HttpEntityMethodProcessorMockTests {
assertConditionalResponse
(
HttpStatus
.
OK
,
"body"
,
etagValue
,
-
1
);
}
@Test
// SPR-13626
@Test
// SPR-13626
public
void
shouldHandleIfNoneMatchIfMatch
()
throws
Exception
{
String
etagValue
=
"\"some-etag\""
;
servletRequest
.
addHeader
(
HttpHeaders
.
IF_NONE_MATCH
,
etagValue
);
...
...
@@ -469,7 +469,7 @@ public class HttpEntityMethodProcessorMockTests {
assertConditionalResponse
(
HttpStatus
.
NOT_MODIFIED
,
null
,
etagValue
,
-
1
);
}
@Test
// SPR-13626
@Test
// SPR-13626
public
void
shouldHandleIfNoneMatchIfUnmodifiedSince
()
throws
Exception
{
String
etagValue
=
"\"some-etag\""
;
servletRequest
.
addHeader
(
HttpHeaders
.
IF_NONE_MATCH
,
etagValue
);
...
...
@@ -498,7 +498,7 @@ public class HttpEntityMethodProcessorMockTests {
assertEquals
(
200
,
servletResponse
.
getStatus
());
}
@Test
//SPR-14767
@Test
//SPR-14767
public
void
shouldHandleValidatorHeadersInPutResponses
()
throws
Exception
{
servletRequest
.
setMethod
(
"PUT"
);
String
etagValue
=
"\"some-etag\""
;
...
...
@@ -510,6 +510,7 @@ public class HttpEntityMethodProcessorMockTests {
assertConditionalResponse
(
HttpStatus
.
OK
,
"body"
,
etagValue
,
-
1
);
}
private
void
initStringMessageConversion
(
MediaType
accepted
)
{
given
(
stringHttpMessageConverter
.
canWrite
(
String
.
class
,
null
)).
willReturn
(
true
);
given
(
stringHttpMessageConverter
.
getSupportedMediaTypes
()).
willReturn
(
Collections
.
singletonList
(
MediaType
.
TEXT_PLAIN
));
...
...
@@ -541,6 +542,7 @@ public class HttpEntityMethodProcessorMockTests {
}
}
@SuppressWarnings
(
"unused"
)
public
ResponseEntity
<
String
>
handle1
(
HttpEntity
<
String
>
httpEntity
,
ResponseEntity
<
String
>
entity
,
int
i
,
RequestEntity
<
String
>
requestEntity
)
{
...
...
spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/HttpEntityMethodProcessorTests.java
浏览文件 @
73493bc4
/*
* Copyright 2002-201
6
the original author or authors.
* Copyright 2002-201
7
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.
...
...
@@ -46,10 +46,7 @@ import org.springframework.web.context.request.ServletWebRequest;
import
org.springframework.web.method.HandlerMethod
;
import
org.springframework.web.method.support.ModelAndViewContainer
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
junit
.
Assert
.
assertNull
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
junit
.
Assert
.*;
/**
* Test fixture with {@link HttpEntityMethodProcessor} delegating to
...
...
@@ -78,7 +75,7 @@ public class HttpEntityMethodProcessorTests {
@Before
public
void
set
U
p
()
throws
Exception
{
public
void
set
u
p
()
throws
Exception
{
Method
method
=
getClass
().
getDeclaredMethod
(
"handle"
,
HttpEntity
.
class
,
HttpEntity
.
class
);
paramList
=
new
MethodParameter
(
method
,
0
);
paramSimpleBean
=
new
MethodParameter
(
method
,
1
);
...
...
@@ -110,9 +107,7 @@ public class HttpEntityMethodProcessorTests {
assertEquals
(
"Jad"
,
result
.
getBody
().
getName
());
}
// SPR-12861
@Test
@Test
// SPR-12861
public
void
resolveArgumentWithEmptyBody
()
throws
Exception
{
this
.
servletRequest
.
setContent
(
new
byte
[
0
]);
this
.
servletRequest
.
setContentType
(
"application/json"
);
...
...
@@ -187,9 +182,7 @@ public class HttpEntityMethodProcessorTests {
assertTrue
(
content
.
contains
(
"\"type\":\"bar\""
));
}
// SPR-13423
@Test
@Test
// SPR-13423
public
void
handleReturnValueCharSequence
()
throws
Exception
{
List
<
HttpMessageConverter
<?>>
converters
=
new
ArrayList
<>();
converters
.
add
(
new
ByteArrayHttpMessageConverter
());
...
...
@@ -207,7 +200,6 @@ public class HttpEntityMethodProcessorTests {
}
@SuppressWarnings
(
"unused"
)
private
void
handle
(
HttpEntity
<
List
<
SimpleBean
>>
arg1
,
HttpEntity
<
SimpleBean
>
arg2
)
{
}
...
...
@@ -216,6 +208,7 @@ public class HttpEntityMethodProcessorTests {
return
null
;
}
@SuppressWarnings
(
"unused"
)
private
static
abstract
class
MyParameterizedController
<
DTO
extends
Identifiable
>
{
...
...
@@ -223,10 +216,12 @@ public class HttpEntityMethodProcessorTests {
}
}
@SuppressWarnings
(
"unused"
)
private
static
class
MySimpleParameterizedController
extends
MyParameterizedController
<
SimpleBean
>
{
}
private
interface
Identifiable
extends
Serializable
{
Long
getId
();
...
...
@@ -275,6 +270,7 @@ public class HttpEntityMethodProcessorTests {
}
}
@JsonTypeInfo
(
use
=
JsonTypeInfo
.
Id
.
NAME
,
include
=
JsonTypeInfo
.
As
.
PROPERTY
,
property
=
"type"
)
private
static
class
ParentClass
{
...
...
@@ -296,6 +292,7 @@ public class HttpEntityMethodProcessorTests {
}
}
@JsonTypeName
(
"foo"
)
private
static
class
Foo
extends
ParentClass
{
...
...
@@ -307,6 +304,7 @@ public class HttpEntityMethodProcessorTests {
}
}
@JsonTypeName
(
"bar"
)
private
static
class
Bar
extends
ParentClass
{
...
...
@@ -318,6 +316,7 @@ public class HttpEntityMethodProcessorTests {
}
}
private
static
class
JacksonController
{
@RequestMapping
...
...
spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/MatrixVariablesMapMethodArgumentResolverTests.java
浏览文件 @
73493bc4
/*
* Copyright 2002-201
6
the original author or authors.
* Copyright 2002-201
7
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.
...
...
@@ -47,22 +47,28 @@ public class MatrixVariablesMapMethodArgumentResolverTests {
private
MatrixVariableMapMethodArgumentResolver
resolver
;
private
MethodParameter
paramString
;
private
MethodParameter
paramMap
;
private
MethodParameter
paramMultivalueMap
;
private
MethodParameter
paramMapForPathVar
;
private
MethodParameter
paramMapWithName
;
private
ModelAndViewContainer
mavContainer
;
private
ServletWebRequest
webRequest
;
private
MockHttpServletRequest
request
;
private
MethodParameter
paramString
;
private
MethodParameter
paramMap
;
private
MethodParameter
paramMultivalueMap
;
private
MethodParameter
paramMapForPathVar
;
private
MethodParameter
paramMapWithName
;
@Before
public
void
set
U
p
()
throws
Exception
{
public
void
set
u
p
()
throws
Exception
{
this
.
resolver
=
new
MatrixVariableMapMethodArgumentResolver
();
this
.
mavContainer
=
new
ModelAndViewContainer
();
this
.
request
=
new
MockHttpServletRequest
();
this
.
webRequest
=
new
ServletWebRequest
(
request
,
new
MockHttpServletResponse
());
Map
<
String
,
MultiValueMap
<
String
,
String
>>
params
=
new
LinkedHashMap
<>();
this
.
request
.
setAttribute
(
HandlerMapping
.
MATRIX_VARIABLES_ATTRIBUTE
,
params
);
Method
method
=
getClass
().
getMethod
(
"handle"
,
String
.
class
,
Map
.
class
,
MultiValueMap
.
class
,
MultiValueMap
.
class
,
Map
.
class
);
...
...
@@ -72,15 +78,9 @@ public class MatrixVariablesMapMethodArgumentResolverTests {
this
.
paramMultivalueMap
=
new
SynthesizingMethodParameter
(
method
,
2
);
this
.
paramMapForPathVar
=
new
SynthesizingMethodParameter
(
method
,
3
);
this
.
paramMapWithName
=
new
SynthesizingMethodParameter
(
method
,
4
);
this
.
mavContainer
=
new
ModelAndViewContainer
();
this
.
request
=
new
MockHttpServletRequest
();
this
.
webRequest
=
new
ServletWebRequest
(
request
,
new
MockHttpServletResponse
());
Map
<
String
,
MultiValueMap
<
String
,
String
>>
params
=
new
LinkedHashMap
<>();
this
.
request
.
setAttribute
(
HandlerMapping
.
MATRIX_VARIABLES_ATTRIBUTE
,
params
);
}
@Test
public
void
supportsParameter
()
{
assertFalse
(
resolver
.
supportsParameter
(
paramString
));
...
...
spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/MatrixVariablesMethodArgumentResolverTests.java
浏览文件 @
73493bc4
...
...
@@ -48,36 +48,35 @@ public class MatrixVariablesMethodArgumentResolverTests {
private
MatrixVariableMethodArgumentResolver
resolver
;
private
MethodParameter
paramString
;
private
MethodParameter
paramColors
;
private
MethodParameter
paramYear
;
private
ModelAndViewContainer
mavContainer
;
private
ServletWebRequest
webRequest
;
private
MockHttpServletRequest
request
;
private
MethodParameter
paramString
;
private
MethodParameter
paramColors
;
private
MethodParameter
paramYear
;
@Before
public
void
set
U
p
()
throws
Exception
{
public
void
set
u
p
()
throws
Exception
{
this
.
resolver
=
new
MatrixVariableMethodArgumentResolver
();
Method
method
=
getClass
().
getMethod
(
"handle"
,
String
.
class
,
List
.
class
,
int
.
class
);
this
.
paramString
=
new
MethodParameter
(
method
,
0
);
this
.
paramColors
=
new
MethodParameter
(
method
,
1
);
this
.
paramYear
=
new
MethodParameter
(
method
,
2
);
this
.
paramColors
.
initParameterNameDiscovery
(
new
LocalVariableTableParameterNameDiscoverer
());
this
.
mavContainer
=
new
ModelAndViewContainer
();
this
.
request
=
new
MockHttpServletRequest
();
this
.
webRequest
=
new
ServletWebRequest
(
request
,
new
MockHttpServletResponse
());
Map
<
String
,
MultiValueMap
<
String
,
String
>>
params
=
new
LinkedHashMap
<>();
this
.
request
.
setAttribute
(
HandlerMapping
.
MATRIX_VARIABLES_ATTRIBUTE
,
params
);
Method
method
=
getClass
().
getMethod
(
"handle"
,
String
.
class
,
List
.
class
,
int
.
class
);
this
.
paramString
=
new
MethodParameter
(
method
,
0
);
this
.
paramColors
=
new
MethodParameter
(
method
,
1
);
this
.
paramColors
.
initParameterNameDiscovery
(
new
LocalVariableTableParameterNameDiscoverer
());
this
.
paramYear
=
new
MethodParameter
(
method
,
2
);
}
@Test
public
void
supportsParameter
()
{
assertFalse
(
resolver
.
supportsParameter
(
paramString
));
...
...
@@ -87,7 +86,6 @@ public class MatrixVariablesMethodArgumentResolverTests {
@Test
public
void
resolveArgument
()
throws
Exception
{
MultiValueMap
<
String
,
String
>
params
=
getMatrixVariables
(
"cars"
);
params
.
add
(
"colors"
,
"red"
);
params
.
add
(
"colors"
,
"green"
);
...
...
@@ -99,7 +97,6 @@ public class MatrixVariablesMethodArgumentResolverTests {
@Test
public
void
resolveArgumentPathVariable
()
throws
Exception
{
getMatrixVariables
(
"cars"
).
add
(
"year"
,
"2006"
);
getMatrixVariables
(
"bikes"
).
add
(
"year"
,
"2005"
);
...
...
@@ -113,7 +110,6 @@ public class MatrixVariablesMethodArgumentResolverTests {
@Test
(
expected
=
ServletRequestBindingException
.
class
)
public
void
resolveArgumentMultipleMatches
()
throws
Exception
{
getMatrixVariables
(
"var1"
).
add
(
"colors"
,
"red"
);
getMatrixVariables
(
"var2"
).
add
(
"colors"
,
"green"
);
...
...
@@ -127,7 +123,6 @@ public class MatrixVariablesMethodArgumentResolverTests {
@Test
public
void
resolveArgumentNoMatch
()
throws
Exception
{
MultiValueMap
<
String
,
String
>
params
=
getMatrixVariables
(
"cars"
);
params
.
add
(
"anotherYear"
,
"2012"
);
...
...
@@ -137,7 +132,6 @@ public class MatrixVariablesMethodArgumentResolverTests {
@SuppressWarnings
(
"unchecked"
)
private
MultiValueMap
<
String
,
String
>
getMatrixVariables
(
String
pathVarName
)
{
Map
<
String
,
MultiValueMap
<
String
,
String
>>
matrixVariables
=
(
Map
<
String
,
MultiValueMap
<
String
,
String
>>)
this
.
request
.
getAttribute
(
HandlerMapping
.
MATRIX_VARIABLES_ATTRIBUTE
);
...
...
spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ModelAndViewMethodReturnValueHandlerTests.java
浏览文件 @
73493bc4
/*
* Copyright 2002-201
6
the original author or authors.
* Copyright 2002-201
7
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,7 +49,7 @@ public class ModelAndViewMethodReturnValueHandlerTests {
@Before
public
void
set
U
p
()
throws
Exception
{
public
void
set
u
p
()
throws
Exception
{
this
.
handler
=
new
ModelAndViewMethodReturnValueHandler
();
this
.
mavContainer
=
new
ModelAndViewContainer
();
this
.
webRequest
=
new
ServletWebRequest
(
new
MockHttpServletRequest
());
...
...
spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ModelAndViewResolverMethodReturnValueHandlerTests.java
浏览文件 @
73493bc4
/*
* Copyright 2002-201
6
the original author or authors.
* Copyright 2002-201
7
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.
...
...
@@ -52,7 +52,7 @@ public class ModelAndViewResolverMethodReturnValueHandlerTests {
@Before
public
void
set
U
p
()
{
public
void
set
u
p
()
{
mavResolvers
=
new
ArrayList
<>();
handler
=
new
ModelAndViewResolverMethodReturnValueHandler
(
mavResolvers
);
mavContainer
=
new
ModelAndViewContainer
();
...
...
@@ -118,7 +118,7 @@ public class ModelAndViewResolverMethodReturnValueHandlerTests {
private
static
class
TestModelAndViewResolver
implements
ModelAndViewResolver
{
private
Class
<?>
returnValueType
;
private
final
Class
<?>
returnValueType
;
public
TestModelAndViewResolver
(
Class
<?>
returnValueType
)
{
this
.
returnValueType
=
returnValueType
;
...
...
spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/MvcUriComponentsBuilderTests.java
浏览文件 @
73493bc4
/*
* Copyright 2012-201
6
the original author or authors.
* Copyright 2012-201
7
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.
...
...
@@ -16,10 +16,6 @@
package
org.springframework.web.servlet.mvc.method.annotation
;
import
static
org
.
hamcrest
.
Matchers
.*;
import
static
org
.
junit
.
Assert
.*;
import
static
org
.
springframework
.
web
.
servlet
.
mvc
.
method
.
annotation
.
MvcUriComponentsBuilder
.*;
import
java.lang.annotation.Documented
;
import
java.lang.annotation.ElementType
;
import
java.lang.annotation.Retention
;
...
...
@@ -58,6 +54,10 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter
import
org.springframework.web.util.UriComponents
;
import
org.springframework.web.util.UriComponentsBuilder
;
import
static
org
.
hamcrest
.
Matchers
.*;
import
static
org
.
junit
.
Assert
.*;
import
static
org
.
springframework
.
web
.
servlet
.
mvc
.
method
.
annotation
.
MvcUriComponentsBuilder
.*;
/**
* Unit tests for {@link org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder}.
*
...
...
@@ -73,12 +73,12 @@ public class MvcUriComponentsBuilderTests {
@Before
public
void
set
U
p
()
{
public
void
set
u
p
()
{
RequestContextHolder
.
setRequestAttributes
(
new
ServletRequestAttributes
(
this
.
request
));
}
@After
public
void
tearDown
()
{
public
void
reset
()
{
RequestContextHolder
.
resetRequestAttributes
();
}
...
...
@@ -372,15 +372,16 @@ public class MvcUriComponentsBuilderTests {
}
}
@RequestMapping
(
"/people"
)
interface
PersonController
{
}
private
class
PersonControllerImpl
implements
PersonController
{
private
class
PersonControllerImpl
implements
PersonController
{
}
@RequestMapping
(
"/people/{id}/addresses"
)
private
static
class
PersonsAddressesController
{
...
...
@@ -390,11 +391,12 @@ public class MvcUriComponentsBuilderTests {
}
}
@RequestMapping
({
"/persons"
,
"/people"
})
private
class
InvalidController
{
@RequestMapping
({
"/persons"
,
"/people"
})
private
class
InvalidController
{
}
private
class
UnmappedController
{
@RequestMapping
...
...
@@ -402,6 +404,7 @@ public class MvcUriComponentsBuilderTests {
}
}
@RequestMapping
(
"/something"
)
static
class
ControllerWithMethods
{
...
...
@@ -439,11 +442,13 @@ public class MvcUriComponentsBuilderTests {
}
}
@RequestMapping
(
"/extended"
)
@SuppressWarnings
(
"WeakerAccess"
)
static
class
ExtendedController
extends
ControllerWithMethods
{
@RequestMapping
(
"/extended"
)
@SuppressWarnings
(
"WeakerAccess"
)
static
class
ExtendedController
extends
ControllerWithMethods
{
}
@RequestMapping
(
"/user/{userId}/contacts"
)
private
static
class
UserContactController
{
...
...
@@ -453,11 +458,13 @@ public class MvcUriComponentsBuilderTests {
}
}
static
abstract
class
AbstractCrudController
<
T
,
ID
>
{
abstract
T
get
(
ID
id
);
}
private
static
class
PersonCrudController
extends
AbstractCrudController
<
Person
,
Long
>
{
@RequestMapping
(
path
=
"/{id}"
,
method
=
RequestMethod
.
GET
)
...
...
@@ -466,6 +473,7 @@ public class MvcUriComponentsBuilderTests {
}
}
@Controller
private
static
class
MetaAnnotationController
{
...
...
@@ -473,12 +481,12 @@ public class MvcUriComponentsBuilderTests {
public
void
handle
()
{
}
@PostJson
(
path
=
"/input"
)
@PostJson
(
path
=
"/input"
)
public
void
handleInput
()
{
}
}
@RequestMapping
(
method
=
RequestMethod
.
POST
,
produces
=
MediaType
.
APPLICATION_JSON_VALUE
,
consumes
=
MediaType
.
APPLICATION_JSON_VALUE
)
...
...
@@ -486,9 +494,11 @@ public class MvcUriComponentsBuilderTests {
@Retention
(
RetentionPolicy
.
RUNTIME
)
@Documented
private
@interface
PostJson
{
String
[]
path
()
default
{};
}
@EnableWebMvc
static
class
WebConfig
extends
WebMvcConfigurerAdapter
{
...
...
spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/PathVariableMapMethodArgumentResolverTests.java
浏览文件 @
73493bc4
/*
* Copyright 2002-201
6
the original author or authors.
* Copyright 2002-201
7
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.
...
...
@@ -43,32 +43,31 @@ public class PathVariableMapMethodArgumentResolverTests {
private
PathVariableMapMethodArgumentResolver
resolver
;
private
MethodParameter
paramMap
;
private
MethodParameter
paramNamedMap
;
private
MethodParameter
paramMapNoAnnot
;
private
ModelAndViewContainer
mavContainer
;
private
ServletWebRequest
webRequest
;
private
MockHttpServletRequest
request
;
private
MethodParameter
paramMap
;
private
MethodParameter
paramNamedMap
;
private
MethodParameter
paramMapNoAnnot
;
@Before
public
void
set
U
p
()
throws
Exception
{
public
void
set
u
p
()
throws
Exception
{
resolver
=
new
PathVariableMapMethodArgumentResolver
();
mavContainer
=
new
ModelAndViewContainer
();
request
=
new
MockHttpServletRequest
();
webRequest
=
new
ServletWebRequest
(
request
,
new
MockHttpServletResponse
());
Method
method
=
getClass
().
getMethod
(
"handle"
,
Map
.
class
,
Map
.
class
,
Map
.
class
);
paramMap
=
new
MethodParameter
(
method
,
0
);
paramNamedMap
=
new
MethodParameter
(
method
,
1
);
paramMapNoAnnot
=
new
MethodParameter
(
method
,
2
);
mavContainer
=
new
ModelAndViewContainer
();
request
=
new
MockHttpServletRequest
();
webRequest
=
new
ServletWebRequest
(
request
,
new
MockHttpServletResponse
());
}
@Test
public
void
supportsParameter
()
{
assertTrue
(
resolver
.
supportsParameter
(
paramMap
));
...
...
@@ -103,4 +102,4 @@ public class PathVariableMapMethodArgumentResolverTests {
Map
<
String
,
String
>
mapWithoutAnnotat
)
{
}
}
\ No newline at end of file
}
spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/PathVariableMethodArgumentResolverTests.java
浏览文件 @
73493bc4
/*
* Copyright 2002-201
6
the original author or authors.
* Copyright 2002-201
7
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.
...
...
@@ -52,34 +52,30 @@ public class PathVariableMethodArgumentResolverTests {
private
PathVariableMethodArgumentResolver
resolver
;
private
MethodParameter
paramNamedString
;
private
MethodParameter
paramString
;
private
MethodParameter
paramNotRequired
;
private
MethodParameter
paramOptional
;
private
ModelAndViewContainer
mavContainer
;
private
ServletWebRequest
webRequest
;
private
MockHttpServletRequest
request
;
private
MethodParameter
paramNamedString
;
private
MethodParameter
paramString
;
private
MethodParameter
paramNotRequired
;
private
MethodParameter
paramOptional
;
@Before
public
void
set
U
p
()
throws
Exception
{
public
void
set
u
p
()
throws
Exception
{
resolver
=
new
PathVariableMethodArgumentResolver
();
mavContainer
=
new
ModelAndViewContainer
();
request
=
new
MockHttpServletRequest
();
webRequest
=
new
ServletWebRequest
(
request
,
new
MockHttpServletResponse
());
Method
method
=
ReflectionUtils
.
findMethod
(
getClass
(),
"handle"
,
(
Class
<?>[])
null
);
paramNamedString
=
new
SynthesizingMethodParameter
(
method
,
0
);
paramString
=
new
SynthesizingMethodParameter
(
method
,
1
);
paramNotRequired
=
new
SynthesizingMethodParameter
(
method
,
2
);
paramOptional
=
new
SynthesizingMethodParameter
(
method
,
3
);
mavContainer
=
new
ModelAndViewContainer
();
request
=
new
MockHttpServletRequest
();
webRequest
=
new
ServletWebRequest
(
request
,
new
MockHttpServletResponse
());
}
...
...
spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/RequestPartIntegrationTests.java
浏览文件 @
73493bc4
/*
* Copyright 2002-201
6
the original author or authors.
* Copyright 2002-201
7
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,7 +123,7 @@ public class RequestPartIntegrationTests {
}
@Before
public
void
set
U
p
()
{
public
void
set
u
p
()
{
ByteArrayHttpMessageConverter
emptyBodyConverter
=
new
ByteArrayHttpMessageConverter
();
emptyBodyConverter
.
setSupportedMediaTypes
(
Collections
.
singletonList
(
MediaType
.
APPLICATION_JSON
));
...
...
spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/RequestPartMethodArgumentResolverTests.java
浏览文件 @
73493bc4
/*
* Copyright 2002-201
6
the original author or authors.
* Copyright 2002-201
7
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.
...
...
@@ -65,13 +65,18 @@ import static org.mockito.BDDMockito.*;
*/
public
class
RequestPartMethodArgumentResolverTests
{
private
RequestPartMethodArgumentResolver
resolver
;
private
HttpMessageConverter
<
SimpleBean
>
messageConverter
;
private
RequestPartMethodArgumentResolver
resolver
;
private
MultipartFile
multipartFile1
;
private
MultipartFile
multipartFile2
;
private
MockMultipartHttpServletRequest
multipartRequest
;
private
NativeWebRequest
webRequest
;
private
MethodParameter
paramRequestPart
;
private
MethodParameter
paramNamedRequestPart
;
private
MethodParameter
paramValidRequestPart
;
...
...
@@ -90,16 +95,26 @@ public class RequestPartMethodArgumentResolverTests {
private
MethodParameter
optionalPartList
;
private
MethodParameter
optionalRequestPart
;
private
NativeWebRequest
webRequest
;
private
MockMultipartHttpServletRequest
multipartRequest
;
@Before
@SuppressWarnings
(
"unchecked"
)
public
void
setup
()
throws
Exception
{
messageConverter
=
mock
(
HttpMessageConverter
.
class
);
given
(
messageConverter
.
getSupportedMediaTypes
()).
willReturn
(
Collections
.
singletonList
(
MediaType
.
TEXT_PLAIN
));
resolver
=
new
RequestPartMethodArgumentResolver
(
Collections
.<
HttpMessageConverter
<?>>
singletonList
(
messageConverter
));
reset
(
messageConverter
);
@SuppressWarnings
(
"unchecked"
)
@Before
public
void
setUp
()
throws
Exception
{
Method
method
=
ReflectionUtils
.
findMethod
(
getClass
(),
"handle"
,
(
Class
<?>[])
null
);
byte
[]
content
=
"doesn't matter as long as not empty"
.
getBytes
(
StandardCharsets
.
UTF_8
);
multipartFile1
=
new
MockMultipartFile
(
"requestPart"
,
""
,
"text/plain"
,
content
);
multipartFile2
=
new
MockMultipartFile
(
"requestPart"
,
""
,
"text/plain"
,
content
);
multipartRequest
=
new
MockMultipartHttpServletRequest
();
multipartRequest
.
addFile
(
multipartFile1
);
multipartRequest
.
addFile
(
multipartFile2
);
multipartRequest
.
addFile
(
new
MockMultipartFile
(
"otherPart"
,
""
,
"text/plain"
,
content
));
webRequest
=
new
ServletWebRequest
(
multipartRequest
,
new
MockHttpServletResponse
());
Method
method
=
ReflectionUtils
.
findMethod
(
getClass
(),
"handle"
,
(
Class
<?>[])
null
);
paramRequestPart
=
new
SynthesizingMethodParameter
(
method
,
0
);
paramRequestPart
.
initParameterNameDiscovery
(
new
LocalVariableTableParameterNameDiscoverer
());
paramNamedRequestPart
=
new
SynthesizingMethodParameter
(
method
,
1
);
...
...
@@ -124,22 +139,6 @@ public class RequestPartMethodArgumentResolverTests {
optionalPartList
=
new
SynthesizingMethodParameter
(
method
,
15
);
optionalPartList
.
initParameterNameDiscovery
(
new
LocalVariableTableParameterNameDiscoverer
());
optionalRequestPart
=
new
SynthesizingMethodParameter
(
method
,
16
);
messageConverter
=
mock
(
HttpMessageConverter
.
class
);
given
(
messageConverter
.
getSupportedMediaTypes
()).
willReturn
(
Collections
.
singletonList
(
MediaType
.
TEXT_PLAIN
));
resolver
=
new
RequestPartMethodArgumentResolver
(
Collections
.<
HttpMessageConverter
<?>>
singletonList
(
messageConverter
));
reset
(
messageConverter
);
byte
[]
content
=
"doesn't matter as long as not empty"
.
getBytes
(
StandardCharsets
.
UTF_8
);
multipartFile1
=
new
MockMultipartFile
(
"requestPart"
,
""
,
"text/plain"
,
content
);
multipartFile2
=
new
MockMultipartFile
(
"requestPart"
,
""
,
"text/plain"
,
content
);
multipartRequest
=
new
MockMultipartHttpServletRequest
();
multipartRequest
.
addFile
(
multipartFile1
);
multipartRequest
.
addFile
(
multipartFile2
);
multipartRequest
.
addFile
(
new
MockMultipartFile
(
"otherPart"
,
""
,
"text/plain"
,
content
));
webRequest
=
new
ServletWebRequest
(
multipartRequest
,
new
MockHttpServletResponse
());
}
...
...
spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/RequestResponseBodyMethodProcessorMockTests.java
浏览文件 @
73493bc4
/*
* Copyright 2002-201
5
the original author or authors.
* Copyright 2002-201
7
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,12 +66,20 @@ import static org.mockito.BDDMockito.*;
*/
public
class
RequestResponseBodyMethodProcessorMockTests
{
private
RequestResponseBodyMethodProcessor
processor
;
private
HttpMessageConverter
<
String
>
stringMessageConverter
;
private
HttpMessageConverter
<
Resource
>
resourceMessageConverter
;
private
RequestResponseBodyMethodProcessor
processor
;
private
ModelAndViewContainer
mavContainer
;
private
MockHttpServletRequest
servletRequest
;
private
MockHttpServletResponse
servletResponse
;
private
NativeWebRequest
webRequest
;
private
MethodParameter
paramRequestBodyString
;
private
MethodParameter
paramInt
;
private
MethodParameter
paramValidBean
;
...
...
@@ -82,18 +90,10 @@ public class RequestResponseBodyMethodProcessorMockTests {
private
MethodParameter
returnTypeStringProduces
;
private
MethodParameter
returnTypeResource
;
private
ModelAndViewContainer
mavContainer
;
private
NativeWebRequest
webRequest
;
private
MockHttpServletRequest
servletRequest
;
private
MockHttpServletResponse
servletResponse
;
@SuppressWarnings
(
"unchecked"
)
@Before
public
void
setUp
()
throws
Exception
{
@SuppressWarnings
(
"unchecked"
)
public
void
setup
()
throws
Exception
{
stringMessageConverter
=
mock
(
HttpMessageConverter
.
class
);
given
(
stringMessageConverter
.
getSupportedMediaTypes
()).
willReturn
(
Collections
.
singletonList
(
MediaType
.
TEXT_PLAIN
));
...
...
@@ -102,6 +102,12 @@ public class RequestResponseBodyMethodProcessorMockTests {
processor
=
new
RequestResponseBodyMethodProcessor
(
Arrays
.
asList
(
stringMessageConverter
,
resourceMessageConverter
));
mavContainer
=
new
ModelAndViewContainer
();
servletRequest
=
new
MockHttpServletRequest
();
servletRequest
.
setMethod
(
"POST"
);
servletResponse
=
new
MockHttpServletResponse
();
webRequest
=
new
ServletWebRequest
(
servletRequest
,
servletResponse
);
Method
methodHandle1
=
getClass
().
getMethod
(
"handle1"
,
String
.
class
,
Integer
.
TYPE
);
paramRequestBodyString
=
new
MethodParameter
(
methodHandle1
,
0
);
paramInt
=
new
MethodParameter
(
methodHandle1
,
1
);
...
...
@@ -112,13 +118,6 @@ public class RequestResponseBodyMethodProcessorMockTests {
returnTypeInt
=
new
MethodParameter
(
getClass
().
getMethod
(
"handle5"
),
-
1
);
returnTypeStringProduces
=
new
MethodParameter
(
getClass
().
getMethod
(
"handle6"
),
-
1
);
returnTypeResource
=
new
MethodParameter
(
getClass
().
getMethod
(
"handle7"
),
-
1
);
mavContainer
=
new
ModelAndViewContainer
();
servletRequest
=
new
MockHttpServletRequest
();
servletRequest
.
setMethod
(
"POST"
);
servletResponse
=
new
MockHttpServletResponse
();
webRequest
=
new
ServletWebRequest
(
servletRequest
,
servletResponse
);
}
@Test
...
...
spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/RequestResponseBodyMethodProcessorTests.java
浏览文件 @
73493bc4
/*
* Copyright 2002-201
6
the original author or authors.
* Copyright 2002-201
7
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.
...
...
@@ -82,45 +82,42 @@ import static org.junit.Assert.*;
@SuppressWarnings
(
"unused"
)
public
class
RequestResponseBodyMethodProcessorTests
{
private
MethodParameter
paramGenericList
;
private
MethodParameter
paramSimpleBean
;
private
MethodParameter
paramMultiValueMap
;
private
MethodParameter
paramString
;
private
MethodParameter
returnTypeString
;
private
ModelAndViewContainer
container
;
private
NativeWebRequest
request
;
private
MockHttpServletRequest
servletRequest
;
private
MockHttpServletResponse
servletResponse
;
private
ValidatingBinderFactory
factory
;
private
NativeWebRequest
request
;
@Before
public
void
setUp
()
throws
Exception
{
private
ValidatingBinderFactory
factory
;
Method
method
=
getClass
().
getDeclaredMethod
(
"handle"
,
List
.
class
,
SimpleBean
.
class
,
MultiValueMap
.
class
,
String
.
class
);
private
MethodParameter
paramGenericList
;
private
MethodParameter
paramSimpleBean
;
private
MethodParameter
paramMultiValueMap
;
private
MethodParameter
paramString
;
private
MethodParameter
returnTypeString
;
paramGenericList
=
new
MethodParameter
(
method
,
0
);
paramSimpleBean
=
new
MethodParameter
(
method
,
1
);
paramMultiValueMap
=
new
MethodParameter
(
method
,
2
);
paramString
=
new
MethodParameter
(
method
,
3
);
returnTypeString
=
new
MethodParameter
(
method
,
-
1
);
@Before
public
void
setup
()
throws
Exception
{
container
=
new
ModelAndViewContainer
();
servletRequest
=
new
MockHttpServletRequest
();
servletRequest
.
setMethod
(
"POST"
);
servletResponse
=
new
MockHttpServletResponse
();
request
=
new
ServletWebRequest
(
servletRequest
,
servletResponse
);
this
.
factory
=
new
ValidatingBinderFactory
();
Method
method
=
getClass
().
getDeclaredMethod
(
"handle"
,
List
.
class
,
SimpleBean
.
class
,
MultiValueMap
.
class
,
String
.
class
);
paramGenericList
=
new
MethodParameter
(
method
,
0
);
paramSimpleBean
=
new
MethodParameter
(
method
,
1
);
paramMultiValueMap
=
new
MethodParameter
(
method
,
2
);
paramString
=
new
MethodParameter
(
method
,
3
);
returnTypeString
=
new
MethodParameter
(
method
,
-
1
);
}
@Test
public
void
resolveArgumentParameterizedType
()
throws
Exception
{
String
content
=
"[{\"name\" : \"Jad\"}, {\"name\" : \"Robert\"}]"
;
...
...
spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ResponseBodyEmitterReturnValueHandlerTests.java
浏览文件 @
73493bc4
/*
* Copyright 2002-201
6
the original author or authors.
* Copyright 2002-201
7
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.
...
...
@@ -15,10 +15,6 @@
*/
package
org.springframework.web.servlet.mvc.method.annotation
;
import
static
org
.
junit
.
Assert
.*;
import
static
org
.
mockito
.
Mockito
.*;
import
static
org
.
springframework
.
web
.
servlet
.
mvc
.
method
.
annotation
.
SseEmitter
.*;
import
java.lang.reflect.Method
;
import
java.util.Arrays
;
import
java.util.Collections
;
...
...
@@ -43,9 +39,12 @@ import org.springframework.web.context.request.async.StandardServletAsyncWebRequ
import
org.springframework.web.context.request.async.WebAsyncUtils
;
import
org.springframework.web.method.support.ModelAndViewContainer
;
import
static
org
.
junit
.
Assert
.*;
import
static
org
.
mockito
.
Mockito
.*;
/**
* Unit tests for ResponseBodyEmitterReturnValueHandler.
*
* @author Rossen Stoyanchev
*/
public
class
ResponseBodyEmitterReturnValueHandlerTests
{
...
...
@@ -60,8 +59,7 @@ public class ResponseBodyEmitterReturnValueHandlerTests {
@Before
public
void
setUp
()
throws
Exception
{
public
void
setup
()
throws
Exception
{
List
<
HttpMessageConverter
<?>>
converters
=
Arrays
.
asList
(
new
StringHttpMessageConverter
(),
new
MappingJackson2HttpMessageConverter
());
...
...
@@ -75,6 +73,7 @@ public class ResponseBodyEmitterReturnValueHandlerTests {
this
.
request
.
setAsyncSupported
(
true
);
}
@Test
public
void
supportsReturnType
()
throws
Exception
{
assertTrue
(
this
.
handler
.
supportsReturnType
(
returnType
(
"handle"
)));
...
...
@@ -158,7 +157,8 @@ public class ResponseBodyEmitterReturnValueHandlerTests {
bean2
.
setId
(
2L
);
bean2
.
setName
(
"John"
);
emitter
.
send
(
event
().
comment
(
"a test"
).
name
(
"update"
).
id
(
"1"
).
reconnectTime
(
5000L
).
data
(
bean1
).
data
(
bean2
));
emitter
.
send
(
SseEmitter
.
event
().
comment
(
"a test"
).
name
(
"update"
).
id
(
"1"
).
reconnectTime
(
5000L
).
data
(
bean1
).
data
(
bean2
));
assertEquals
(
":a test\n"
+
"event:update\n"
+
...
...
@@ -193,6 +193,7 @@ public class ResponseBodyEmitterReturnValueHandlerTests {
assertEquals
(
Collections
.
singletonList
(
"bar"
),
this
.
response
.
getHeaders
(
"foo"
));
}
private
void
handleReturnValue
(
Object
returnValue
,
MethodParameter
returnType
)
throws
Exception
{
ModelAndViewContainer
mavContainer
=
new
ModelAndViewContainer
();
this
.
handler
.
handleReturnValue
(
returnValue
,
returnType
,
mavContainer
,
this
.
webRequest
);
...
...
@@ -204,7 +205,6 @@ public class ResponseBodyEmitterReturnValueHandlerTests {
}
@SuppressWarnings
(
"unused"
)
private
static
class
TestController
{
...
...
@@ -235,9 +235,9 @@ public class ResponseBodyEmitterReturnValueHandlerTests {
private
ResponseEntity
handleRawResponseEntity
()
{
return
null
;
}
}
private
static
class
SimpleBean
{
private
Long
id
;
...
...
spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ServletCookieValueMethodArgumentResolverTests.java
浏览文件 @
73493bc4
/*
* Copyright 2002-201
5
the original author or authors.
* Copyright 2002-201
7
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.
...
...
@@ -41,25 +41,23 @@ public class ServletCookieValueMethodArgumentResolverTests {
private
ServletCookieValueMethodArgumentResolver
resolver
;
private
MethodParameter
cookieParameter
;
private
MethodParameter
cookieStringParameter
;
private
MockHttpServletRequest
request
;
private
ServletWebRequest
webRequest
;
private
MockHttpServletRequest
request
;
private
MethodParameter
cookieParameter
;
private
MethodParameter
cookieStringParameter
;
@Before
public
void
set
U
p
()
throws
Exception
{
public
void
set
u
p
()
throws
Exception
{
resolver
=
new
ServletCookieValueMethodArgumentResolver
(
null
);
request
=
new
MockHttpServletRequest
();
webRequest
=
new
ServletWebRequest
(
request
,
new
MockHttpServletResponse
());
Method
method
=
getClass
().
getMethod
(
"params"
,
Cookie
.
class
,
String
.
class
);
cookieParameter
=
new
SynthesizingMethodParameter
(
method
,
0
);
cookieStringParameter
=
new
SynthesizingMethodParameter
(
method
,
1
);
request
=
new
MockHttpServletRequest
();
webRequest
=
new
ServletWebRequest
(
request
,
new
MockHttpServletResponse
());
}
...
...
spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ServletModelAttributeMethodProcessorTests.java
浏览文件 @
73493bc4
/*
* Copyright 2002-201
6
the original author or authors.
* Copyright 2002-201
7
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.
...
...
@@ -48,40 +48,36 @@ public class ServletModelAttributeMethodProcessorTests {
private
ServletModelAttributeMethodProcessor
processor
;
private
MethodParameter
testBeanModelAttr
;
private
MethodParameter
testBeanWithoutStringConstructorModelAttr
;
private
MethodParameter
testBeanWithOptionalModelAttr
;
private
WebDataBinderFactory
binderFactory
;
private
ModelAndViewContainer
mavContainer
;
private
NativeWebRequest
webRequest
;
private
MockHttpServletRequest
request
;
private
WebDataBinderFactory
binderFactory
;
private
NativeWebRequest
webRequest
;
@Before
p
ublic
void
setUp
()
throws
Exception
{
this
.
processor
=
new
ServletModelAttributeMethodProcessor
(
false
)
;
private
MethodParameter
testBeanModelAttr
;
p
rivate
MethodParameter
testBeanWithoutStringConstructorModelAttr
;
private
MethodParameter
testBeanWithOptionalModelAttr
;
Method
method
=
getClass
().
getDeclaredMethod
(
"modelAttribute"
,
TestBean
.
class
,
TestBeanWithoutStringConstructor
.
class
,
Optional
.
class
);
this
.
testBeanModelAttr
=
new
MethodParameter
(
method
,
0
);
this
.
testBeanWithoutStringConstructorModelAttr
=
new
MethodParameter
(
method
,
1
);
this
.
testBeanWithOptionalModelAttr
=
new
MethodParameter
(
method
,
2
);
@Before
public
void
setup
()
throws
Exception
{
processor
=
new
ServletModelAttributeMethodProcessor
(
false
);
ConfigurableWebBindingInitializer
initializer
=
new
ConfigurableWebBindingInitializer
();
initializer
.
setConversionService
(
new
DefaultConversionService
());
binderFactory
=
new
ServletRequestDataBinderFactory
(
null
,
initializer
);
this
.
binderFactory
=
new
ServletRequestDataBinderFactory
(
null
,
initializer
);
this
.
mavContainer
=
new
ModelAndViewContainer
();
mavContainer
=
new
ModelAndViewContainer
();
request
=
new
MockHttpServletRequest
();
webRequest
=
new
ServletWebRequest
(
request
);
this
.
request
=
new
MockHttpServletRequest
();
this
.
webRequest
=
new
ServletWebRequest
(
request
);
Method
method
=
getClass
().
getDeclaredMethod
(
"modelAttribute"
,
TestBean
.
class
,
TestBeanWithoutStringConstructor
.
class
,
Optional
.
class
);
testBeanModelAttr
=
new
MethodParameter
(
method
,
0
);
testBeanWithoutStringConstructorModelAttr
=
new
MethodParameter
(
method
,
1
);
testBeanWithOptionalModelAttr
=
new
MethodParameter
(
method
,
2
);
}
...
...
@@ -89,13 +85,11 @@ public class ServletModelAttributeMethodProcessorTests {
public
void
createAttributeUriTemplateVar
()
throws
Exception
{
Map
<
String
,
String
>
uriTemplateVars
=
new
HashMap
<>();
uriTemplateVars
.
put
(
"testBean1"
,
"Patty"
);
this
.
request
.
setAttribute
(
HandlerMapping
.
URI_TEMPLATE_VARIABLES_ATTRIBUTE
,
uriTemplateVars
);
request
.
setAttribute
(
HandlerMapping
.
URI_TEMPLATE_VARIABLES_ATTRIBUTE
,
uriTemplateVars
);
// Type conversion from "Patty" to TestBean via TestBean(String) constructor
TestBean
testBean
=
(
TestBean
)
this
.
processor
.
resolveArgument
(
this
.
testBeanModelAttr
,
this
.
mavContainer
,
this
.
webRequest
,
this
.
binderFactory
);
TestBean
testBean
=
(
TestBean
)
processor
.
resolveArgument
(
testBeanModelAttr
,
mavContainer
,
webRequest
,
binderFactory
);
assertEquals
(
"Patty"
,
testBean
.
getName
());
}
...
...
@@ -106,9 +100,8 @@ public class ServletModelAttributeMethodProcessorTests {
uriTemplateVars
.
put
(
"testBean2"
,
"Patty"
);
request
.
setAttribute
(
HandlerMapping
.
URI_TEMPLATE_VARIABLES_ATTRIBUTE
,
uriTemplateVars
);
TestBeanWithoutStringConstructor
testBean
=
(
TestBeanWithoutStringConstructor
)
this
.
processor
.
resolveArgument
(
this
.
testBeanWithoutStringConstructorModelAttr
,
this
.
mavContainer
,
this
.
webRequest
,
this
.
binderFactory
);
TestBeanWithoutStringConstructor
testBean
=
(
TestBeanWithoutStringConstructor
)
processor
.
resolveArgument
(
testBeanWithoutStringConstructorModelAttr
,
mavContainer
,
webRequest
,
binderFactory
);
assertNotNull
(
testBean
);
}
...
...
@@ -117,89 +110,81 @@ public class ServletModelAttributeMethodProcessorTests {
public
void
createAttributeUriTemplateVarWithOptional
()
throws
Exception
{
Map
<
String
,
String
>
uriTemplateVars
=
new
HashMap
<>();
uriTemplateVars
.
put
(
"testBean3"
,
"Patty"
);
this
.
request
.
setAttribute
(
HandlerMapping
.
URI_TEMPLATE_VARIABLES_ATTRIBUTE
,
uriTemplateVars
);
request
.
setAttribute
(
HandlerMapping
.
URI_TEMPLATE_VARIABLES_ATTRIBUTE
,
uriTemplateVars
);
// Type conversion from "Patty" to TestBean via TestBean(String) constructor
Optional
<
TestBean
>
testBean
=
(
Optional
<
TestBean
>)
this
.
processor
.
resolveArgument
(
this
.
testBeanWithOptionalModelAttr
,
this
.
mavContainer
,
this
.
webRequest
,
this
.
binderFactory
);
Optional
<
TestBean
>
testBean
=
(
Optional
<
TestBean
>)
processor
.
resolveArgument
(
testBeanWithOptionalModelAttr
,
mavContainer
,
webRequest
,
binderFactory
);
assertEquals
(
"Patty"
,
testBean
.
get
().
getName
());
}
@Test
public
void
createAttributeRequestParameter
()
throws
Exception
{
this
.
request
.
addParameter
(
"testBean1"
,
"Patty"
);
request
.
addParameter
(
"testBean1"
,
"Patty"
);
// Type conversion from "Patty" to TestBean via TestBean(String) constructor
TestBean
testBean
=
(
TestBean
)
this
.
processor
.
resolveArgument
(
this
.
testBeanModelAttr
,
this
.
mavContainer
,
this
.
webRequest
,
this
.
binderFactory
);
TestBean
testBean
=
(
TestBean
)
processor
.
resolveArgument
(
testBeanModelAttr
,
mavContainer
,
webRequest
,
binderFactory
);
assertEquals
(
"Patty"
,
testBean
.
getName
());
}
@Test
public
void
createAttributeRequestParameterCannotConvert
()
throws
Exception
{
this
.
request
.
addParameter
(
"testBean2"
,
"Patty"
);
request
.
addParameter
(
"testBean2"
,
"Patty"
);
TestBeanWithoutStringConstructor
testBean
=
(
TestBeanWithoutStringConstructor
)
this
.
processor
.
resolveArgument
(
this
.
testBeanWithoutStringConstructorModelAttr
,
this
.
mavContainer
,
this
.
webRequest
,
this
.
binderFactory
);
TestBeanWithoutStringConstructor
testBean
=
(
TestBeanWithoutStringConstructor
)
processor
.
resolveArgument
(
testBeanWithoutStringConstructorModelAttr
,
mavContainer
,
webRequest
,
binderFactory
);
assertNotNull
(
testBean
);
}
@Test
public
void
createAttributeRequestParameterWithOptional
()
throws
Exception
{
this
.
request
.
addParameter
(
"testBean3"
,
"Patty"
);
request
.
addParameter
(
"testBean3"
,
"Patty"
);
Optional
<
TestBean
>
testBean
=
(
Optional
<
TestBean
>)
this
.
processor
.
resolveArgument
(
this
.
testBeanWithOptionalModelAttr
,
this
.
mavContainer
,
this
.
webRequest
,
this
.
binderFactory
);
Optional
<
TestBean
>
testBean
=
(
Optional
<
TestBean
>)
processor
.
resolveArgument
(
testBeanWithOptionalModelAttr
,
mavContainer
,
webRequest
,
binderFactory
);
assertEquals
(
"Patty"
,
testBean
.
get
().
getName
());
}
@Test
public
void
attributesAsNullValues
()
throws
Exception
{
this
.
request
.
addParameter
(
"name"
,
"Patty"
);
request
.
addParameter
(
"name"
,
"Patty"
);
this
.
mavContainer
.
getModel
().
put
(
"testBean1"
,
null
);
this
.
mavContainer
.
getModel
().
put
(
"testBean2"
,
null
);
this
.
mavContainer
.
getModel
().
put
(
"testBean3"
,
null
);
mavContainer
.
getModel
().
put
(
"testBean1"
,
null
);
mavContainer
.
getModel
().
put
(
"testBean2"
,
null
);
mavContainer
.
getModel
().
put
(
"testBean3"
,
null
);
assertNull
(
this
.
processor
.
resolveArgument
(
t
his
.
testBeanModelAttr
,
this
.
mavContainer
,
this
.
webRequest
,
this
.
binderFactory
));
assertNull
(
processor
.
resolveArgument
(
t
estBeanModelAttr
,
mavContainer
,
webRequest
,
binderFactory
));
assertNull
(
this
.
processor
.
resolveArgument
(
t
his
.
testBeanWithoutStringConstructorModelAttr
,
this
.
mavContainer
,
this
.
webRequest
,
this
.
binderFactory
));
assertNull
(
processor
.
resolveArgument
(
t
estBeanWithoutStringConstructorModelAttr
,
mavContainer
,
webRequest
,
binderFactory
));
Optional
<
TestBean
>
testBean
=
(
Optional
<
TestBean
>)
this
.
processor
.
resolveArgument
(
this
.
testBeanWithOptionalModelAttr
,
this
.
mavContainer
,
this
.
webRequest
,
this
.
binderFactory
);
Optional
<
TestBean
>
testBean
=
(
Optional
<
TestBean
>)
processor
.
resolveArgument
(
testBeanWithOptionalModelAttr
,
mavContainer
,
webRequest
,
binderFactory
);
assertFalse
(
testBean
.
isPresent
());
}
@Test
public
void
attributesAsOptionalEmpty
()
throws
Exception
{
this
.
request
.
addParameter
(
"name"
,
"Patty"
);
request
.
addParameter
(
"name"
,
"Patty"
);
this
.
mavContainer
.
getModel
().
put
(
"testBean1"
,
Optional
.
empty
());
this
.
mavContainer
.
getModel
().
put
(
"testBean2"
,
Optional
.
empty
());
this
.
mavContainer
.
getModel
().
put
(
"testBean3"
,
Optional
.
empty
());
mavContainer
.
getModel
().
put
(
"testBean1"
,
Optional
.
empty
());
mavContainer
.
getModel
().
put
(
"testBean2"
,
Optional
.
empty
());
mavContainer
.
getModel
().
put
(
"testBean3"
,
Optional
.
empty
());
assertNull
(
this
.
processor
.
resolveArgument
(
t
his
.
testBeanModelAttr
,
this
.
mavContainer
,
this
.
webRequest
,
this
.
binderFactory
));
assertNull
(
processor
.
resolveArgument
(
t
estBeanModelAttr
,
mavContainer
,
webRequest
,
binderFactory
));
assertNull
(
this
.
processor
.
resolveArgument
(
t
his
.
testBeanWithoutStringConstructorModelAttr
,
this
.
mavContainer
,
this
.
webRequest
,
this
.
binderFactory
));
assertNull
(
processor
.
resolveArgument
(
t
estBeanWithoutStringConstructorModelAttr
,
mavContainer
,
webRequest
,
binderFactory
));
Optional
<
TestBean
>
testBean
=
(
Optional
<
TestBean
>)
this
.
processor
.
resolveArgument
(
this
.
testBeanWithOptionalModelAttr
,
this
.
mavContainer
,
this
.
webRequest
,
this
.
binderFactory
);
Optional
<
TestBean
>
testBean
=(
Optional
<
TestBean
>)
processor
.
resolveArgument
(
testBeanWithOptionalModelAttr
,
mavContainer
,
webRequest
,
binderFactory
);
assertFalse
(
testBean
.
isPresent
());
}
...
...
@@ -219,7 +204,6 @@ public class ServletModelAttributeMethodProcessorTests {
public
TestBeanWithoutStringConstructor
(
int
i
)
{
}
}
}
spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ServletResponseMethodArgumentResolverTests.java
浏览文件 @
73493bc4
...
...
@@ -41,22 +41,23 @@ public class ServletResponseMethodArgumentResolverTests {
private
ServletResponseMethodArgumentResolver
resolver
;
private
Method
method
;
private
ModelAndViewContainer
mavContainer
;
private
MockHttpServletResponse
servletResponse
;
private
ServletWebRequest
webRequest
;
private
M
ockHttpServletResponse
servletResponse
;
private
M
ethod
method
;
@Before
public
void
set
U
p
()
throws
Exception
{
public
void
set
u
p
()
throws
Exception
{
resolver
=
new
ServletResponseMethodArgumentResolver
();
method
=
getClass
().
getMethod
(
"supportedParams"
,
ServletResponse
.
class
,
OutputStream
.
class
,
Writer
.
class
);
servletResponse
=
new
MockHttpServletResponse
();
mavContainer
=
new
ModelAndViewContainer
();
servletResponse
=
new
MockHttpServletResponse
();
webRequest
=
new
ServletWebRequest
(
new
MockHttpServletRequest
(),
servletResponse
);
method
=
getClass
().
getMethod
(
"supportedParams"
,
ServletResponse
.
class
,
OutputStream
.
class
,
Writer
.
class
);
}
...
...
spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/StreamingResponseBodyReturnValueHandlerTests.java
浏览文件 @
73493bc4
...
...
@@ -62,7 +62,7 @@ public class StreamingResponseBodyReturnValueHandlerTests {
@Before
public
void
set
U
p
()
throws
Exception
{
public
void
set
u
p
()
throws
Exception
{
this
.
handler
=
new
StreamingResponseBodyReturnValueHandler
();
this
.
mavContainer
=
new
ModelAndViewContainer
();
...
...
spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/UriComponentsBuilderMethodArgumentResolverTests.java
浏览文件 @
73493bc4
/*
* Copyright 2002-201
2
the original author or authors.
* Copyright 2002-201
7
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.
...
...
@@ -39,27 +39,28 @@ public class UriComponentsBuilderMethodArgumentResolverTests {
private
UriComponentsBuilderMethodArgumentResolver
resolver
;
private
MethodParameter
builderParam
;
private
ServletWebRequest
webRequest
;
private
M
ethodParameter
servletBuilderParam
;
private
M
ockHttpServletRequest
servletRequest
;
private
MethodParameter
builderParam
;
private
MethodParameter
servletBuilderParam
;
private
MethodParameter
intParam
;
private
ServletWebRequest
webRequest
;
private
MockHttpServletRequest
servletRequest
;
@Before
public
void
set
U
p
()
throws
Exception
{
public
void
set
u
p
()
throws
Exception
{
this
.
resolver
=
new
UriComponentsBuilderMethodArgumentResolver
();
this
.
servletRequest
=
new
MockHttpServletRequest
();
this
.
webRequest
=
new
ServletWebRequest
(
this
.
servletRequest
);
Method
method
=
this
.
getClass
().
getDeclaredMethod
(
"handle"
,
UriComponentsBuilder
.
class
,
ServletUriComponentsBuilder
.
class
,
int
.
class
);
this
.
builderParam
=
new
MethodParameter
(
method
,
0
);
this
.
servletBuilderParam
=
new
MethodParameter
(
method
,
1
);
this
.
intParam
=
new
MethodParameter
(
method
,
2
);
this
.
servletRequest
=
new
MockHttpServletRequest
();
this
.
webRequest
=
new
ServletWebRequest
(
this
.
servletRequest
);
}
@Test
public
void
supportsParameter
()
throws
Exception
{
assertTrue
(
this
.
resolver
.
supportsParameter
(
this
.
builderParam
));
...
...
spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ViewMethodReturnValueHandlerTests.java
浏览文件 @
73493bc4
/*
* Copyright 2002-201
2
the original author or authors.
* Copyright 2002-201
7
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.
...
...
@@ -46,13 +46,15 @@ public class ViewMethodReturnValueHandlerTests {
private
ServletWebRequest
webRequest
;
@Before
public
void
set
U
p
()
{
public
void
set
u
p
()
{
this
.
handler
=
new
ViewMethodReturnValueHandler
();
this
.
mavContainer
=
new
ModelAndViewContainer
();
this
.
webRequest
=
new
ServletWebRequest
(
new
MockHttpServletRequest
());
}
@Test
public
void
supportsReturnType
()
throws
Exception
{
assertTrue
(
this
.
handler
.
supportsReturnType
(
createReturnValueParam
(
"view"
)));
...
...
@@ -83,6 +85,7 @@ public class ViewMethodReturnValueHandlerTests {
return
new
MethodParameter
(
method
,
-
1
);
}
View
view
()
{
return
null
;
}
...
...
spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ViewNameMethodReturnValueHandlerTests.java
浏览文件 @
73493bc4
/*
* Copyright 2002-201
4
the original author or authors.
* Copyright 2002-201
7
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.
...
...
@@ -45,13 +45,15 @@ public class ViewNameMethodReturnValueHandlerTests {
@Before
public
void
set
U
p
()
throws
NoSuchMethodException
{
public
void
set
u
p
()
throws
NoSuchMethodException
{
this
.
handler
=
new
ViewNameMethodReturnValueHandler
();
this
.
mavContainer
=
new
ModelAndViewContainer
();
this
.
webRequest
=
new
ServletWebRequest
(
new
MockHttpServletRequest
());
this
.
param
=
new
MethodParameter
(
getClass
().
getDeclaredMethod
(
"viewName"
),
-
1
);
}
@Test
public
void
supportsReturnType
()
throws
Exception
{
assertTrue
(
this
.
handler
.
supportsReturnType
(
this
.
param
));
...
...
@@ -98,4 +100,4 @@ public class ViewNameMethodReturnValueHandlerTests {
return
null
;
}
}
\ No newline at end of file
}
spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/support/DefaultHandlerExceptionResolverTests.java
浏览文件 @
73493bc4
/*
* Copyright 2002-201
6
the original author or authors.
* Copyright 2002-201
7
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.
...
...
@@ -52,21 +52,19 @@ import static org.junit.Assert.*;
*/
public
class
DefaultHandlerExceptionResolverTests
{
private
DefaultHandlerExceptionResolver
exceptionResolver
;
private
final
DefaultHandlerExceptionResolver
exceptionResolver
=
new
DefaultHandlerExceptionResolver
()
;
private
MockHttpServletRequest
request
;
private
final
MockHttpServletRequest
request
=
new
MockHttpServletRequest
(
"GET"
,
"/"
);
private
final
MockHttpServletResponse
response
=
new
MockHttpServletResponse
();
private
MockHttpServletResponse
response
;
@Before
public
void
setUp
()
{
exceptionResolver
=
new
DefaultHandlerExceptionResolver
();
public
void
setup
()
{
exceptionResolver
.
setWarnLogCategory
(
exceptionResolver
.
getClass
().
getName
());
request
=
new
MockHttpServletRequest
();
response
=
new
MockHttpServletResponse
();
request
.
setMethod
(
"GET"
);
}
@Test
public
void
handleHttpRequestMethodNotSupported
()
{
HttpRequestMethodNotSupportedException
ex
=
...
...
@@ -207,7 +205,7 @@ public class DefaultHandlerExceptionResolverTests {
assertSame
(
ex
,
request
.
getAttribute
(
"javax.servlet.error.exception"
));
}
@Test
// SPR-14669
@Test
// SPR-14669
public
void
handleAsyncRequestTimeoutException
()
throws
Exception
{
Exception
ex
=
new
AsyncRequestTimeoutException
();
ModelAndView
mav
=
exceptionResolver
.
resolveException
(
request
,
response
,
null
,
ex
);
...
...
spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/support/ParameterizableViewControllerTests.java
浏览文件 @
73493bc4
/*
* Copyright 2002-201
4
the original author or authors.
* Copyright 2002-201
7
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.
...
...
@@ -16,7 +16,6 @@
package
org.springframework.web.servlet.mvc.support
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.springframework.http.HttpStatus
;
...
...
@@ -38,19 +37,11 @@ import static org.junit.Assert.*;
*/
public
class
ParameterizableViewControllerTests
{
private
ParameterizableViewController
controller
;
private
final
ParameterizableViewController
controller
=
new
ParameterizableViewController
()
;
private
MockHttpServletRequest
request
;
private
final
MockHttpServletRequest
request
=
new
MockHttpServletRequest
(
"GET"
,
"/"
)
;
private
MockHttpServletResponse
response
;
@Before
public
void
setUp
()
throws
Exception
{
this
.
controller
=
new
ParameterizableViewController
();
this
.
request
=
new
MockHttpServletRequest
(
"GET"
,
"/"
);
this
.
response
=
new
MockHttpServletResponse
();
}
private
final
MockHttpServletResponse
response
=
new
MockHttpServletResponse
();
@Test
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录