1   /*
2    * Copyright 2006 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
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().getResourceAsStream("complete.wsdl");
46          try {
47              Definition wsdl4jDefinition = reader.readWSDL(null, new InputSource(is));
48              definition = new Wsdl4jDefinition(wsdl4jDefinition);
49          }
50          finally {
51              is.close();
52          }
53          transformer = TransformerFactory.newInstance().newTransformer();
54      }
55  
56      public void testGetSource() throws Exception {
57          Source source = definition.getSource();
58          assertNotNull("Source is null", source);
59          DOMResult result = new DOMResult();
60          transformer.transform(source, result);
61          DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
62          documentBuilderFactory.setNamespaceAware(true);
63          DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
64          Document expected = documentBuilder.parse(getClass().getResourceAsStream("complete.wsdl"));
65          assertXMLEqual(expected, (Document) result.getNode());
66      }
67  }