BAEL-1273: add two test of the articles feed controller
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user