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