Search in sources :

Example 1 with ClasspathAssetAliasManager

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();
}
Also used : Resource(org.apache.tapestry5.commons.Resource) UnknownValueException(org.apache.tapestry5.commons.util.UnknownValueException) ClasspathAssetAliasManager(org.apache.tapestry5.services.ClasspathAssetAliasManager) Test(org.testng.annotations.Test)

Example 2 with ClasspathAssetAliasManager

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();
}
Also used : Resource(org.apache.tapestry5.commons.Resource) ClasspathAssetAliasManager(org.apache.tapestry5.services.ClasspathAssetAliasManager) Test(org.testng.annotations.Test)

Example 3 with ClasspathAssetAliasManager

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);
}
Also used : ClasspathAssetAliasManager(org.apache.tapestry5.services.ClasspathAssetAliasManager) Test(org.testng.annotations.Test)

Example 4 with ClasspathAssetAliasManager

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();
}
Also used : Resource(org.apache.tapestry5.commons.Resource) AssetAlias(org.apache.tapestry5.services.AssetAlias) ClasspathAssetAliasManager(org.apache.tapestry5.services.ClasspathAssetAliasManager) Test(org.testng.annotations.Test)

Example 5 with ClasspathAssetAliasManager

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);
}
Also used : ContextAssetRequestHandler(org.apache.tapestry5.internal.services.assets.ContextAssetRequestHandler) ClasspathAssetRequestHandler(org.apache.tapestry5.internal.services.assets.ClasspathAssetRequestHandler) Contribute(org.apache.tapestry5.ioc.annotations.Contribute) AssetRequestDispatcher(org.apache.tapestry5.services.AssetRequestDispatcher)

Aggregations

ClasspathAssetAliasManager (org.apache.tapestry5.services.ClasspathAssetAliasManager)4 Test (org.testng.annotations.Test)4 Resource (org.apache.tapestry5.commons.Resource)3 UnknownValueException (org.apache.tapestry5.commons.util.UnknownValueException)1 ClasspathAssetRequestHandler (org.apache.tapestry5.internal.services.assets.ClasspathAssetRequestHandler)1 ContextAssetRequestHandler (org.apache.tapestry5.internal.services.assets.ContextAssetRequestHandler)1 Contribute (org.apache.tapestry5.ioc.annotations.Contribute)1 AssetAlias (org.apache.tapestry5.services.AssetAlias)1 AssetRequestDispatcher (org.apache.tapestry5.services.AssetRequestDispatcher)1