Search in sources :

Example 71 with ByteArrayResource

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

the class YamlProcessorTests method mapConvertedToIndexedBeanReference.

@Test
public void mapConvertedToIndexedBeanReference() {
    this.processor.setResources(new ByteArrayResource("foo: bar\nbar:\n spam: bucket".getBytes()));
    this.processor.process(new MatchCallback() {

        @Override
        public void process(Properties properties, Map<String, Object> map) {
            // System.err.println(properties);
            assertEquals("bucket", properties.get("bar.spam"));
            assertEquals(2, properties.size());
        }
    });
}
Also used : ByteArrayResource(org.springframework.core.io.ByteArrayResource) Properties(java.util.Properties) Test(org.junit.Test)

Example 72 with ByteArrayResource

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

the class YamlProcessorTests method integerKeyBehaves.

@Test
public void integerKeyBehaves() {
    this.processor.setResources(new ByteArrayResource("foo: bar\n1: bar".getBytes()));
    this.processor.process(new MatchCallback() {

        @Override
        public void process(Properties properties, Map<String, Object> map) {
            assertEquals("bar", properties.get("[1]"));
            assertEquals(2, properties.size());
        }
    });
}
Also used : ByteArrayResource(org.springframework.core.io.ByteArrayResource) Properties(java.util.Properties) Test(org.junit.Test)

Example 73 with ByteArrayResource

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

the class YamlPropertiesFactoryBeanTests method testLoadResourcesWithOverride.

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

Example 74 with ByteArrayResource

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

the class YamlPropertiesFactoryBeanTests method testLoadResourceWithSelectedDocuments.

@Test
public void testLoadResourceWithSelectedDocuments() throws Exception {
    YamlPropertiesFactoryBean factory = new YamlPropertiesFactoryBean();
    factory.setResources(new ByteArrayResource("foo: bar\nspam: baz\n---\nfoo: bag\nspam: bad".getBytes()));
    factory.setDocumentMatchers(new DocumentMatcher() {

        @Override
        public MatchStatus matches(Properties properties) {
            return ("bag".equals(properties.getProperty("foo")) ? MatchStatus.FOUND : MatchStatus.NOT_FOUND);
        }
    });
    Properties properties = factory.getObject();
    assertThat(properties.getProperty("foo"), equalTo("bag"));
    assertThat(properties.getProperty("spam"), equalTo("bad"));
}
Also used : ByteArrayResource(org.springframework.core.io.ByteArrayResource) Properties(java.util.Properties) Test(org.junit.Test)

Example 75 with ByteArrayResource

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

the class YamlPropertiesFactoryBeanTests method testLoadResourcesWithNestedInternalOverride.

@Test
@Ignore("We can't fail on duplicate keys because the Map is created by the YAML library")
public void testLoadResourcesWithNestedInternalOverride() throws Exception {
    YamlPropertiesFactoryBean factory = new YamlPropertiesFactoryBean();
    factory.setResources(new ByteArrayResource("foo:\n  bar: spam\n  foo: baz\nbreak: it\nfoo: bucket".getBytes()));
    Properties properties = factory.getObject();
    assertThat(properties.getProperty("foo.bar"), equalTo("spam"));
}
Also used : ByteArrayResource(org.springframework.core.io.ByteArrayResource) Properties(java.util.Properties) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

ByteArrayResource (org.springframework.core.io.ByteArrayResource)95 Test (org.junit.Test)67 Resource (org.springframework.core.io.Resource)32 Properties (java.util.Properties)26 IOException (java.io.IOException)6 InputStream (java.io.InputStream)6 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 Before (org.junit.Before)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 LinkedHashMap (java.util.LinkedHashMap)4 Map (java.util.Map)4 MutablePropertySources (org.springframework.core.env.MutablePropertySources)4