Direct-BT v3.3.0-1-gc2d430c
Direct-BT - Direct Bluetooth Programming.
TestAssetURLConnectionRegistered.java
Go to the documentation of this file.
1package jau.test.net;
2
3import java.io.IOException;
4import java.net.URISyntaxException;
5import java.net.URL;
6import java.net.URLConnection;
7
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;
14import org.junit.Test;
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 assetRegisteredURLConnection_RT() throws IOException {
35 testAssetConnection(createAssetURLConnection(test_asset_rt_url), test_asset_rt_entry);
36 }
37
38 @Test
39 public void assetRegisteredURLConnection_Test() throws IOException {
40 testAssetConnection(createAssetURLConnection(test_asset_test1_url), test_asset_test1_entry);
41 }
42
43 @Test
44 public void assetRegisteredIOUtilGetResourceRel1_RT() throws IOException, URISyntaxException {
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);
49
50 final Uri uri1 = Uri.valueOf(urlConn0.getURL()).getRelativeOf(test_asset_test3_rel);
51 Assert.assertNotNull(uri1);
52 Assert.assertEquals(test_asset_test3a_url, uri1.toString());
53 testAssetConnection(uri1.toURL().openConnection(), test_asset_test3_entry);
54
55 final Uri uri2 = Uri.valueOf(urlConn0.getURL()).getRelativeOf(test_asset_test4_rel);
56 Assert.assertNotNull(uri2);
57 Assert.assertEquals(test_asset_test4a_url, uri2.toString());
58 testAssetConnection(uri2.toURL().openConnection(), test_asset_test4_entry);
59 }
60
61 @Test
62 public void assetRegisteredIOUtilGetResourceRel2_RT() throws IOException, URISyntaxException {
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);
67
68 final Uri uri1 = Uri.valueOf(urlConn0.getURL()).getRelativeOf(test_asset_test3_rel);
69 Assert.assertNotNull(uri1);
70 Assert.assertEquals(test_asset_test3b_url, uri1.toString());
71 testAssetConnection(uri1.toURL().openConnection(), test_asset_test3_entry);
72
73 final Uri uri2 = Uri.valueOf(urlConn0.getURL()).getRelativeOf(test_asset_test4_rel);
74 Assert.assertNotNull(uri2);
75 Assert.assertEquals(test_asset_test4b_url, uri2.toString());
76 testAssetConnection(uri2.toURL().openConnection(), test_asset_test4_entry);
77 }
78
79 URLConnection createAssetURLConnection(final String path) throws IOException {
80 final URL url = AssetURLContext.createURL(path);
81 final URLConnection c = url.openConnection();
82 System.err.println("createAssetURL: "+path+" -> url: "+url+" -> conn: "+c+" / connURL "+(null!=c?c.getURL():null));
83 return c;
84
85 }
86
87 public static void main(final String args[]) throws IOException {
88 final String tstname = TestAssetURLConnectionRegistered.class.getName();
89 org.junit.runner.JUnitCore.main(tstname);
90 }
91}