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