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