Search in sources :

Example 36 with ByteArrayResource

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(""));
}
Also used : ByteArrayResource(org.springframework.core.io.ByteArrayResource) Properties(java.util.Properties) Test(org.junit.Test)

Example 37 with ByteArrayResource

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();
}
Also used : ByteArrayResource(org.springframework.core.io.ByteArrayResource) Test(org.junit.Test)

Example 38 with ByteArrayResource

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"));
}
Also used : ByteArrayResource(org.springframework.core.io.ByteArrayResource) Properties(java.util.Properties) Test(org.junit.Test)

Example 39 with ByteArrayResource

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

the class ResourceEncoderTests method encode.

@Test
public void encode() throws Exception {
    String s = "foo";
    Resource resource = new ByteArrayResource(s.getBytes(StandardCharsets.UTF_8));
    Mono<Resource> source = Mono.just(resource);
    Flux<DataBuffer> output = this.encoder.encode(source, this.bufferFactory, ResolvableType.forClass(Resource.class), null, Collections.emptyMap());
    StepVerifier.create(output).consumeNextWith(stringConsumer(s)).expectComplete().verify();
}
Also used : ByteArrayResource(org.springframework.core.io.ByteArrayResource) InputStreamResource(org.springframework.core.io.InputStreamResource) Resource(org.springframework.core.io.Resource) ByteArrayResource(org.springframework.core.io.ByteArrayResource) DataBuffer(org.springframework.core.io.buffer.DataBuffer) Test(org.junit.Test)

Example 40 with ByteArrayResource

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

the class ResourceRegionEncoderTests method shouldEncodeResourceRegionByteArrayResource.

@Test
public void shouldEncodeResourceRegionByteArrayResource() throws Exception {
    String content = "Spring Framework test resource content.";
    shouldEncodeResourceRegion(new ByteArrayResource(content.getBytes(StandardCharsets.UTF_8)));
}
Also used : ByteArrayResource(org.springframework.core.io.ByteArrayResource) 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