1   /*
2    * Copyright 2005-2010 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.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  }