Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
c33cb26a
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,发现更多精彩内容 >>
提交
c33cb26a
编写于
11月 14, 2019
作者:
R
Rossen Stoyanchev
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Polishing contribution
See gh-1885
上级
46fe74d2
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
39 addition
and
43 deletion
+39
-43
spring-web/src/main/java/org/springframework/http/converter/feed/AbstractWireFeedHttpMessageConverter.java
.../converter/feed/AbstractWireFeedHttpMessageConverter.java
+1
-1
spring-web/src/test/java/org/springframework/http/converter/feed/AtomFeedHttpMessageConverterTests.java
...ttp/converter/feed/AtomFeedHttpMessageConverterTests.java
+19
-20
spring-web/src/test/java/org/springframework/http/converter/feed/RssChannelHttpMessageConverterTests.java
...p/converter/feed/RssChannelHttpMessageConverterTests.java
+19
-22
未找到文件。
spring-web/src/main/java/org/springframework/http/converter/feed/AbstractWireFeedHttpMessageConverter.java
浏览文件 @
c33cb26a
/*
/*
* Copyright 2002-201
8
the original author or authors.
* Copyright 2002-201
9
the original author or authors.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
...
...
spring-web/src/test/java/org/springframework/http/converter/feed/AtomFeedHttpMessageConverterTests.java
浏览文件 @
c33cb26a
...
@@ -21,15 +21,12 @@ import java.io.InputStream;
...
@@ -21,15 +21,12 @@ import java.io.InputStream;
import
java.nio.charset.Charset
;
import
java.nio.charset.Charset
;
import
java.nio.charset.StandardCharsets
;
import
java.nio.charset.StandardCharsets
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
com.rometools.rome.feed.atom.Entry
;
import
com.rometools.rome.feed.atom.Entry
;
import
com.rometools.rome.feed.atom.Feed
;
import
com.rometools.rome.feed.atom.Feed
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.Test
;
import
org.xml.sax.SAXException
;
import
org.xmlunit.diff.DefaultNodeMatcher
;
import
org.xmlunit.diff.DefaultNodeMatcher
;
import
org.xmlunit.diff.ElementSelectors
;
import
org.xmlunit.diff.ElementSelectors
;
import
org.xmlunit.diff.NodeMatcher
;
import
org.xmlunit.diff.NodeMatcher
;
...
@@ -47,6 +44,10 @@ import static org.assertj.core.api.Assertions.assertThat;
...
@@ -47,6 +44,10 @@ import static org.assertj.core.api.Assertions.assertThat;
*/
*/
public
class
AtomFeedHttpMessageConverterTests
{
public
class
AtomFeedHttpMessageConverterTests
{
private
static
final
MediaType
ATOM_XML_UTF8
=
new
MediaType
(
MediaType
.
APPLICATION_ATOM_XML
,
StandardCharsets
.
UTF_8
);
private
AtomFeedHttpMessageConverter
converter
;
private
AtomFeedHttpMessageConverter
converter
;
...
@@ -58,21 +59,21 @@ public class AtomFeedHttpMessageConverterTests {
...
@@ -58,21 +59,21 @@ public class AtomFeedHttpMessageConverterTests {
@Test
@Test
public
void
canRead
()
{
public
void
canRead
()
{
assertThat
(
converter
.
canRead
(
Feed
.
class
,
new
MediaType
(
"application"
,
"atom+xml"
)
)).
isTrue
();
assertThat
(
converter
.
canRead
(
Feed
.
class
,
MediaType
.
APPLICATION_ATOM_XML
)).
isTrue
();
assertThat
(
converter
.
canRead
(
Feed
.
class
,
new
MediaType
(
"application"
,
"atom+xml"
,
StandardCharsets
.
UTF_8
)
)).
isTrue
();
assertThat
(
converter
.
canRead
(
Feed
.
class
,
ATOM_XML_UTF8
)).
isTrue
();
}
}
@Test
@Test
public
void
canWrite
()
{
public
void
canWrite
()
{
assertThat
(
converter
.
canWrite
(
Feed
.
class
,
new
MediaType
(
"application"
,
"atom+xml"
)
)).
isTrue
();
assertThat
(
converter
.
canWrite
(
Feed
.
class
,
MediaType
.
APPLICATION_ATOM_XML
)).
isTrue
();
assertThat
(
converter
.
canWrite
(
Feed
.
class
,
new
MediaType
(
"application"
,
"atom+xml"
,
StandardCharsets
.
UTF_8
)
)).
isTrue
();
assertThat
(
converter
.
canWrite
(
Feed
.
class
,
ATOM_XML_UTF8
)).
isTrue
();
}
}
@Test
@Test
public
void
read
()
throws
IOException
{
public
void
read
()
throws
IOException
{
InputStream
is
=
getClass
().
getResourceAsStream
(
"atom.xml"
);
InputStream
is
=
getClass
().
getResourceAsStream
(
"atom.xml"
);
MockHttpInputMessage
inputMessage
=
new
MockHttpInputMessage
(
is
);
MockHttpInputMessage
inputMessage
=
new
MockHttpInputMessage
(
is
);
inputMessage
.
getHeaders
().
setContentType
(
new
MediaType
(
"application"
,
"atom+xml"
,
StandardCharsets
.
UTF_8
)
);
inputMessage
.
getHeaders
().
setContentType
(
ATOM_XML_UTF8
);
Feed
result
=
converter
.
read
(
Feed
.
class
,
inputMessage
);
Feed
result
=
converter
.
read
(
Feed
.
class
,
inputMessage
);
assertThat
(
result
.
getTitle
()).
isEqualTo
(
"title"
);
assertThat
(
result
.
getTitle
()).
isEqualTo
(
"title"
);
assertThat
(
result
.
getSubtitle
().
getValue
()).
isEqualTo
(
"subtitle"
);
assertThat
(
result
.
getSubtitle
().
getValue
()).
isEqualTo
(
"subtitle"
);
...
@@ -89,7 +90,7 @@ public class AtomFeedHttpMessageConverterTests {
...
@@ -89,7 +90,7 @@ public class AtomFeedHttpMessageConverterTests {
}
}
@Test
@Test
public
void
write
()
throws
IOException
,
SAXException
{
public
void
write
()
throws
IOException
{
Feed
feed
=
new
Feed
(
"atom_1.0"
);
Feed
feed
=
new
Feed
(
"atom_1.0"
);
feed
.
setTitle
(
"title"
);
feed
.
setTitle
(
"title"
);
...
@@ -111,7 +112,7 @@ public class AtomFeedHttpMessageConverterTests {
...
@@ -111,7 +112,7 @@ public class AtomFeedHttpMessageConverterTests {
assertThat
(
outputMessage
.
getHeaders
().
getContentType
())
assertThat
(
outputMessage
.
getHeaders
().
getContentType
())
.
as
(
"Invalid content-type"
)
.
as
(
"Invalid content-type"
)
.
isEqualTo
(
new
MediaType
(
"application"
,
"atom+xml"
,
StandardCharsets
.
UTF_8
)
);
.
isEqualTo
(
ATOM_XML_UTF8
);
String
expected
=
"<feed xmlns=\"http://www.w3.org/2005/Atom\">"
+
"<title>title</title>"
+
String
expected
=
"<feed xmlns=\"http://www.w3.org/2005/Atom\">"
+
"<title>title</title>"
+
"<entry><id>id1</id><title>title1</title></entry>"
+
"<entry><id>id1</id><title>title1</title></entry>"
+
"<entry><id>id2</id><title>title2</title></entry></feed>"
;
"<entry><id>id2</id><title>title2</title></entry></feed>"
;
...
@@ -121,7 +122,7 @@ public class AtomFeedHttpMessageConverterTests {
...
@@ -121,7 +122,7 @@ public class AtomFeedHttpMessageConverterTests {
}
}
@Test
@Test
public
void
writeOtherCharset
()
throws
IOException
,
SAXException
{
public
void
writeOtherCharset
()
throws
IOException
{
Feed
feed
=
new
Feed
(
"atom_1.0"
);
Feed
feed
=
new
Feed
(
"atom_1.0"
);
feed
.
setTitle
(
"title"
);
feed
.
setTitle
(
"title"
);
String
encoding
=
"ISO-8859-1"
;
String
encoding
=
"ISO-8859-1"
;
...
@@ -137,17 +138,15 @@ public class AtomFeedHttpMessageConverterTests {
...
@@ -137,17 +138,15 @@ public class AtomFeedHttpMessageConverterTests {
@Test
@Test
public
void
writeOtherContentTypeParameters
()
throws
IOException
{
public
void
writeOtherContentTypeParameters
()
throws
IOException
{
Feed
feed
=
new
Feed
(
"atom_1.0"
);
MockHttpOutputMessage
message
=
new
MockHttpOutputMessage
();
MediaType
contentType
=
new
MediaType
(
"application"
,
"atom+xml"
,
singletonMap
(
"type"
,
"feed"
));
converter
.
write
(
new
Feed
(
"atom_1.0"
),
contentType
,
message
);
MockHttpOutputMessage
outputMessage
=
new
MockHttpOutputMessage
();
assertThat
(
message
.
getHeaders
().
getContentType
().
getParameters
())
converter
.
write
(
feed
,
new
MediaType
(
"application"
,
"atom+xml"
,
singletonMap
(
"type"
,
"feed"
)),
outputMessage
);
Map
<
String
,
String
>
expectedParameters
=
new
HashMap
<>();
expectedParameters
.
put
(
"charset"
,
"UTF-8"
);
expectedParameters
.
put
(
"type"
,
"feed"
);
assertThat
(
outputMessage
.
getHeaders
().
getContentType
())
.
as
(
"Invalid content-type"
)
.
as
(
"Invalid content-type"
)
.
isEqualTo
(
new
MediaType
(
"application"
,
"atom+xml"
,
expectedParameters
));
.
hasSize
(
2
)
.
containsEntry
(
"type"
,
"feed"
)
.
containsEntry
(
"charset"
,
"UTF-8"
);
}
}
}
}
spring-web/src/test/java/org/springframework/http/converter/feed/RssChannelHttpMessageConverterTests.java
浏览文件 @
c33cb26a
...
@@ -21,15 +21,12 @@ import java.io.InputStream;
...
@@ -21,15 +21,12 @@ import java.io.InputStream;
import
java.nio.charset.Charset
;
import
java.nio.charset.Charset
;
import
java.nio.charset.StandardCharsets
;
import
java.nio.charset.StandardCharsets
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
com.rometools.rome.feed.rss.Channel
;
import
com.rometools.rome.feed.rss.Channel
;
import
com.rometools.rome.feed.rss.Item
;
import
com.rometools.rome.feed.rss.Item
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.Test
;
import
org.xml.sax.SAXException
;
import
org.springframework.http.MediaType
;
import
org.springframework.http.MediaType
;
import
org.springframework.http.MockHttpInputMessage
;
import
org.springframework.http.MockHttpInputMessage
;
...
@@ -44,6 +41,10 @@ import static org.assertj.core.api.Assertions.assertThat;
...
@@ -44,6 +41,10 @@ import static org.assertj.core.api.Assertions.assertThat;
*/
*/
public
class
RssChannelHttpMessageConverterTests
{
public
class
RssChannelHttpMessageConverterTests
{
private
static
final
MediaType
RSS_XML_UTF8
=
new
MediaType
(
MediaType
.
APPLICATION_RSS_XML
,
StandardCharsets
.
UTF_8
);
private
RssChannelHttpMessageConverter
converter
;
private
RssChannelHttpMessageConverter
converter
;
...
@@ -54,22 +55,19 @@ public class RssChannelHttpMessageConverterTests {
...
@@ -54,22 +55,19 @@ public class RssChannelHttpMessageConverterTests {
@Test
@Test
public
void
canRead
()
{
public
void
canReadAndWrite
()
{
assertThat
(
converter
.
canRead
(
Channel
.
class
,
new
MediaType
(
"application"
,
"rss+xml"
))).
isTrue
();
assertThat
(
converter
.
canRead
(
Channel
.
class
,
MediaType
.
APPLICATION_RSS_XML
)).
isTrue
();
assertThat
(
converter
.
canRead
(
Channel
.
class
,
new
MediaType
(
"application"
,
"rss+xml"
,
StandardCharsets
.
UTF_8
))).
isTrue
();
assertThat
(
converter
.
canRead
(
Channel
.
class
,
RSS_XML_UTF8
)).
isTrue
();
}
@Test
assertThat
(
converter
.
canWrite
(
Channel
.
class
,
MediaType
.
APPLICATION_RSS_XML
)).
isTrue
();
public
void
canWrite
()
{
assertThat
(
converter
.
canWrite
(
Channel
.
class
,
RSS_XML_UTF8
)).
isTrue
();
assertThat
(
converter
.
canWrite
(
Channel
.
class
,
new
MediaType
(
"application"
,
"rss+xml"
))).
isTrue
();
assertThat
(
converter
.
canWrite
(
Channel
.
class
,
new
MediaType
(
"application"
,
"rss+xml"
,
StandardCharsets
.
UTF_8
))).
isTrue
();
}
}
@Test
@Test
public
void
read
()
throws
IOException
{
public
void
read
()
throws
IOException
{
InputStream
is
=
getClass
().
getResourceAsStream
(
"rss.xml"
);
InputStream
is
=
getClass
().
getResourceAsStream
(
"rss.xml"
);
MockHttpInputMessage
inputMessage
=
new
MockHttpInputMessage
(
is
);
MockHttpInputMessage
inputMessage
=
new
MockHttpInputMessage
(
is
);
inputMessage
.
getHeaders
().
setContentType
(
new
MediaType
(
"application"
,
"rss+xml"
,
StandardCharsets
.
UTF_8
)
);
inputMessage
.
getHeaders
().
setContentType
(
RSS_XML_UTF8
);
Channel
result
=
converter
.
read
(
Channel
.
class
,
inputMessage
);
Channel
result
=
converter
.
read
(
Channel
.
class
,
inputMessage
);
assertThat
(
result
.
getTitle
()).
isEqualTo
(
"title"
);
assertThat
(
result
.
getTitle
()).
isEqualTo
(
"title"
);
assertThat
(
result
.
getLink
()).
isEqualTo
(
"https://example.com"
);
assertThat
(
result
.
getLink
()).
isEqualTo
(
"https://example.com"
);
...
@@ -86,7 +84,7 @@ public class RssChannelHttpMessageConverterTests {
...
@@ -86,7 +84,7 @@ public class RssChannelHttpMessageConverterTests {
}
}
@Test
@Test
public
void
write
()
throws
IOException
,
SAXException
{
public
void
write
()
throws
IOException
{
Channel
channel
=
new
Channel
(
"rss_2.0"
);
Channel
channel
=
new
Channel
(
"rss_2.0"
);
channel
.
setTitle
(
"title"
);
channel
.
setTitle
(
"title"
);
channel
.
setLink
(
"https://example.com"
);
channel
.
setLink
(
"https://example.com"
);
...
@@ -108,7 +106,7 @@ public class RssChannelHttpMessageConverterTests {
...
@@ -108,7 +106,7 @@ public class RssChannelHttpMessageConverterTests {
assertThat
(
outputMessage
.
getHeaders
().
getContentType
())
assertThat
(
outputMessage
.
getHeaders
().
getContentType
())
.
as
(
"Invalid content-type"
)
.
as
(
"Invalid content-type"
)
.
isEqualTo
(
new
MediaType
(
"application"
,
"rss+xml"
,
StandardCharsets
.
UTF_8
)
);
.
isEqualTo
(
RSS_XML_UTF8
);
String
expected
=
"<rss version=\"2.0\">"
+
String
expected
=
"<rss version=\"2.0\">"
+
"<channel><title>title</title><link>https://example.com</link><description>description</description>"
+
"<channel><title>title</title><link>https://example.com</link><description>description</description>"
+
"<item><title>title1</title></item>"
+
"<item><title>title1</title></item>"
+
...
@@ -119,7 +117,7 @@ public class RssChannelHttpMessageConverterTests {
...
@@ -119,7 +117,7 @@ public class RssChannelHttpMessageConverterTests {
}
}
@Test
@Test
public
void
writeOtherCharset
()
throws
IOException
,
SAXException
{
public
void
writeOtherCharset
()
throws
IOException
{
Channel
channel
=
new
Channel
(
"rss_2.0"
);
Channel
channel
=
new
Channel
(
"rss_2.0"
);
channel
.
setTitle
(
"title"
);
channel
.
setTitle
(
"title"
);
channel
.
setLink
(
"https://example.com"
);
channel
.
setLink
(
"https://example.com"
);
...
@@ -146,15 +144,14 @@ public class RssChannelHttpMessageConverterTests {
...
@@ -146,15 +144,14 @@ public class RssChannelHttpMessageConverterTests {
channel
.
setLink
(
"http://example.com"
);
channel
.
setLink
(
"http://example.com"
);
channel
.
setDescription
(
"description"
);
channel
.
setDescription
(
"description"
);
MockHttpOutputMessage
outputM
essage
=
new
MockHttpOutputMessage
();
MockHttpOutputMessage
m
essage
=
new
MockHttpOutputMessage
();
converter
.
write
(
channel
,
new
MediaType
(
"application"
,
"rss+xml"
,
singletonMap
(
"x"
,
"y"
)),
outputM
essage
);
converter
.
write
(
channel
,
new
MediaType
(
"application"
,
"rss+xml"
,
singletonMap
(
"x"
,
"y"
)),
m
essage
);
Map
<
String
,
String
>
expectedParameters
=
new
HashMap
<>();
assertThat
(
message
.
getHeaders
().
getContentType
().
getParameters
())
expectedParameters
.
put
(
"charset"
,
"UTF-8"
);
expectedParameters
.
put
(
"x"
,
"y"
);
assertThat
(
outputMessage
.
getHeaders
().
getContentType
())
.
as
(
"Invalid content-type"
)
.
as
(
"Invalid content-type"
)
.
isEqualTo
(
new
MediaType
(
"application"
,
"rss+xml"
,
expectedParameters
));
.
hasSize
(
2
)
.
containsEntry
(
"x"
,
"y"
)
.
containsEntry
(
"charset"
,
"UTF-8"
);
}
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录