Author: mck
Date: Tue Jun 19 23:17:06 2012
New Revision: 1351903

URL: http://svn.apache.org/viewvc?rev=1351903&view=rev
Log:
TREQ-15 - URLApplicationResource(String path, Locale locale, URL url) shouldn't 
transform the URL of the resource when it can't parse it 

Added:
    
tiles/request/trunk/tiles-request-api/src/test/java/org/apache/tiles/request/locale/URLApplicationResourceTest.java
      - copied, changed from r1334692, 
tiles/request/trunk/tiles-request-api/src/test/java/org/apache/tiles/request/locale/PostfixedApplicationResourceTest.java
Modified:
    
tiles/request/trunk/tiles-request-api/src/main/java/org/apache/tiles/request/locale/URLApplicationResource.java

Modified: 
tiles/request/trunk/tiles-request-api/src/main/java/org/apache/tiles/request/locale/URLApplicationResource.java
URL: 
http://svn.apache.org/viewvc/tiles/request/trunk/tiles-request-api/src/main/java/org/apache/tiles/request/locale/URLApplicationResource.java?rev=1351903&r1=1351902&r2=1351903&view=diff
==============================================================================
--- 
tiles/request/trunk/tiles-request-api/src/main/java/org/apache/tiles/request/locale/URLApplicationResource.java
 (original)
+++ 
tiles/request/trunk/tiles-request-api/src/main/java/org/apache/tiles/request/locale/URLApplicationResource.java
 Tue Jun 19 23:17:06 2012
@@ -46,7 +46,7 @@ public class URLApplicationResource exte
 
     /**
      * Creates a URLApplicationResource for the specified path that can be 
accessed through the specified URL.
-     * 
+     *
      * @param localePath the path including localization.
      * @param url the URL where the contents can be found.
      */
@@ -60,16 +60,16 @@ public class URLApplicationResource exte
 
     /**
      * Creates a URLApplicationResource for the specified path that can be 
accessed through the specified URL.
-     * 
+     *
      * @param path the path excluding localization.
      * @param locale the Locale.
      * @param url the URL where the contents can be found.
      */
     public URLApplicationResource(String path, Locale locale, URL url) throws 
MalformedURLException {
         super(path, locale);
-        this.url = new URL(url, getLocalePath());
+        this.url = url;
         if ("file".equals(url.getProtocol())) {
-            file = new File(this.url.getPath());
+            file = new File(url.getPath());
         }
     }
 
@@ -104,4 +104,12 @@ public class URLApplicationResource exte
     public String toString() {
         return "Resource " + getLocalePath() + " at " + url.toString();
     }
+
+    protected URL getURL(){
+        return url;
+    }
+
+    protected File getFile(){
+        return file;
+    }
 }

Copied: 
tiles/request/trunk/tiles-request-api/src/test/java/org/apache/tiles/request/locale/URLApplicationResourceTest.java
 (from r1334692, 
tiles/request/trunk/tiles-request-api/src/test/java/org/apache/tiles/request/locale/PostfixedApplicationResourceTest.java)
URL: 
http://svn.apache.org/viewvc/tiles/request/trunk/tiles-request-api/src/test/java/org/apache/tiles/request/locale/URLApplicationResourceTest.java?p2=tiles/request/trunk/tiles-request-api/src/test/java/org/apache/tiles/request/locale/URLApplicationResourceTest.java&p1=tiles/request/trunk/tiles-request-api/src/test/java/org/apache/tiles/request/locale/PostfixedApplicationResourceTest.java&r1=1334692&r2=1351903&rev=1351903&view=diff
==============================================================================
--- 
tiles/request/trunk/tiles-request-api/src/test/java/org/apache/tiles/request/locale/PostfixedApplicationResourceTest.java
 (original)
+++ 
tiles/request/trunk/tiles-request-api/src/test/java/org/apache/tiles/request/locale/URLApplicationResourceTest.java
 Tue Jun 19 23:17:06 2012
@@ -20,92 +20,110 @@
  */
 
 package org.apache.tiles.request.locale;
+import java.io.File;
 import static org.junit.Assert.assertEquals;
 
-import java.io.IOException;
-import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
 import java.util.Locale;
 
 import org.junit.Test;
 
 /**
- * Tests PostfixedApplicationResource.
+ * Tests URLApplicationResource.
  *
  * @version $Rev$ $Date$
  */
