GlueGen v2.6.0-rc-20250712
GlueGen, Native Binding Generator for Java™ (public API).
TestUri02Composing.java
Go to the documentation of this file.
1package com.jogamp.common.net;
2
3import java.io.IOException;
4import java.net.MalformedURLException;
5import java.net.URISyntaxException;
6import java.net.URL;
7
8import org.junit.Assert;
9import org.junit.BeforeClass;
10import org.junit.Test;
11
12import com.jogamp.junit.util.SingletonJunitCase;
13
14import org.junit.FixMethodOrder;
15import org.junit.runners.MethodSorters;
16
17@FixMethodOrder(MethodSorters.NAME_ASCENDING)
19
20 @BeforeClass
21 public static void assetRegistration() throws Exception {
22 try {
23 System.err.println("******* Asset URL Stream Handler Registration: PRE");
24 Assert.assertTrue("GenericURLStreamHandlerFactory.register() failed", AssetURLContext.registerHandler(TestAssetURLConnectionRegistered.class.getClassLoader()));
25 Assert.assertNotNull(AssetURLContext.getRegisteredHandler());
26 System.err.println("******* Asset URL Stream Handler Registration: POST");
27 } catch (final Exception e) {
28 setTestSupported(false);
29 throw e;
30 }
31 }
32
33 @Test
34 public void test01URLCompositioning() throws IOException, URISyntaxException {
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");
42
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"));
47
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"));
52 }
53
54 static void testURNCompositioning(final String urn) throws MalformedURLException, URISyntaxException {
55 testURICompositioning( Uri.cast(urn) );
56 testURLCompositioning( new URL(urn) );
57 }
58
59 static void testURICompositioning(final Uri uri) throws MalformedURLException, URISyntaxException {
60 testUriCompositioning(uri, uri);
61 }
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);
65
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);
71 }
72
73 static void testURLCompositioning(final URL url) throws MalformedURLException, URISyntaxException {
74 testURLCompositioning(url, url);
75 }
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);
80
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()));
90 }
91
92 public static void main(final String args[]) throws IOException {
93 final String tstname = TestUri02Composing.class.getName();
94 org.junit.runner.JUnitCore.main(tstname);
95 }
96}
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 main(final String args[])
This class implements an immutable Uri as defined by RFC 2396.
Definition: Uri.java:160
static Uri cast(final String encodedUri)
Casts the given encoded String to a new Encoded instance used to create the resulting Uri instance vi...
Definition: Uri.java:1068