3import java.io.IOException;
4import java.net.URISyntaxException;
6import java.net.URLConnection;
8import org.jau.io.IOUtil;
9import org.jau.net.AssetURLContext;
10import org.jau.net.Uri;
11import org.junit.Assert;
12import org.junit.BeforeClass;
13import 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 testAssetConnection(createAssetURLConnection(test_asset_rt_url), test_asset_rt_entry);
40 testAssetConnection(createAssetURLConnection(test_asset_test1_url), test_asset_test1_entry);
45 final URLConnection urlConn0 =
IOUtil.
getResource(test_asset_test2a_url, this.getClass().getClassLoader());
46 Assert.assertNotNull(urlConn0);
47 Assert.assertEquals(test_asset_test2a_url, urlConn0.getURL().toExternalForm());
48 testAssetConnection(urlConn0, test_asset_test2_entry);
51 Assert.assertNotNull(uri1);
52 Assert.assertEquals(test_asset_test3a_url, uri1.
toString());
53 testAssetConnection(uri1.
toURL().openConnection(), test_asset_test3_entry);
56 Assert.assertNotNull(uri2);
57 Assert.assertEquals(test_asset_test4a_url, uri2.
toString());
58 testAssetConnection(uri2.
toURL().openConnection(), test_asset_test4_entry);
63 final URLConnection urlConn0 =
IOUtil.
getResource(test_asset_test2b_url, this.getClass().getClassLoader());
64 Assert.assertNotNull(urlConn0);
65 Assert.assertEquals(test_asset_test2b_url, urlConn0.getURL().toExternalForm());
66 testAssetConnection(urlConn0, test_asset_test2_entry);
69 Assert.assertNotNull(uri1);
70 Assert.assertEquals(test_asset_test3b_url, uri1.
toString());
71 testAssetConnection(uri1.
toURL().openConnection(), test_asset_test3_entry);
74 Assert.assertNotNull(uri2);
75 Assert.assertEquals(test_asset_test4b_url, uri2.
toString());
76 testAssetConnection(uri2.
toURL().openConnection(), test_asset_test4_entry);
79 URLConnection createAssetURLConnection(
final String path)
throws IOException {
81 final URLConnection c = url.openConnection();
82 System.err.println(
"createAssetURL: "+path+
" -> url: "+url+
" -> conn: "+c+
" / connURL "+(
null!=c?c.getURL():
null));
87 public static void main(
final String args[])
throws IOException {
89 org.junit.runner.JUnitCore.
main(tstname);
void assetRegisteredURLConnection_RT()
void assetRegisteredIOUtilGetResourceRel2_RT()
static void main(final String args[])
void assetRegisteredURLConnection_Test()
void assetRegisteredIOUtilGetResourceRel1_RT()
static void assetRegistration()
static URLConnection getResource(final String resourcePath, final ClassLoader classLoader, final Class<?> relContext)
Locating a resource using getResource(String, ClassLoader):
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 URL createURL(final String path, final ClassLoader cl)
Create an asset URL, suitable even w/o the registered asset URLStreamHandler.
This class implements an immutable Uri as defined by RFC 2396.
final String toString()
Returns the encoded input as String, never null, same as getEncoded().
final java.net.URL toURL()
Returns a new URL instance using the encoded input string, new URL(uri.input), i.e.
static Uri valueOf(final File file)
Creates a new Uri instance using the given File instance.
Uri getRelativeOf(final Encoded appendPath)
Returns a new Uri appending the given appendPath to this instance's directory.