BAEL-1273: add two test of the articles feed controller

This commit is contained in:
Dassi Orleando
2018-03-07 05:56:04 +01:00
parent b874c2a312
commit 3e4ced8a16
2 changed files with 46 additions and 1 deletions

View File

@@ -24,7 +24,7 @@ import java.util.List;
@Configuration
@EnableWebMvc
@ComponentScan(basePackages = { "com.baeldung.springmvcforms", "com.baeldung.spring.controller", "com.baeldung.spring.validator" })
class ApplicationConfiguration extends WebMvcConfigurerAdapter {
public class ApplicationConfiguration extends WebMvcConfigurerAdapter {
@Override
public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {

View File

@@ -0,0 +1,45 @@
package com.baeldung.controller.rss;
import com.baeldung.spring.configuration.ApplicationConfiguration;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.junit.jupiter.web.SpringJUnitWebConfig;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
@SpringJUnitWebConfig(ApplicationConfiguration.class)
public class ArticleRssIntegrationTest {
public static final String APPLICATION_RSS_XML = "application/rss+xml";
public static final String APPLICATION_RSS_JSON = "application/rss+json";
public static final String APPLICATION_RSS_XML_CHARSET_UTF_8 = "application/rss+xml;charset=UTF-8";
@Autowired
private WebApplicationContext webAppContext;
private MockMvc mockMvc;
@BeforeEach
public void setup() {
mockMvc = MockMvcBuilders.webAppContextSetup(webAppContext)
.build();
}
@Test
public void whenRequestingXMLFeed_thenContentTypeIsOk() throws Exception {
mockMvc.perform(get("/rss2").accept(APPLICATION_RSS_XML))
.andExpect(status().isOk())
.andExpect(content().contentType(APPLICATION_RSS_XML_CHARSET_UTF_8));
}
@Test
public void whenRequestingJSONFeed_thenContentTypeIsOk() throws Exception {
mockMvc.perform(get("/rss2").accept(APPLICATION_RSS_JSON))
.andExpect(status().isOk())
.andExpect(content().contentType(APPLICATION_RSS_JSON));
}
}