List of usage examples for org.springframework.mock.env MockEnvironment MockEnvironment
public MockEnvironment()
From source file:fi.helsinki.opintoni.config.AppConfigurationTest.java
@Before public void setUp() { appConfiguration = new AppConfiguration( new MockEnvironment().withProperty("url", "http://www.mysite.com").withProperty("enabled", "true")); appConfiguration.override("url", "http://www.radiogaga.com"); }
From source file:org.cloudfoundry.identity.uaa.db.DatabaseParametersTests.java
@Override @Before/* w w w. j a v a 2 s. co m*/ public void setUp() throws Exception { MockEnvironment environment = new MockEnvironment(); environment.setProperty("database.initialsize", "0"); environment.setProperty("database.validationquerytimeout", "5"); environment.setProperty("database.connecttimeout", "5"); if (System.getProperty("spring.profiles.active") != null) { environment.setActiveProfiles( StringUtils.commaDelimitedListToStringArray(System.getProperty("spring.profiles.active"))); } super.setUp(environment); vendor = webApplicationContext.getBean(DatabaseUrlModifier.class).getDatabaseType(); }
From source file:io.lavagna.service.config.TestServiceConfig.java
@Bean public Environment env() { MockEnvironment m = new MockEnvironment(); String dialect = System.getProperty("datasource.dialect", "HSQLDB"); for (Entry<String, String> kv : datasourceConf().get(dialect).entrySet()) { m.setProperty(kv.getKey(), kv.getValue()); }/*w w w. j a va2 s .co m*/ return m; }
From source file:org.cloudfoundry.identity.uaa.login.RemoteUaaControllerMockMvcTests.java
@Test public void testLoginWithExplicitPrompts() throws Exception { RemoteUaaController controller = new RemoteUaaController(new MockEnvironment(), new RestTemplate()); Prompt first = new Prompt("how", "text", "How did I get here?"); Prompt second = new Prompt("where", "password", "Where does that highway go to?"); controller.setPrompts(Arrays.asList(first, second)); MockMvc mockMvc = getMockMvc(controller); mockMvc.perform(get("/login").accept(APPLICATION_JSON)).andExpect(status().isOk()) .andExpect(view().name("login")).andExpect(model().attribute("prompts", hasKey("how"))) .andExpect(model().attribute("prompts", hasKey("where"))) .andExpect(model().attribute("prompts", not(hasKey("password")))); }
From source file:com.github.nblair.web.ProfileConditionalDelegatingFilterProxyTest.java
/** * Verify behavior when the single required profile is not active (delegate should NOT be invoked). * /*from w w w . j a va2 s. c o m*/ * @throws ServletException * @throws IOException */ @Test public void doFilter_required_profile_not_set() throws ServletException, IOException { Filter delegate = mock(Filter.class); ProfileConditionalDelegatingFilterProxy filterProxy = new ProfileConditionalDelegatingFilterProxy(delegate); filterProxy.setRequiredProfile("foo"); ServletContext servletContext = mockServletContextWithEnvironment(new MockEnvironment()); filterProxy.setServletContext(servletContext); ServletRequest request = mock(ServletRequest.class); ServletResponse response = mock(ServletResponse.class); FilterChain filterChain = mock(FilterChain.class); filterProxy.doFilter(request, response, filterChain); verify(delegate, never()).doFilter(request, response, filterChain); verify(filterChain).doFilter(request, response); }
From source file:org.cloudfoundry.identity.uaa.login.RemoteUaaControllerMockMvcTests.java
@Test public void testLoginWithRemoteUaaPrompts() throws Exception { RestTemplate restTemplate = new RestTemplate(); RemoteUaaController controller = new RemoteUaaController(new MockEnvironment(), restTemplate); controller.setUaaBaseUrl("https://uaa.example.com"); MockMvc mockMvc = getMockMvc(controller); MockRestServiceServer mockServer = MockRestServiceServer.createServer(restTemplate); mockServer.expect(requestTo("https://uaa.example.com/login")).andExpect(method(GET)) .andExpect(header("Accept", APPLICATION_JSON_VALUE)) .andRespond(withSuccess("{\n" + " \"prompts\": {\n" + " \"how\": [\n" + " \"text\",\n" + " \"Made-up field.\"\n" + " ],\n" + " \"passcode\": [\n" + " \"password\",\n" + " \"Passcode should not be filtered out in API.\"\n" + " ]\n" + " }\n" + "}", APPLICATION_JSON)); mockMvc.perform(get("/login").accept(APPLICATION_JSON)).andExpect(status().isOk()) .andExpect(view().name("login")).andExpect(model().attribute("prompts", hasKey("how"))) .andExpect(model().attribute("prompts", hasKey("passcode"))) .andExpect(model().attribute("prompts", not(hasKey("password")))); }
From source file:com.github.nblair.web.ProfileConditionalDelegatingFilterProxyTest.java
/** * Verify behavior when the single required profile is active (delegate SHOULD be invoked). * //from w ww . j ava 2 s . co m * @throws ServletException * @throws IOException */ @Test public void doFilter_required_profile_set() throws ServletException, IOException { Filter delegate = mock(Filter.class); ProfileConditionalDelegatingFilterProxy filterProxy = new ProfileConditionalDelegatingFilterProxy(delegate); filterProxy.setRequiredProfile("foo"); MockEnvironment environment = new MockEnvironment(); environment.setActiveProfiles("foo"); ServletContext servletContext = mockServletContextWithEnvironment(environment); filterProxy.setServletContext(servletContext); ServletRequest request = mock(ServletRequest.class); ServletResponse response = mock(ServletResponse.class); FilterChain filterChain = mock(FilterChain.class); filterProxy.doFilter(request, response, filterChain); verify(delegate).doFilter(request, response, filterChain); }
From source file:org.cloudfoundry.identity.uaa.login.RemoteUaaControllerMockMvcTests.java
@Test public void testLoginWithDefaultPrompts() throws Exception { RestTemplate restTemplate = new RestTemplate(); RemoteUaaController controller = new RemoteUaaController(new MockEnvironment(), restTemplate); controller.setUaaBaseUrl("https://uaa.example.com"); MockMvc mockMvc = getMockMvc(controller); MockRestServiceServer mockServer = MockRestServiceServer.createServer(restTemplate); mockServer.expect(requestTo("https://uaa.example.com/login")).andExpect(method(GET)) .andExpect(header("Accept", APPLICATION_JSON_VALUE)).andRespond(withSuccess("", APPLICATION_JSON)); mockMvc.perform(get("/login").accept(APPLICATION_JSON)).andExpect(status().isOk()) .andExpect(view().name("login")).andExpect(model().attribute("prompts", hasKey("username"))) .andExpect(model().attribute("prompts", hasKey("password"))); }
From source file:com.github.nblair.web.ProfileConditionalDelegatingFilterProxyTest.java
/** * Verify behavior when multiple required profiles are active in the environment (delegate SHOULD be invoked). * /*from w w w . j a va2 s . c o m*/ * @throws ServletException * @throws IOException */ @Test public void doFilter_required_multiple_profiles_all_set() throws ServletException, IOException { Filter delegate = mock(Filter.class); ProfileConditionalDelegatingFilterProxy filterProxy = new ProfileConditionalDelegatingFilterProxy(delegate); filterProxy.setRequiredProfiles("foo", "bar"); MockEnvironment environment = new MockEnvironment(); environment.setActiveProfiles("foo", "bar"); ServletContext servletContext = mockServletContextWithEnvironment(environment); filterProxy.setServletContext(servletContext); ServletRequest request = mock(ServletRequest.class); ServletResponse response = mock(ServletResponse.class); FilterChain filterChain = mock(FilterChain.class); filterProxy.doFilter(request, response, filterChain); verify(delegate).doFilter(request, response, filterChain); }
From source file:org.cloudfoundry.identity.uaa.login.RemoteUaaControllerMockMvcTests.java
@Test public void testDefaultSignupLink() throws Exception { RemoteUaaController controller = new RemoteUaaController(new MockEnvironment(), new RestTemplate()); Prompt first = new Prompt("how", "text", "How did I get here?"); Prompt second = new Prompt("where", "password", "Where does that highway go to?"); controller.setPrompts(Arrays.asList(first, second)); MockMvc mockMvc = getMockMvc(controller); mockMvc.perform(get("/login").accept(TEXT_HTML)).andExpect(status().isOk()) .andExpect(model().attribute("createAccountLink", "/create_account")); }