1   package org.codehaus.classworlds.uberjar.protocol.jar;
2   
3   import junit.framework.TestCase;
4   
5   import java.net.URL;
6   
7   public class HandlerTest
8       extends TestCase
9   {
10  
11      public void setUp()
12      {
13          System.setProperty( "java.protocol.handler.pkgs",
14                              "org.codehaus.classworlds.uberjar.protocol" );
15      }
16  
17      public void testSimpleImplicit()
18          throws Exception
19      {
20          URL url = new URL( "jar:/foo.jar" );
21  
22          assertEquals( "jar:/foo.jar",
23                        url.toExternalForm() );
24      }
25  
26      public void testRelativeFile()
27          throws Exception
28      {
29          URL url = buildUrl( "jar:/path/to/foo.jar",
30                              "bar.jar" );
31  
32          assertEquals( "jar:/path/to/bar.jar",
33                        url.toExternalForm() );
34      }
35  
36      public void testRelativeSegment()
37          throws Exception
38      {
39          URL url = buildUrl( "jar:/path/to/foo.jar!/segment.jar",
40                              "!/other-segment.jar" );
41  
42          assertEquals( "jar:/path/to/foo.jar!/other-segment.jar",
43                        url.toExternalForm() );
44      }
45  
46      public void testRelativeMultiSegment()
47          throws Exception
48      {
49          URL url = buildUrl( "jar:/path/to/foo.jar!/segment-a.jar!/segment-b.jar",
50                              "!/other-segment.jar#cheese" );
51  
52          assertEquals( "jar:/path/to/foo.jar!/segment-a.jar!/other-segment.jar",
53                        url.toExternalForm() );
54      }
55  
56      protected URL buildUrl( String contextText,
57                              String urlText )
58          throws Exception
59      {
60          URL context = new URL( contextText );
61  
62          URL url = new URL( context,
63                             urlText );
64  
65          System.err.println( "build('" + context + "', '" + urlText + "') -- " + url );
66  
67          return url;
68      }
69  }
70