1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package tests.customext.elt;
17
18 import junit.framework.TestCase;
19 import org.apache.ws.commons.schema.XmlSchema;
20 import org.apache.ws.commons.schema.XmlSchemaCollection;
21 import org.apache.ws.commons.schema.XmlSchemaElement;
22 import org.apache.ws.commons.schema.constants.Constants;
23 import org.w3c.dom.Document;
24 import tests.Resources;
25
26 import javax.xml.parsers.DocumentBuilderFactory;
27 import java.io.ByteArrayInputStream;
28 import java.io.ByteArrayOutputStream;
29 import java.util.Iterator;
30 import java.util.Map;
31
32
33
34
35 public class CustomExtElementSerializerTest extends TestCase {
36
37
38 public void testSerialization() throws Exception {
39
40 System.setProperty(Constants.SystemConstants.EXTENSION_REGISTRY_KEY,
41 CustomExtensionRegistry.class.getName());
42
43
44 DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
45 documentBuilderFactory.setNamespaceAware(true);
46 Document doc = documentBuilderFactory.newDocumentBuilder().
47 parse(Resources.asURI("/external/externalElementAnnotations.xsd"));
48
49 XmlSchemaCollection schemaCol = new XmlSchemaCollection();
50 XmlSchema schema = schemaCol.read(doc,null);
51 assertNotNull(schema);
52
53
54
55 ByteArrayOutputStream baos = new ByteArrayOutputStream();
56 schema.write(baos);
57 Document doc2 = documentBuilderFactory.newDocumentBuilder().
58 parse(new ByteArrayInputStream(baos.toByteArray()));
59
60 schema = schemaCol.read(doc2,null);
61 assertNotNull(schema);
62
63
64
65 Iterator values = schema.getElements().getValues();
66 while (values.hasNext()) {
67 XmlSchemaElement elt = (XmlSchemaElement) values.next();
68 assertNotNull(elt);
69 Map metaInfoMap = elt.getMetaInfoMap();
70 assertNotNull(metaInfoMap);
71
72 CustomElement customElt = (CustomElement)metaInfoMap.get(CustomElement.CUSTOM_ELT_QNAME);
73 assertNotNull(customElt);
74
75 }
76
77
78 System.getProperties().remove(Constants.SystemConstants.EXTENSION_REGISTRY_KEY);
79
80 }
81 }