Search in sources :

Example 1 with StaticResourceVersion

use of org.apache.wicket.request.resource.caching.version.StaticResourceVersion in project wicket by apache.

the class ContextRelativeResourceCachingTest method init.

private void init(ContextRelativeResource resource, String mountPath) {
    final IResourceVersion resourceVersion = new StaticResourceVersion("123");
    final IResourceCachingStrategy strategy = new FilenameWithVersionResourceCachingStrategy("-version-", resourceVersion);
    tester.getApplication().getSharedResources().add(SHARED_NAME, resource);
    tester.getApplication().getResourceSettings().setCachingStrategy(strategy);
    final ResourceReference resourceReference = new SharedResourceReference(SHARED_NAME);
    tester.getApplication().mountResource(mountPath, resourceReference);
}
Also used : SharedResourceReference(org.apache.wicket.request.resource.SharedResourceReference) StaticResourceVersion(org.apache.wicket.request.resource.caching.version.StaticResourceVersion) IResourceVersion(org.apache.wicket.request.resource.caching.version.IResourceVersion) SharedResourceReference(org.apache.wicket.request.resource.SharedResourceReference) ResourceReference(org.apache.wicket.request.resource.ResourceReference)

Example 2 with StaticResourceVersion

use of org.apache.wicket.request.resource.caching.version.StaticResourceVersion in project wicket by apache.

the class BasicResourceReferenceMapperTest method versionStringInResourceFilename.

/**
 */
@Test
public void versionStringInResourceFilename() {
    final IStaticCacheableResource resource = new IStaticCacheableResource() {

        private static final long serialVersionUID = 1L;

        @Override
        public Serializable getCacheKey() {
            return null;
        }

        @Override
        public IResourceStream getResourceStream() {
            return new StringResourceStream("foo-bar");
        }

        @Override
        public void respond(Attributes attributes) {
        }

        @Override
        public boolean isCachingEnabled() {
            return true;
        }
    };
    IResourceCachingStrategy strategy = new FilenameWithVersionResourceCachingStrategy("-version-", new AlphaDigitResourceVersion("foobar"));
    INamedParameters params = new PageParameters();
    ResourceUrl url = new ResourceUrl("test.js", params);
    strategy.decorateUrl(url, resource);
    assertEquals("test-version-foobar.js", url.getFileName());
    strategy.undecorateUrl(url);
    assertEquals("test.js", url.getFileName());
    url = new ResourceUrl("test", params);
    strategy.decorateUrl(url, resource);
    assertEquals("test-version-foobar", url.getFileName());
    strategy.undecorateUrl(url);
    assertEquals("test", url.getFileName());
    // this behavior is o.k. since a browser could request an
    // previous version of the resource. for example we
    // could first have 'test-alpha.txt' which would be later replaced
    // by 'test-beta.txt' but in any case will point to
    // internal resource 'test.txt'
    url = new ResourceUrl("test-version-older.txt", params);
    strategy.undecorateUrl(url);
    assertEquals("test.txt", url.getFileName());
    // weird but valid
    url = new ResourceUrl("test-version-.txt", params);
    strategy.undecorateUrl(url);
    assertEquals("test.txt", url.getFileName());
    // weird but valid
    url = new ResourceUrl("test-version--------", params);
    strategy.undecorateUrl(url);
    assertEquals("test", url.getFileName());
    // weird but valid
    url = new ResourceUrl("test-version-1.0.3-alpha.txt", params);
    strategy.undecorateUrl(url);
    assertEquals("test.txt", url.getFileName());
    // check a version that contains a dot which also marks the filename
    // extension
    strategy = new FilenameWithVersionResourceCachingStrategy("-version-", new StaticResourceVersion("1.0.4-beta"));
    url = new ResourceUrl("test.txt", params);
    strategy.decorateUrl(url, resource);
    assertEquals("test-version-1.0.4-beta.txt", url.getFileName());
}
Also used : IStaticCacheableResource(org.apache.wicket.request.resource.caching.IStaticCacheableResource) FilenameWithVersionResourceCachingStrategy(org.apache.wicket.request.resource.caching.FilenameWithVersionResourceCachingStrategy) INamedParameters(org.apache.wicket.request.mapper.parameter.INamedParameters) StaticResourceVersion(org.apache.wicket.request.resource.caching.version.StaticResourceVersion) StringResourceStream(org.apache.wicket.util.resource.StringResourceStream) PageParameters(org.apache.wicket.request.mapper.parameter.PageParameters) IResourceCachingStrategy(org.apache.wicket.request.resource.caching.IResourceCachingStrategy) ResourceUrl(org.apache.wicket.request.resource.caching.ResourceUrl) Test(org.junit.Test)

Aggregations

StaticResourceVersion (org.apache.wicket.request.resource.caching.version.StaticResourceVersion)2 INamedParameters (org.apache.wicket.request.mapper.parameter.INamedParameters)1 PageParameters (org.apache.wicket.request.mapper.parameter.PageParameters)1 ResourceReference (org.apache.wicket.request.resource.ResourceReference)1 SharedResourceReference (org.apache.wicket.request.resource.SharedResourceReference)1 FilenameWithVersionResourceCachingStrategy (org.apache.wicket.request.resource.caching.FilenameWithVersionResourceCachingStrategy)1 IResourceCachingStrategy (org.apache.wicket.request.resource.caching.IResourceCachingStrategy)1 IStaticCacheableResource (org.apache.wicket.request.resource.caching.IStaticCacheableResource)1 ResourceUrl (org.apache.wicket.request.resource.caching.ResourceUrl)1 IResourceVersion (org.apache.wicket.request.resource.caching.version.IResourceVersion)1 StringResourceStream (org.apache.wicket.util.resource.StringResourceStream)1 Test (org.junit.Test)1