1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package tests.customext.attrib;
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 CustomExtensionSerializerTest extends TestCase {
39
40 public void testSerialization() throws Exception {
41
42 System.setProperty(Constants.SystemConstants.EXTENSION_REGISTRY_KEY,
43 CustomExtensionRegistry.class.getName());
44
45
46 DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
47 documentBuilderFactory.setNamespaceAware(true);
48 Document doc1 = documentBuilderFactory.newDocumentBuilder().
49 parse(Resources.asURI("/external/externalAnnotations.xsd"));
50
51 XmlSchemaCollection schemaCol = new XmlSchemaCollection();
52 XmlSchema schema = schemaCol.read(doc1,null);
53 assertNotNull(schema);
54
55
56
57 ByteArrayOutputStream baos = new ByteArrayOutputStream();
58 schema.write(baos);
59
60
61 Document doc2 = documentBuilderFactory.newDocumentBuilder().
62 parse(new ByteArrayInputStream(baos.toByteArray()));
63
64 schema = schemaCol.read(doc2,null);
65 assertNotNull(schema);
66
67
68
69 Iterator values = schema.getElements().getValues();
70 while (values.hasNext()) {
71 XmlSchemaElement elt = (XmlSchemaElement) values.next();
72 assertNotNull(elt);
73 Map metaInfoMap = elt.getMetaInfoMap();
74 assertNotNull(metaInfoMap);
75
76 CustomAttribute customAttrib = (CustomAttribute)metaInfoMap.get(CustomAttribute.CUSTOM_ATTRIBUTE_QNAME);
77 assertNotNull(customAttrib);
78
79 }
80
81
82
83 System.getProperties().remove(Constants.SystemConstants.EXTENSION_REGISTRY_KEY);
84
85 }
86
87 }