use of org.apache.tapestry5.services.ClasspathAssetAliasManager in project tapestry-5 by apache.
the class ClasspathAssetAliasManagerImplTest method failure_if_path_not_in_mapped_alias_folder.
@Test
public void failure_if_path_not_in_mapped_alias_folder() {
ClasspathAssetAliasManager manager = new ClasspathAssetAliasManagerImpl(configuration());
Resource resource = mockResource();
expect(resource.getPath()).andReturn("org/example/icons/flag.gif").atLeastOnce();
replay();
try {
manager.extractAssetAlias(resource);
unreachable();
} catch (UnknownValueException ex) {
assertMessageContains(ex, "Unable to create a client URL for classpath resource org/example/icons/flag.gif");
assertListsEquals(ex.getAvailableValues().getValues(), "com/example/mylib", "org/apache/tapestry5", "org/apache/tapestry5/internal");
}
verify();
}
use of org.apache.tapestry5.services.ClasspathAssetAliasManager in project tapestry-5 by apache.
the class ClasspathAssetAliasManagerImplTest method can_not_map_resource_path_that_matches_virtual_folder.
@Test
public void can_not_map_resource_path_that_matches_virtual_folder() throws IOException {
Resource r = mockResource();
expect(r.getPath()).andReturn("com/example/mylib");
replay();
ClasspathAssetAliasManager manager = new ClasspathAssetAliasManagerImpl(configuration());
try {
manager.extractAssetAlias(r);
unreachable();
} catch (IllegalArgumentException ex) {
}
verify();
}
use of org.apache.tapestry5.services.ClasspathAssetAliasManager in project tapestry-5 by apache.
the class ClasspathAssetAliasManagerImplTest method get_mappings.
@Test
public void get_mappings() {
// Notice how all the trailing slashes (which are tolerated but not wanted)
// have been removed.
Map<String, String> expected = CollectionFactory.newCaseInsensitiveMap();
expected.put("tapestry", "org/apache/tapestry5");
expected.put("tapestry-internal", "org/apache/tapestry5/internal");
expected.put("mylib", "com/example/mylib");
ClasspathAssetAliasManager manager = new ClasspathAssetAliasManagerImpl(configuration());
assertEquals(manager.getMappings(), expected);
}
use of org.apache.tapestry5.services.ClasspathAssetAliasManager in project tapestry-5 by apache.
the class ClasspathAssetAliasManagerImplTest method to_client_url.
@Test(dataProvider = "to_client_url_data")
public void to_client_url(String resourcePath, String expectedFolder, String expectedPath) throws IOException {
Resource r = mockResource();
expect(r.getPath()).andReturn(resourcePath);
replay();
ClasspathAssetAliasManager manager = new ClasspathAssetAliasManagerImpl(configuration());
AssetAlias alias = manager.extractAssetAlias(r);
assertEquals(alias.virtualFolder, expectedFolder);
assertEquals(alias.path, expectedPath);
verify();
}
use of org.apache.tapestry5.services.ClasspathAssetAliasManager in project tapestry-5 by apache.
the class AssetsModule method provideBuiltinAssetDispatchers.
/**
* Contributes an handler for each mapped classpath alias, as well handlers for context assets
* and stack assets (combined {@link org.apache.tapestry5.services.javascript.JavaScriptStack} files).
*/
@Contribute(Dispatcher.class)
@AssetRequestDispatcher
public static void provideBuiltinAssetDispatchers(MappedConfiguration<String, AssetRequestHandler> configuration, @ContextProvider AssetFactory contextAssetFactory, @Autobuild StackAssetRequestHandler stackAssetRequestHandler, ClasspathAssetAliasManager classpathAssetAliasManager, ResourceStreamer streamer, AssetSource assetSource, ClasspathAssetProtectionRule classpathAssetProtectionRule) {
Map<String, String> mappings = classpathAssetAliasManager.getMappings();
for (String folder : mappings.keySet()) {
String path = mappings.get(folder);
configuration.add(folder, new ClasspathAssetRequestHandler(streamer, assetSource, path, classpathAssetProtectionRule));
}
configuration.add(RequestConstants.CONTEXT_FOLDER, new ContextAssetRequestHandler(streamer, contextAssetFactory.getRootResource()));
configuration.add(RequestConstants.STACK_FOLDER, stackAssetRequestHandler);
}
Aggregations