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