KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > jocl > TestJOCLContentHandler


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

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 JavaDoc;
24
25 /**
26  * @version $Revision: 1.8 $ $Date: 2004/02/28 12:18:18 $
27  */

28 public class TestJOCLContentHandler extends TestCase {
29     public TestJOCLContentHandler(String JavaDoc 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 JavaDoc args[]) {
38         String JavaDoc[] 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 JavaDoc {
49         jocl.startDocument();
50         jocl.startElement("http://apache.org/xml/xmlns/jakarta/commons/jocl","jocl","jocl",new AttributesImpl JavaDoc());
51         {
52             AttributesImpl JavaDoc attr = new AttributesImpl JavaDoc();
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 JavaDoc attr = new AttributesImpl JavaDoc();
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 JavaDoc attr = new AttributesImpl JavaDoc();
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 JavaDoc attr = new AttributesImpl JavaDoc();
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 JavaDoc attr = new AttributesImpl JavaDoc();
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 JavaDoc attr = new AttributesImpl JavaDoc();
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 JavaDoc attr = new AttributesImpl JavaDoc();
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 JavaDoc attr = new AttributesImpl JavaDoc();
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 JavaDoc attr = new AttributesImpl JavaDoc();
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 JavaDoc.class,jocl.getType(8));
117
118         assertEquals(Boolean.TRUE,jocl.getValue(0));
119         assertEquals(new Byte JavaDoc("1"),jocl.getValue(1));
120         assertEquals(new Character JavaDoc('c'),jocl.getValue(2));
121         assertEquals(new Double JavaDoc("2.0"),jocl.getValue(3));
122         assertEquals(new Float JavaDoc("3.0"),jocl.getValue(4));
123         assertEquals(new Integer JavaDoc("5"),jocl.getValue(5));
124         assertEquals(new Long JavaDoc("7"),jocl.getValue(6));
125         assertEquals(new Short JavaDoc("11"),jocl.getValue(7));
126         assertEquals("All your base are belong to us.",jocl.getValue(8));
127     }
128
129     public void testObject() throws Exception JavaDoc {
130         jocl.startDocument();
131         jocl.startElement("http://apache.org/xml/xmlns/jakarta/commons/jocl","jocl","jocl",new AttributesImpl JavaDoc());
132         {
133             AttributesImpl JavaDoc attr = new AttributesImpl JavaDoc();
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 JavaDoc attr = new AttributesImpl JavaDoc();
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 JavaDoc attr = new AttributesImpl JavaDoc();
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 JavaDoc attr = new AttributesImpl JavaDoc();
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 JavaDoc.class,jocl.getType(0));
161         assertEquals(java.util.Date JavaDoc.class,jocl.getType(1));
162         assertEquals(java.util.Date JavaDoc.class,jocl.getType(2));
163
164         assertTrue(null == jocl.getValue(0));
165         assertTrue(null != jocl.getValue(1));
166         assertEquals(new java.util.Date JavaDoc(345L),jocl.getValue(2));
167     }
168 }
169
Popular Tags