1 16 17 package org.apache.commons.jocl; 18 19 import junit.framework.Test; 20 import junit.framework.TestCase; 21 import junit.framework.TestSuite; 22 23 import org.xml.sax.helpers.AttributesImpl ; 24 25 28 public class TestJOCLContentHandler extends TestCase { 29 public TestJOCLContentHandler(String testName) { 30 super(testName); 31 } 32 33 public static Test suite() { 34 return new TestSuite(TestJOCLContentHandler.class); 35 } 36 37 public static void main(String args[]) { 38 String [] testCaseName = { TestJOCLContentHandler.class.getName() }; 39 junit.textui.TestRunner.main(testCaseName); 40 } 41 42 private JOCLContentHandler jocl = null; 43 44 public void setUp() { 45 jocl = new JOCLContentHandler(); 46 } 47 48 public void testPrimatives() throws Exception { 49 jocl.startDocument(); 50 jocl.startElement("http://apache.org/xml/xmlns/jakarta/commons/jocl","jocl","jocl",new AttributesImpl ()); 51 { 52 AttributesImpl attr = new AttributesImpl (); 53 attr.addAttribute("http://apache.org/xml/xmlns/jakarta/commons/jocl","value","value","CDATA","true"); 54 jocl.startElement("http://apache.org/xml/xmlns/jakarta/commons/jocl","boolean","boolean",attr); 55 jocl.endElement("http://apache.org/xml/xmlns/jakarta/commons/jocl","boolean","boolean"); 56 } 57 { 58 AttributesImpl attr = new AttributesImpl (); 59 attr.addAttribute("http://apache.org/xml/xmlns/jakarta/commons/jocl","value","value","CDATA","1"); 60 jocl.startElement("http://apache.org/xml/xmlns/jakarta/commons/jocl","byte","byte",attr); 61 jocl.endElement("http://apache.org/xml/xmlns/jakarta/commons/jocl","byte","byte"); 62 } 63 { 64 AttributesImpl attr = new AttributesImpl (); 65 attr.addAttribute("http://apache.org/xml/xmlns/jakarta/commons/jocl","value","value","CDATA","c"); 66 jocl.startElement("http://apache.org/xml/xmlns/jakarta/commons/jocl","char","char",attr); 67 jocl.endElement("http://apache.org/xml/xmlns/jakarta/commons/jocl","char","char"); 68 } 69 { 70 AttributesImpl attr = new AttributesImpl (); 71 attr.addAttribute("http://apache.org/xml/xmlns/jakarta/commons/jocl","value","value","CDATA","2.0"); 72 jocl.startElement("http://apache.org/xml/xmlns/jakarta/commons/jocl","double","double",attr); 73 jocl.endElement("http://apache.org/xml/xmlns/jakarta/commons/jocl","double","double"); 74 } 75 { 76 AttributesImpl attr = new AttributesImpl (); 77 attr.addAttribute("http://apache.org/xml/xmlns/jakarta/commons/jocl","value","value","CDATA","3.0"); 78 jocl.startElement("http://apache.org/xml/xmlns/jakarta/commons/jocl","float","float",attr); 79 jocl.endElement("http://apache.org/xml/xmlns/jakarta/commons/jocl","float","float"); 80 } 81 { 82 AttributesImpl attr = new AttributesImpl (); 83 attr.addAttribute("http://apache.org/xml/xmlns/jakarta/commons/jocl","value","value","CDATA","5"); 84 jocl.startElement("http://apache.org/xml/xmlns/jakarta/commons/jocl","int","int",attr); 85 jocl.endElement("http://apache.org/xml/xmlns/jakarta/commons/jocl","int","int"); 86 } 87 { 88 AttributesImpl attr = new AttributesImpl (); 89 attr.addAttribute("http://apache.org/xml/xmlns/jakarta/commons/jocl","value","value","CDATA","7"); 90 jocl.startElement("http://apache.org/xml/xmlns/jakarta/commons/jocl","long","long",attr); 91 jocl.endElement("http://apache.org/xml/xmlns/jakarta/commons/jocl","long","long"); 92 } 93 { 94 AttributesImpl attr = new AttributesImpl (); 95 attr.addAttribute("http://apache.org/xml/xmlns/jakarta/commons/jocl","value","value","CDATA","11"); 96 jocl.startElement("http://apache.org/xml/xmlns/jakarta/commons/jocl","short","short",attr); 97 jocl.endElement("http://apache.org/xml/xmlns/jakarta/commons/jocl","short","short"); 98 } 99 { 100 AttributesImpl attr = new AttributesImpl (); 101 attr.addAttribute("http://apache.org/xml/xmlns/jakarta/commons/jocl","value","value","CDATA","All your base are belong to us."); 102 jocl.startElement("http://apache.org/xml/xmlns/jakarta/commons/jocl","string","string",attr); 103 jocl.endElement("http://apache.org/xml/xmlns/jakarta/commons/jocl","string","string"); 104 } 105 jocl.endElement("http://apache.org/xml/xmlns/jakarta/commons/jocl","jocl","jocl"); 106 jocl.endDocument(); 107 108 assertEquals(Boolean.TYPE,jocl.getType(0)); 109 assertEquals(Byte.TYPE,jocl.getType(1)); 110 assertEquals(Character.TYPE,jocl.getType(2)); 111 assertEquals(Double.TYPE,jocl.getType(3)); 112 assertEquals(Float.TYPE,jocl.getType(4)); 113 assertEquals(Integer.TYPE,jocl.getType(5)); 114 assertEquals(Long.TYPE,jocl.getType(6)); 115 assertEquals(Short.TYPE,jocl.getType(7)); 116 assertEquals(String .class,jocl.getType(8)); 117 118 assertEquals(Boolean.TRUE,jocl.getValue(0)); 119 assertEquals(new Byte ("1"),jocl.getValue(1)); 120 assertEquals(new Character ('c'),jocl.getValue(2)); 121 assertEquals(new Double ("2.0"),jocl.getValue(3)); 122 assertEquals(new Float ("3.0"),jocl.getValue(4)); 123 assertEquals(new Integer ("5"),jocl.getValue(5)); 124 assertEquals(new Long ("7"),jocl.getValue(6)); 125 assertEquals(new Short ("11"),jocl.getValue(7)); 126 assertEquals("All your base are belong to us.",jocl.getValue(8)); 127 } 128 129 public void testObject() throws Exception { 130 jocl.startDocument(); 131 jocl.startElement("http://apache.org/xml/xmlns/jakarta/commons/jocl","jocl","jocl",new AttributesImpl ()); 132 { 133 AttributesImpl attr = new AttributesImpl (); 134 attr.addAttribute("http://apache.org/xml/xmlns/jakarta/commons/jocl","null","null","CDATA","true"); 135 attr.addAttribute("http://apache.org/xml/xmlns/jakarta/commons/jocl","class","class","CDATA","java.lang.String"); 136 jocl.startElement("http://apache.org/xml/xmlns/jakarta/commons/jocl","object","object",attr); 137 jocl.endElement("http://apache.org/xml/xmlns/jakarta/commons/jocl","object","object"); 138 } 139 { 140 AttributesImpl attr = new AttributesImpl (); 141 attr.addAttribute("http://apache.org/xml/xmlns/jakarta/commons/jocl","class","class","CDATA","java.util.Date"); 142 jocl.startElement("http://apache.org/xml/xmlns/jakarta/commons/jocl","object","object",attr); 143 jocl.endElement("http://apache.org/xml/xmlns/jakarta/commons/jocl","object","object"); 144 } 145 { 146 AttributesImpl attr = new AttributesImpl (); 147 attr.addAttribute("http://apache.org/xml/xmlns/jakarta/commons/jocl","class","class","CDATA","java.util.Date"); 148 jocl.startElement("http://apache.org/xml/xmlns/jakarta/commons/jocl","object","object",attr); 149 } 150 { 151 AttributesImpl attr = new AttributesImpl (); 152 attr.addAttribute("http://apache.org/xml/xmlns/jakarta/commons/jocl","value","value","CDATA","345"); 153 jocl.startElement("http://apache.org/xml/xmlns/jakarta/commons/jocl","long","long",attr); 154 jocl.endElement("http://apache.org/xml/xmlns/jakarta/commons/jocl","long","long"); 155 } 156 jocl.endElement("http://apache.org/xml/xmlns/jakarta/commons/jocl","object","object"); 157 jocl.endElement("http://apache.org/xml/xmlns/jakarta/commons/jocl","jocl","jocl"); 158 jocl.endDocument(); 159 160 assertEquals(String .class,jocl.getType(0)); 161 assertEquals(java.util.Date .class,jocl.getType(1)); 162 assertEquals(java.util.Date .class,jocl.getType(2)); 163 164 assertTrue(null == jocl.getValue(0)); 165 assertTrue(null != jocl.getValue(1)); 166 assertEquals(new java.util.Date (345L),jocl.getValue(2)); 167 } 168 } 169 | Popular Tags |