01: /*
02: * Copyright 2006 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
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.XMLTestCase;
31: import org.custommonkey.xmlunit.XMLUnit;
32: import org.w3c.dom.Document;
33: import org.xml.sax.InputSource;
34:
35: public class Wsdl4jDefinitionTest extends XMLTestCase {
36:
37: private Wsdl4jDefinition definition;
38:
39: private Transformer transformer;
40:
41: protected void setUp() throws Exception {
42: XMLUnit.setIgnoreWhitespace(true);
43: WSDLFactory factory = WSDLFactory.newInstance();
44: WSDLReader reader = factory.newWSDLReader();
45: InputStream is = getClass()
46: .getResourceAsStream("complete.wsdl");
47: try {
48: Definition wsdl4jDefinition = reader.readWSDL(null,
49: new InputSource(is));
50: definition = new Wsdl4jDefinition(wsdl4jDefinition);
51: } finally {
52: is.close();
53: }
54: transformer = TransformerFactory.newInstance().newTransformer();
55: }
56:
57: public void testGetSource() throws Exception {
58: Source source = definition.getSource();
59: assertNotNull("Source is null", source);
60: DOMResult result = new DOMResult();
61: transformer.transform(source, result);
62: DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory
63: .newInstance();
64: documentBuilderFactory.setNamespaceAware(true);
65: DocumentBuilder documentBuilder = documentBuilderFactory
66: .newDocumentBuilder();
67: Document expected = documentBuilder.parse(getClass()
68: .getResourceAsStream("complete.wsdl"));
69: assertXMLEqual(expected, (Document) result.getNode());
70: }
71: }
|