Search in sources :

Example 1 with CachingResourceStreamLocator

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);
}
Also used : FileResourceStream(org.apache.wicket.util.resource.FileResourceStream) CachingResourceStreamLocator(org.apache.wicket.core.util.resource.locator.caching.CachingResourceStreamLocator) IResourceStreamLocator(org.apache.wicket.core.util.resource.locator.IResourceStreamLocator) File(java.io.File) Test(org.junit.Test)

Example 2 with CachingResourceStreamLocator

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");
}
Also used : UrlResourceStream(org.apache.wicket.core.util.resource.UrlResourceStream) CachingResourceStreamLocator(org.apache.wicket.core.util.resource.locator.caching.CachingResourceStreamLocator) IResourceStreamLocator(org.apache.wicket.core.util.resource.locator.IResourceStreamLocator) URL(java.net.URL) Test(org.junit.Test)

Example 3 with CachingResourceStreamLocator

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");
}
Also used : CachingResourceStreamLocator(org.apache.wicket.core.util.resource.locator.caching.CachingResourceStreamLocator) IResourceStreamLocator(org.apache.wicket.core.util.resource.locator.IResourceStreamLocator) Test(org.junit.Test)

Example 4 with CachingResourceStreamLocator

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);
}
Also used : FileResourceStream(org.apache.wicket.util.resource.FileResourceStream) CachingResourceStreamLocator(org.apache.wicket.core.util.resource.locator.caching.CachingResourceStreamLocator) IResourceStreamLocator(org.apache.wicket.core.util.resource.locator.IResourceStreamLocator) File(java.io.File) Test(org.junit.Test)

Example 5 with CachingResourceStreamLocator

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())));
}
Also used : Locale(java.util.Locale) CachingResourceStreamLocator(org.apache.wicket.core.util.resource.locator.caching.CachingResourceStreamLocator) IResourceStream(org.apache.wicket.util.resource.IResourceStream) IResourceStreamLocator(org.apache.wicket.core.util.resource.locator.IResourceStreamLocator) ResourceStreamLocator(org.apache.wicket.core.util.resource.locator.ResourceStreamLocator) IResourceStreamLocator(org.apache.wicket.core.util.resource.locator.IResourceStreamLocator) CachingResourceStreamLocator(org.apache.wicket.core.util.resource.locator.caching.CachingResourceStreamLocator) ClassPathResourceFinder(org.apache.wicket.core.util.resource.ClassPathResourceFinder) Test(org.junit.Test)

Aggregations

IResourceStreamLocator (org.apache.wicket.core.util.resource.locator.IResourceStreamLocator)10 CachingResourceStreamLocator (org.apache.wicket.core.util.resource.locator.caching.CachingResourceStreamLocator)10 Test (org.junit.Test)8 ResourceStreamLocator (org.apache.wicket.core.util.resource.locator.ResourceStreamLocator)4 Locale (java.util.Locale)3 ClassPathResourceFinder (org.apache.wicket.core.util.resource.ClassPathResourceFinder)3 IResourceStream (org.apache.wicket.util.resource.IResourceStream)3 File (java.io.File)2 FileResourceStream (org.apache.wicket.util.resource.FileResourceStream)2 MidPointApplicationConfiguration (com.evolveum.midpoint.gui.api.util.MidPointApplicationConfiguration)1 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)1 PageMounter (com.evolveum.midpoint.web.application.PageMounter)1 MidPointResourceStreamLocator (com.evolveum.midpoint.web.util.MidPointResourceStreamLocator)1 MidPointStringResourceLoader (com.evolveum.midpoint.web.util.MidPointStringResourceLoader)1 SystemConfigurationType (com.evolveum.midpoint.xml.ns._public.common.common_3.SystemConfigurationType)1 URL (java.net.URL)1 ServletContext (javax.servlet.ServletContext)1 AbstractDefaultAjaxBehavior (org.apache.wicket.ajax.AbstractDefaultAjaxBehavior)1 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)1 AjaxRequestAttributes (org.apache.wicket.ajax.attributes.AjaxRequestAttributes)1