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