Search in sources :

Example 66 with ByteArrayResource

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

the class YamlPropertiesFactoryBeanTests method testLoadResourceWithDefaultMatch.

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

        @Override
        public MatchStatus matches(Properties properties) {
            if (!properties.containsKey("foo")) {
                return MatchStatus.ABSTAIN;
            }
            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"));
    assertThat(properties.getProperty("one"), equalTo("two"));
}
Also used : ByteArrayResource(org.springframework.core.io.ByteArrayResource) Properties(java.util.Properties) Test(org.junit.Test)

Example 67 with ByteArrayResource

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

the class YamlProcessorTests method testBadDocumentStart.

@Test
public void testBadDocumentStart() throws Exception {
    this.processor.setResources(new ByteArrayResource("foo # a document\nbar: baz".getBytes()));
    this.exception.expect(ParserException.class);
    this.exception.expectMessage("line 2, column 1");
    this.processor.process(new MatchCallback() {

        @Override
        public void process(Properties properties, Map<String, Object> map) {
        }
    });
}
Also used : ByteArrayResource(org.springframework.core.io.ByteArrayResource) Properties(java.util.Properties) Test(org.junit.Test)

Example 68 with ByteArrayResource

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

the class YamlProcessorTests method integerDeepKeyBehaves.

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

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

Example 69 with ByteArrayResource

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

the class YamlProcessorTests method testStringResource.

@Test
public void testStringResource() throws Exception {
    this.processor.setResources(new ByteArrayResource("foo # a document that is a literal".getBytes()));
    this.processor.process(new MatchCallback() {

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

Example 70 with ByteArrayResource

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

the class YamlProcessorTests method arrayConvertedToIndexedBeanReference.

@Test
public void arrayConvertedToIndexedBeanReference() {
    this.processor.setResources(new ByteArrayResource("foo: bar\nbar: [1,2,3]".getBytes()));
    this.processor.process(new MatchCallback() {

        @Override
        public void process(Properties properties, Map<String, Object> map) {
            assertEquals(4, properties.size());
            assertEquals("bar", properties.get("foo"));
            assertEquals("bar", properties.getProperty("foo"));
            assertEquals(1, properties.get("bar[0]"));
            assertEquals("1", properties.getProperty("bar[0]"));
            assertEquals(2, properties.get("bar[1]"));
            assertEquals("2", properties.getProperty("bar[1]"));
            assertEquals(3, properties.get("bar[2]"));
            assertEquals("3", properties.getProperty("bar[2]"));
        }
    });
}
Also used : ByteArrayResource(org.springframework.core.io.ByteArrayResource) Properties(java.util.Properties) 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