KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > extbrowser > URLUtilTest


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  *
19  * ExtWebBrowserTest.java
20  * NetBeans JUnit based test
21  *
22  * Created on November 2, 2001, 10:42 AM
23  */

24
25 package org.netbeans.modules.extbrowser;
26
27 import java.io.File JavaDoc;
28 import java.net.URL JavaDoc;
29 import junit.framework.*;
30 import org.netbeans.junit.*;
31 import java.beans.*;
32 import org.openide.ErrorManager;
33 import org.openide.execution.NbProcessDescriptor;
34 import org.openide.filesystems.FileObject;
35 import org.openide.filesystems.FileUtil;
36 import org.openide.modules.InstalledFileLocator;
37 import org.openide.util.NbBundle;
38 import org.openide.awt.HtmlBrowser;
39          
40 /**
41  *
42  * @author rk109395
43  */

44 public class URLUtilTest extends NbTestCase {
45
46     public URLUtilTest (java.lang.String JavaDoc testName) {
47         super(testName);
48     }
49         
50     public static void main(java.lang.String JavaDoc[] args) {
51         junit.textui.TestRunner.run(suite());
52     }
53     
54     public void testCreateExternalURL() throws Exception JavaDoc {
55         // find fileobject for
56
// jar:file:/${NB}/ide5/modules/docs/org-netbeans-modules-usersguide.jar!/org/netbeans/modules/usersguide/pending.html
57
File JavaDoc f = InstalledFileLocator.getDefault().locate("modules/docs/org-netbeans-modules-usersguide.jar", null, false);
58         assertNotNull("Usersguide module not found", f);
59         FileObject fo = FileUtil.toFileObject(f);
60         log("jar fileobject is " + fo);
61         assertNotNull("FileObject corresponding to usersguide module not found", fo);
62         FileObject jar = FileUtil.getArchiveRoot(fo);
63         assertNotNull("FileObject corresponding to usersguide as jar not found", jar);
64         FileObject pendingPage = jar.getFileObject("org/netbeans/modules/usersguide/pending.html");
65         URL JavaDoc pendingURL = pendingPage.getURL();
66         log("original url is " + pendingURL);
67         URL JavaDoc newURL1 = URLUtil.createExternalURL(pendingURL, true);
68         log("jar url " + newURL1);
69         URL JavaDoc newURL2 = URLUtil.createExternalURL(pendingURL, false);
70         log("http url " + newURL2);
71         assertEquals("HTTP URL is not local - does not contain 127.0.0.1", "127.0.0.1", newURL2.getHost());
72     }
73     
74     public static Test suite () {
75         TestSuite suite = new NbTestSuite (URLUtilTest.class);
76         return suite;
77     }
78     
79     
80 }
81
Popular Tags