Skip to content

Commit 3e4ced8

Browse files
author
Dassi Orleando
committed
BAEL-1273: add two test of the articles feed controller
1 parent b874c2a commit 3e4ced8

2 files changed

Lines changed: 46 additions & 1 deletion

File tree

‎spring-mvc-simple/src/main/java/com/baeldung/spring/configuration/ApplicationConfiguration.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
@Configuration
2525
@EnableWebMvc
2626
@ComponentScan(basePackages = { "com.baeldung.springmvcforms", "com.baeldung.spring.controller", "com.baeldung.spring.validator" })
27-
class ApplicationConfiguration extends WebMvcConfigurerAdapter {
27+
public class ApplicationConfiguration extends WebMvcConfigurerAdapter {
2828

2929
@Override
3030
public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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

Comments
 (0)