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