1 7 8 package org.jdesktop.jdnc.markup; 9 10 import java.net.URL ; 11 import java.net.MalformedURLException ; 12 13 import junit.framework.TestCase; 14 15 import net.openmarkup.ApplierException; 16 17 import org.jdesktop.jdnc.markup.RealizationUtils; 18 19 25 public class RealizationUtilsTest extends TestCase { 26 27 private static String VALID_URL = "http://www.sun.com"; 28 private static String INVALID_URL = "http://wwww.thisisnotavalidurl.com"; 29 private static String MALFORMED_URL = "htp:\\invalid.com"; 30 31 private static String VALID_FILE_URL = "resources/bike.html"; 32 private static String INVALID_FILE_URL = "resources/steves-not-here.html"; 33 34 35 public void testData() { 36 try { 37 URL url = new URL (MALFORMED_URL); 38 } catch (MalformedURLException ex) { 39 return; 40 } 41 fail("Malformed URL: " + MALFORMED_URL); 42 } 43 44 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 url = new URL (INVALID_URL); 92 93 assertFalse(RealizationUtils.validateURL(url)); 94 } catch (ApplierException ex) { 95 return; 96 } catch (MalformedURLException 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 url = RealizationUtilsTest.class.getResource(INVALID_FILE_URL); 114 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 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 |