1
2
3
4
5
6
7
8
9
10
11
12
13
14
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.soap12.SOAP12Address;
35 import javax.wsdl.extensions.soap12.SOAP12Binding;
36 import javax.wsdl.extensions.soap12.SOAP12Body;
37 import javax.wsdl.extensions.soap12.SOAP12Fault;
38 import javax.wsdl.extensions.soap12.SOAP12Operation;
39 import javax.wsdl.factory.WSDLFactory;
40 import javax.xml.namespace.QName;
41
42 import junit.framework.TestCase;
43
44 public class Soap12ProviderTest extends TestCase {
45
46 private Soap12Provider provider;
47
48 private Definition definition;
49
50 protected void setUp() throws Exception {
51 provider = new Soap12Provider();
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, "PortTypeSoap12"));
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 SOAP12Binding soapBinding = (SOAP12Binding) 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 SOAP12Operation soapOperation = (SOAP12Operation) 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 SOAP12Body soapBody = (SOAP12Body) 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 = (SOAP12Body) 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 SOAP12Fault soapFault = (SOAP12Fault) 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("PortTypeSoap12");
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 SOAP12Address soapAddress = (SOAP12Address) port.getExtensibilityElements().get(0);
138 assertEquals("Invalid soap address", locationUri, soapAddress.getLocationURI());
139 }
140
141
142 }