001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package org.apache.commons.jocl;
019:
020: import junit.framework.Test;
021: import junit.framework.TestCase;
022: import junit.framework.TestSuite;
023:
024: import org.xml.sax.helpers.AttributesImpl;
025:
026: /**
027: * @version $Revision: 479137 $ $Date: 2006-11-25 08:51:48 -0700 (Sat, 25 Nov 2006) $
028: */
029: public class TestJOCLContentHandler extends TestCase {
030: public TestJOCLContentHandler(String testName) {
031: super (testName);
032: }
033:
034: public static Test suite() {
035: return new TestSuite(TestJOCLContentHandler.class);
036: }
037:
038: public static void main(String args[]) {
039: String[] testCaseName = { TestJOCLContentHandler.class
040: .getName() };
041: junit.textui.TestRunner.main(testCaseName);
042: }
043:
044: private JOCLContentHandler jocl = null;
045:
046: public void setUp() {
047: jocl = new JOCLContentHandler();
048: }
049:
050: public void testPrimatives() throws Exception {
051: jocl.startDocument();
052: jocl.startElement(
053: "http://apache.org/xml/xmlns/jakarta/commons/jocl",
054: "jocl", "jocl", new AttributesImpl());
055: {
056: AttributesImpl attr = new AttributesImpl();
057: attr.addAttribute(
058: "http://apache.org/xml/xmlns/jakarta/commons/jocl",
059: "value", "value", "CDATA", "true");
060: jocl.startElement(
061: "http://apache.org/xml/xmlns/jakarta/commons/jocl",
062: "boolean", "boolean", attr);
063: jocl.endElement(
064: "http://apache.org/xml/xmlns/jakarta/commons/jocl",
065: "boolean", "boolean");
066: }
067: {
068: AttributesImpl attr = new AttributesImpl();
069: attr.addAttribute(
070: "http://apache.org/xml/xmlns/jakarta/commons/jocl",
071: "value", "value", "CDATA", "1");
072: jocl.startElement(
073: "http://apache.org/xml/xmlns/jakarta/commons/jocl",
074: "byte", "byte", attr);
075: jocl.endElement(
076: "http://apache.org/xml/xmlns/jakarta/commons/jocl",
077: "byte", "byte");
078: }
079: {
080: AttributesImpl attr = new AttributesImpl();
081: attr.addAttribute(
082: "http://apache.org/xml/xmlns/jakarta/commons/jocl",
083: "value", "value", "CDATA", "c");
084: jocl.startElement(
085: "http://apache.org/xml/xmlns/jakarta/commons/jocl",
086: "char", "char", attr);
087: jocl.endElement(
088: "http://apache.org/xml/xmlns/jakarta/commons/jocl",
089: "char", "char");
090: }
091: {
092: AttributesImpl attr = new AttributesImpl();
093: attr.addAttribute(
094: "http://apache.org/xml/xmlns/jakarta/commons/jocl",
095: "value", "value", "CDATA", "2.0");
096: jocl.startElement(
097: "http://apache.org/xml/xmlns/jakarta/commons/jocl",
098: "double", "double", attr);
099: jocl.endElement(
100: "http://apache.org/xml/xmlns/jakarta/commons/jocl",
101: "double", "double");
102: }
103: {
104: AttributesImpl attr = new AttributesImpl();
105: attr.addAttribute(
106: "http://apache.org/xml/xmlns/jakarta/commons/jocl",
107: "value", "value", "CDATA", "3.0");
108: jocl.startElement(
109: "http://apache.org/xml/xmlns/jakarta/commons/jocl",
110: "float", "float", attr);
111: jocl.endElement(
112: "http://apache.org/xml/xmlns/jakarta/commons/jocl",
113: "float", "float");
114: }
115: {
116: AttributesImpl attr = new AttributesImpl();
117: attr.addAttribute(
118: "http://apache.org/xml/xmlns/jakarta/commons/jocl",
119: "value", "value", "CDATA", "5");
120: jocl.startElement(
121: "http://apache.org/xml/xmlns/jakarta/commons/jocl",
122: "int", "int", attr);
123: jocl.endElement(
124: "http://apache.org/xml/xmlns/jakarta/commons/jocl",
125: "int", "int");
126: }
127: {
128: AttributesImpl attr = new AttributesImpl();
129: attr.addAttribute(
130: "http://apache.org/xml/xmlns/jakarta/commons/jocl",
131: "value", "value", "CDATA", "7");
132: jocl.startElement(
133: "http://apache.org/xml/xmlns/jakarta/commons/jocl",
134: "long", "long", attr);
135: jocl.endElement(
136: "http://apache.org/xml/xmlns/jakarta/commons/jocl",
137: "long", "long");
138: }
139: {
140: AttributesImpl attr = new AttributesImpl();
141: attr.addAttribute(
142: "http://apache.org/xml/xmlns/jakarta/commons/jocl",
143: "value", "value", "CDATA", "11");
144: jocl.startElement(
145: "http://apache.org/xml/xmlns/jakarta/commons/jocl",
146: "short", "short", attr);
147: jocl.endElement(
148: "http://apache.org/xml/xmlns/jakarta/commons/jocl",
149: "short", "short");
150: }
151: {
152: AttributesImpl attr = new AttributesImpl();
153: attr.addAttribute(
154: "http://apache.org/xml/xmlns/jakarta/commons/jocl",
155: "value", "value", "CDATA",
156: "All your base are belong to us.");
157: jocl.startElement(
158: "http://apache.org/xml/xmlns/jakarta/commons/jocl",
159: "string", "string", attr);
160: jocl.endElement(
161: "http://apache.org/xml/xmlns/jakarta/commons/jocl",
162: "string", "string");
163: }
164: jocl.endElement(
165: "http://apache.org/xml/xmlns/jakarta/commons/jocl",
166: "jocl", "jocl");
167: jocl.endDocument();
168:
169: assertEquals(Boolean.TYPE, jocl.getType(0));
170: assertEquals(Byte.TYPE, jocl.getType(1));
171: assertEquals(Character.TYPE, jocl.getType(2));
172: assertEquals(Double.TYPE, jocl.getType(3));
173: assertEquals(Float.TYPE, jocl.getType(4));
174: assertEquals(Integer.TYPE, jocl.getType(5));
175: assertEquals(Long.TYPE, jocl.getType(6));
176: assertEquals(Short.TYPE, jocl.getType(7));
177: assertEquals(String.class, jocl.getType(8));
178:
179: assertEquals(Boolean.TRUE, jocl.getValue(0));
180: assertEquals(new Byte("1"), jocl.getValue(1));
181: assertEquals(new Character('c'), jocl.getValue(2));
182: assertEquals(new Double("2.0"), jocl.getValue(3));
183: assertEquals(new Float("3.0"), jocl.getValue(4));
184: assertEquals(new Integer("5"), jocl.getValue(5));
185: assertEquals(new Long("7"), jocl.getValue(6));
186: assertEquals(new Short("11"), jocl.getValue(7));
187: assertEquals("All your base are belong to us.", jocl
188: .getValue(8));
189: }
190:
191: public void testObject() throws Exception {
192: jocl.startDocument();
193: jocl.startElement(
194: "http://apache.org/xml/xmlns/jakarta/commons/jocl",
195: "jocl", "jocl", new AttributesImpl());
196: {
197: AttributesImpl attr = new AttributesImpl();
198: attr.addAttribute(
199: "http://apache.org/xml/xmlns/jakarta/commons/jocl",
200: "null", "null", "CDATA", "true");
201: attr.addAttribute(
202: "http://apache.org/xml/xmlns/jakarta/commons/jocl",
203: "class", "class", "CDATA", "java.lang.String");
204: jocl.startElement(
205: "http://apache.org/xml/xmlns/jakarta/commons/jocl",
206: "object", "object", attr);
207: jocl.endElement(
208: "http://apache.org/xml/xmlns/jakarta/commons/jocl",
209: "object", "object");
210: }
211: {
212: AttributesImpl attr = new AttributesImpl();
213: attr.addAttribute(
214: "http://apache.org/xml/xmlns/jakarta/commons/jocl",
215: "class", "class", "CDATA", "java.util.Date");
216: jocl.startElement(
217: "http://apache.org/xml/xmlns/jakarta/commons/jocl",
218: "object", "object", attr);
219: jocl.endElement(
220: "http://apache.org/xml/xmlns/jakarta/commons/jocl",
221: "object", "object");
222: }
223: {
224: AttributesImpl attr = new AttributesImpl();
225: attr.addAttribute(
226: "http://apache.org/xml/xmlns/jakarta/commons/jocl",
227: "class", "class", "CDATA", "java.util.Date");
228: jocl.startElement(
229: "http://apache.org/xml/xmlns/jakarta/commons/jocl",
230: "object", "object", attr);
231: }
232: {
233: AttributesImpl attr = new AttributesImpl();
234: attr.addAttribute(
235: "http://apache.org/xml/xmlns/jakarta/commons/jocl",
236: "value", "value", "CDATA", "345");
237: jocl.startElement(
238: "http://apache.org/xml/xmlns/jakarta/commons/jocl",
239: "long", "long", attr);
240: jocl.endElement(
241: "http://apache.org/xml/xmlns/jakarta/commons/jocl",
242: "long", "long");
243: }
244: jocl.endElement(
245: "http://apache.org/xml/xmlns/jakarta/commons/jocl",
246: "object", "object");
247: jocl.endElement(
248: "http://apache.org/xml/xmlns/jakarta/commons/jocl",
249: "jocl", "jocl");
250: jocl.endDocument();
251:
252: assertEquals(String.class, jocl.getType(0));
253: assertEquals(java.util.Date.class, jocl.getType(1));
254: assertEquals(java.util.Date.class, jocl.getType(2));
255:
256: assertTrue(null == jocl.getValue(0));
257: assertTrue(null != jocl.getValue(1));
258: assertEquals(new java.util.Date(345L), jocl.getValue(2));
259: }
260: }
|