1   /*
2    * Copyright ${YEAR} 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.BindingFault;
22  import javax.wsdl.BindingInput;
23  import javax.wsdl.BindingOperation;
24  import javax.wsdl.BindingOutput;
25  import javax.wsdl.Definition;
26  import javax.wsdl.Fault;
27  import javax.wsdl.Input;
28  import javax.wsdl.Operation;
29  import javax.wsdl.OperationType;
30  import javax.wsdl.Output;
31  import javax.wsdl.Port;
32  import javax.wsdl.PortType;
33  import javax.wsdl.Service;
34  import javax.wsdl.extensions.soap.SOAPAddress;
35  import javax.wsdl.extensions.soap.SOAPBinding;
36  import javax.wsdl.extensions.soap.SOAPBody;
37  import javax.wsdl.extensions.soap.SOAPFault;
38  import javax.wsdl.extensions.soap.SOAPOperation;
39  import javax.wsdl.factory.WSDLFactory;
40  import javax.xml.namespace.QName;
41  
42  import junit.framework.TestCase;
43  
44  public class Soap11ProviderTest extends TestCase {
45  
46      private Soap11Provider provider;
47  
48      private Definition definition;
49  
50      protected void setUp() throws Exception {
51          provider = new Soap11Provider();
52          WSDLFactory factory = WSDLFactory.newInstance();
53          definition = factory.newDefinition();
54      }
55  
56      public void testPopulateBinding() throws Exception {
57          String namespace = "http://springframework.org/spring-ws";
58          definition.addNamespace("tns", namespace);
59          definition.setTargetNamespace(namespace);
60  
61          PortType portType = definition.createPortType();
62          portType.setQName(new QName(namespace, "PortType"));
63          portType.setUndefined(false);
64          definition.addPortType(portType);
65          Operation operation = definition.createOperation();
66          operation.setName("Operation");
67          operation.setUndefined(false);
68          operation.setStyle(OperationType.REQUEST_RESPONSE);
69          portType.addOperation(operation);
70          Input input = definition.createInput();
71          input.setName("Input");
72          operation.setInput(input);
73          Output output = definition.createOutput();
74          output.setName("Output");
75          operation.setOutput(output);
76          Fault fault = definition.createFault();
77          fault.setName("Fault");
78          operation.addFault(fault);
79  
80          Properties soapActions = new Properties();
81          soapActions.setProperty("Operation", namespace + "/Action");
82          provider.setSoapActions(soapActions);
83  
84          provider.setServiceName("Service");
85  
86          String locationUri = "http://localhost:8080/services";
87          provider.setLocationUri(locationUri);
88  
89          provider.addBindings(definition);
90          provider.addServices(definition);
91  
92          Binding binding = definition.getBinding(new QName(namespace, "PortTypeSoap11"));
93          assertNotNull("No binding created", binding);
94          assertEquals("Invalid port type", portType, binding.getPortType());
95          assertEquals("Invalid amount of extensibility elements", 1, binding.getExtensibilityElements().size());
96  
97          SOAPBinding soapBinding = (SOAPBinding) binding.getExtensibilityElements().get(0);
98          assertEquals("Invalid style", "document", soapBinding.getStyle());
99          assertEquals("Invalid amount of binding operations", 1, binding.getBindingOperations().size());
100 
101         BindingOperation bindingOperation = binding.getBindingOperation("Operation", "Input", "Output");
102         assertNotNull("No binding operation created", bindingOperation);
103         assertEquals("Invalid amount of extensibility elements", 1, bindingOperation.getExtensibilityElements().size());
104 
105         SOAPOperation soapOperation = (SOAPOperation) bindingOperation.getExtensibilityElements().get(0);
106         assertEquals("Invalid SOAPAction", namespace + "/Action", soapOperation.getSoapActionURI());
107 
108         BindingInput bindingInput = bindingOperation.getBindingInput();
109         assertNotNull("No binding input", bindingInput);
110         assertEquals("Invalid name", "Input", bindingInput.getName());
111         assertEquals("Invalid amount of extensibility elements", 1, bindingInput.getExtensibilityElements().size());
112         SOAPBody soapBody = (SOAPBody) bindingInput.getExtensibilityElements().get(0);
113         assertEquals("Invalid soap body use", "literal", soapBody.getUse());
114 
115         BindingOutput bindingOutput = bindingOperation.getBindingOutput();
116         assertNotNull("No binding output", bindingOutput);
117         assertEquals("Invalid name", "Output", bindingOutput.getName());
118         assertEquals("Invalid amount of extensibility elements", 1, bindingOutput.getExtensibilityElements().size());
119         soapBody = (SOAPBody) bindingOutput.getExtensibilityElements().get(0);
120         assertEquals("Invalid soap body use", "literal", soapBody.getUse());
121 
122         BindingFault bindingFault = bindingOperation.getBindingFault("Fault");
123         assertNotNull("No binding fault", bindingFault);
124         assertEquals("Invalid amount of extensibility elements", 1, bindingFault.getExtensibilityElements().size());
125         SOAPFault soapFault = (SOAPFault) bindingFault.getExtensibilityElements().get(0);
126         assertEquals("Invalid soap fault use", "literal", soapFault.getUse());
127 
128         Service service = definition.getService(new QName(namespace, "Service"));
129         assertNotNull("No Service created", service);
130         assertEquals("Invalid amount of ports", 1, service.getPorts().size());
131 
132         Port port = service.getPort("PortTypeSoap11");
133         assertNotNull("No port created", port);
134         assertEquals("Invalid binding", binding, port.getBinding());
135         assertEquals("Invalid amount of extensibility elements", 1, port.getExtensibilityElements().size());
136 
137         SOAPAddress soapAddress = (SOAPAddress) port.getExtensibilityElements().get(0);
138         assertEquals("Invalid soap address", locationUri, soapAddress.getLocationURI());
139     }
140 
141 
142 }