use of org.springframework.core.io.ClassPathResource in project spring-framework by spring-projects.
the class ProxyFactoryBeanTests method testInnerBeanTargetUsingAutowiring.
/**
* Simple test of a ProxyFactoryBean that has an inner bean as target that specifies autowiring.
* Checks for correct use of getType() by bean factory.
*/
@Test
public void testInnerBeanTargetUsingAutowiring() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(new ClassPathResource(AUTOWIRING_CONTEXT, CLASS));
bf.getBean("testBean");
}
use of org.springframework.core.io.ClassPathResource in project spring-framework by spring-projects.
the class TestPathHelper method loadBeanDefinitions.
private void loadBeanDefinitions(String fileName) {
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(this.appContext);
Resource resource = new ClassPathResource(fileName, AnnotationDrivenBeanDefinitionParserTests.class);
reader.loadBeanDefinitions(resource);
this.appContext.refresh();
}
use of org.springframework.core.io.ClassPathResource in project spring-framework by spring-projects.
the class MvcNamespaceTests method loadBeanDefinitions.
private void loadBeanDefinitions(String fileName, int expectedBeanCount) {
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(appContext);
ClassPathResource resource = new ClassPathResource(fileName, AnnotationDrivenBeanDefinitionParserTests.class);
reader.loadBeanDefinitions(resource);
String names = Arrays.toString(this.appContext.getBeanDefinitionNames());
assertEquals("Bean names: " + names, expectedBeanCount, appContext.getBeanDefinitionCount());
appContext.refresh();
}
use of org.springframework.core.io.ClassPathResource in project spring-framework by spring-projects.
the class RequestPartIntegrationTests method testCreate.
private void testCreate(String url, String basename) {
MultiValueMap<String, Object> parts = new LinkedMultiValueMap<>();
parts.add("json-data", new HttpEntity<>(new TestData(basename)));
parts.add("file-data", new ClassPathResource("logo.jpg", getClass()));
// SPR-12860
parts.add("empty-data", new HttpEntity<>(new byte[0]));
HttpHeaders headers = new HttpHeaders();
headers.setContentType(new MediaType("application", "octet-stream", StandardCharsets.ISO_8859_1));
// SPR-13096
parts.add("iso-8859-1-data", new HttpEntity<>(new byte[] { (byte) 0xC4 }, headers));
URI location = restTemplate.postForLocation(url, parts);
assertEquals("http://localhost:8080/test/" + basename + "/logo.jpg", location.toString());
}
use of org.springframework.core.io.ClassPathResource in project spring-framework by spring-projects.
the class RequestResponseBodyMethodProcessorTests method handleReturnValueImage.
// SPR-12894
@Test
public void handleReturnValueImage() throws Exception {
this.servletRequest.addHeader("Accept", "*/*");
Method method = getClass().getDeclaredMethod("getImage");
MethodParameter returnType = new MethodParameter(method, -1);
List<HttpMessageConverter<?>> converters = new ArrayList<>();
converters.add(new ResourceHttpMessageConverter());
RequestResponseBodyMethodProcessor processor = new RequestResponseBodyMethodProcessor(converters);
ClassPathResource resource = new ClassPathResource("logo.jpg", getClass());
processor.writeWithMessageConverters(resource, returnType, this.request);
assertEquals("image/jpeg", this.servletResponse.getHeader("Content-Type"));
}
Aggregations