KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > portal > test > common > URLNavigatorTestCase


1 /*****************************************
2  * *
3  * JBoss Portal: The OpenSource Portal *
4  * *
5  * Distributable under LGPL license. *
6  * See terms of license at gnu.org. *
7  * *
8  *****************************************/

9 package org.jboss.portal.test.common;
10
11 import junit.framework.TestCase;
12
13 import java.io.File JavaDoc;
14 import java.io.IOException JavaDoc;
15 import java.net.URL JavaDoc;
16
17 import org.jboss.portal.common.net.jar.JarURLNavigationProvider;
18 import org.jboss.portal.common.net.URLVisitor;
19
20 /**
21  * @author <a HREF="mailto:julien@jboss.org">Julien Viet</a>
22  * @version $Revision: 1.1 $
23  */

24 public class URLNavigatorTestCase extends TestCase
25 {
26
27    public URLNavigatorTestCase(String JavaDoc name)
28    {
29       super(name);
30    }
31
32    public void testJar() throws Exception JavaDoc
33    {
34       File JavaDoc libDir = new File JavaDoc(System.getProperty("build.lib"));
35       assertTrue(libDir.exists());
36       assertTrue(libDir.isDirectory());
37       File JavaDoc jarFile = new File JavaDoc(libDir, "test.jar");
38       assertTrue(jarFile.exists());
39       assertFalse(jarFile.isDirectory());
40
41       //
42
URL JavaDoc jarURL = new URL JavaDoc("jar", "", jarFile.toURL() + "!" + "/a1/b1/");
43       JarURLNavigationProvider provider = new JarURLNavigationProvider();
44       provider.visit(jarURL, new URLVisitor()
45       {
46          public void startDir(String JavaDoc name)
47          {
48             System.out.println("<name = " + name + " >");
49          }
50          public void endDir(String JavaDoc name)
51          {
52             System.out.println("</name = " + name + " >");
53          }
54          public void file(String JavaDoc name, URL JavaDoc url)
55          {
56             System.out.println("url = " + url);
57             try
58             {
59                Object JavaDoc content = url.getContent();
60                System.out.println("content = " + content);
61             }
62             catch (IOException JavaDoc e)
63             {
64                e.printStackTrace();
65             }
66          }
67       });
68
69       //
70
jarFile.deleteOnExit();
71    }
72
73 }
74
Popular Tags