From 5205e47e8a2e84e793b26305391b1c4f8648597c Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Sun, 7 Sep 2014 10:20:12 +0200 Subject: Bug 1063 - Utilize own Uri and Uri.Encoded class w/ proper encoding and differentiating encoded/decoded variants by type [Part 1] - Add immutable com.jogamp.common.net.Uri class impl. RFC 2396 w/ encoding of RFC 3986 - Class Uri.Encoded is used to represent encoded parts - IOUtil: Remove unused methods (residing in Uri) and mark others deprecated (will move to Uri) - Adopt usage of Uri: This must be completet in follow-up commits! --- .../com/jogamp/common/net/TestUri02Composing.java | 96 ++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 src/junit/com/jogamp/common/net/TestUri02Composing.java (limited to 'src/junit/com/jogamp/common/net/TestUri02Composing.java') diff --git a/src/junit/com/jogamp/common/net/TestUri02Composing.java b/src/junit/com/jogamp/common/net/TestUri02Composing.java new file mode 100644 index 0000000..33d17b8 --- /dev/null +++ b/src/junit/com/jogamp/common/net/TestUri02Composing.java @@ -0,0 +1,96 @@ +package com.jogamp.common.net; + +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URISyntaxException; +import java.net.URL; + +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + +import com.jogamp.junit.util.JunitTracer; + +import org.junit.FixMethodOrder; +import org.junit.runners.MethodSorters; + +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class TestUri02Composing extends JunitTracer { + + @BeforeClass + public static void assetRegistration() throws Exception { + try { + System.err.println("******* Asset URL Stream Handler Registration: PRE"); + Assert.assertTrue("GenericURLStreamHandlerFactory.register() failed", AssetURLContext.registerHandler(AssetURLConnectionRegisteredTest.class.getClassLoader())); + Assert.assertNotNull(AssetURLContext.getRegisteredHandler()); + System.err.println("******* Asset URL Stream Handler Registration: POST"); + } catch (final Exception e) { + setTestSupported(false); + throw e; + } + } + + @Test + public void test01URLCompositioning() 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 = Uri.cast("asset:jar:file:/web1/file1.jar!/rootDir/file1.txt"); + testURICompositioning(file1URI); + testUriCompositioning(file1URI, Uri.cast("asset:jar:file:/web1/file1.jar!/rootDir/./file1.txt")); + testUriCompositioning(file1URI, Uri.cast("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 testURNCompositioning(final String urn) throws MalformedURLException, URISyntaxException { + testURICompositioning( Uri.cast(urn) ); + testURLCompositioning( new URL(urn) ); + } + + static void testURICompositioning(final Uri uri) throws MalformedURLException, URISyntaxException { + testUriCompositioning(uri, uri); + } + static void testUriCompositioning(final Uri refURI, final Uri uri1) throws MalformedURLException, URISyntaxException { + System.err.println("scheme <"+uri1.scheme+">, ssp <"+uri1.schemeSpecificPart+">, fragment <"+uri1.fragment+">"); + final Uri uri2 = Uri.compose(uri1.scheme, uri1.schemeSpecificPart, null, uri1.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(final URL url) throws MalformedURLException, URISyntaxException { + testURLCompositioning(url, url); + } + static void testURLCompositioning(final URL refURL, final URL url1) throws MalformedURLException, URISyntaxException { + final Uri uri1 = Uri.valueOf(url1); + System.err.println("scheme <"+uri1.scheme+">, ssp <"+uri1.schemeSpecificPart+">, fragment <"+uri1.fragment+">"); + final Uri uri2 = Uri.compose(uri1.scheme, uri1.schemeSpecificPart, null, uri1.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 : <"+url1+">"); + System.err.println("URL-comp : <"+uri2+">"); + Assert.assertEquals(Uri.valueOf(refURL), uri2); + Assert.assertEquals(refURL, uri2.toURL()); + Assert.assertTrue(refURL.sameFile(uri2.toURL())); + } + + public static void main(final String args[]) throws IOException { + final String tstname = TestUri02Composing.class.getName(); + org.junit.runner.JUnitCore.main(tstname); + } +} -- cgit v1.2.3