Search in sources :

Example 61 with ClassPathResource

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");
}
Also used : XmlBeanDefinitionReader(org.springframework.beans.factory.xml.XmlBeanDefinitionReader) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.Test)

Example 62 with ClassPathResource

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();
}
Also used : XmlBeanDefinitionReader(org.springframework.beans.factory.xml.XmlBeanDefinitionReader) ClassPathResource(org.springframework.core.io.ClassPathResource) Resource(org.springframework.core.io.Resource) ClassPathResource(org.springframework.core.io.ClassPathResource)

Example 63 with ClassPathResource

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();
}
Also used : XmlBeanDefinitionReader(org.springframework.beans.factory.xml.XmlBeanDefinitionReader) ClassPathResource(org.springframework.core.io.ClassPathResource)

Example 64 with ClassPathResource

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());
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) MediaType(org.springframework.http.MediaType) URI(java.net.URI) ClassPathResource(org.springframework.core.io.ClassPathResource)

Example 65 with ClassPathResource

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"));
}
Also used : ArrayList(java.util.ArrayList) AllEncompassingFormHttpMessageConverter(org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter) ResourceHttpMessageConverter(org.springframework.http.converter.ResourceHttpMessageConverter) MappingJackson2XmlHttpMessageConverter(org.springframework.http.converter.xml.MappingJackson2XmlHttpMessageConverter) StringHttpMessageConverter(org.springframework.http.converter.StringHttpMessageConverter) HttpMessageConverter(org.springframework.http.converter.HttpMessageConverter) ByteArrayHttpMessageConverter(org.springframework.http.converter.ByteArrayHttpMessageConverter) MappingJackson2HttpMessageConverter(org.springframework.http.converter.json.MappingJackson2HttpMessageConverter) ResourceHttpMessageConverter(org.springframework.http.converter.ResourceHttpMessageConverter) HandlerMethod(org.springframework.web.method.HandlerMethod) Method(java.lang.reflect.Method) MethodParameter(org.springframework.core.MethodParameter) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.Test)

Aggregations

ClassPathResource (org.springframework.core.io.ClassPathResource)628 Test (org.junit.Test)404 Resource (org.springframework.core.io.Resource)182 DhisSpringTest (org.hisp.dhis.DhisSpringTest)85 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)80 List (java.util.List)63 XmlBeanDefinitionReader (org.springframework.beans.factory.xml.XmlBeanDefinitionReader)62 Before (org.junit.Before)55 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)54 ImportSummary (org.hisp.dhis.dxf2.importsummary.ImportSummary)39 ObjectBundleValidationReport (org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleValidationReport)36 ArrayList (java.util.ArrayList)35 DataElement (org.hisp.dhis.dataelement.DataElement)32 File (java.io.File)29 UrlResource (org.springframework.core.io.UrlResource)29 TestBean (org.springframework.tests.sample.beans.TestBean)27 IOException (java.io.IOException)26 InputStream (java.io.InputStream)23 FileSystemResource (org.springframework.core.io.FileSystemResource)23 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)19