Author: jbq Date: Fri Aug 24 08:26:54 2007 New Revision: 569418 URL: http://svn.apache.org/viewvc?rev=569418&view=rev Log: WICKET-646 Do not throw an error when image not found while testing
Modified: wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/PackageResource.java wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/html/PackageResourceTest.java Modified: wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/PackageResource.java URL: http://svn.apache.org/viewvc/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/PackageResource.java?rev=569418&r1=569417&r2=569418&view=diff ============================================================================== --- wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/PackageResource.java (original) +++ wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/PackageResource.java Fri Aug 24 08:26:54 2007 @@ -106,8 +106,6 @@ private static final long serialVersionUID = 1L; - private boolean probingOnly = false; - /** * Binds the resources that match the provided pattern to the given application object. Will * create any resources if not already in the shared resources of the application object. @@ -485,16 +483,14 @@ if (locale != null) { - // Request to silently ignore unresolvable resources as we are not serving the resource for now - probingOnly = true; - - // Get the resource stream so that the real locale that could be - // resolved is set. - getResourceStream(); + /* + * Get the resource stream so that the real locale that could be resolved is set. + * Silently ignore unresolvable resources as we are not serving the resource for now + */ + getResourceStream(false); // Invalidate it again so that it won't hold up resources invalidate(); - probingOnly = false; } } @@ -533,6 +529,15 @@ */ public IResourceStream getResourceStream() { + return getResourceStream(true); + } + + /** + * @return Gets the resource for the component. + * @param failOnError throw an AbortException when resource does not exist + */ + public IResourceStream getResourceStream(boolean failOnError) + { // Locate resource IResourceStream resourceStream = Application.get().getResourceSettings() .getResourceStreamLocator().locate(getScope(), absolutePath, style, locale, null); @@ -540,7 +545,7 @@ // Check that resource was found if (resourceStream == null) { - if (probingOnly) + if (! failOnError) { // Do not abort the request, as we are not yet serving the resource return null; Modified: wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/html/PackageResourceTest.java URL: http://svn.apache.org/viewvc/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/html/PackageResourceTest.java?rev=569418&r1=569417&r2=569418&view=diff ============================================================================== --- wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/html/PackageResourceTest.java (original) +++ wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/html/PackageResourceTest.java Fri Aug 24 08:26:54 2007 @@ -16,9 +16,13 @@ */ package org.apache.wicket.markup.html; +import java.util.Locale; + import junit.framework.TestCase; +import org.apache.wicket.AbortException; import org.apache.wicket.Application; +import org.apache.wicket.Resource; import org.apache.wicket.SharedResources; import org.apache.wicket.protocol.http.WebApplication; import org.apache.wicket.util.tester.WicketTester; @@ -85,6 +89,23 @@ assertTrue(guard.accept(PackageResourceTest.class, ".Bar")); assertTrue(guard.accept(PackageResourceTest.class, ".java")); assertFalse(guard.accept(PackageResourceTest.class, "Bar.java")); + } + + public void testInvalidPackageResource() throws Exception + { + final SharedResources sharedResources = Application.get().getSharedResources(); + Resource invalidResource = new PackageResource(PackageResourceTest.class, "packaged3.txt", Locale.ENGLISH, null); + assertNotNull("resource packaged3.txt SHOULD be available as a packaged resource even if it doesn't exist", + invalidResource); + + try + { + invalidResource.getResourceStream(); + fail("Should have raised an AbortException"); + } + catch (AbortException e) + { + } } /**