Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
915350d0
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,体验更适合开发者的 AI 搜索 >>
提交
915350d0
编写于
9月 13, 2016
作者:
J
Juergen Hoeller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Reliable last-modified timestamp tests on Windows
上级
118d093e
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
11 addition
and
16 deletion
+11
-16
spring-web-reactive/src/test/java/org/springframework/web/reactive/resource/ResourceWebHandlerTests.java
...mework/web/reactive/resource/ResourceWebHandlerTests.java
+11
-16
未找到文件。
spring-web-reactive/src/test/java/org/springframework/web/reactive/resource/ResourceWebHandlerTests.java
浏览文件 @
915350d0
...
...
@@ -49,15 +49,12 @@ 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
.
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
.*;
import
static
org
.
springframework
.
web
.
reactive
.
HandlerMapping
.*;
/**
* Unit tests for {@link ResourceWebHandler}.
*
* @author Rossen Stoyanchev
*/
public
class
ResourceWebHandlerTests
{
...
...
@@ -75,7 +72,6 @@ public class ResourceWebHandlerTests {
@Before
public
void
setUp
()
throws
Exception
{
List
<
Resource
>
paths
=
new
ArrayList
<>(
2
);
paths
.
add
(
new
ClassPathResource
(
"test/"
,
getClass
()));
paths
.
add
(
new
ClassPathResource
(
"testalternatepath/"
,
getClass
()));
...
...
@@ -90,6 +86,7 @@ public class ResourceWebHandlerTests {
this
.
exchange
=
new
DefaultServerWebExchange
(
this
.
request
,
this
.
response
,
this
.
sessionManager
);
}
@Test
public
void
getResource
()
throws
Exception
{
this
.
exchange
.
getAttributes
().
put
(
PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE
,
"foo.css"
);
...
...
@@ -100,7 +97,7 @@ public class ResourceWebHandlerTests {
assertEquals
(
17
,
headers
.
getContentLength
());
assertEquals
(
"max-age=3600"
,
headers
.
getCacheControl
());
assertTrue
(
headers
.
containsKey
(
"Last-Modified"
));
assertEquals
(
headers
.
getLastModified
()
,
resourceLastModifiedDate
(
"test/foo.css"
)
);
assertEquals
(
headers
.
getLastModified
()
/
1000
,
resourceLastModifiedDate
(
"test/foo.css"
)
/
1000
);
assertEquals
(
"bytes"
,
headers
.
getFirst
(
"Accept-Ranges"
));
assertEquals
(
1
,
headers
.
get
(
"Accept-Ranges"
).
size
());
assertResponseBody
(
"h1 { color:red; }"
);
...
...
@@ -118,7 +115,7 @@ public class ResourceWebHandlerTests {
assertEquals
(
17
,
headers
.
getContentLength
());
assertEquals
(
"max-age=3600"
,
headers
.
getCacheControl
());
assertTrue
(
headers
.
containsKey
(
"Last-Modified"
));
assertEquals
(
headers
.
getLastModified
()
,
resourceLastModifiedDate
(
"test/foo.css"
)
);
assertEquals
(
headers
.
getLastModified
()
/
1000
,
resourceLastModifiedDate
(
"test/foo.css"
)
/
1000
);
assertEquals
(
"bytes"
,
headers
.
getFirst
(
"Accept-Ranges"
));
assertEquals
(
1
,
headers
.
get
(
"Accept-Ranges"
).
size
());
assertNull
(
this
.
response
.
getBody
());
...
...
@@ -142,7 +139,7 @@ public class ResourceWebHandlerTests {
assertEquals
(
"no-store"
,
this
.
response
.
getHeaders
().
getCacheControl
());
assertTrue
(
this
.
response
.
getHeaders
().
containsKey
(
"Last-Modified"
));
assertEquals
(
this
.
response
.
getHeaders
().
getLastModified
()
,
resourceLastModifiedDate
(
"test/foo.css"
)
);
assertEquals
(
this
.
response
.
getHeaders
().
getLastModified
()
/
1000
,
resourceLastModifiedDate
(
"test/foo.css"
)
/
1000
);
assertEquals
(
"bytes"
,
this
.
response
.
getHeaders
().
getFirst
(
"Accept-Ranges"
));
assertEquals
(
1
,
this
.
response
.
getHeaders
().
get
(
"Accept-Ranges"
).
size
());
}
...
...
@@ -172,7 +169,7 @@ public class ResourceWebHandlerTests {
assertEquals
(
MediaType
.
TEXT_HTML
,
headers
.
getContentType
());
assertEquals
(
"max-age=3600"
,
headers
.
getCacheControl
());
assertTrue
(
headers
.
containsKey
(
"Last-Modified"
));
assertEquals
(
headers
.
getLastModified
()
,
resourceLastModifiedDate
(
"test/foo.html"
)
);
assertEquals
(
headers
.
getLastModified
()
/
1000
,
resourceLastModifiedDate
(
"test/foo.html"
)
/
1000
);
assertEquals
(
"bytes"
,
headers
.
getFirst
(
"Accept-Ranges"
));
assertEquals
(
1
,
headers
.
get
(
"Accept-Ranges"
).
size
());
}
...
...
@@ -187,7 +184,7 @@ public class ResourceWebHandlerTests {
assertEquals
(
17
,
headers
.
getContentLength
());
assertEquals
(
"max-age=3600"
,
headers
.
getCacheControl
());
assertTrue
(
headers
.
containsKey
(
"Last-Modified"
));
assertEquals
(
headers
.
getLastModified
()
,
resourceLastModifiedDate
(
"testalternatepath/baz.css"
)
);
assertEquals
(
headers
.
getLastModified
()
/
1000
,
resourceLastModifiedDate
(
"testalternatepath/baz.css"
)
/
1000
);
assertEquals
(
"bytes"
,
headers
.
getFirst
(
"Accept-Ranges"
));
assertEquals
(
1
,
headers
.
get
(
"Accept-Ranges"
).
size
());
assertResponseBody
(
"h1 { color:red; }"
);
...
...
@@ -545,7 +542,6 @@ public class ResourceWebHandlerTests {
TestSubscriber
.
subscribe
(
this
.
response
.
getBody
())
.
assertValuesWith
(
buf
->
{
String
content
=
DataBufferTestUtils
.
dumpString
(
buf
,
StandardCharsets
.
UTF_8
);
String
[]
ranges
=
StringUtils
.
tokenizeToStringArray
(
content
,
"\r\n"
,
false
,
true
);
...
...
@@ -563,20 +559,19 @@ public class ResourceWebHandlerTests {
assertEquals
(
"Content-Type: text/plain"
,
ranges
[
9
]);
assertEquals
(
"Content-Range: bytes 8-9/10"
,
ranges
[
10
]);
assertEquals
(
"t."
,
ranges
[
11
]);
});
}
@Test
// SPR-14005
@Test
// SPR-14005
public
void
doOverwriteExistingCacheControlHeaders
()
throws
Exception
{
this
.
exchange
.
getAttributes
().
put
(
PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE
,
"foo.css"
);
this
.
response
.
getHeaders
().
setCacheControl
(
CacheControl
.
noStore
().
getHeaderValue
());
this
.
handler
.
handle
(
this
.
exchange
).
blockMillis
(
5000
);
assertEquals
(
"max-age=3600"
,
this
.
response
.
getHeaders
().
getCacheControl
());
}
private
long
resourceLastModified
(
String
resourceName
)
throws
IOException
{
return
new
ClassPathResource
(
resourceName
,
getClass
()).
getFile
().
lastModified
();
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录