1+ package com .baeldung .controller .rss ;
2+
3+ import com .baeldung .spring .configuration .ApplicationConfiguration ;
4+ import org .junit .jupiter .api .BeforeEach ;
5+ import org .junit .jupiter .api .Test ;
6+ import org .springframework .beans .factory .annotation .Autowired ;
7+ import org .springframework .test .context .junit .jupiter .web .SpringJUnitWebConfig ;
8+ import org .springframework .test .web .servlet .MockMvc ;
9+ import org .springframework .test .web .servlet .setup .MockMvcBuilders ;
10+ import org .springframework .web .context .WebApplicationContext ;
11+
12+ import static org .springframework .test .web .servlet .request .MockMvcRequestBuilders .get ;
13+ import static org .springframework .test .web .servlet .result .MockMvcResultMatchers .content ;
14+ import static org .springframework .test .web .servlet .result .MockMvcResultMatchers .status ;
15+
16+ @ SpringJUnitWebConfig (ApplicationConfiguration .class )
17+ public class ArticleRssIntegrationTest {
18+ public static final String APPLICATION_RSS_XML = "application/rss+xml" ;
19+ public static final String APPLICATION_RSS_JSON = "application/rss+json" ;
20+ public static final String APPLICATION_RSS_XML_CHARSET_UTF_8 = "application/rss+xml;charset=UTF-8" ;
21+
22+ @ Autowired
23+ private WebApplicationContext webAppContext ;
24+ private MockMvc mockMvc ;
25+
26+ @ BeforeEach
27+ public void setup () {
28+ mockMvc = MockMvcBuilders .webAppContextSetup (webAppContext )
29+ .build ();
30+ }
31+
32+ @ Test
33+ public void whenRequestingXMLFeed_thenContentTypeIsOk () throws Exception {
34+ mockMvc .perform (get ("/rss2" ).accept (APPLICATION_RSS_XML ))
35+ .andExpect (status ().isOk ())
36+ .andExpect (content ().contentType (APPLICATION_RSS_XML_CHARSET_UTF_8 ));
37+ }
38+
39+ @ Test
40+ public void whenRequestingJSONFeed_thenContentTypeIsOk () throws Exception {
41+ mockMvc .perform (get ("/rss2" ).accept (APPLICATION_RSS_JSON ))
42+ .andExpect (status ().isOk ())
43+ .andExpect (content ().contentType (APPLICATION_RSS_JSON ));
44+ }
45+ }
0 commit comments