Search in sources :

Example 56 with MapPropertySource

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();
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) ApplicationListener(org.springframework.context.ApplicationListener) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) URL(java.net.URL) MapPropertySource(org.springframework.core.env.MapPropertySource) File(java.io.File) ChangedFile(org.springframework.boot.devtools.filewatch.ChangedFile) Test(org.junit.Test)

Example 57 with MapPropertySource

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();
}
Also used : ConfigurableEnvironment(org.springframework.core.env.ConfigurableEnvironment) SpringApplication(org.springframework.boot.SpringApplication) MapPropertySource(org.springframework.core.env.MapPropertySource) StandardEnvironment(org.springframework.core.env.StandardEnvironment) LinkedHashMap(java.util.LinkedHashMap)

Example 58 with MapPropertySource

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");
}
Also used : MapPropertySource(org.springframework.core.env.MapPropertySource) Test(org.junit.Test)

Example 59 with MapPropertySource

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();
}
Also used : MapPropertySource(org.springframework.core.env.MapPropertySource) DataBinder(org.springframework.validation.DataBinder) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 60 with MapPropertySource

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");
}
Also used : MapPropertySource(org.springframework.core.env.MapPropertySource) DataBinder(org.springframework.validation.DataBinder) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Aggregations

MapPropertySource (org.springframework.core.env.MapPropertySource)74 Test (org.junit.Test)53 HashMap (java.util.HashMap)36 StandardEnvironment (org.springframework.core.env.StandardEnvironment)27 URI (java.net.URI)24 AnnotationConfigWebApplicationContext (org.springframework.web.context.support.AnnotationConfigWebApplicationContext)23 MessageSerDe (com.kixeye.chassis.transport.serde.MessageSerDe)21 ProtobufMessageSerDe (com.kixeye.chassis.transport.serde.converter.ProtobufMessageSerDe)15 RestTemplate (org.springframework.web.client.RestTemplate)15 ServiceError (com.kixeye.chassis.transport.dto.ServiceError)14 JsonJacksonMessageSerDe (com.kixeye.chassis.transport.serde.converter.JsonJacksonMessageSerDe)14 XmlMessageSerDe (com.kixeye.chassis.transport.serde.converter.XmlMessageSerDe)14 YamlJacksonMessageSerDe (com.kixeye.chassis.transport.serde.converter.YamlJacksonMessageSerDe)14 SerDeHttpMessageConverter (com.kixeye.chassis.transport.http.SerDeHttpMessageConverter)13 HttpMessageConverter (org.springframework.http.converter.HttpMessageConverter)13 MutablePropertySources (org.springframework.core.env.MutablePropertySources)11 QueuingWebSocketListener (com.kixeye.chassis.transport.websocket.QueuingWebSocketListener)9 WebSocketMessageRegistry (com.kixeye.chassis.transport.websocket.WebSocketMessageRegistry)9 ArrayList (java.util.ArrayList)9 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)9