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.provider;
18  
19  import javax.wsdl.Definition;
20  import javax.wsdl.Message;
21  import javax.wsdl.Operation;
22  import javax.wsdl.PortType;
23  import javax.wsdl.factory.WSDLFactory;
24  import javax.xml.namespace.QName;
25  
26  import org.junit.Assert;
27  import org.junit.Before;
28  import org.junit.Test;
29  
30  public class SuffixBasedPortTypesProviderTest {
31  
32      private SuffixBasedPortTypesProvider provider;
33  
34      private Definition definition;
35  
36      @Before
37      public void setUp() throws Exception {
38          provider = new SuffixBasedPortTypesProvider();
39          WSDLFactory factory = WSDLFactory.newInstance();
40          definition = factory.newDefinition();
41      }
42  
43      @Test
44      public void testAddPortTypes() throws Exception {
45          String namespace = "http://springframework.org/spring-ws";
46          definition.addNamespace("tns", namespace);
47          definition.setTargetNamespace(namespace);
48  
49          Message message = definition.createMessage();
50          message.setQName(new QName(namespace, "OperationRequest"));
51          definition.addMessage(message);
52  
53          message = definition.createMessage();
54          message.setQName(new QName(namespace, "OperationResponse"));
55          definition.addMessage(message);
56  
57          message = definition.createMessage();
58          message.setQName(new QName(namespace, "OperationFault"));
59          definition.addMessage(message);
60  
61          provider.setPortTypeName("PortType");
62          provider.addPortTypes(definition);
63  
64          PortType portType = definition.getPortType(new QName(namespace, "PortType"));
65          Assert.assertNotNull("No port type created", portType);
66  
67          Operation operation = portType.getOperation("Operation", "OperationRequest", "OperationResponse");
68          Assert.assertNotNull("No operation created", operation);
69          Assert.assertNotNull("No input created", operation.getInput());
70          Assert.assertNotNull("No output created", operation.getOutput());
71          Assert.assertFalse("No fault created", operation.getFaults().isEmpty());
72      }
73  }