1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.springframework.ws.wsdl.wsdl11;
18
19 import java.io.InputStream;
20 import javax.wsdl.Definition;
21 import javax.wsdl.factory.WSDLFactory;
22 import javax.wsdl.xml.WSDLReader;
23 import javax.xml.parsers.DocumentBuilder;
24 import javax.xml.parsers.DocumentBuilderFactory;
25 import javax.xml.transform.Source;
26 import javax.xml.transform.Transformer;
27 import javax.xml.transform.TransformerFactory;
28 import javax.xml.transform.dom.DOMResult;
29
30 import org.custommonkey.xmlunit.XMLUnit;
31 import org.junit.Assert;
32 import org.junit.Before;
33 import org.junit.Test;
34 import org.w3c.dom.Document;
35 import org.xml.sax.InputSource;
36
37 import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
38
39 public class Wsdl4jDefinitionTest {
40
41 private Wsdl4jDefinition definition;
42
43 private Transformer transformer;
44
45 @Before
46 public void setUp() throws Exception {
47 XMLUnit.setIgnoreWhitespace(true);
48 WSDLFactory factory = WSDLFactory.newInstance();
49 WSDLReader reader = factory.newWSDLReader();
50 InputStream is = getClass().getResourceAsStream("complete.wsdl");
51 try {
52 Definition wsdl4jDefinition = reader.readWSDL(null, new InputSource(is));
53 definition = new Wsdl4jDefinition(wsdl4jDefinition);
54 }
55 finally {
56 is.close();
57 }
58 transformer = TransformerFactory.newInstance().newTransformer();
59 }
60
61 @Test
62 public void testGetSource() throws Exception {
63 Source source = definition.getSource();
64 Assert.assertNotNull("Source is null", source);
65 DOMResult result = new DOMResult();
66 transformer.transform(source, result);
67 DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
68 documentBuilderFactory.setNamespaceAware(true);
69 DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
70 Document expected = documentBuilder.parse(getClass().getResourceAsStream("complete.wsdl"));
71 assertXMLEqual(expected, (Document) result.getNode());
72 }
73 }