Author: hlship
Date: Sun Oct 30 12:26:50 2005
New Revision: 329628

URL: http://svn.apache.org/viewcvs?rev=329628&view=rev
Log:
TAPESTRY-526: Tapestry throws a NPE if you try to configure an asset without an 
extension

Added:
    
jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/web/WebContextResourceTest.java
      - copied, changed from r329587, 
jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/web/TestWebContextResource.java
Removed:
    
jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/web/TestWebContextResource.java
Modified:
    
jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/web/LocalizedWebContextResourceFinder.java
    jakarta/tapestry/trunk/status.xml

Modified: 
jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/web/LocalizedWebContextResourceFinder.java
URL: 
http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/web/LocalizedWebContextResourceFinder.java?rev=329628&r1=329627&r2=329628&view=diff
==============================================================================
--- 
jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/web/LocalizedWebContextResourceFinder.java
 (original)
+++ 
jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/web/LocalizedWebContextResourceFinder.java
 Sun Oct 30 12:26:50 2005
@@ -46,8 +46,18 @@
     public LocalizedResource resolve(String contextPath, Locale locale)
     {
         int dotx = contextPath.lastIndexOf('.');
-        String basePath = contextPath.substring(0, dotx);
-        String suffix = contextPath.substring(dotx);
+        String basePath;
+        String suffix;
+        if (dotx >= 0) {
+               basePath = contextPath.substring(0, dotx);
+               suffix = contextPath.substring(dotx);
+        }
+        else
+        {
+               // Resource without extension
+               basePath = contextPath;
+               suffix = "";
+        }
 
         LocalizedNameGenerator generator = new 
LocalizedNameGenerator(basePath, locale, suffix);
 

Copied: 
jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/web/WebContextResourceTest.java
 (from r329587, 
jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/web/TestWebContextResource.java)
URL: 
http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/web/WebContextResourceTest.java?p2=jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/web/WebContextResourceTest.java&p1=jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/web/TestWebContextResource.java&r1=329587&r2=329628&rev=329628&view=diff
==============================================================================
--- 
jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/web/TestWebContextResource.java
 (original)
+++ 
jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/web/WebContextResourceTest.java
 Sun Oct 30 12:26:50 2005
@@ -19,9 +19,6 @@
 
 import org.apache.hivemind.Resource;
 import org.apache.hivemind.test.HiveMindTestCase;
-import org.apache.tapestry.web.WebContextResource;
-import org.apache.tapestry.web.WebContext;
-import org.easymock.MockControl;
 
 /**
  * Tests for [EMAIL PROTECTED] org.apache.tapestry.web.WebContextResource}.
@@ -29,7 +26,7 @@
  * @author Howard M. Lewis Ship
  * @since 4.0
  */
-public class TestWebContextResource extends HiveMindTestCase
+public class WebContextResourceTest extends HiveMindTestCase
 {
     private WebContext newContext()
     {
@@ -57,11 +54,9 @@
 
     public void testLocalizationExists() throws Exception
     {
-        MockControl control = newControl(WebContext.class);
-        WebContext context = (WebContext) control.getMock();
+        WebContext context = newContext();
 
-        context.getResource("/foo/bar/baz_en.html");
-        control.setReturnValue(new URL("http://foo.com";));
+        trainGetResource(context, "/foo/bar/baz_en.html", new 
URL("http://foo.com";));
 
         replayControls();
 
@@ -75,16 +70,18 @@
         verifyControls();
     }
 
-    public void testLocalizationSame() throws Exception
+    private void trainGetResource(WebContext context, String path, URL url)
     {
-        MockControl control = newControl(WebContext.class);
-        WebContext context = (WebContext) control.getMock();
+        context.getResource(path);
+        setReturnValue(context, url);
+    }
 
-        context.getResource("/foo/bar/baz_en.html");
-        control.setReturnValue(null);
+    public void testLocalizationSame() throws Exception
+    {
+        WebContext context = newContext();
 
-        context.getResource("/foo/bar/baz.html");
-        control.setReturnValue(new URL("http://foo.com";));
+        trainGetResource(context, "/foo/bar/baz_en.html", null);
+        trainGetResource(context, "/foo/bar/baz.html", new 
URL("http://foo.com";));
 
         replayControls();
 
@@ -99,14 +96,10 @@
 
     public void testLocalizationMissing() throws Exception
     {
-        MockControl control = newControl(WebContext.class);
-        WebContext context = (WebContext) control.getMock();
-
-        context.getResource("/foo/bar/baz_en.html");
-        control.setReturnValue(null);
+        WebContext context = newContext();
 
-        context.getResource("/foo/bar/baz.html");
-        control.setReturnValue(null);
+        trainGetResource(context, "/foo/bar/baz_en.html", null);
+        trainGetResource(context, "/foo/bar/baz.html", null);
 
         replayControls();
 
@@ -127,6 +120,24 @@
         Resource r2 = r1.getRelativeResource("baz.gif");
 
         assertEquals("/foo/bar/baz.gif", r2.getPath());
+
+        verifyControls();
+    }
+
+    public void testGetExtensionlessResource() throws Exception
+    {
+        WebContext context = newContext();
+
+        trainGetResource(context, "/foo/bar/baz_en", new 
URL("http://foo.com";));
+
+        replayControls();
+
+        Resource r1 = new WebContextResource(context, "/foo/bar/baz");
+
+        Resource r2 = r1.getLocalization(Locale.ENGLISH);
+
+        assertEquals("/foo/bar/baz_en", r2.getPath());
+        assertEquals(Locale.ENGLISH, r2.getLocale());
 
         verifyControls();
     }

Modified: jakarta/tapestry/trunk/status.xml
URL: 
http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/status.xml?rev=329628&r1=329627&r2=329628&view=diff
==============================================================================
--- jakarta/tapestry/trunk/status.xml (original)
+++ jakarta/tapestry/trunk/status.xml Sun Oct 30 12:26:50 2005
@@ -61,6 +61,7 @@
       <action type="fix" dev="HLS" fixes-bug="TAPESTRY-715">LinkSubmit 
component should render its body, even when disabled</action>
       <action type="fix" dev="HLS" fixes-bug="TAPESTRY-602">Add annotation to 
define default value of property</action>
       <action type="fix" dev="HLS" fixes-bug="TAPESTRY-723">The "empty" 
property of StringTranslator is broken</action>
+      <action type="fix" dev="HLS" fixes-bug="TAPESTRY-526" due-to="Marcus 
Brito">Tapestry throws a NPE if you try to configure an asset without an 
extension</action>
     </release>
     <release version="4.0-beta-11" date="Oct 16 2005">
       <action type="fix" dev="HLS" 
fixes-bug="TAPESTRY-650">ClassNotFoundException thrown when deserializing an 
object from a client persistent property</action>



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to