Search in sources :

Example 1 with PropertySourceOptions

use of cn.taketoday.framework.context.config.ConfigData.PropertySourceOptions in project today-infrastructure by TAKETODAY.

the class ConfigDataTests method propertySourceOptionsAlwaysReturnsSameOptionsEachTime.

@Test
void propertySourceOptionsAlwaysReturnsSameOptionsEachTime() {
    PropertySourceOptions options = PropertySourceOptions.always(Option.IGNORE_IMPORTS, Option.IGNORE_PROFILES);
    assertThat(options.get(mock(PropertySource.class)).asSet()).containsExactly(Option.IGNORE_IMPORTS, Option.IGNORE_PROFILES);
}
Also used : PropertySourceOptions(cn.taketoday.framework.context.config.ConfigData.PropertySourceOptions) Test(org.junit.jupiter.api.Test)

Example 2 with PropertySourceOptions

use of cn.taketoday.framework.context.config.ConfigData.PropertySourceOptions in project today-infrastructure by TAKETODAY.

the class ConfigDataTests method getOptionsReturnsOptionsFromPropertySourceOptions.

@Test
void getOptionsReturnsOptionsFromPropertySourceOptions() {
    MapPropertySource source1 = new MapPropertySource("test", Collections.emptyMap());
    MapPropertySource source2 = new MapPropertySource("test", Collections.emptyMap());
    Options options1 = Options.of(Option.IGNORE_IMPORTS);
    Options options2 = Options.of(Option.IGNORE_PROFILES);
    PropertySourceOptions propertySourceOptions = (source) -> (source != source1) ? options2 : options1;
    ConfigData configData = new ConfigData(Arrays.asList(source1, source2), propertySourceOptions);
    assertThat(configData.getOptions(source1)).isEqualTo(options1);
    assertThat(configData.getOptions(source2)).isEqualTo(options2);
}
Also used : Arrays(java.util.Arrays) MapPropertySource(cn.taketoday.core.env.MapPropertySource) Option(cn.taketoday.framework.context.config.ConfigData.Option) Options(cn.taketoday.framework.context.config.ConfigData.Options) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) PropertySource(cn.taketoday.core.env.PropertySource) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test) List(java.util.List) Assertions.assertThatIllegalArgumentException(org.assertj.core.api.Assertions.assertThatIllegalArgumentException) PropertySourceOptions(cn.taketoday.framework.context.config.ConfigData.PropertySourceOptions) Collections(java.util.Collections) Mockito.mock(org.mockito.Mockito.mock) Options(cn.taketoday.framework.context.config.ConfigData.Options) PropertySourceOptions(cn.taketoday.framework.context.config.ConfigData.PropertySourceOptions) MapPropertySource(cn.taketoday.core.env.MapPropertySource) PropertySourceOptions(cn.taketoday.framework.context.config.ConfigData.PropertySourceOptions) Test(org.junit.jupiter.api.Test)

Example 3 with PropertySourceOptions

use of cn.taketoday.framework.context.config.ConfigData.PropertySourceOptions in project today-infrastructure by TAKETODAY.

the class ConfigDataTests method getOptionsWhenPropertySourceOptionsReturnsNullReturnsNone.

@Test
void getOptionsWhenPropertySourceOptionsReturnsNullReturnsNone() {
    MapPropertySource source = new MapPropertySource("test", Collections.emptyMap());
    PropertySourceOptions propertySourceOptions = (propertySource) -> null;
    ConfigData configData = new ConfigData(Collections.singleton(source), propertySourceOptions);
    assertThat(configData.getOptions(source)).isEqualTo(Options.NONE);
}
Also used : Arrays(java.util.Arrays) MapPropertySource(cn.taketoday.core.env.MapPropertySource) Option(cn.taketoday.framework.context.config.ConfigData.Option) Options(cn.taketoday.framework.context.config.ConfigData.Options) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) PropertySource(cn.taketoday.core.env.PropertySource) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test) List(java.util.List) Assertions.assertThatIllegalArgumentException(org.assertj.core.api.Assertions.assertThatIllegalArgumentException) PropertySourceOptions(cn.taketoday.framework.context.config.ConfigData.PropertySourceOptions) Collections(java.util.Collections) Mockito.mock(org.mockito.Mockito.mock) MapPropertySource(cn.taketoday.core.env.MapPropertySource) PropertySourceOptions(cn.taketoday.framework.context.config.ConfigData.PropertySourceOptions) Test(org.junit.jupiter.api.Test)

Example 4 with PropertySourceOptions

