Search in sources :

Example 81 with ByteArrayResource

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

the class HttpEntityMethodProcessorMockTests method shouldHandleResource.

@Test
public void shouldHandleResource() throws Exception {
    ResponseEntity<Resource> returnValue = ResponseEntity.ok(new ByteArrayResource("Content".getBytes(StandardCharsets.UTF_8)));
    given(resourceMessageConverter.canWrite(ByteArrayResource.class, null)).willReturn(true);
    given(resourceMessageConverter.getSupportedMediaTypes()).willReturn(Collections.singletonList(MediaType.ALL));
    given(resourceMessageConverter.canWrite(ByteArrayResource.class, MediaType.APPLICATION_OCTET_STREAM)).willReturn(true);
    processor.handleReturnValue(returnValue, returnTypeResponseEntityResource, mavContainer, webRequest);
    then(resourceMessageConverter).should(times(1)).write(any(ByteArrayResource.class), eq(MediaType.APPLICATION_OCTET_STREAM), any(HttpOutputMessage.class));
    assertEquals(200, servletResponse.getStatus());
}
Also used : HttpOutputMessage(org.springframework.http.HttpOutputMessage) ByteArrayResource(org.springframework.core.io.ByteArrayResource) Resource(org.springframework.core.io.Resource) ByteArrayResource(org.springframework.core.io.ByteArrayResource) Test(org.junit.Test)

Example 82 with ByteArrayResource

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

the class YamlPropertySourceLoaderTests method load.

@Test
public void load() throws Exception {
    ByteArrayResource resource = new ByteArrayResource("foo:\n  bar: spam".getBytes());
    PropertySource<?> source = this.loader.load("resource", resource, null);
    assertThat(source).isNotNull();
    assertThat(source.getProperty("foo.bar")).isEqualTo("spam");
}
Also used : ByteArrayResource(org.springframework.core.io.ByteArrayResource) Test(org.junit.Test)

Example 83 with ByteArrayResource

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

the class ResourcePropertySourceTests method withResourceHavingNoDescription.

@Test
public void withResourceHavingNoDescription() throws IOException {
    PropertySource<?> ps = new ResourcePropertySource(new ByteArrayResource("foo=bar".getBytes(), ""));
    assertEquals("bar", ps.getProperty("foo"));
    assertEquals("Byte array resource []", ps.getName());
}
Also used : ByteArrayResource(org.springframework.core.io.ByteArrayResource) Test(org.junit.Test)

Example 84 with ByteArrayResource

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

the class ConfigFileApplicationListenerTests method loadCustomResource.

@Test
public void loadCustomResource() throws Exception {
    this.application.setResourceLoader(new ResourceLoader() {

        @Override
        public Resource getResource(final String location) {
            if (location.equals("classpath:/custom.properties")) {
                return new ByteArrayResource("the.property: fromcustom".getBytes(), location) {

                    @Override
                    public String getFilename() {
                        return location;
                    }
                };
            }
            return null;
        }

        @Override
        public ClassLoader getClassLoader() {
            return getClass().getClassLoader();
        }
    });
    this.initializer.setSearchNames("custom");
    this.initializer.postProcessEnvironment(this.environment, this.application);
    String property = this.environment.getProperty("the.property");
    assertThat(property).isEqualTo("fromcustom");
}
Also used : ResourceLoader(org.springframework.core.io.ResourceLoader) ByteArrayResource(org.springframework.core.io.ByteArrayResource) Resource(org.springframework.core.io.Resource) ByteArrayResource(org.springframework.core.io.ByteArrayResource) Test(org.junit.Test)

Example 85 with ByteArrayResource

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

the class SpringProfileDocumentMatcherTests method getProperties.

private Properties getProperties(String values) throws IOException {
    YamlPropertiesFactoryBean yamlPropertiesFactoryBean = new YamlPropertiesFactoryBean();
    ByteArrayResource resource = new ByteArrayResource(values.getBytes());
    yamlPropertiesFactoryBean.setResources(resource);
    yamlPropertiesFactoryBean.afterPropertiesSet();
    return yamlPropertiesFactoryBean.getObject();
}
Also used : YamlPropertiesFactoryBean(org.springframework.beans.factory.config.YamlPropertiesFactoryBean) ByteArrayResource(org.springframework.core.io.ByteArrayResource)

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