01: package net.sourceforge.jaxor.parser.tests;
02:
03: import net.sourceforge.jaxor.example.tests.JaxorTestCase;
04: import net.sourceforge.jaxor.parser.DynamicParser;
05: import net.sourceforge.jaxor.parser.JMethod;
06: import net.sourceforge.jaxor.parser.Query;
07: import org.jdom.CDATA;
08: import org.jdom.Element;
09: import org.xml.sax.SAXException;
10: import org.xml.sax.XMLReader;
11:
12: import javax.xml.parsers.ParserConfigurationException;
13: import javax.xml.parsers.SAXParser;
14: import javax.xml.parsers.SAXParserFactory;
15: import java.io.IOException;
16:
17: /*
18: * User: Mike
19: * Date: Oct 21, 2002
20: * Time: 11:39:26 PM
21: */
22:
23: public class DynamicParserTest extends JaxorTestCase {
24: private Query _query;
25: private JMethod _method;
26:
27: public void testQueryWithParam() throws SAXException,
28: ParserConfigurationException, IOException {
29: DynamicParser parser = new DynamicParser(this );
30: SAXParser saxParser = SAXParserFactory.newInstance()
31: .newSAXParser();
32: XMLReader _parser = saxParser.getXMLReader();
33:
34: _parser.setContentHandler(parser);
35: _parser.parse(getInputSource(EntityParserTest.createQuery()));
36: assertEquals(1, _query.getParams().size());
37: }
38:
39: public void addQuery(Query q) {
40: _query = q;
41: }
42:
43: public void testCharacterData() throws SAXException,
44: ParserConfigurationException, IOException {
45: DynamicParser parser = new DynamicParser(this );
46: parser.addAlias("method", JMethod.class);
47: SAXParser saxParser = SAXParserFactory.newInstance()
48: .newSAXParser();
49: XMLReader _parser = saxParser.getXMLReader();
50: _parser.setContentHandler(parser);
51: _parser.parse(getInputSource(createMethod()));
52: assertEquals("return null;", _method.getBody());
53: assertEquals("methodName", _method.getName());
54: assertEquals("java.lang.Long", _method.getType());
55: }
56:
57: public void addMethod(JMethod method) {
58: _method = method;
59: }
60:
61: private static Element createMethod() {
62: Element el = new Element("method");
63: el.setAttribute("name", "methodName");
64: el.setAttribute("type", "java.lang.Long");
65: el.addContent(new CDATA("return null;"));
66: return el;
67: }
68: }
|