01: package org.geotools.xml;
02:
03: import java.util.List;
04:
05: import javax.xml.parsers.DocumentBuilder;
06: import javax.xml.parsers.DocumentBuilderFactory;
07:
08: import org.geotools.xs.XSConfiguration;
09: import org.w3c.dom.Document;
10:
11: import junit.framework.TestCase;
12:
13: public class FacetTest extends TestCase {
14:
15: public void testList() throws Exception {
16:
17: DocumentBuilderFactory dbf = DocumentBuilderFactory
18: .newInstance();
19: dbf.setNamespaceAware(true);
20:
21: DocumentBuilder db = dbf.newDocumentBuilder();
22: Document doc = db.parse(getClass().getResourceAsStream(
23: "list.xml"));
24:
25: String schemaLocation = "http://geotools.org/test "
26: + getClass().getResource("facets.xsd").getFile();
27:
28: doc.getDocumentElement().setAttributeNS(
29: "http://www.w3.org/2001/XMLSchema-instance",
30: "schemaLocation", schemaLocation);
31:
32: DOMParser parser = new DOMParser(new XSConfiguration(), doc);
33: Object o = parser.parse();
34: assertTrue(o instanceof List);
35:
36: List list = (List) o;
37: assertEquals(3, list.size());
38:
39: assertEquals(new Integer(1), list.get(0));
40: assertEquals(new Integer(2), list.get(1));
41: assertEquals(new Integer(3), list.get(2));
42: }
43:
44: public void testWhitespace() throws Exception {
45: DocumentBuilderFactory dbf = DocumentBuilderFactory
46: .newInstance();
47: dbf.setNamespaceAware(true);
48:
49: DocumentBuilder db = dbf.newDocumentBuilder();
50: Document doc = db.parse(getClass().getResourceAsStream(
51: "whitespace.xml"));
52:
53: String schemaLocation = "http://geotools.org/test "
54: + getClass().getResource("facets.xsd").getFile();
55:
56: doc.getDocumentElement().setAttributeNS(
57: "http://www.w3.org/2001/XMLSchema-instance",
58: "schemaLocation", schemaLocation);
59:
60: DOMParser parser = new DOMParser(new XSConfiguration(), doc);
61: String s = (String) parser.parse();
62:
63: assertEquals(
64: "this is a normal string with some whitespace and some new lines",
65: s);
66: }
67: }
|