Revision: 20001
          http://sourceforge.net/p/gate/code/20001
Author:   markagreenwood
Date:     2017-01-27 09:25:49 +0000 (Fri, 27 Jan 2017)
Log Message:
-----------
test creation from absolute uri with null context

Modified Paths:
--------------
    
gate/branches/sawdust2/gate-core/src/main/java/gate/creole/ResourceReference.java
    
gate/branches/sawdust2/gate-core/src/test/java/gate/creole/TestResourceReference.java

Modified: 
gate/branches/sawdust2/gate-core/src/main/java/gate/creole/ResourceReference.java
===================================================================
--- 
gate/branches/sawdust2/gate-core/src/main/java/gate/creole/ResourceReference.java
   2017-01-27 02:24:36 UTC (rev 20000)
+++ 
gate/branches/sawdust2/gate-core/src/main/java/gate/creole/ResourceReference.java
   2017-01-27 09:25:49 UTC (rev 20001)
@@ -38,21 +38,57 @@
 
   public ResourceReference(Plugin plugin, String path)
       throws URISyntaxException {
-    this(plugin.getBaseURI(), path);
+    if (plugin != null) {
+      uri = plugin.getBaseURI().resolve(path);
+    }
+    else {
+      uri = new URI(path);
+    }
+    
+    if(!uri.isAbsolute())
+      throw new URISyntaxException(path,
+          "Context is null and path is not absolute");
   }
 
   public ResourceReference(URL context, String path)
       throws URISyntaxException, MalformedURLException {
-    uri = (new URL(context, path)).toURI();
+    
+    if(context != null) {
+      uri = (new URL(context, path)).toURI();
+    } else {
+      uri = new URI(path);
+    }
+    
+    if(!uri.isAbsolute())
+      throw new URISyntaxException(path,
+          "Context is null and path is not absolute");
   }
 
-  public ResourceReference(URI context, String path) {
-    uri = context.resolve(path);
+  public ResourceReference(URI context, String path) throws URISyntaxException 
{    
+    if (context != null) {
+      uri = context.resolve(path);
+    }
+    else {
+      uri = new URI(path);
+    }
+    
+    if(!uri.isAbsolute())
+      throw new URISyntaxException(path,
+          "Context is null and path is not absolute");
   }
 
   public ResourceReference(ResourceReference context, String path)
       throws IOException, URISyntaxException {
-    this(context.uri, path);
+    if (context != null) {
+      uri = context.uri.resolve(path);
+    }
+    else {
+      uri = new URI(path);
+    }
+    
+    if(!uri.isAbsolute())
+      throw new URISyntaxException(path,
+          "Context is null and path is not absolute");
   }
 
   public InputStream openStream() throws IOException {
@@ -91,4 +127,12 @@
   public URI toURI() throws URISyntaxException {
     return uri;
   }
+
+  public String toString() {
+    return uri.toString();
+  }
+
+  public String toExternalForm() {
+    return toString();
+  }
 }

Modified: 
gate/branches/sawdust2/gate-core/src/test/java/gate/creole/TestResourceReference.java
===================================================================
--- 
gate/branches/sawdust2/gate-core/src/test/java/gate/creole/TestResourceReference.java
       2017-01-27 02:24:36 UTC (rev 20000)
+++ 
gate/branches/sawdust2/gate-core/src/test/java/gate/creole/TestResourceReference.java
       2017-01-27 09:25:49 UTC (rev 20001)
@@ -111,4 +111,22 @@
                assertEquals("References do not match (4)", creoleURI, 
rr.toURI());
                assertEquals("URLs do not match (4)", creoleURL, rr.toURL());
        }
+       
+       public void testCreateFromString() throws Exception {
+         String path = "creole://group;artifact;version/creole.xml";
+         
+         ResourceReference rr = new ResourceReference((ResourceReference)null, 
path);
+         assertEquals("String representations don't match (1)",path, 
rr.toString());
+         
+         rr = new ResourceReference((URL)null, path);
+    assertEquals("String representations don't match (2)",path, rr.toString());
+    
+    rr = new ResourceReference((URI)null, path);
+    assertEquals("String representations don't match (3)",path, rr.toString());
+    
+    rr = new ResourceReference((Plugin)null, path);
+    assertEquals("String representations don't match (4)",path, rr.toString());
+    
+    
+       }
 }

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
GATE-cvs mailing list
GATE-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gate-cvs

Reply via email to