1 7 8 package org.jdesktop.jdnc.markup; 9 10 import java.net.URL ; 11 import java.net.MalformedURLException ; 12 13 import java.util.logging.Level ; 14 import java.util.logging.Logger ; 15 16 import junit.framework.TestCase; 17 18 import org.jdesktop.jdnc.markup.ElementTypes; 19 20 import net.openmarkup.ObjectRealizer; 21 import net.openmarkup.Scribe; 22 23 public class ErrorTest extends TestCase { 24 25 private ObjectRealizer realizer; 26 27 public ErrorTest() { 28 super("Error Test"); 29 } 30 31 protected void setUp() { 32 realizer = RealizerUnitTest.createObjectRealizer(); 33 realizer.add(ElementTypes.get()); 34 } 35 36 protected void tearDown() { 37 realizer = null; 38 } 39 40 public void testIntroduction() { 41 Scribe.getLogger().info("This test exercise the logging/error handling system"); 42 Scribe.getLogger().info("Messages printed to System.err is normal"); 43 } 44 45 public void testNullURL() throws Exception { 46 Object obj = null; 47 try { 48 URL url = null; 49 obj = realizer.getObject(url); 50 fail("getObject should fail parsing a null url"); 51 } catch (Exception ex) { 52 } 53 assertNull(obj); 54 } 55 56 public void testNonXML() { 58 URL url = ErrorTest.class.getResource("resources/error0.xml"); 59 assertNotNull(url); 60 61 Object obj = null; 62 try { 63 obj = realizer.getObject(url); 64 fail("getObject should fail parsing non-xml"); 65 } catch (Exception ex) { 66 } 67 assertNull(obj); 68 } 69 70 public void testMalformedXML() { 72 URL url = ErrorTest.class.getResource("resources/error1.xml"); 73 assertNotNull(url); 74 75 Object obj = null; 76 try { 77 obj = realizer.getObject(url); 78 fail("getObject should fail parsing malformed xml"); 79 } catch (Exception ex) { 80 } 81 assertNull(obj); 82 } 83 84 85 public void testMissingElement() throws Exception { 86 URL url = ErrorTest.class.getResource("resources/error2.xml"); 87 assertNotNull(url); 88 assertNotNull(realizer.getObject(url)); 89 90 url = ErrorTest.class.getResource("resources/error2-1.xml"); 93 assertNotNull(url); 94 assertNotNull(realizer.getObject(url)); 95 96 } 97 98 public void testMissingAttribute() throws Exception { 99 URL url = ErrorTest.class.getResource("resources/error3.xml"); 100 assertNotNull(url); 101 assertNotNull(realizer.getObject(url)); 102 103 url = ErrorTest.class.getResource("resources/error3-1.xml"); 105 assertNotNull(url); 106 assertNotNull(realizer.getObject(url)); 107 } 108 109 113 public void testInvalidURL() throws Exception { 114 URL url = ErrorTest.class.getResource("resources/error4-0.xml"); 116 assertNotNull(url); 117 118 Object obj = null; 119 try { 120 obj = realizer.getObject(url); 121 fail("getObject should fail parsing invalid url"); 122 } catch (Exception ex) { 123 } 124 assertNull(obj); 125 126 url = ErrorTest.class.getResource("resources/error4-1.xml"); 129 assertNotNull(url); 130 assertNotNull(realizer.getObject(url)); 131 132 url = ErrorTest.class.getResource("resources/error4-2.xml"); 134 assertNotNull(url); 135 try { 136 obj = realizer.getObject(url); 137 fail("getObject should fail parsing invalid url"); 138 } catch (Exception ex) { 139 } 140 assertNull(obj); 141 } 142 } 143 | Popular Tags |