Search in sources :

Example 91 with ClassPathResource

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

the class TestValidator method loadBeanDefinitions.

private void loadBeanDefinitions(String fileName) {
    XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(this.appContext);
    ClassPathResource resource = new ClassPathResource(fileName, MessageBrokerBeanDefinitionParserTests.class);
    reader.loadBeanDefinitions(resource);
    this.appContext.setServletContext(new MockServletContext());
    this.appContext.refresh();
}
Also used : XmlBeanDefinitionReader(org.springframework.beans.factory.xml.XmlBeanDefinitionReader) ClassPathResource(org.springframework.core.io.ClassPathResource) MockServletContext(org.springframework.mock.web.test.MockServletContext)

Example 92 with ClassPathResource

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

the class EnvironmentSystemIntegrationTests method fileSystemXmlApplicationContext.

@Test
public void fileSystemXmlApplicationContext() throws IOException {
    ClassPathResource xml = new ClassPathResource(XML_PATH);
    File tmpFile = File.createTempFile("test", "xml");
    FileCopyUtils.copy(xml.getFile(), tmpFile);
    // strange - FSXAC strips leading '/' unless prefixed with 'file:'
    ConfigurableApplicationContext ctx = new FileSystemXmlApplicationContext(new String[] { "file:" + tmpFile.getPath() }, false);
    ctx.setEnvironment(prodEnv);
    ctx.refresh();
    assertEnvironmentBeanRegistered(ctx);
    assertHasEnvironment(ctx, prodEnv);
    assertEnvironmentAwareInvoked(ctx, ctx.getEnvironment());
    assertThat(ctx.containsBean(DEV_BEAN_NAME), is(false));
    assertThat(ctx.containsBean(PROD_BEAN_NAME), is(true));
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) FileSystemXmlApplicationContext(org.springframework.context.support.FileSystemXmlApplicationContext) File(java.io.File) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.Test)

Example 93 with ClassPathResource

use of org.springframework.core.io.ClassPathResource in project camel by apache.

the class CamelContextFactoryBeanTest method testGenericApplicationContextUsingNamespaces.

public void testGenericApplicationContextUsingNamespaces() throws Exception {
    applicationContext = new GenericApplicationContext();
    XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader((BeanDefinitionRegistry) applicationContext);
    xmlReader.loadBeanDefinitions(new ClassPathResource("org/apache/camel/spring/camelContextFactoryBean.xml"));
    // lets refresh to inject the applicationContext into beans
    applicationContext.refresh();
    CamelContext context = applicationContext.getBean("camel3", CamelContext.class);
    assertValidContext(context);
}
Also used : CamelContext(org.apache.camel.CamelContext) SpringCamelContext(org.apache.camel.spring.SpringCamelContext) GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) XmlBeanDefinitionReader(org.springframework.beans.factory.xml.XmlBeanDefinitionReader) ClassPathResource(org.springframework.core.io.ClassPathResource)

Example 94 with ClassPathResource

use of org.springframework.core.io.ClassPathResource in project spring-boot-admin by codecentric.

the class ConcatenatingResourceResolverTest method test_concatenation.

@Test
public void test_concatenation() throws IOException {
    Resource testResource = new ClassPathResource("/testResource.txt");
    List<Resource> resources = asList(testResource, testResource, testResource);
    Resource resolvedResource = new ConcatenatingResourceResolver(";".getBytes()).resolveResource(null, "/foo.txt", resources, null);
    assertThat(resolvedResource.getFilename(), is("foo.txt"));
    assertThat(resolvedResource.lastModified(), is(testResource.lastModified()));
    assertThat(resolvedResource.getDescription(), is("Byte array resource [(class path resource [testResource.txt], class path resource [testResource.txt], class path resource [testResource.txt])]"));
    assertThat(copyToByteArray(resolvedResource.getInputStream()), is("Foobar;Foobar;Foobar".getBytes()));
}
Also used : ClassPathResource(org.springframework.core.io.ClassPathResource) Resource(org.springframework.core.io.Resource) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.Test)

Example 95 with ClassPathResource

use of org.springframework.core.io.ClassPathResource in project spring-boot-admin by codecentric.

the class PreferMinifiedFilteringResourceResolverTest method test_resolveResource.

@Test
public void test_resolveResource() {
    List<? extends Resource> resources = asList(new ClassPathResource("testResource.txt"), new ClassPathResource("application.properties"));
    new PreferMinifiedFilteringResourceResolver(".min").resolveResource(null, null, resources, new ResourceResolverChain() {

        @Override
        public Resource resolveResource(HttpServletRequest request, String requestPath, List<? extends Resource> locations) {
            assertThat(locations.size(), is(2));
            assertThat(locations, contains((Resource) new ClassPathResource("testResource.min.txt"), (Resource) new ClassPathResource("application.properties")));
            return null;
        }

        @Override
        public String resolveUrlPath(String resourcePath, List<? extends Resource> locations) {
            return null;
        }
    });
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ClassPathResource(org.springframework.core.io.ClassPathResource) Resource(org.springframework.core.io.Resource) ResourceResolverChain(org.springframework.web.servlet.resource.ResourceResolverChain) 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