Java Code Examples for org.springframework.core.env.MutablePropertySources#precedenceOf()

The following examples show how to use org.springframework.core.env.MutablePropertySources#precedenceOf() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ContextRefresherOrderingIntegrationTests.java    From spring-cloud-commons with Apache License 2.0 6 votes vote down vote up
@Test
public void orderingIsCorrect() {
	refresher.refresh();
	MutablePropertySources propertySources = environment.getPropertySources();
	PropertySource<?> test1 = propertySources
			.get("bootstrapProperties-testContextRefresherOrdering1");
	PropertySource<?> test2 = propertySources
			.get("bootstrapProperties-testContextRefresherOrdering2");
	PropertySource<?> test3 = propertySources
			.get("bootstrapProperties-testContextRefresherOrdering3");
	int index1 = propertySources.precedenceOf(test1);
	int index2 = propertySources.precedenceOf(test2);
	int index3 = propertySources.precedenceOf(test3);
	assertThat(index1).as("source1 index not less then source2").isLessThan(index2);
	assertThat(index2).as("source2 index not less then source3").isLessThan(index3);
}
 
Example 2
Source File: PropertySourcesProcessor.java    From apollo with Apache License 2.0 5 votes vote down vote up
private void ensureBootstrapPropertyPrecedence(ConfigurableEnvironment environment) {
  MutablePropertySources propertySources = environment.getPropertySources();

  PropertySource<?> bootstrapPropertySource = propertySources
      .get(PropertySourcesConstants.APOLLO_BOOTSTRAP_PROPERTY_SOURCE_NAME);

  // not exists or already in the first place
  if (bootstrapPropertySource == null || propertySources.precedenceOf(bootstrapPropertySource) == 0) {
    return;
  }

  propertySources.remove(PropertySourcesConstants.APOLLO_BOOTSTRAP_PROPERTY_SOURCE_NAME);
  propertySources.addFirst(bootstrapPropertySource);
}
 
Example 3
Source File: BootstrapOrderingCustomOverrideSystemPropertiesIntegrationTests.java    From spring-cloud-commons with Apache License 2.0 5 votes vote down vote up
@Test
public void orderingIsCorrect() {
	MutablePropertySources propertySources = environment.getPropertySources();
	PropertySource<?> test1 = propertySources
			.get("bootstrapProperties-testBootstrap1");
	PropertySource<?> test2 = propertySources
			.get("bootstrapProperties-testBootstrap2");
	PropertySource<?> test3 = propertySources
			.get("bootstrapProperties-testBootstrap3");
	int index1 = propertySources.precedenceOf(test1);
	int index2 = propertySources.precedenceOf(test2);
	int index3 = propertySources.precedenceOf(test3);
	assertThat(index1).as("source1 index not less then source2").isLessThan(index2);
	assertThat(index2).as("source2 index not less then source3").isLessThan(index3);
}