1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.springframework.ws.soap.saaj.support;
18
19 import javax.xml.soap.MessageFactory;
20 import javax.xml.soap.SOAPEnvelope;
21 import javax.xml.soap.SOAPMessage;
22 import javax.xml.transform.Source;
23 import javax.xml.transform.Transformer;
24 import javax.xml.transform.TransformerFactory;
25 import javax.xml.transform.dom.DOMResult;
26 import javax.xml.transform.dom.DOMSource;
27 import javax.xml.transform.sax.SAXSource;
28
29 import org.custommonkey.xmlunit.XMLTestCase;
30 import org.w3c.dom.Document;
31 import org.xml.sax.InputSource;
32
33 public class SaajXmlReaderTest extends XMLTestCase {
34
35 private SaajXmlReader saajReader;
36
37 private SOAPMessage message;
38
39 private Transformer transformer;
40
41 protected void setUp() throws Exception {
42 MessageFactory messageFactory = MessageFactory.newInstance();
43 message = messageFactory.createMessage();
44 SOAPEnvelope envelope = message.getSOAPPart().getEnvelope();
45 saajReader = new SaajXmlReader(envelope);
46 transformer = TransformerFactory.newInstance().newTransformer();
47 }
48
49 public void testNamespacesPrefixes() throws Exception {
50 saajReader.setFeature("http://xml.org/sax/features/namespaces", true);
51 saajReader.setFeature("http://xml.org/sax/features/namespace-prefixes", true);
52 DOMResult result = new DOMResult();
53 Source source = new SAXSource(saajReader, new InputSource());
54 transformer.transform(source, result);
55 DOMResult expected = new DOMResult();
56 transformer.transform(new DOMSource(message.getSOAPPart().getEnvelope()), expected);
57 assertXMLEqual((Document) expected.getNode(), (Document) result.getNode());
58 }
59
60 public void testNamespacesNoPrefixes() throws Exception {
61 saajReader.setFeature("http://xml.org/sax/features/namespaces", true);
62 saajReader.setFeature("http://xml.org/sax/features/namespace-prefixes", false);
63 DOMResult result = new DOMResult();
64 Source source = new SAXSource(saajReader, new InputSource());
65 transformer.transform(source, result);
66 DOMResult expected = new DOMResult();
67 transformer.transform(new DOMSource(message.getSOAPPart().getEnvelope()), expected);
68 assertXMLEqual((Document) expected.getNode(), (Document) result.getNode());
69 }
70 }