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 java.util.Properties;
20  import javax.wsdl.Binding;
21  import javax.wsdl.Definition;
22  import javax.wsdl.Fault;
23  import javax.wsdl.Input;
24  import javax.wsdl.Operation;
25  import javax.wsdl.OperationType;
26  import javax.wsdl.Output;
27  import javax.wsdl.Port;
28  import javax.wsdl.PortType;
29  import javax.wsdl.Service;
30  import javax.wsdl.factory.WSDLFactory;
31  import javax.xml.namespace.QName;
32  
33  import org.junit.Assert;
34  import org.junit.Before;
35  import org.junit.Test;
36  
37  public class SoapProviderTest {
38  
39      private SoapProvider provider;
40  
41      private Definition definition;
42  
43      @Before
44      public void setUp() throws Exception {
45          provider = new SoapProvider();
46          WSDLFactory factory = WSDLFactory.newInstance();
47          definition = factory.newDefinition();
48      }
49  
50      @Test
51      public void testPopulateBinding() throws Exception {
52          String namespace = "http://springframework.org/spring-ws";
53          definition.addNamespace("tns", namespace);
54          definition.setTargetNamespace(namespace);
55  
56          PortType portType = definition.createPortType();
57          portType.setQName(new QName(namespace, "PortType"));
58          portType.setUndefined(false);
59          definition.addPortType(portType);
60          Operation operation = definition.createOperation();
61          operation.setName("Operation");
62          operation.setUndefined(false);
63          operation.setStyle(OperationType.REQUEST_RESPONSE);
64          portType.addOperation(operation);
65          Input input = definition.createInput();
66          input.setName("Input");
67          operation.setInput(input);
68          Output output = definition.createOutput();
69          output.setName("Output");
70          operation.setOutput(output);
71          Fault fault = definition.createFault();
72          fault.setName("Fault");
73          operation.addFault(fault);
74  
75          Properties soapActions = new Properties();
76          soapActions.setProperty("Operation", namespace + "/Action");
77          provider.setSoapActions(soapActions);
78  
79          provider.setServiceName("Service");
80  
81          String locationUri = "http://localhost:8080/services";
82          provider.setLocationUri(locationUri);
83  
84          provider.setCreateSoap11Binding(true);
85          provider.setCreateSoap12Binding(true);
86  
87          provider.addBindings(definition);
88          provider.addServices(definition);
89  
90          Binding binding = definition.getBinding(new QName(namespace, "PortTypeSoap11"));
91          Assert.assertNotNull("No SOAP 1.1 binding created", binding);
92          binding = definition.getBinding(new QName(namespace, "PortTypeSoap12"));
93          Assert.assertNotNull("No SOAP 1.2 binding created", binding);
94  
95          Service service = definition.getService(new QName(namespace, "Service"));
96          Assert.assertNotNull("No Service created", service);
97          Assert.assertEquals("Invalid amount of ports", 2, service.getPorts().size());
98  
99          Port port = service.getPort("PortTypeSoap11");
100         Assert.assertNotNull("No SOAP 1.1 port created", port);
101         port = service.getPort("PortTypeSoap12");
102         Assert.assertNotNull("No SOAP 1.2 port created", port);
103     }
104 
105 
106 }