use of org.apache.wicket.core.util.resource.locator.caching.CachingResourceStreamLocator in project wicket by apache.
the class CachingResourceStreamLocatorTest method fileResource.
/**
* Tests FileResourceStreamReference
*/
@Test
public void fileResource() {
IResourceStreamLocator resourceStreamLocator = mock(IResourceStreamLocator.class);
FileResourceStream frs = new FileResourceStream(new File("."));
when(resourceStreamLocator.locate(String.class, "path", "style", "variation", null, "extension", true)).thenReturn(frs);
CachingResourceStreamLocator cachingLocator = new CachingResourceStreamLocator(resourceStreamLocator);
cachingLocator.locate(String.class, "path", "style", "variation", null, "extension", true);
cachingLocator.locate(String.class, "path", "style", "variation", null, "extension", true);
// there is a file resource with that Key so expect just one call to the delegate
verify(resourceStreamLocator, times(1)).locate(String.class, "path", "style", "variation", null, "extension", true);
}
use of org.apache.wicket.core.util.resource.locator.caching.CachingResourceStreamLocator in project wicket by apache.
the class CachingResourceStreamLocatorTest method urlResource.
/**
* Tests UrlResourceStreamReference
*
* @throws Exception
*/
@Test
public void urlResource() throws Exception {
IResourceStreamLocator resourceStreamLocator = mock(IResourceStreamLocator.class);
UrlResourceStream urs = new UrlResourceStream(new URL("file:///"));
when(resourceStreamLocator.locate(String.class, "path")).thenReturn(urs);
CachingResourceStreamLocator cachingLocator = new CachingResourceStreamLocator(resourceStreamLocator);
cachingLocator.locate(String.class, "path");
cachingLocator.locate(String.class, "path");
// there is a url resource with that Key so expect just one call to the delegate
verify(resourceStreamLocator, times(1)).locate(String.class, "path");
}
use of org.apache.wicket.core.util.resource.locator.caching.CachingResourceStreamLocator in project wicket by apache.
the class CachingResourceStreamLocatorTest method notExistingResource.
/**
* Tests NullResourceStreamReference
*/
@Test
public void notExistingResource() {
IResourceStreamLocator resourceStreamLocator = mock(IResourceStreamLocator.class);
CachingResourceStreamLocator cachingLocator = new CachingResourceStreamLocator(resourceStreamLocator);
cachingLocator.locate(String.class, "path");
cachingLocator.locate(String.class, "path");
// there is no resource with that Key so a "miss" will be cached and expect 1 call to the
// delegate
verify(resourceStreamLocator, times(1)).locate(String.class, "path");
}
use of org.apache.wicket.core.util.resource.locator.caching.CachingResourceStreamLocator in project wicket by apache.
the class CachingResourceStreamLocatorTest method fileResourceDifferentExtensions.
/**
* Tests two FileResourceStreamReferences with different extensions
*/
@Test
public void fileResourceDifferentExtensions() {
IResourceStreamLocator resourceStreamLocator = mock(IResourceStreamLocator.class);
FileResourceStream frs = new FileResourceStream(new File("."));
when(resourceStreamLocator.locate(String.class, "path", "style", "variation", null, "extension", true)).thenReturn(frs);
CachingResourceStreamLocator cachingLocator = new CachingResourceStreamLocator(resourceStreamLocator);
cachingLocator.locate(String.class, "path", "style", "variation", null, "extension", true);
cachingLocator.locate(String.class, "path", "style", "variation", null, "extension", true);
cachingLocator.locate(String.class, "path", "style", "variation", null, "extension2", true);
// there is a file resource with that Key so expect just one call to the delegate
verify(resourceStreamLocator, times(1)).locate(String.class, "path", "style", "variation", null, "extension", true);
verify(resourceStreamLocator, times(1)).locate(String.class, "path", "style", "variation", null, "extension2", true);
}
use of org.apache.wicket.core.util.resource.locator.caching.CachingResourceStreamLocator in project wicket by apache.
the class CachingResourceStreamLocatorTest method strictMatchingDoesntInvalidateNonStrictMatching.
/**
* Tests strict before non-strict matching with a specific locale.
*/
@Test
public void strictMatchingDoesntInvalidateNonStrictMatching() {
IResourceStreamLocator resourceStreamLocator = new ResourceStreamLocator(new ClassPathResourceFinder(""));
CachingResourceStreamLocator cachingLocator = new CachingResourceStreamLocator(resourceStreamLocator);
String style = null;
String variation = null;
Locale locale = new Locale("nl", "NL");
String extension = null;
String filename = "org/apache/wicket/ajax/res/js/wicket-ajax-jquery-debug.js";
// a strict lookup of a localized resource should not find the non-localized resource
IResourceStream strictLocate = cachingLocator.locate(AbstractDefaultAjaxBehavior.class, filename, style, variation, locale, extension, true);
assertThat(strictLocate, is(nullValue()));
// but a non-strict lookup with a locale should fall back to the non-localized resource
IResourceStream nonStrictLocate = cachingLocator.locate(AbstractDefaultAjaxBehavior.class, filename, style, variation, locale, extension, false);
assertThat(nonStrictLocate, is(not(nullValue())));
}
Aggregations