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.builder;
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.springframework.core.io.ClassPathResource;
28: import org.springframework.ws.wsdl.wsdl11.Wsdl11Definition;
29: import org.w3c.dom.Document;
30:
31: public class XsdBasedSoap11Wsdl4jDefinitionBuilderTest extends
32: XMLTestCase {
33:
34: private XsdBasedSoap11Wsdl4jDefinitionBuilder builder;
35:
36: private Transformer transformer;
37:
38: protected void setUp() throws Exception {
39: builder = new XsdBasedSoap11Wsdl4jDefinitionBuilder();
40: builder.setSchema(new ClassPathResource("schema.xsd",
41: getClass()));
42: builder.setPortTypeName("Airline");
43: builder
44: .setTargetNamespace("http://www.springframework.org/spring-ws/wsdl/definitions");
45: builder.setLocationUri("http://localhost:8080/");
46: builder.afterPropertiesSet();
47: TransformerFactory transformerFactory = TransformerFactory
48: .newInstance();
49: transformer = transformerFactory.newTransformer();
50: }
51:
52: public void testNonExistingSchema() throws Exception {
53: try {
54: builder.setSchema(new ClassPathResource("bla"));
55: fail("IllegalArgumentException expected");
56: } catch (IllegalArgumentException ex) {
57: // expected
58: }
59: }
60:
61: public void testBuilder() throws Exception {
62: builder.buildDefinition();
63: builder.buildDefinition();
64: builder.buildImports();
65: builder.buildTypes();
66: builder.buildMessages();
67: builder.buildPortTypes();
68: builder.buildBindings();
69: builder.buildServices();
70: Wsdl11Definition definition = builder.getDefinition();
71: DOMResult domResult = new DOMResult();
72: transformer.transform(definition.getSource(), domResult);
73:
74: Document result = (Document) domResult.getNode();
75: DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory
76: .newInstance();
77: documentBuilderFactory.setNamespaceAware(true);
78: DocumentBuilder documentBuilder = documentBuilderFactory
79: .newDocumentBuilder();
80: Document expected = documentBuilder.parse(getClass()
81: .getResourceAsStream("expected.wsdl"));
82: XMLUnit.setIgnoreWhitespace(true);
83: assertXMLEqual("Invalid WSDL built", expected, result);
84: }
85:
86: }
|