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 javax.xml.parsers.DocumentBuilder;
20 import javax.xml.parsers.DocumentBuilderFactory;
21 import javax.xml.transform.Transformer;
22 import javax.xml.transform.TransformerFactory;
23 import javax.xml.transform.dom.DOMResult;
24
25 import org.springframework.core.io.ClassPathResource;
26 import org.springframework.core.io.Resource;
27 import org.springframework.xml.xsd.SimpleXsdSchema;
28 import org.springframework.xml.xsd.commons.CommonsXsdSchemaCollection;
29
30 import org.custommonkey.xmlunit.XMLUnit;
31 import org.junit.Before;
32 import org.junit.Test;
33 import org.w3c.dom.Document;
34
35 import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
36
37 public class DefaultWsdl11DefinitionTest {
38
39 private DefaultWsdl11Definition definition;
40
41 private Transformer transformer;
42
43 private DocumentBuilder documentBuilder;
44
45 @Before
46 public void setUp() throws Exception {
47 definition = new DefaultWsdl11Definition();
48 TransformerFactory transformerFactory = TransformerFactory.newInstance();
49 transformer = transformerFactory.newTransformer();
50 DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
51 documentBuilderFactory.setNamespaceAware(true);
52 documentBuilder = documentBuilderFactory.newDocumentBuilder();
53 XMLUnit.setIgnoreWhitespace(true);
54 }
55
56 @Test
57 public void testSingle() throws Exception {
58 Resource resource = new ClassPathResource("single.xsd", getClass());
59 SimpleXsdSchema schema = new SimpleXsdSchema(resource);
60 schema.afterPropertiesSet();
61 definition.setSchema(schema);
62
63 definition.setTargetNamespace("http://www.springframework.org/spring-ws/single/definitions");
64 definition.setPortTypeName("Order");
65 definition.setLocationUri("http://localhost:8080/");
66
67 definition.afterPropertiesSet();
68
69 DOMResult domResult = new DOMResult();
70 transformer.transform(definition.getSource(), domResult);
71
72 Document result = (Document) domResult.getNode();
73 Document expected = documentBuilder.parse(getClass().getResourceAsStream("single-inline.wsdl"));
74
75 assertXMLEqual("Invalid WSDL built", expected, result);
76
77 }
78
79 @Test
80 public void testInclude() throws Exception {
81 ClassPathResource resource = new ClassPathResource("including.xsd", getClass());
82 CommonsXsdSchemaCollection schemaCollection = new CommonsXsdSchemaCollection(new Resource[]{resource});
83 schemaCollection.setInline(true);
84 schemaCollection.afterPropertiesSet();
85 definition.setSchemaCollection(schemaCollection);
86
87 definition.setPortTypeName("Order");
88 definition.setTargetNamespace("http://www.springframework.org/spring-ws/include/definitions");
89 definition.setLocationUri("http://localhost:8080/");
90 definition.afterPropertiesSet();
91
92 DOMResult domResult = new DOMResult();
93 transformer.transform(definition.getSource(), domResult);
94
95 Document result = (Document) domResult.getNode();
96 Document expected = documentBuilder.parse(getClass().getResourceAsStream("include-inline.wsdl"));
97 assertXMLEqual("Invalid WSDL built", expected, result);
98 }
99
100 @Test
101 public void testImport() throws Exception {
102 ClassPathResource resource = new ClassPathResource("importing.xsd", getClass());
103 CommonsXsdSchemaCollection schemaCollection = new CommonsXsdSchemaCollection(new Resource[]{resource});
104 schemaCollection.setInline(true);
105 schemaCollection.afterPropertiesSet();
106 definition.setSchemaCollection(schemaCollection);
107
108 definition.setPortTypeName("Order");
109 definition.setTargetNamespace("http://www.springframework.org/spring-ws/import/definitions");
110 definition.setLocationUri("http://localhost:8080/");
111 definition.afterPropertiesSet();
112
113 DOMResult domResult = new DOMResult();
114 transformer.transform(definition.getSource(), domResult);
115
116 Document result = (Document) domResult.getNode();
117 Document expected = documentBuilder.parse(getClass().getResourceAsStream("import-inline.wsdl"));
118 assertXMLEqual("Invalid WSDL built", expected, result);
119 }
120
121 @Test
122 public void testSoap11And12() throws Exception {
123 Resource resource = new ClassPathResource("single.xsd", getClass());
124 SimpleXsdSchema schema = new SimpleXsdSchema(resource);
125 schema.afterPropertiesSet();
126 definition.setSchema(schema);
127
128 definition.setTargetNamespace("http://www.springframework.org/spring-ws/single/definitions");
129 definition.setPortTypeName("Order");
130 definition.setLocationUri("http://localhost:8080/");
131 definition.setCreateSoap11Binding(true);
132 definition.setCreateSoap12Binding(true);
133
134 definition.afterPropertiesSet();
135
136 DOMResult domResult = new DOMResult();
137 transformer.transform(definition.getSource(), domResult);
138
139 Document result = (Document) domResult.getNode();
140 Document expected = documentBuilder.parse(getClass().getResourceAsStream("soap-11-12.wsdl"));
141
142 assertXMLEqual("Invalid WSDL built", expected, result);
143
144 }
145
146
147 }