Created
June 16, 2014 19:59
-
-
Save ilayaperumalg/9d737c99640ae7d07e01 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Copyright 2013-2014 the original author or authors. | |
* | |
* Licensed under the Apache License, Version 2.0 (the "License"); | |
* you may not use this file except in compliance with the License. | |
* You may obtain a copy of the License at | |
* | |
* http://www.apache.org/licenses/LICENSE-2.0 | |
* | |
* Unless required by applicable law or agreed to in writing, software | |
* distributed under the License is distributed on an "AS IS" BASIS, | |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
* See the License for the specific language governing permissions and | |
* limitations under the License. | |
*/ | |
package org.springframework.xd.dirt.server; | |
import java.util.Properties; | |
import org.springframework.boot.autoconfigure.EnableAutoConfiguration; | |
import org.springframework.boot.builder.SpringApplicationBuilder; | |
import org.springframework.context.EnvironmentAware; | |
import org.springframework.context.annotation.Configuration; | |
import org.springframework.core.env.ConfigurableEnvironment; | |
import org.springframework.core.env.Environment; | |
import org.springframework.core.env.PropertiesPropertySource; | |
import org.springframework.core.env.PropertySource; | |
import org.springframework.util.Assert; | |
@EnableAutoConfiguration | |
public class TestApplication implements EnvironmentAware { | |
private ConfigurableEnvironment environment; | |
public static void main(String[] args) { | |
new TestApplication().run(args); | |
} | |
public TestApplication run(String... args) { | |
new SpringApplicationBuilder(ParentTestApplication.class) | |
.child(TestApplication.class) | |
.run(args); | |
return this; | |
} | |
@Override | |
public void setEnvironment(Environment environment) { | |
this.environment = (ConfigurableEnvironment) environment; | |
int precedence = this.environment.getPropertySources().precedenceOf(ParentTestApplication.testPropertySource); | |
Assert.isTrue(precedence == 1, "Expected the precedence level is 1. But, the actual precedence level is: " | |
+ String.valueOf(precedence)); | |
} | |
} | |
@Configuration | |
class ParentTestApplication implements EnvironmentAware { | |
private ConfigurableEnvironment environment; | |
protected static PropertySource testPropertySource = new PropertiesPropertySource("testing", new Properties()); | |
@Override | |
public void setEnvironment(Environment environment) { | |
this.environment = (ConfigurableEnvironment) environment; | |
this.environment.getPropertySources().addFirst(testPropertySource); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment