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()));
}
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"));
}
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()));
}
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"));
}
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()));
}
Aggregations