package de.asideas.crowdsource.controller; import junit.framework.TestCase; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.web.WebAppConfiguration; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.MvcResult; import org.springframework.test.web.servlet.setup.MockMvcBuilders; import org.springframework.web.context.WebApplicationContext; import org.springframework.web.servlet.config.annotation.EnableWebMvc; import javax.annotation.Resource; import java.util.Arrays; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @RunWith(SpringJUnit4ClassRunner.class) @WebAppConfiguration @ContextConfiguration(classes = ConfigControllerTest.Config.class) public class ConfigControllerTest extends TestCase { @Resource private WebApplicationContext webApplicationContext; private MockMvc mockMvc; @Before public void init() { mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build(); } @Test public void testConfig() throws Exception { final MvcResult mvcResult = mockMvc.perform(get("/config.js")) .andExpect(status().isOk()) .andReturn(); assertThat(mvcResult.getResponse().getContentAsString(), is("angular.module('crowdsource').value('emailDomain', '@crowd.source.de').value('emailBlacklistPatterns', [\"_extern\",\"foo\"])")); } @Configuration @EnableWebMvc static class Config { @Bean public ConfigController configController() { return new ConfigController("crowd.source.de", Arrays.asList("_extern", "foo")); } } }