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.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 }