1package com.jogamp.common.net;
3import java.io.IOException;
4import java.net.MalformedURLException;
5import java.net.URISyntaxException;
8import org.junit.Assert;
9import org.junit.BeforeClass;
12import com.jogamp.junit.util.SingletonJunitCase;
14import org.junit.FixMethodOrder;
15import org.junit.runners.MethodSorters;
17@FixMethodOrder(MethodSorters.NAME_ASCENDING)
23 System.err.println(
"******* Asset URL Stream Handler Registration: PRE");
26 System.err.println(
"******* Asset URL Stream Handler Registration: POST");
27 }
catch (
final Exception e) {
28 setTestSupported(
false);
35 testURNCompositioning(
"file:///rootDir/file1.txt");
36 testURNCompositioning(
"file://host/rootDir/file1.txt");
37 testURNCompositioning(
"jar:file:/web1/file1.jar!/rootDir/file1.txt");
38 testURNCompositioning(
"asset:gluegen-test/info.txt");
39 testURNCompositioning(
"asset:/gluegen-test/info.txt");
40 testURNCompositioning(
"http://domain.com/web1/index.html?lala=23&lili=24#anchor");
41 testURNCompositioning(
"http://domain.com:1234/web1/index.html?lala=23&lili=24#anchor");
43 final Uri file1URI =
Uri.
cast(
"asset:jar:file:/web1/file1.jar!/rootDir/file1.txt");
44 testURICompositioning(file1URI);
45 testUriCompositioning(file1URI,
Uri.
cast(
"asset:jar:file:/web1/file1.jar!/rootDir/./file1.txt"));
46 testUriCompositioning(file1URI,
Uri.
cast(
"asset:jar:file:/web1/file1.jar!/rootDir/dummyParent/../file1.txt"));
48 final URL file1URL =
new URL(
"asset:jar:file:/web1/file1.jar!/rootDir/file1.txt");
49 testURLCompositioning(file1URL);
50 testURLCompositioning(file1URL,
new URL(
"asset:jar:file:/web1/file1.jar!/rootDir/./file1.txt"));
51 testURLCompositioning(file1URL,
new URL(
"asset:jar:file:/web1/file1.jar!/rootDir/dummyParent/../file1.txt"));
54 static void testURNCompositioning(
final String urn)
throws MalformedURLException, URISyntaxException {
55 testURICompositioning(
Uri.
cast(urn) );
56 testURLCompositioning(
new URL(urn) );
59 static void testURICompositioning(
final Uri uri)
throws MalformedURLException, URISyntaxException {
60 testUriCompositioning(uri, uri);
62 static void testUriCompositioning(
final Uri refURI,
final Uri uri1)
throws MalformedURLException, URISyntaxException {
63 System.err.println(
"scheme <"+uri1.scheme+
">, ssp <"+uri1.schemeSpecificPart+
">, fragment <"+uri1.fragment+
">");
64 final Uri uri2 = uri1.getRelativeOf(
null);
66 System.err.println(
"URL-equals: "+refURI.equals(uri2));
67 System.err.println(
"URL-ref : <"+refURI+
">");
68 System.err.println(
"URL-orig : <"+uri1+
">");
69 System.err.println(
"URL-comp : <"+uri2+
">");
70 Assert.assertEquals(refURI, uri2);
73 static void testURLCompositioning(
final URL url)
throws MalformedURLException, URISyntaxException {
74 testURLCompositioning(url, url);
76 static void testURLCompositioning(
final URL refURL,
final URL url1)
throws MalformedURLException, URISyntaxException {
77 final Uri uri1 = Uri.valueOf(url1);
78 System.err.println(
"scheme <"+uri1.scheme+
">, ssp <"+uri1.schemeSpecificPart+
">, fragment <"+uri1.fragment+
">");
79 final Uri uri2 = uri1.getRelativeOf(
null);
81 System.err.println(
"URL-equals(1): "+refURL.toURI().equals(uri2));
82 System.err.println(
"URL-equals(2): "+refURL.equals(uri2.toURL()));
83 System.err.println(
"URL-same : "+refURL.sameFile(uri2.toURL()));
84 System.err.println(
"URL-ref : <"+refURL+
">");
85 System.err.println(
"URL-orig : <"+url1+
">");
86 System.err.println(
"URL-comp : <"+uri2+
">");
87 Assert.assertEquals(Uri.valueOf(refURL), uri2);
88 Assert.assertEquals(refURL, uri2.toURL());
89 Assert.assertTrue(refURL.sameFile(uri2.toURL()));
92 public static void main(
final String args[])
throws IOException {
94 org.junit.runner.JUnitCore.
main(tstname);
See PiggybackURLConnection for description and examples.
static boolean registerHandler(final ClassLoader cl)
Registers the generic URLStreamHandlerFactory via GenericURLStreamHandlerFactory#register() and if su...
static URLStreamHandler getRegisteredHandler()
Returns the asset handler previously set via registerHandler(ClassLoader), or null if none was set.
static void assetRegistration()
void test01URLCompositioning()
static void main(final String args[])
This class implements an immutable Uri as defined by RFC 2396.
static Uri cast(final String encodedUri)
Casts the given encoded String to a new Encoded instance used to create the resulting Uri instance vi...