KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jdesktop > jdnc > markup > RealizationUtilsTest


1 /*
2  * $Id: RealizationUtilsTest.java,v 1.3 2004/10/29 15:34:58 davidson1 Exp $
3  *
4  * Copyright 2004 Sun Microsystems, Inc., 4150 Network Circle,
5  * Santa Clara, California 95054, U.S.A. All rights reserved.
6  */

7
8 package org.jdesktop.jdnc.markup;
9
10 import java.net.URL JavaDoc;
11 import java.net.MalformedURLException JavaDoc;
12
13 import junit.framework.TestCase;
14
15 import net.openmarkup.ApplierException;
16
17 import org.jdesktop.jdnc.markup.RealizationUtils;
18
19 /**
20  * A set of tests to ensure that the url validataion methods are
21  * working correctly.
22  *
23  * @author Mark Davidson
24  */

25 public class RealizationUtilsTest extends TestCase {
26
27     private static String JavaDoc VALID_URL = "http://www.sun.com";
28     private static String JavaDoc INVALID_URL = "http://wwww.thisisnotavalidurl.com";
29     private static String JavaDoc MALFORMED_URL = "htp:\\invalid.com";
30
31     private static String JavaDoc VALID_FILE_URL = "resources/bike.html";
32     private static String JavaDoc INVALID_FILE_URL = "resources/steves-not-here.html";
33
34
35     public void testData() {
36         try {
37             URL JavaDoc url = new URL JavaDoc(MALFORMED_URL);
38         } catch (MalformedURLException JavaDoc ex) {
39             return;
40         }
41         fail("Malformed URL: " + MALFORMED_URL);
42     }
43
44     /*
45       Exclude these tests for now since we have to determine what constitutes
46       a valid url inside and outside the Sun firewall.
47
48       On the one hand, a Sun internal url like http://cerebus.sfbay is valid
49       in the firewall but not on the public internet.
50
51       On the other hand, a public url like http://www.sun.com is valid on
52       the internet but must use an http proxy to gain access from within the
53       firewall.
54
55       May have to set a proxy when invoking the test from behind the firewall
56
57       <arg value="-DproxyHost=scaweb1.sfbay"/>
58       <arg value="-DproxyPort=8080"/>
59       <arg value="-Dhttp.proxyHost=scaweb1.sfbay"/>
60       <arg value="-Dhttp.proxyPort=8080"/>
61
62     public void testValidURL() {
63         try {
64             assertTrue(RealizationUtils.validateURL(VALID_URL));
65         } catch (Exception ex) {
66             fail(ex.getMessage());
67         }
68     }
69
70     public void testValidURL2() {
71         try {
72             URL url = new URL(VALID_URL);
73             assertTrue(RealizationUtils.validateURL(url));
74         } catch (Exception ex) {
75             fail(ex.getMessage());
76         }
77     }
78     */

79
80     public void testInvalidURL() {
81         try {
82             assertFalse(RealizationUtils.validateURL(INVALID_URL));
83         } catch (ApplierException ex) {
84             return;
85         }
86         fail("Invalid URL: " + INVALID_URL);
87     }
88
89     public void testInvalidURL2() {
90         try {
91             URL JavaDoc url = new URL JavaDoc(INVALID_URL);
92
93             assertFalse(RealizationUtils.validateURL(url));
94         } catch (ApplierException ex) {
95             return;
96         } catch (MalformedURLException JavaDoc ex2) {
97             fail(ex2.getMessage());
98         }
99         fail("Invalid URL: " + INVALID_URL);
100     }
101
102     public void testMalformedURL() {
103         try {
104             assertFalse(RealizationUtils.validateURL(MALFORMED_URL));
105         } catch (ApplierException ex) {
106             return;
107         }
108         fail("Malformed URL: " + MALFORMED_URL);
109     }
110
111     public void testInvalidFileURL() {
112         try {
113             URL JavaDoc url = RealizationUtilsTest.class.getResource(INVALID_FILE_URL);
114             // url should be null;
115
assertFalse(RealizationUtils.validateURL(url));
116
117             assertFalse(RealizationUtils.validateURL(INVALID_FILE_URL));
118
119         } catch (ApplierException ex) {
120             return;
121         }
122         fail("Invalid file URL: " + INVALID_FILE_URL);
123     }
124
125     public void testValidFileURL() {
126         try {
127             URL JavaDoc url = RealizationUtilsTest.class.getResource(VALID_FILE_URL);
128
129             assertTrue(RealizationUtils.validateURL(url));
130         } catch (ApplierException ex) {
131             fail(ex.getMessage());
132         }
133     }
134 }
135
Popular Tags