List of usage examples for org.springframework.core.env StandardEnvironment StandardEnvironment
StandardEnvironment
From source file:org.cloudfoundry.identity.uaa.config.EnvironmentMapFactoryBeanTests.java
@Test public void testOverrideProperties() throws Exception { EnvironmentMapFactoryBean factory = new EnvironmentMapFactoryBean(); factory.setDefaultProperties(getProperties("foo=foo")); StandardEnvironment environment = new StandardEnvironment(); environment.getPropertySources().addLast(new NestedMapPropertySource("override", getProperties("foo=bar"))); factory.setEnvironment(environment); Map<String, ?> properties = factory.getObject(); assertEquals("bar", properties.get("foo")); }
From source file:io.servicecomb.springboot.starter.configuration.ConfigurableEnvironmentConfiguration.java
private Map<String, PropertySource<?>> getPropertySources() { Map<String, PropertySource<?>> map = new LinkedHashMap<>(); MutablePropertySources sources = (this.environment != null ? this.environment.getPropertySources() : new StandardEnvironment().getPropertySources()); for (PropertySource<?> source : sources) { extract("", map, source); }//from w w w .j a v a2s . c o m return map; }
From source file:org.ventiv.webjars.requirejs.config.RequireJsConfigBuilderTest.java
@Test public void overridePath() throws Exception { Map<String, Object> properties = new HashMap<>(); properties.put("webjars.requirejs.newModules", "kendo-angular,kendo-colorpicker"); properties.put("webjars.requirejs.paths.kendo-ui-core", "js/kendo.core.min"); properties.put("webjars.requirejs.paths.kendo-angular", "/webjars/kendo-ui-core/2014.2.716/js/kendo.angular.min"); properties.put("webjars.requirejs.paths.kendo-colorpicker", "/webjars/kendo-ui-core/2014.2.716/js/kendo.colorpicker.min"); StandardEnvironment env = new StandardEnvironment(); env.getPropertySources().addFirst(new MapPropertySource("props", properties)); RequireJsConfigBuilder builder = new RequireJsConfigBuilder("/webjars/", env); Map<String, Object> requireJsConfig = builder.buildConfig(); Map<String, String> paths = (Map<String, String>) requireJsConfig.get("paths"); assertEquals(paths.size(), 170);/*from w ww .ja va 2 s.c o m*/ assertEquals(paths.get("kendo-ui-core"), "/webjars/kendo-ui-core/2014.2.716/js/kendo.core.min"); assertEquals(paths.get("kendo-angular"), "/webjars/kendo-ui-core/2014.2.716/js/kendo.angular.min"); assertEquals(paths.get("kendo-colorpicker"), "/webjars/kendo-ui-core/2014.2.716/js/kendo.colorpicker.min"); }
From source file:org.cloudfoundry.identity.uaa.varz.VarzEndpointTests.java
@Test public void testActiveProfiles() throws Exception { endpoint.setEnvironment(new StandardEnvironment()); assertNotNull(endpoint.getVarz("http://uua.vcap.me").get("spring.profiles.active")); }
From source file:com.kixeye.chassis.transport.MetricsTest.java
@Test public void testMetricsPing() throws Exception { Map<String, Object> properties = new HashMap<String, Object>(); properties.put("admin.enabled", "true"); properties.put("admin.port", "" + SocketUtils.findAvailableTcpPort()); properties.put("admin.hostname", "localhost"); properties.put("websocket.enabled", "true"); properties.put("websocket.port", "" + SocketUtils.findAvailableTcpPort()); properties.put("websocket.hostname", "localhost"); properties.put("http.enabled", "true"); properties.put("http.port", "" + SocketUtils.findAvailableTcpPort()); properties.put("http.hostname", "localhost"); AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext(); StandardEnvironment environment = new StandardEnvironment(); environment.getPropertySources().addFirst(new MapPropertySource("default", properties)); context.setEnvironment(environment); context.register(PropertySourcesPlaceholderConfigurer.class); context.register(TransportConfiguration.class); context.register(MetricsConfiguration.class); RestTemplate httpClient = new RestTemplate(); try {//from w w w. j a v a2s .c om context.refresh(); httpClient.setInterceptors(Lists.newArrayList(LOGGING_INTERCEPTOR)); List<HttpMessageConverter<?>> messageConverters = new ArrayList<>(); for (MessageSerDe serDe : context.getBeansOfType(MessageSerDe.class).values()) { messageConverters.add(new SerDeHttpMessageConverter(serDe)); } messageConverters.add(new StringHttpMessageConverter(StandardCharsets.UTF_8)); httpClient.setMessageConverters(messageConverters); ResponseEntity<String> response = httpClient.getForEntity( new URI("http://localhost:" + properties.get("admin.port") + "/metrics/ping"), String.class); logger.info("Got response: [{}]", response); Assert.assertEquals(response.getStatusCode().value(), HttpStatus.OK.value()); Assert.assertEquals("pong".trim(), response.getBody().trim()); } finally { context.close(); } }
From source file:org.ventiv.webjars.requirejs.config.RequireJsConfigBuilderTest.java
@Test public void overrideShim() throws Exception { Map<String, Object> properties = new HashMap<>(); properties.put("webjars.requirejs.newModules", "kendo-angular,kendo-colorpicker,kendo-ui-core"); properties.put("webjars.requirejs.dependencies.kendo-angular", "angular,kendo-ui-core"); properties.put("webjars.requirejs.dependencies.kendo-ui-core", "jquery"); StandardEnvironment env = new StandardEnvironment(); env.getPropertySources().addFirst(new MapPropertySource("props", properties)); RequireJsConfigBuilder builder = new RequireJsConfigBuilder("/webjars/", env); Map<String, Object> requireJsConfig = builder.buildConfig(); Map<String, Object> shim = (Map<String, Object>) requireJsConfig.get("shim"); assertEquals(Arrays.asList("angular"), shim.get("angular-animate")); assertEquals(Arrays.asList("angular", "kendo-ui-core"), shim.get("kendo-angular")); assertEquals(Arrays.asList("jquery"), shim.get("kendo-ui-core")); assertEquals(null, shim.get("kendo-colorpicker")); }
From source file:org.agilemicroservices.autoconfigure.orm.RepositoryConfigurationDelegate.java
/** * Defaults the environment in case the given one is null. Used as fallback, in case the legacy constructor was * invoked.//from w w w. j a v a2 s. c o m * * @param environment can be {@literal null}. * @param resourceLoader can be {@literal null}. * @return */ private static Environment defaultEnvironment(Environment environment, ResourceLoader resourceLoader) { if (environment != null) { return environment; } return resourceLoader instanceof EnvironmentCapable ? ((EnvironmentCapable) resourceLoader).getEnvironment() : new StandardEnvironment(); }
From source file:com.kixeye.chassis.transport.shared.SharedTest.java
@Test public void testClassPath() throws Exception { Map<String, Object> properties = new HashMap<String, Object>(); properties.put("admin.enabled", "true"); properties.put("admin.port", "" + SocketUtils.findAvailableTcpPort()); properties.put("admin.hostname", "localhost"); properties.put("websocket.enabled", "true"); properties.put("websocket.port", "" + SocketUtils.findAvailableTcpPort()); properties.put("websocket.hostname", "localhost"); properties.put("http.enabled", "true"); properties.put("http.port", "" + SocketUtils.findAvailableTcpPort()); properties.put("http.hostname", "localhost"); AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext(); StandardEnvironment environment = new StandardEnvironment(); environment.getPropertySources().addFirst(new MapPropertySource("default", properties)); context.setEnvironment(environment); context.register(PropertySourcesPlaceholderConfigurer.class); context.register(TransportConfiguration.class); context.register(MetricsConfiguration.class); RestTemplate httpClient = new RestTemplate(); try {/*from ww w .j av a 2 s . c o m*/ context.refresh(); httpClient.setInterceptors(Lists.newArrayList(LOGGING_INTERCEPTOR)); List<HttpMessageConverter<?>> messageConverters = new ArrayList<>(); for (MessageSerDe messageSerDe : context.getBeansOfType(MessageSerDe.class).values()) { messageConverters.add(new SerDeHttpMessageConverter(messageSerDe)); } messageConverters.add(new StringHttpMessageConverter(StandardCharsets.UTF_8)); httpClient.setMessageConverters(messageConverters); ResponseEntity<String> response = httpClient.getForEntity( new URI("http://localhost:" + properties.get("admin.port") + "/admin/classpath"), String.class); logger.info("Got response: [{}]", response); Assert.assertEquals(response.getStatusCode().value(), HttpStatus.OK.value()); Assert.assertTrue(response.getBody().length() > 0); } finally { context.close(); } }
From source file:com.rllc.batch.webcast.DynamicFtpChannelResolver.java
/** * Use Spring 3.1. environment support to set properties for the * file-specific application context./* ww w . j av a2s.co m*/ * * @param ctx * @param customer */ private void setEnvironmentForFile(ConfigurableApplicationContext ctx, String fileName) { StandardEnvironment environment = new StandardEnvironment(); Properties props = new Properties(); // populate properties for file props.setProperty("host", env.getProperty("batch.sftp.hostname")); props.setProperty("user", env.getProperty("batch.sftp.username")); props.setProperty("password", env.getProperty("batch.sftp.password")); props.setProperty("port", env.getProperty("batch.sftp.port")); props.setProperty("remote.directory", getRemoteDirectoryForFile(fileName)); PropertiesPropertySource pps = new PropertiesPropertySource("ftpprops", props); environment.getPropertySources().addLast(pps); ctx.setEnvironment(environment); }
From source file:com.kixeye.chassis.transport.WebSocketTransportTest.java
@Test public void testEmptyWebSocketFrameUsingBinary() throws Exception { Map<String, Object> properties = new HashMap<String, Object>(); properties.put("websocket.enabled", "true"); properties.put("websocket.port", "" + SocketUtils.findAvailableTcpPort()); properties.put("websocket.hostname", "localhost"); properties.put("http.enabled", "false"); properties.put("http.port", "" + SocketUtils.findAvailableTcpPort()); properties.put("http.hostname", "localhost"); AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext(); StandardEnvironment environment = new StandardEnvironment(); environment.getPropertySources().addFirst(new MapPropertySource("default", properties)); context.setEnvironment(environment); context.register(PropertySourcesPlaceholderConfigurer.class); context.register(TransportConfiguration.class); context.register(TestWebSocketService.class); WebSocketClient wsClient = new WebSocketClient(); try {/*from www .j a va2 s . com*/ //start server context.refresh(); // start client wsClient.start(); final MessageSerDe serDe = context.getBean(JsonJacksonMessageSerDe.class); final WebSocketMessageRegistry messageRegistry = context.getBean(WebSocketMessageRegistry.class); QueuingWebSocketListener listener = new QueuingWebSocketListener(serDe, messageRegistry, null); WebSocketSession session = (WebSocketSession) wsClient.connect(listener, new URI( "ws://localhost:" + properties.get("websocket.port") + "/" + serDe.getMessageFormatName())) .get(5000, TimeUnit.MILLISECONDS); session.getRemote().sendBytes(ByteBuffer.wrap(new byte[0])); ServiceError error = listener.getResponse(5, TimeUnit.SECONDS); Assert.assertNotNull(error); Assert.assertEquals("EMPTY_ENVELOPE", error.code); Assert.assertEquals("STOPPED", session.getState()); } finally { try { wsClient.stop(); } finally { context.close(); } } }