Search in sources :

Example 11 with ByteArrayResource

use of org.springframework.core.io.ByteArrayResource in project spring-framework by spring-projects.

the class YamlPropertiesFactoryBeanTests method testLoadResourceWithMultipleDocuments.

@Test
public void testLoadResourceWithMultipleDocuments() throws Exception {
    YamlPropertiesFactoryBean factory = new YamlPropertiesFactoryBean();
    factory.setResources(new ByteArrayResource("foo: bar\nspam: baz\n---\nfoo: bag".getBytes()));
    Properties properties = factory.getObject();
    assertThat(properties.getProperty("foo"), equalTo("bag"));
    assertThat(properties.getProperty("spam"), equalTo("baz"));
}
Also used : ByteArrayResource(org.springframework.core.io.ByteArrayResource) Properties(java.util.Properties) Test(org.junit.Test)

Example 12 with ByteArrayResource

use of org.springframework.core.io.ByteArrayResource in project spring-framework by spring-projects.

the class YamlPropertiesFactoryBeanTests method testLoadArrayOfInteger.

@Test
public void testLoadArrayOfInteger() throws Exception {
    YamlPropertiesFactoryBean factory = new YamlPropertiesFactoryBean();
    factory.setResources(new ByteArrayResource("foo:\n- 1\n- 2".getBytes()));
    Properties properties = factory.getObject();
    assertThat(properties.getProperty("foo[0]"), equalTo("1"));
    assertThat(properties.getProperty("foo[1]"), equalTo("2"));
    assertThat(properties.get("foo"), is(nullValue()));
}
Also used : ByteArrayResource(org.springframework.core.io.ByteArrayResource) Properties(java.util.Properties) Test(org.junit.Test)

Example 13 with ByteArrayResource

use of org.springframework.core.io.ByteArrayResource in project spring-framework by spring-projects.

the class YamlPropertiesFactoryBeanTests method testLoadNull.

@Test
public void testLoadNull() throws Exception {
    YamlPropertiesFactoryBean factory = new YamlPropertiesFactoryBean();
    factory.setResources(new ByteArrayResource("foo: bar\nspam:".getBytes()));
    Properties properties = factory.getObject();
    assertThat(properties.getProperty("foo"), equalTo("bar"));
    assertThat(properties.getProperty("spam"), equalTo(""));
}
Also used : ByteArrayResource(org.springframework.core.io.ByteArrayResource) Properties(java.util.Properties) Test(org.junit.Test)

Example 14 with ByteArrayResource

use of org.springframework.core.io.ByteArrayResource in project spring-framework by spring-projects.

the class YamlPropertiesFactoryBeanTests method testBadResource.

@Test
public void testBadResource() throws Exception {
    YamlPropertiesFactoryBean factory = new YamlPropertiesFactoryBean();
    factory.setResources(new ByteArrayResource("foo: bar\ncd\nspam:\n  foo: baz".getBytes()));
    this.exception.expect(ScannerException.class);
    this.exception.expectMessage("line 3, column 1");
    factory.getObject();
}
Also used : ByteArrayResource(org.springframework.core.io.ByteArrayResource) Test(org.junit.Test)

Example 15 with ByteArrayResource

use of org.springframework.core.io.ByteArrayResource in project spring-framework by spring-projects.

the class YamlPropertiesFactoryBeanTests method testLoadResource.

@Test
public void testLoadResource() throws Exception {
    YamlPropertiesFactoryBean factory = new YamlPropertiesFactoryBean();
    factory.setResources(new ByteArrayResource("foo: bar\nspam:\n  foo: baz".getBytes()));
    Properties properties = factory.getObject();
    assertThat(properties.getProperty("foo"), equalTo("bar"));
    assertThat(properties.getProperty("spam.foo"), equalTo("baz"));
}
Also used : ByteArrayResource(org.springframework.core.io.ByteArrayResource) Properties(java.util.Properties) Test(org.junit.Test)

Aggregations

ByteArrayResource (org.springframework.core.io.ByteArrayResource)89 Test (org.junit.Test)66 Resource (org.springframework.core.io.Resource)30 Properties (java.util.Properties)26 JmsNorthbounderConfig (org.opennms.netmgt.alarmd.northbounder.jms.JmsNorthbounderConfig)6 JmsNorthbounderConfigDao (org.opennms.netmgt.alarmd.northbounder.jms.JmsNorthbounderConfigDao)6 InetAddress (java.net.InetAddress)5 ArrayList (java.util.ArrayList)5 LinkedList (java.util.LinkedList)5 NorthboundAlarm (org.opennms.netmgt.alarmd.api.NorthboundAlarm)5 JmsDestination (org.opennms.netmgt.alarmd.northbounder.jms.JmsDestination)5 OnmsAlarm (org.opennms.netmgt.model.OnmsAlarm)5 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)5 OnmsNode (org.opennms.netmgt.model.OnmsNode)5 IOException (java.io.IOException)4 LinkedHashMap (java.util.LinkedHashMap)4 Map (java.util.Map)4 MutablePropertySources (org.springframework.core.env.MutablePropertySources)4 FileSystemResource (org.springframework.core.io.FileSystemResource)4 InputStream (java.io.InputStream)3