use of cn.taketoday.framework.context.config.ConfigData.PropertySourceOptions in project today-framework by TAKETODAY.

the class ConfigDataTests method getOptionsWhenPropertySourceOptionsReturnsNullReturnsNone.

@Test
void getOptionsWhenPropertySourceOptionsReturnsNullReturnsNone() {
    MapPropertySource source = new MapPropertySource("test", Collections.emptyMap());
    PropertySourceOptions propertySourceOptions = (propertySource) -> null;
    ConfigData configData = new ConfigData(Collections.singleton(source), propertySourceOptions);
    assertThat(configData.getOptions(source)).isEqualTo(Options.NONE);
}
Also used : Arrays(java.util.Arrays) MapPropertySource(cn.taketoday.core.env.MapPropertySource) Option(cn.taketoday.framework.context.config.ConfigData.Option) Options(cn.taketoday.framework.context.config.ConfigData.Options) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) PropertySource(cn.taketoday.core.env.PropertySource) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test) List(java.util.List) Assertions.assertThatIllegalArgumentException(org.assertj.core.api.Assertions.assertThatIllegalArgumentException) PropertySourceOptions(cn.taketoday.framework.context.config.ConfigData.PropertySourceOptions) Collections(java.util.Collections) Mockito.mock(org.mockito.Mockito.mock) MapPropertySource(cn.taketoday.core.env.MapPropertySource) PropertySourceOptions(cn.taketoday.framework.context.config.ConfigData.PropertySourceOptions) Test(org.junit.jupiter.api.Test)

Example 5 with PropertySourceOptions

use of cn.taketoday.framework.context.config.ConfigData.PropertySourceOptions in project today-framework by TAKETODAY.

the class ConfigDataTests method getOptionsReturnsOptionsFromPropertySourceOptions.

@Test
void getOptionsReturnsOptionsFromPropertySourceOptions() {
    MapPropertySource source1 = new MapPropertySource("test", Collections.emptyMap());
    MapPropertySource source2 = new MapPropertySource("test", Collections.emptyMap());
    Options options1 = Options.of(Option.IGNORE_IMPORTS);
    Options options2 = Options.of(Option.IGNORE_PROFILES);
    PropertySourceOptions propertySourceOptions = (source) -> (source != source1) ? options2 : options1;
    ConfigData configData = new ConfigData(Arrays.asList(source1, source2), propertySourceOptions);
    assertThat(configData.getOptions(source1)).isEqualTo(options1);
    assertThat(configData.getOptions(source2)).isEqualTo(options2);
}
Also used : Arrays(java.util.Arrays) MapPropertySource(cn.taketoday.core.env.MapPropertySource) Option(cn.taketoday.framework.context.config.ConfigData.Option) Options(cn.taketoday.framework.context.config.ConfigData.Options) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) PropertySource(cn.taketoday.core.env.PropertySource) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test) List(java.util.List) Assertions.assertThatIllegalArgumentException(org.assertj.core.api.Assertions.assertThatIllegalArgumentException) PropertySourceOptions(cn.taketoday.framework.context.config.ConfigData.PropertySourceOptions) Collections(java.util.Collections) Mockito.mock(org.mockito.Mockito.mock) Options(cn.taketoday.framework.context.config.ConfigData.Options) PropertySourceOptions(cn.taketoday.framework.context.config.ConfigData.PropertySourceOptions) MapPropertySource(cn.taketoday.core.env.MapPropertySource) PropertySourceOptions(cn.taketoday.framework.context.config.ConfigData.PropertySourceOptions) Test(org.junit.jupiter.api.Test)

Aggregations

PropertySourceOptions (cn.taketoday.framework.context.config.ConfigData.PropertySourceOptions)8 PropertySource (cn.taketoday.core.env.PropertySource)6 Test (org.junit.jupiter.api.Test)6 MapPropertySource (cn.taketoday.core.env.MapPropertySource)4 Option (cn.taketoday.framework.context.config.ConfigData.Option)4 Options (cn.taketoday.framework.context.config.ConfigData.Options)4 ArrayList (java.util.ArrayList)4 Arrays (java.util.Arrays)4 Collections (java.util.Collections)4 List (java.util.List)4 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)4 Assertions.assertThatIllegalArgumentException (org.assertj.core.api.Assertions.assertThatIllegalArgumentException)4 Mockito.mock (org.mockito.Mockito.mock)4 Resource (cn.taketoday.core.io.Resource)2 OriginTrackedResource (cn.taketoday.origin.OriginTrackedResource)2