Search in sources :

Example 6 with ByteArrayResource

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

the class YamlProcessorTests method testBadResource.

@Test
public void testBadResource() throws Exception {
    this.processor.setResources(new ByteArrayResource("foo: bar\ncd\nspam:\n  foo: baz".getBytes()));
    this.exception.expect(ScannerException.class);
    this.exception.expectMessage("line 3, 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 7 with ByteArrayResource

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

the class YamlProcessorTests method flattenedMapIsSameAsPropertiesButOrdered.

@Test
@SuppressWarnings("unchecked")
public void flattenedMapIsSameAsPropertiesButOrdered() {
    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) {
            assertEquals("bucket", properties.get("bar.spam"));
            assertEquals(2, properties.size());
            Map<String, Object> flattenedMap = processor.getFlattenedMap(map);
            assertEquals("bucket", flattenedMap.get("bar.spam"));
            assertEquals(2, flattenedMap.size());
            assertTrue(flattenedMap instanceof LinkedHashMap);
            Map<String, Object> bar = (Map<String, Object>) map.get("bar");
            assertEquals("bucket", bar.get("spam"));
        }
    });
}
Also used : ByteArrayResource(org.springframework.core.io.ByteArrayResource) Properties(java.util.Properties) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 8 with ByteArrayResource

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

the class YamlPropertiesFactoryBeanTests method testLoadArrayOfObject.

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

Example 9 with ByteArrayResource

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

the class YamlPropertiesFactoryBeanTests method testLoadResourceWithDefaultMatchSkippingMissedMatch.

@Test
public void testLoadResourceWithDefaultMatchSkippingMissedMatch() throws Exception {
    YamlPropertiesFactoryBean factory = new YamlPropertiesFactoryBean();
    factory.setMatchDefault(true);
    factory.setResources(new ByteArrayResource("one: two\n---\nfoo: bag\nspam: bad\n---\nfoo: bar\nspam: baz".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 10 with ByteArrayResource

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

the class YamlPropertiesFactoryBeanTests method testLoadArrayOfString.

@Test
public void testLoadArrayOfString() throws Exception {
    YamlPropertiesFactoryBean factory = new YamlPropertiesFactoryBean();
    factory.setResources(new ByteArrayResource("foo:\n- bar\n- baz".getBytes()));
    Properties properties = factory.getObject();
    assertThat(properties.getProperty("foo[0]"), equalTo("bar"));
    assertThat(properties.getProperty("foo[1]"), equalTo("baz"));
    assertThat(properties.get("foo"), is(nullValue()));
}
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