3import java.io.IOException;
4import java.net.MalformedURLException;
5import java.net.URISyntaxException;
8import org.jau.net.AssetURLContext;
10import org.junit.Assert;
11import org.junit.BeforeClass;
12import org.junit.FixMethodOrder;
14import org.junit.runners.MethodSorters;
16import jau.test.junit.util.JunitTracer;
18@FixMethodOrder(MethodSorters.NAME_ASCENDING)
24 System.err.println(
"******* Asset URL Stream Handler Registration: PRE");
25 Assert.assertTrue(
"GenericURLStreamHandlerFactory.register() failed", AssetURLContext.registerHandler(
TestAssetURLConnectionRegistered.class.getClassLoader()));
26 Assert.assertNotNull(AssetURLContext.getRegisteredHandler());
27 System.err.println(
"******* Asset URL Stream Handler Registration: POST");
28 }
catch (
final Exception e) {
29 setTestSupported(
false);
36 testURNCompositioning(
"file:///rootDir/file1.txt");
37 testURNCompositioning(
"file://host/rootDir/file1.txt");
38 testURNCompositioning(
"jar:file:/web1/file1.jar!/rootDir/file1.txt");
39 testURNCompositioning(
"asset:gluegen-test/info.txt");
40 testURNCompositioning(
"asset:/gluegen-test/info.txt");
41 testURNCompositioning(
"http://domain.com/web1/index.html?lala=23&lili=24#anchor");
42 testURNCompositioning(
"http://domain.com:1234/web1/index.html?lala=23&lili=24#anchor");
44 final Uri file1URI = Uri.cast(
"asset:jar:file:/web1/file1.jar!/rootDir/file1.txt");
45 testURICompositioning(file1URI);
46 testUriCompositioning(file1URI, Uri.cast(
"asset:jar:file:/web1/file1.jar!/rootDir/./file1.txt"));
47 testUriCompositioning(file1URI, Uri.cast(
"asset:jar:file:/web1/file1.jar!/rootDir/dummyParent/../file1.txt"));
49 final URL file1URL =
new URL(
"asset:jar:file:/web1/file1.jar!/rootDir/file1.txt");
50 testURLCompositioning(file1URL);
51 testURLCompositioning(file1URL,
new URL(
"asset:jar:file:/web1/file1.jar!/rootDir/./file1.txt"));
52 testURLCompositioning(file1URL,
new URL(
"asset:jar:file:/web1/file1.jar!/rootDir/dummyParent/../file1.txt"));
55 static void testURNCompositioning(
final String urn)
throws MalformedURLException, URISyntaxException {
56 testURICompositioning( Uri.cast(urn) );
57 testURLCompositioning(
new URL(urn) );
60 static void testURICompositioning(
final Uri uri)
throws MalformedURLException, URISyntaxException {
61 testUriCompositioning(uri, uri);
63 static void testUriCompositioning(
final Uri refURI,
final Uri uri1)
throws MalformedURLException, URISyntaxException {
64 System.err.println(
"scheme <"+uri1.scheme+
">, ssp <"+uri1.schemeSpecificPart+
">, fragment <"+uri1.fragment+
">");
65 final Uri uri2 = uri1.getRelativeOf(
null);
67 System.err.println(
"URL-equals: "+refURI.equals(uri2));
68 System.err.println(
"URL-ref : <"+refURI+
">");
69 System.err.println(
"URL-orig : <"+uri1+
">");
70 System.err.println(
"URL-comp : <"+uri2+
">");
71 Assert.assertEquals(refURI, uri2);
74 static void testURLCompositioning(
final URL url)
throws MalformedURLException, URISyntaxException {
75 testURLCompositioning(url, url);
77 static void testURLCompositioning(
final URL refURL,
final URL url1)
throws MalformedURLException, URISyntaxException {
78 final Uri uri1 = Uri.valueOf(url1);
79 System.err.println(
"scheme <"+uri1.scheme+
">, ssp <"+uri1.schemeSpecificPart+
">, fragment <"+uri1.fragment+
">");
80 final Uri uri2 = uri1.getRelativeOf(
null);
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);
static void assetRegistration()
void test01URLCompositioning()
static void main(final String args[])