use of org.springframework.core.io.Resource in project spring-framework by spring-projects.
the class VersionResourceResolverTests method resolveResourceNoResourceAfterVersionRemoved.
@Test
public void resolveResourceNoResourceAfterVersionRemoved() throws Exception {
String versionFile = "bar-version.css";
String version = "version";
String file = "bar.css";
given(this.chain.resolveResource(null, versionFile, this.locations)).willReturn(null);
given(this.chain.resolveResource(null, file, this.locations)).willReturn(null);
given(this.versionStrategy.extractVersion(versionFile)).willReturn(version);
given(this.versionStrategy.removeVersion(versionFile, version)).willReturn(file);
this.resolver.setStrategyMap(Collections.singletonMap("/**", this.versionStrategy));
Resource actual = this.resolver.resolveResourceInternal(null, versionFile, this.locations, this.chain);
assertNull(actual);
verify(this.versionStrategy, times(1)).removeVersion(versionFile, version);
}
use of org.springframework.core.io.Resource in project spring-framework by spring-projects.
the class WebJarsResourceResolverTests method resolveResourceWebJar.
@Test
public void resolveResourceWebJar() {
Resource expected = mock(Resource.class);
String file = "underscorejs/underscore.js";
String expectedPath = "underscorejs/1.8.3/underscore.js";
this.locations = Collections.singletonList(new ClassPathResource("/META-INF/resources/webjars/", getClass()));
given(this.chain.resolveResource(this.request, expectedPath, this.locations)).willReturn(expected);
Resource actual = this.resolver.resolveResource(this.request, file, this.locations, this.chain);
assertEquals(expected, actual);
verify(this.chain, times(1)).resolveResource(this.request, file, this.locations);
}
use of org.springframework.core.io.Resource in project camel by apache.
the class RoutesCollector method loadXmlRests.
private void loadXmlRests(ApplicationContext applicationContext, CamelContext camelContext, String directory) {
LOG.info("Loading additional Camel XML rests from: {}", directory);
try {
final Resource[] xmlRests = applicationContext.getResources(directory);
for (final Resource xmlRest : xmlRests) {
final RestsDefinition xmlDefinitions = camelContext.loadRestsDefinition(xmlRest.getInputStream());
camelContext.addRestDefinitions(xmlDefinitions.getRests());
for (final RestDefinition xmlDefinition : xmlDefinitions.getRests()) {
final List<RouteDefinition> routeDefinitions = xmlDefinition.asRouteDefinition(camelContext);
camelContext.addRouteDefinitions(routeDefinitions);
}
}
} catch (FileNotFoundException e) {
LOG.debug("No XML rests found in {}. Skipping XML rests detection.", directory);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of org.springframework.core.io.Resource in project camel by apache.
the class RoutesCollector method loadXmlRoutes.
// Helpers
private void loadXmlRoutes(ApplicationContext applicationContext, CamelContext camelContext, String directory) throws Exception {
LOG.info("Loading additional Camel XML routes from: {}", directory);
try {
Resource[] xmlRoutes = applicationContext.getResources(directory);
for (Resource xmlRoute : xmlRoutes) {
LOG.debug("Found XML route: {}", xmlRoute);
RoutesDefinition xmlDefinition = camelContext.loadRoutesDefinition(xmlRoute.getInputStream());
camelContext.addRouteDefinitions(xmlDefinition.getRoutes());
}
} catch (FileNotFoundException e) {
LOG.debug("No XML routes found in {}. Skipping XML routes detection.", directory);
}
}
use of org.springframework.core.io.Resource 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()));
}
Aggregations