summaryrefslogtreecommitdiffstats
path: root/src/junit/com/jogamp/common/net/URLCompositionTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/junit/com/jogamp/common/net/URLCompositionTest.java')
-rw-r--r--src/junit/com/jogamp/common/net/URLCompositionTest.java134
1 files changed, 110 insertions, 24 deletions
diff --git a/src/junit/com/jogamp/common/net/URLCompositionTest.java b/src/junit/com/jogamp/common/net/URLCompositionTest.java
index 36b38ab..405e877 100644
--- a/src/junit/com/jogamp/common/net/URLCompositionTest.java
+++ b/src/junit/com/jogamp/common/net/URLCompositionTest.java
@@ -2,6 +2,8 @@ package com.jogamp.common.net;
import java.io.IOException;
import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URISyntaxException;
import java.net.URL;
import org.junit.Assert;
@@ -27,41 +29,125 @@ public class URLCompositionTest extends JunitTracer {
}
@Test
- public void showURLComponents() throws IOException {
- testURLCompositioning(new URL("file:///rootDir/file1.txt"));
- testURLCompositioning(new URL("file://host/rootDir/file1.txt"));
- testURLCompositioning(new URL("jar:file:/web1/file1.jar!/rootDir/file1.txt"));
- testURLCompositioning(new URL("asset:gluegen-test/info.txt"));
- testURLCompositioning(new URL("asset:/gluegen-test/info.txt"));
- testURLCompositioning(new URL("http://domain.com:1234/web1/index.html?lala=23&lili=24#anchor"));
+ public void showURLComponents0() throws IOException, URISyntaxException {
+ showURX("file:///rootDir/file1.txt");
+ showURX("file://host/rootDir/file1.txt");
+ showURX("jar:file:/web1/file1.jar!/rootDir/file1.txt");
+ showURX("asset:gluegen-test/info.txt");
+ showURX("asset:/gluegen-test/info.txt");
+ showURX("http://domain.com/web1/index.html?lala=23&lili=24#anchor");
+ showURX("http://domain.com:1234/web1/index.html?lala=23&lili=24#anchor");
+ showURX("asset:jar:file:/web1/file1.jar!/rootDir/file1.txt");
+ showURX("asset:jar:file:/web1/file1.jar!/rootDir/./file1.txt");
+ showURX("asset:jar:file:/web1/file1.jar!/rootDir/dummyParent/../file1.txt");
+ }
+
+ static void showURX(String urx) throws MalformedURLException, URISyntaxException {
+ System.err.println("XXXXXX "+urx);
+ showURL(new URL(urx));
+ showURI(new URI(urx));
+ System.err.println("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
+ }
+
+ static void showURL(URL url) {
+ System.err.println("YYYYYY URL "+url);
+ System.err.println("protocol: "+url.getProtocol());
+ System.err.println("auth: "+url.getAuthority());
+ System.err.println("host: "+url.getHost());
+ System.err.println("port: "+url.getPort() + " ( " + url.getDefaultPort() + " ) " );
+ System.err.println("file: "+url.getFile() + " ( path " + url.getPath() + ", query " + url.getQuery() + " ) " );
+ System.err.println("ref: "+url.getRef());
+ }
+ static void showURI(URI uri) {
+ System.err.println("ZZZZZZ URI "+uri);
+ // 1 [scheme:]scheme-specific-part[#fragment]
+ System.err.println("1 scheme: "+uri.getScheme());
+ System.err.println("1 scheme-part: "+uri.getRawSchemeSpecificPart());
+ System.err.println("1 fragment: "+uri.getRawFragment());
+
+ // 2 [scheme:][//authority][path][?query][#fragment]
+ System.err.println("2 scheme: "+uri.getScheme());
+ System.err.println("2 auth: "+uri.getRawAuthority());
+ System.err.println("2 path: "+uri.getRawPath());
+ System.err.println("2 query: "+uri.getRawQuery());
+ System.err.println("2 fragment: "+uri.getRawFragment());
+
+ // 3 [scheme:][//authority][path][?query][#fragment]
+ // authority: [user-info@]host[:port]
+ System.err.println("3 scheme: "+uri.getScheme());
+ System.err.println("3 user-info: "+uri.getRawUserInfo());
+ System.err.println("3 host: "+uri.getHost());
+ System.err.println("3 port: "+uri.getPort());
+ System.err.println("3 path: "+uri.getRawPath());
+ System.err.println("3 query: "+uri.getRawQuery());
+ System.err.println("3 fragment: "+uri.getRawFragment());
+ }
+
+ @Test
+ public void showURLComponents1() throws IOException, URISyntaxException {
+ testURNCompositioning("file:///rootDir/file1.txt");
+ testURNCompositioning("file://host/rootDir/file1.txt");
+ testURNCompositioning("jar:file:/web1/file1.jar!/rootDir/file1.txt");
+ testURNCompositioning("asset:gluegen-test/info.txt");
+ testURNCompositioning("asset:/gluegen-test/info.txt");
+ testURNCompositioning("http://domain.com/web1/index.html?lala=23&lili=24#anchor");
+ testURNCompositioning("http://domain.com:1234/web1/index.html?lala=23&lili=24#anchor");
+
+ final URI file1URI = new URI("asset:jar:file:/web1/file1.jar!/rootDir/file1.txt");
+ testURICompositioning(file1URI);
+ testURICompositioning(file1URI, new URI("asset:jar:file:/web1/file1.jar!/rootDir/./file1.txt"));
+ testURICompositioning(file1URI, new URI("asset:jar:file:/web1/file1.jar!/rootDir/dummyParent/../file1.txt"));
final URL file1URL = new URL("asset:jar:file:/web1/file1.jar!/rootDir/file1.txt");
testURLCompositioning(file1URL);
testURLCompositioning(file1URL, new URL("asset:jar:file:/web1/file1.jar!/rootDir/./file1.txt"));
testURLCompositioning(file1URL, new URL("asset:jar:file:/web1/file1.jar!/rootDir/dummyParent/../file1.txt"));
}
-
- static void testURLCompositioning(URL u) throws MalformedURLException {
- testURLCompositioning(u, u);
+
+ static void testURNCompositioning(String urn) throws MalformedURLException, URISyntaxException {
+ testURICompositioning( new URI(urn) );
+ testURLCompositioning( new URL(urn) );
}
- static void testURLCompositioning(URL refURL, URL u) throws MalformedURLException {
- final String scheme = u.getProtocol();
- final String auth = u.getAuthority();
- String path = u.getPath();
- String query = u.getQuery();
- String fragment = u.getRef();
+ static void testURICompositioning(URI uri) throws MalformedURLException, URISyntaxException {
+ testURICompositioning(uri, uri);
+ }
+ static void testURICompositioning(URI refURI, URI uri1) throws MalformedURLException, URISyntaxException {
+ final String scheme = uri1.getScheme();
+ final String ssp = uri1.getRawSchemeSpecificPart();
+ final String fragment = uri1.getRawFragment();
- System.err.println("scheme <"+scheme+">, auth <"+auth+">, path <"+path+">, query <"+query+">, fragment <"+fragment+">");
- URL u2 = IOUtil.compose(scheme, auth, path, null, query, fragment);
+ System.err.println("scheme <"+scheme+">, ssp <"+ssp+">, fragment <"+fragment+">");
+ final URI uri2 = IOUtil.compose(scheme, ssp, null, fragment);
+
+ System.err.println("URL-equals: "+refURI.equals(uri2));
+ System.err.println("URL-ref : <"+refURI+">");
+ System.err.println("URL-orig : <"+uri1+">");
+ System.err.println("URL-comp : <"+uri2+">");
+ Assert.assertEquals(refURI, uri2);
+ }
+
+ static void testURLCompositioning(URL url) throws MalformedURLException, URISyntaxException {
+ testURLCompositioning(url, url);
+ }
+ static void testURLCompositioning(URL refURL, URL url1) throws MalformedURLException, URISyntaxException {
+ final URI uri1 = url1.toURI();
+ final String scheme = uri1.getScheme();
+ final String ssp = uri1.getRawSchemeSpecificPart();
+ final String fragment = uri1.getRawFragment();
- System.err.println("URL-equals: "+refURL.equals(u2));
- System.err.println("URL-same : "+refURL.sameFile(u2));
+ System.err.println("scheme <"+scheme+">, ssp <"+ssp+">, fragment <"+fragment+">");
+ final URI uri2 = IOUtil.compose(scheme, ssp, null, fragment);
+
+ System.err.println("URL-equals(1): "+refURL.toURI().equals(uri2));
+ System.err.println("URL-equals(2): "+refURL.equals(uri2.toURL()));
+ System.err.println("URL-same : "+refURL.sameFile(uri2.toURL()));
System.err.println("URL-ref : <"+refURL+">");
- System.err.println("URL-orig : <"+u+">");
- System.err.println("URL-comp : <"+u2+">");
- Assert.assertEquals(refURL, u2);
- Assert.assertTrue(refURL.sameFile(u2));
+ System.err.println("URL-orig : <"+url1+">");
+ System.err.println("URL-comp : <"+uri2+">");
+ Assert.assertEquals(refURL.toURI(), uri2);
+ Assert.assertEquals(refURL, uri2.toURL());
+ Assert.assertTrue(refURL.sameFile(uri2.toURL()));
}
public static void main(String args[]) throws IOException {