-public class PostfixedApplicationResourceTest {
+public class URLApplicationResourceTest {
 
-    private class TestApplicationResource extends PostfixedApplicationResource 
{
-        public TestApplicationResource(String path, Locale locale) {
-            super(path, locale);
+    private class TestApplicationResource extends URLApplicationResource {
+        public TestApplicationResource(String localePath, URL url) {
+            super(localePath, url);
         }
 
-        public TestApplicationResource(String localePath) {
-            super(localePath);
+        public TestApplicationResource(String path, Locale locale, URL url) 
throws MalformedURLException {
+            super(path, locale, url);
         }
 
         @Override
-        public InputStream getInputStream() throws IOException {
-            return null;
+        protected URL getURL(){
+            return super.getURL();
         }
 
         @Override
-        public long getLastModified() throws IOException {
-            return 0;
+        protected File getFile(){
+            return super.getFile();
         }
-        
     };
-    
+
     /**
      * Test getLocalePath(String path, Locale locale).
      */
     @Test
-    public void testGetLocalePath() {
-        TestApplicationResource resource = new 
TestApplicationResource("/my/path_fr.html");
+    public void testGetLocalePath() throws MalformedURLException {
+        TestApplicationResource resource = new 
TestApplicationResource("/my/path_fr.html", new URL("file:///"));
         assertEquals("/my/path.html", resource.getLocalePath(null));
         assertEquals("/my/path.html", resource.getLocalePath(Locale.ROOT));
         assertEquals("/my/path_it.html", 
resource.getLocalePath(Locale.ITALIAN));
         assertEquals("/my/path_it_IT.html", 
resource.getLocalePath(Locale.ITALY));
         assertEquals("/my/path_en_GB_scotland.html", 
resource.getLocalePath(new Locale("en", "GB", "scotland")));
+        assertEquals("file:/", resource.getURL().toString());
+        assertEquals("/", resource.getFile().toString());
     }
-    
+
     @Test
-    public void testBuildFromString() {
-        TestApplicationResource resource = new 
TestApplicationResource("/my/path_en_GB_scotland.html");
+    public void testBuildFromString() throws MalformedURLException {
+        TestApplicationResource resource = new 
TestApplicationResource("/my/path_en_GB_scotland.html", new URL("file:///"));
         assertEquals("/my/path_en_GB_scotland.html", resource.getLocalePath());
         assertEquals("/my/path.html", resource.getPath());
+        assertEquals("file:/", resource.getURL().toString());
+        assertEquals("/", resource.getFile().toString());
         assertEquals(new Locale("en", "GB", "scotland"), resource.getLocale());
-        resource = new TestApplicationResource("/my/path_it_IT.html");
+        resource = new TestApplicationResource("/my/path_it_IT.html", new 
URL("file:///"));
         assertEquals("/my/path_it_IT.html", resource.getLocalePath());
         assertEquals("/my/path.html", resource.getPath());
+        assertEquals("file:/", resource.getURL().toString());
+        assertEquals("/", resource.getFile().toString());
         assertEquals(Locale.ITALY, resource.getLocale());
-        resource = new TestApplicationResource("/my/path_it.html");
+        resource = new TestApplicationResource("/my/path_it.html", new 
URL("file:///"));
         assertEquals("/my/path_it.html", resource.getLocalePath());
         assertEquals("/my/path.html", resource.getPath());
+        assertEquals("file:/", resource.getURL().toString());
+        assertEquals("/", resource.getFile().toString());
         assertEquals(Locale.ITALIAN, resource.getLocale());
-        resource = new TestApplicationResource("/my/path.html");
+        resource = new TestApplicationResource("/my/path.html", new 
URL("file:///"));
         assertEquals("/my/path.html", resource.getLocalePath());
         assertEquals("/my/path.html", resource.getPath());
+        assertEquals("file:/", resource.getURL().toString());
+        assertEquals("/", resource.getFile().toString());
         assertEquals(Locale.ROOT, resource.getLocale());
     }
-    
+
     @Test
-    public void testBuildFromStringAndLocale() {
-        TestApplicationResource resource = new 
TestApplicationResource("/my/path.html", new Locale("en", "GB", "scotland"));
+    public void testBuildFromStringAndLocale() throws MalformedURLException {
+        TestApplicationResource resource = new 
TestApplicationResource("/my/path.html", new Locale("en", "GB", "scotland"), 
new URL("file:///"));
         assertEquals("/my/path_en_GB_scotland.html", resource.getLocalePath());
         assertEquals("/my/path.html", resource.getPath());
         assertEquals(new Locale("en", "GB", "scotland"), resource.getLocale());
-        resource = new TestApplicationResource("/my/path.html", Locale.ITALY);
+        assertEquals("file:/", resource.getURL().toString());
+        assertEquals("/", resource.getFile().toString());
+        resource = new TestApplicationResource("/my/path.html", Locale.ITALY, 
new URL("file:///"));
         assertEquals("/my/path_it_IT.html", resource.getLocalePath());
         assertEquals("/my/path.html", resource.getPath());
         assertEquals(Locale.ITALY, resource.getLocale());
-        resource = new TestApplicationResource("/my/path.html", 
Locale.ITALIAN);
+        assertEquals("file:/", resource.getURL().toString());
+        assertEquals("/", resource.getFile().toString());
+        resource = new TestApplicationResource("/my/path.html", 
Locale.ITALIAN, new URL("file:///"));
         assertEquals("/my/path_it.html", resource.getLocalePath());
         assertEquals("/my/path.html", resource.getPath());
         assertEquals(Locale.ITALIAN, resource.getLocale());
-        resource = new TestApplicationResource("/my/path.html", Locale.ROOT);
+        assertEquals("file:/", resource.getURL().toString());
+        assertEquals("/", resource.getFile().toString());
+        resource = new TestApplicationResource("/my/path.html", Locale.ROOT, 
new URL("file:///"));
         assertEquals("/my/path.html", resource.getLocalePath());
         assertEquals("/my/path.html", resource.getPath());
         assertEquals(Locale.ROOT, resource.getLocale());
+        assertEquals("file:/", resource.getURL().toString());
+        assertEquals("/", resource.getFile().toString());
     }
 }


Reply via email to