use of org.springframework.core.env.MapPropertySource in project spring-boot by spring-projects.
the class ClassPathFileSystemWatcherTests method configuredWithRestartStrategy.
@Test
public void configuredWithRestartStrategy() throws Exception {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
Map<String, Object> properties = new HashMap<>();
File folder = this.temp.newFolder();
List<URL> urls = new ArrayList<>();
urls.add(new URL("http://spring.io"));
urls.add(folder.toURI().toURL());
properties.put("urls", urls);
MapPropertySource propertySource = new MapPropertySource("test", properties);
context.getEnvironment().getPropertySources().addLast(propertySource);
context.register(Config.class);
context.refresh();
Thread.sleep(200);
File classFile = new File(folder, "Example.class");
FileCopyUtils.copy("file".getBytes(), classFile);
Thread.sleep(1000);
List<ClassPathChangedEvent> events = context.getBean(Listener.class).getEvents();
for (int i = 0; i < 20; i++) {
if (!events.isEmpty()) {
break;
}
Thread.sleep(500);
}
assertThat(events.size()).isEqualTo(1);
assertThat(events.get(0).getChangeSet().iterator().next().getFiles().iterator().next().getFile()).isEqualTo(classFile);
context.close();
}
use of org.springframework.core.env.MapPropertySource in project spring-boot by spring-projects.
the class SpringApplicationBindContextLoader method loadContext.
@Override
public ApplicationContext loadContext(MergedContextConfiguration config) throws Exception {
SpringApplication application = new SpringApplication();
application.setMainApplicationClass(config.getTestClass());
application.setWebApplicationType(WebApplicationType.NONE);
application.setSources(new LinkedHashSet<Object>(Arrays.asList(config.getClasses())));
ConfigurableEnvironment environment = new StandardEnvironment();
Map<String, Object> properties = new LinkedHashMap<>();
properties.put("spring.jmx.enabled", "false");
properties.putAll(TestPropertySourceUtils.convertInlinedPropertiesToMap(config.getPropertySourceProperties()));
environment.getPropertySources().addAfter(StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME, new MapPropertySource("integrationTest", properties));
application.setEnvironment(environment);
return application.run();
}
use of org.springframework.core.env.MapPropertySource in project spring-boot by spring-projects.
the class PropertySourcesPropertyValuesTests method testOverriddenValue.
@Test
public void testOverriddenValue() {
this.propertySources.addFirst(new MapPropertySource("new", Collections.<String, Object>singletonMap("name", "spam")));
PropertySourcesPropertyValues propertyValues = new PropertySourcesPropertyValues(this.propertySources);
assertThat(propertyValues.getPropertyValue("name").getValue()).isEqualTo("spam");
}
use of org.springframework.core.env.MapPropertySource in project spring-boot by spring-projects.
the class PropertySourcesPropertyValuesTests method testFirstCollectionPropertyWinsNestedAttributes.
@Test
public void testFirstCollectionPropertyWinsNestedAttributes() throws Exception {
ListTestBean target = new ListTestBean();
DataBinder binder = new DataBinder(target);
Map<String, Object> first = new LinkedHashMap<>();
first.put("list[0].description", "another description");
Map<String, Object> second = new LinkedHashMap<>();
second.put("list[0].name", "first name");
second.put("list[0].description", "first description");
second.put("list[1].name", "second name");
second.put("list[1].description", "second description");
this.propertySources.addFirst(new MapPropertySource("s", second));
this.propertySources.addFirst(new MapPropertySource("f", first));
binder.bind(new PropertySourcesPropertyValues(this.propertySources));
assertThat(target.getList()).hasSize(1);
assertThat(target.getList().get(0).getDescription()).isEqualTo("another description");
assertThat(target.getList().get(0).getName()).isNull();
}
use of org.springframework.core.env.MapPropertySource in project spring-boot by spring-projects.
the class PropertySourcesPropertyValuesTests method testFirstCollectionPropertyWins.
@Test
public void testFirstCollectionPropertyWins() throws Exception {
ListBean target = new ListBean();
DataBinder binder = new DataBinder(target);
Map<String, Object> first = new LinkedHashMap<>();
first.put("list[0]", "f0");
Map<String, Object> second = new LinkedHashMap<>();
second.put("list[0]", "s0");
second.put("list[1]", "s1");
this.propertySources.addFirst(new MapPropertySource("s", second));
this.propertySources.addFirst(new MapPropertySource("f", first));
binder.bind(new PropertySourcesPropertyValues(this.propertySources));
assertThat(target.getList()).containsExactly("f0");
}
Aggregations