Done working on WSDL in sandbox.

This commit is contained in:
Arjen Poutsma
2008-03-08 02:47:59 +00:00
parent b56e6313ca
commit a833243ac2
53 changed files with 2902 additions and 1957 deletions

View File

@@ -0,0 +1,75 @@
/*
* Copyright ${YEAR} the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.ws.wsdl.wsdl11;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;
import junit.framework.TestCase;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.ws.wsdl.wsdl11.provider.InliningXsdSchemaTypesProviderTest;
import org.springframework.xml.xsd.SimpleXsdSchema;
import org.springframework.xml.xsd.commons.CommonsXsdSchemaCollection;
public class DefaultWsdl11DefinitionTest extends TestCase {
private DefaultWsdl11Definition definition;
private Transformer transformer;
protected void setUp() throws Exception {
definition = new DefaultWsdl11Definition();
TransformerFactory transformerFactory = TransformerFactory.newInstance();
transformer = transformerFactory.newTransformer();
}
public void testSingle() throws Exception {
Resource resource = new ClassPathResource("single.xsd", getClass());
SimpleXsdSchema schema = new SimpleXsdSchema(resource);
schema.afterPropertiesSet();
definition.setSchema(schema);
definition.setTargetNamespace("http://www.springframework.org/spring-ws/single/definitions");
definition.setPortTypeName("Order");
definition.setLocationUri("http://localhost:8080/");
definition.afterPropertiesSet();
transformer.transform(definition.getSource(), new StreamResult(System.out));
}
public void testComplex() throws Exception {
Resource resource = new ClassPathResource("A.xsd", InliningXsdSchemaTypesProviderTest.class);
CommonsXsdSchemaCollection collection = new CommonsXsdSchemaCollection(new Resource[]{resource});
collection.setInline(true);
collection.afterPropertiesSet();
definition.setSchemaCollection(collection);
definition.setTargetNamespace("http://www.springframework.org/spring-ws/single/definitions");
definition.setPortTypeName("Order");
definition.setLocationUri("http://localhost:8080/");
definition.afterPropertiesSet();
transformer.transform(definition.getSource(), new StreamResult(System.out));
}
}

View File

@@ -1,51 +0,0 @@
/*
* Copyright ${YEAR} the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.ws.wsdl.wsdl11;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.stream.StreamResult;
import junit.framework.*;
import org.springframework.ws.wsdl.wsdl11.XsdSchemaWsdl11Definition;
import org.springframework.xml.xsd.XsdSchema;
import org.springframework.xml.xsd.SimpleXsdSchema;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ClassPathResource;
public class XsdSchemaWsdl11DefinitionTest extends TestCase {
private XsdSchemaWsdl11Definition definition;
protected void setUp() throws Exception {
definition = new XsdSchemaWsdl11Definition();
}
public void testDefinition() throws Exception {
ClassPathResource resource = new ClassPathResource("A.xsd", getClass());
definition.setSchemas(new Resource[] {resource});
definition.setTargetNamespace("http://springframework.org/spring-ws");
definition.afterPropertiesSet();
Transformer tr = TransformerFactory.newInstance().newTransformer();
tr.setOutputProperty(OutputKeys.INDENT, "yes");
tr.transform(definition.getSource(), new StreamResult(System.out));
}
}

View File

@@ -0,0 +1,89 @@
/*
* Copyright ${YEAR} the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.ws.wsdl.wsdl11.provider;
import javax.wsdl.Definition;
import javax.wsdl.Message;
import javax.wsdl.Part;
import javax.wsdl.Types;
import javax.wsdl.extensions.schema.Schema;
import javax.wsdl.factory.WSDLFactory;
import javax.xml.namespace.QName;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import junit.framework.TestCase;
import org.w3c.dom.Document;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.xml.sax.SaxUtils;
public class DefaultMessagesProviderTest extends TestCase {
private DefaultMessagesProvider provider;
private Definition definition;
private DocumentBuilder documentBuilder;
protected void setUp() throws Exception {
provider = new DefaultMessagesProvider();
WSDLFactory factory = WSDLFactory.newInstance();
definition = factory.newDefinition();
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
documentBuilderFactory.setNamespaceAware(true);
documentBuilder = documentBuilderFactory.newDocumentBuilder();
}
public void testAddMessages() throws Exception {
String definitionNamespace = "http://springframework.org/spring-ws";
definition.addNamespace("tns", definitionNamespace);
definition.setTargetNamespace(definitionNamespace);
String schemaNamespace = "http://www.springframework.org/spring-ws/schema";
definition.addNamespace("schema", schemaNamespace);
Resource resource = new ClassPathResource("schema.xsd", getClass());
Document schemaDocument = documentBuilder.parse(SaxUtils.createInputSource(resource));
Types types = definition.createTypes();
definition.setTypes(types);
Schema schema = (Schema) definition.getExtensionRegistry()
.createExtension(Types.class, new QName("http://www.w3.org/2001/XMLSchema", "schema"));
types.addExtensibilityElement(schema);
schema.setElement(schemaDocument.getDocumentElement());
provider.addMessages(definition);
Message message = definition.getMessage(new QName(definitionNamespace, "GetOrderRequest"));
assertNotNull("Message not created", message);
Part part = message.getPart("GetOrderRequest");
assertNotNull("Part not created", part);
assertEquals("Invalid element on part", new QName(schemaNamespace, "GetOrderRequest"), part.getElementName());
message = definition.getMessage(new QName(definitionNamespace, "GetOrderResponse"));
assertNotNull("Message not created", message);
part = message.getPart("GetOrderResponse");
assertNotNull("Part not created", part);
assertEquals("Invalid element on part", new QName(schemaNamespace, "GetOrderResponse"), part.getElementName());
message = definition.getMessage(new QName(definitionNamespace, "GetOrderFault"));
assertNotNull("Message not created", message);
part = message.getPart("GetOrderFault");
assertNotNull("Part not created", part);
assertEquals("Invalid element on part", new QName(schemaNamespace, "GetOrderFault"), part.getElementName());
}
}

View File

@@ -0,0 +1,92 @@
/*
* Copyright ${YEAR} the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.ws.wsdl.wsdl11.provider;
import javax.wsdl.Definition;
import javax.wsdl.Types;
import javax.wsdl.extensions.schema.Schema;
import javax.wsdl.factory.WSDLFactory;
import junit.framework.TestCase;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.xml.xsd.SimpleXsdSchema;
import org.springframework.xml.xsd.commons.CommonsXsdSchemaCollection;
public class InliningXsdSchemaTypesProviderTest extends TestCase {
private InliningXsdSchemaTypesProvider provider;
private Definition definition;
protected void setUp() throws Exception {
provider = new InliningXsdSchemaTypesProvider();
WSDLFactory factory = WSDLFactory.newInstance();
definition = factory.newDefinition();
}
public void testSingle() throws Exception {
String definitionNamespace = "http://springframework.org/spring-ws";
definition.addNamespace("tns", definitionNamespace);
definition.setTargetNamespace(definitionNamespace);
String schemaNamespace = "http://www.springframework.org/spring-ws/schema";
definition.addNamespace("schema", schemaNamespace);
Resource resource = new ClassPathResource("schema.xsd", getClass());
SimpleXsdSchema schema = new SimpleXsdSchema(resource);
schema.afterPropertiesSet();
provider.setSchema(schema);
provider.addTypes(definition);
Types types = definition.getTypes();
assertNotNull("No types created", types);
assertEquals("Invalid amount of schemas", 1, types.getExtensibilityElements().size());
Schema wsdlSchema = (Schema) types.getExtensibilityElements().get(0);
assertNotNull("No element defined", wsdlSchema.getElement());
}
public void testComplex() throws Exception {
String definitionNamespace = "http://springframework.org/spring-ws";
definition.addNamespace("tns", definitionNamespace);
definition.setTargetNamespace(definitionNamespace);
String schemaNamespace = "http://www.springframework.org/spring-ws/schema";
definition.addNamespace("schema", schemaNamespace);
Resource resource = new ClassPathResource("A.xsd", getClass());
CommonsXsdSchemaCollection collection = new CommonsXsdSchemaCollection(new Resource[]{resource});
collection.setInline(true);
collection.afterPropertiesSet();
provider.setSchemaCollection(collection);
provider.addTypes(definition);
Types types = definition.getTypes();
assertNotNull("No types created", types);
assertEquals("Invalid amount of schemas", 2, types.getExtensibilityElements().size());
Schema wsdlSchema = (Schema) types.getExtensibilityElements().get(0);
assertNotNull("No element defined", wsdlSchema.getElement());
wsdlSchema = (Schema) types.getExtensibilityElements().get(1);
assertNotNull("No element defined", wsdlSchema.getElement());
}
}

View File

@@ -0,0 +1,142 @@
/*
* Copyright ${YEAR} the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.ws.wsdl.wsdl11.provider;
import java.util.Properties;
import javax.wsdl.Binding;
import javax.wsdl.BindingFault;
import javax.wsdl.BindingInput;
import javax.wsdl.BindingOperation;
import javax.wsdl.BindingOutput;
import javax.wsdl.Definition;
import javax.wsdl.Fault;
import javax.wsdl.Input;
import javax.wsdl.Operation;
import javax.wsdl.OperationType;
import javax.wsdl.Output;
import javax.wsdl.Port;
import javax.wsdl.PortType;
import javax.wsdl.Service;
import javax.wsdl.extensions.soap.SOAPAddress;
import javax.wsdl.extensions.soap.SOAPBinding;
import javax.wsdl.extensions.soap.SOAPBody;
import javax.wsdl.extensions.soap.SOAPFault;
import javax.wsdl.extensions.soap.SOAPOperation;
import javax.wsdl.factory.WSDLFactory;
import javax.xml.namespace.QName;
import junit.framework.TestCase;
public class Soap11ProviderTest extends TestCase {
private Soap11Provider provider;
private Definition definition;
protected void setUp() throws Exception {
provider = new Soap11Provider();
WSDLFactory factory = WSDLFactory.newInstance();
definition = factory.newDefinition();
}
public void testPopulateBinding() throws Exception {
String namespace = "http://springframework.org/spring-ws";
definition.addNamespace("tns", namespace);
definition.setTargetNamespace(namespace);
PortType portType = definition.createPortType();
portType.setQName(new QName(namespace, "PortType"));
portType.setUndefined(false);
definition.addPortType(portType);
Operation operation = definition.createOperation();
operation.setName("Operation");
operation.setUndefined(false);
operation.setStyle(OperationType.REQUEST_RESPONSE);
portType.addOperation(operation);
Input input = definition.createInput();
input.setName("Input");
operation.setInput(input);
Output output = definition.createOutput();
output.setName("Output");
operation.setOutput(output);
Fault fault = definition.createFault();
fault.setName("Fault");
operation.addFault(fault);
Properties soapActions = new Properties();
soapActions.setProperty("Operation", namespace + "/Action");
provider.setSoapActions(soapActions);
provider.setServiceName("Service");
String locationUri = "http://localhost:8080/services";
provider.setLocationUri(locationUri);
provider.addBindings(definition);
provider.addServices(definition);
Binding binding = definition.getBinding(new QName(namespace, "PortTypeSoap11"));
assertNotNull("No binding created", binding);
assertEquals("Invalid port type", portType, binding.getPortType());
assertEquals("Invalid amount of extensibility elements", 1, binding.getExtensibilityElements().size());
SOAPBinding soapBinding = (SOAPBinding) binding.getExtensibilityElements().get(0);
assertEquals("Invalid style", "document", soapBinding.getStyle());
assertEquals("Invalid amount of binding operations", 1, binding.getBindingOperations().size());
BindingOperation bindingOperation = binding.getBindingOperation("Operation", "Input", "Output");
assertNotNull("No binding operation created", bindingOperation);
assertEquals("Invalid amount of extensibility elements", 1, bindingOperation.getExtensibilityElements().size());
SOAPOperation soapOperation = (SOAPOperation) bindingOperation.getExtensibilityElements().get(0);
assertEquals("Invalid SOAPAction", namespace + "/Action", soapOperation.getSoapActionURI());
BindingInput bindingInput = bindingOperation.getBindingInput();
assertNotNull("No binding input", bindingInput);
assertEquals("Invalid name", "Input", bindingInput.getName());
assertEquals("Invalid amount of extensibility elements", 1, bindingInput.getExtensibilityElements().size());
SOAPBody soapBody = (SOAPBody) bindingInput.getExtensibilityElements().get(0);
assertEquals("Invalid soap body use", "literal", soapBody.getUse());
BindingOutput bindingOutput = bindingOperation.getBindingOutput();
assertNotNull("No binding output", bindingOutput);
assertEquals("Invalid name", "Output", bindingOutput.getName());
assertEquals("Invalid amount of extensibility elements", 1, bindingOutput.getExtensibilityElements().size());
soapBody = (SOAPBody) bindingOutput.getExtensibilityElements().get(0);
assertEquals("Invalid soap body use", "literal", soapBody.getUse());
BindingFault bindingFault = bindingOperation.getBindingFault("Fault");
assertNotNull("No binding fault", bindingFault);
assertEquals("Invalid amount of extensibility elements", 1, bindingFault.getExtensibilityElements().size());
SOAPFault soapFault = (SOAPFault) bindingFault.getExtensibilityElements().get(0);
assertEquals("Invalid soap fault use", "literal", soapFault.getUse());
Service service = definition.getService(new QName(namespace, "Service"));
assertNotNull("No Service created", service);
assertEquals("Invalid amount of ports", 1, service.getPorts().size());
Port port = service.getPort("PortTypeSoap11");
assertNotNull("No port created", port);
assertEquals("Invalid binding", binding, port.getBinding());
assertEquals("Invalid amount of extensibility elements", 1, port.getExtensibilityElements().size());
SOAPAddress soapAddress = (SOAPAddress) port.getExtensibilityElements().get(0);
assertEquals("Invalid soap address", locationUri, soapAddress.getLocationURI());
}
}

View File

@@ -0,0 +1,142 @@
/*
* Copyright ${YEAR} the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.ws.wsdl.wsdl11.provider;
import java.util.Properties;
import javax.wsdl.Binding;
import javax.wsdl.BindingFault;
import javax.wsdl.BindingInput;
import javax.wsdl.BindingOperation;
import javax.wsdl.BindingOutput;
import javax.wsdl.Definition;
import javax.wsdl.Fault;
import javax.wsdl.Input;
import javax.wsdl.Operation;
import javax.wsdl.OperationType;
import javax.wsdl.Output;
import javax.wsdl.Port;
import javax.wsdl.PortType;
import javax.wsdl.Service;
import javax.wsdl.extensions.soap12.SOAP12Address;
import javax.wsdl.extensions.soap12.SOAP12Binding;
import javax.wsdl.extensions.soap12.SOAP12Body;
import javax.wsdl.extensions.soap12.SOAP12Fault;
import javax.wsdl.extensions.soap12.SOAP12Operation;
import javax.wsdl.factory.WSDLFactory;
import javax.xml.namespace.QName;
import junit.framework.TestCase;
public class Soap12ProviderTest extends TestCase {
private Soap12Provider provider;
private Definition definition;
protected void setUp() throws Exception {
provider = new Soap12Provider();
WSDLFactory factory = WSDLFactory.newInstance();
definition = factory.newDefinition();
}
public void testPopulateBinding() throws Exception {
String namespace = "http://springframework.org/spring-ws";
definition.addNamespace("tns", namespace);
definition.setTargetNamespace(namespace);
PortType portType = definition.createPortType();
portType.setQName(new QName(namespace, "PortType"));
portType.setUndefined(false);
definition.addPortType(portType);
Operation operation = definition.createOperation();
operation.setName("Operation");
operation.setUndefined(false);
operation.setStyle(OperationType.REQUEST_RESPONSE);
portType.addOperation(operation);
Input input = definition.createInput();
input.setName("Input");
operation.setInput(input);
Output output = definition.createOutput();
output.setName("Output");
operation.setOutput(output);
Fault fault = definition.createFault();
fault.setName("Fault");
operation.addFault(fault);
Properties soapActions = new Properties();
soapActions.setProperty("Operation", namespace + "/Action");
provider.setSoapActions(soapActions);
provider.setServiceName("Service");
String locationUri = "http://localhost:8080/services";
provider.setLocationUri(locationUri);
provider.addBindings(definition);
provider.addServices(definition);
Binding binding = definition.getBinding(new QName(namespace, "PortTypeSoap12"));
assertNotNull("No binding created", binding);
assertEquals("Invalid port type", portType, binding.getPortType());
assertEquals("Invalid amount of extensibility elements", 1, binding.getExtensibilityElements().size());
SOAP12Binding soapBinding = (SOAP12Binding) binding.getExtensibilityElements().get(0);
assertEquals("Invalid style", "document", soapBinding.getStyle());
assertEquals("Invalid amount of binding operations", 1, binding.getBindingOperations().size());
BindingOperation bindingOperation = binding.getBindingOperation("Operation", "Input", "Output");
assertNotNull("No binding operation created", bindingOperation);
assertEquals("Invalid amount of extensibility elements", 1, bindingOperation.getExtensibilityElements().size());
SOAP12Operation soapOperation = (SOAP12Operation) bindingOperation.getExtensibilityElements().get(0);
assertEquals("Invalid SOAPAction", namespace + "/Action", soapOperation.getSoapActionURI());
BindingInput bindingInput = bindingOperation.getBindingInput();
assertNotNull("No binding input", bindingInput);
assertEquals("Invalid name", "Input", bindingInput.getName());
assertEquals("Invalid amount of extensibility elements", 1, bindingInput.getExtensibilityElements().size());
SOAP12Body soapBody = (SOAP12Body) bindingInput.getExtensibilityElements().get(0);
assertEquals("Invalid soap body use", "literal", soapBody.getUse());
BindingOutput bindingOutput = bindingOperation.getBindingOutput();
assertNotNull("No binding output", bindingOutput);
assertEquals("Invalid name", "Output", bindingOutput.getName());
assertEquals("Invalid amount of extensibility elements", 1, bindingOutput.getExtensibilityElements().size());
soapBody = (SOAP12Body) bindingOutput.getExtensibilityElements().get(0);
assertEquals("Invalid soap body use", "literal", soapBody.getUse());
BindingFault bindingFault = bindingOperation.getBindingFault("Fault");
assertNotNull("No binding fault", bindingFault);
assertEquals("Invalid amount of extensibility elements", 1, bindingFault.getExtensibilityElements().size());
SOAP12Fault soapFault = (SOAP12Fault) bindingFault.getExtensibilityElements().get(0);
assertEquals("Invalid soap fault use", "literal", soapFault.getUse());
Service service = definition.getService(new QName(namespace, "Service"));
assertNotNull("No Service created", service);
assertEquals("Invalid amount of ports", 1, service.getPorts().size());
Port port = service.getPort("PortTypeSoap12");
assertNotNull("No port created", port);
assertEquals("Invalid binding", binding, port.getBinding());
assertEquals("Invalid amount of extensibility elements", 1, port.getExtensibilityElements().size());
SOAP12Address soapAddress = (SOAP12Address) port.getExtensibilityElements().get(0);
assertEquals("Invalid soap address", locationUri, soapAddress.getLocationURI());
}
}

View File

@@ -0,0 +1,102 @@
/*
* Copyright ${YEAR} the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.ws.wsdl.wsdl11.provider;
import java.util.Properties;
import javax.wsdl.Binding;
import javax.wsdl.Definition;
import javax.wsdl.Fault;
import javax.wsdl.Input;
import javax.wsdl.Operation;
import javax.wsdl.OperationType;
import javax.wsdl.Output;
import javax.wsdl.Port;
import javax.wsdl.PortType;
import javax.wsdl.Service;
import javax.wsdl.factory.WSDLFactory;
import javax.xml.namespace.QName;
import junit.framework.TestCase;
public class SoapProviderTest extends TestCase {
private SoapProvider provider;
private Definition definition;
protected void setUp() throws Exception {
provider = new SoapProvider();
WSDLFactory factory = WSDLFactory.newInstance();
definition = factory.newDefinition();
}
public void testPopulateBinding() throws Exception {
String namespace = "http://springframework.org/spring-ws";
definition.addNamespace("tns", namespace);
definition.setTargetNamespace(namespace);
PortType portType = definition.createPortType();
portType.setQName(new QName(namespace, "PortType"));
portType.setUndefined(false);
definition.addPortType(portType);
Operation operation = definition.createOperation();
operation.setName("Operation");
operation.setUndefined(false);
operation.setStyle(OperationType.REQUEST_RESPONSE);
portType.addOperation(operation);
Input input = definition.createInput();
input.setName("Input");
operation.setInput(input);
Output output = definition.createOutput();
output.setName("Output");
operation.setOutput(output);
Fault fault = definition.createFault();
fault.setName("Fault");
operation.addFault(fault);
Properties soapActions = new Properties();
soapActions.setProperty("Operation", namespace + "/Action");
provider.setSoapActions(soapActions);
provider.setServiceName("Service");
String locationUri = "http://localhost:8080/services";
provider.setLocationUri(locationUri);
provider.setCreateSoap11Binding(true);
provider.setCreateSoap12Binding(true);
provider.addBindings(definition);
provider.addServices(definition);
Binding binding = definition.getBinding(new QName(namespace, "PortTypeSoap11"));
assertNotNull("No SOAP 1.1 binding created", binding);
binding = definition.getBinding(new QName(namespace, "PortTypeSoap12"));
assertNotNull("No SOAP 1.2 binding created", binding);
Service service = definition.getService(new QName(namespace, "Service"));
assertNotNull("No Service created", service);
assertEquals("Invalid amount of ports", 2, service.getPorts().size());
Port port = service.getPort("PortTypeSoap11");
assertNotNull("No SOAP 1.1 port created", port);
port = service.getPort("PortTypeSoap12");
assertNotNull("No SOAP 1.2 port created", port);
}
}

View File

@@ -0,0 +1,69 @@
/*
* Copyright ${YEAR} the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.ws.wsdl.wsdl11.provider;
import javax.wsdl.Definition;
import javax.wsdl.Message;
import javax.wsdl.Operation;
import javax.wsdl.PortType;
import javax.wsdl.factory.WSDLFactory;
import javax.xml.namespace.QName;
import junit.framework.TestCase;
public class SuffixBasedPortTypesProviderTest extends TestCase {
private SuffixBasedPortTypesProvider provider;
private Definition definition;
protected void setUp() throws Exception {
provider = new SuffixBasedPortTypesProvider();
WSDLFactory factory = WSDLFactory.newInstance();
definition = factory.newDefinition();
}
public void testAddPortTypes() throws Exception {
String namespace = "http://springframework.org/spring-ws";
definition.addNamespace("tns", namespace);
definition.setTargetNamespace(namespace);
Message message = definition.createMessage();
message.setQName(new QName(namespace, "OperationRequest"));
definition.addMessage(message);
message = definition.createMessage();
message.setQName(new QName(namespace, "OperationResponse"));
definition.addMessage(message);
message = definition.createMessage();
message.setQName(new QName(namespace, "OperationFault"));
definition.addMessage(message);
provider.setPortTypeName("PortType");
provider.addPortTypes(definition);
PortType portType = definition.getPortType(new QName(namespace, "PortType"));
assertNotNull("No port type created", portType);
Operation operation = portType.getOperation("Operation", "OperationRequest", "OperationResponse");
assertNotNull("No operation created", operation);
assertNotNull("No input created", operation.getInput());
assertNotNull("No output created", operation.getOutput());
assertFalse("No fault created", operation.getFaults().isEmpty());
}
}

View File

@@ -1,75 +0,0 @@
/*
* Copyright ${YEAR} the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.ws.wsdl.wsdl11.soap;
import java.util.Properties;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.stream.StreamResult;
import junit.framework.*;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
public class SoapWsdl11DefinitionTest extends TestCase {
private SoapWsdl11Definition definition;
protected void setUp() throws Exception {
definition = new MySoapWsdl11Definition();
}
public void testIt() throws Exception {
definition.setBeanName("wsdlDefinition");
definition.setTargetNamespace("http://springframework.org/spring-ws");
definition.setServiceName("Service");
definition.setLocationUri("http://localhost");
definition.setCreateSoap11Binding(true);
definition.setCreateSoap12Binding(true);
Properties soapActions = new Properties();
soapActions.setProperty("Operation", "http://springframework.org/spring-ws/Action");
definition.setSoapActions(soapActions);
definition.afterPropertiesSet();
Transformer tr = TransformerFactory.newInstance().newTransformer();
tr.setOutputProperty(OutputKeys.INDENT, "yes");
tr.transform(definition.getSource(), new StreamResult(System.out));
}
private static class MySoapWsdl11Definition extends SoapWsdl11Definition {
protected void addPortTypes(Document document, Element definitions) {
Element portType = createWsdlElement(document, "portType");
definitions.appendChild(portType);
portType.setAttribute("name", "PortType");
Element operation = createWsdlElement(document, "operation");
portType.appendChild(operation);
operation.setAttribute("name", "Operation");
Element input = createWsdlElement(document, "input");
operation.appendChild(input);
// input.setAttribute("name", "Input");
Element output = createWsdlElement(document, "output");
operation.appendChild(output);
// output.setAttribute("name", "Output");
Element fault = createWsdlElement(document, "fault");
operation.appendChild(fault);
fault.setAttribute("name", "Fault");
}
}
}

View File

@@ -1,83 +0,0 @@
/*
* Copyright ${YEAR} the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.ws.wsdl.wsdl11.visitor;
import java.util.Iterator;
import javax.wsdl.Definition;
import javax.wsdl.Fault;
import javax.wsdl.Operation;
import javax.wsdl.PortType;
import javax.wsdl.factory.WSDLFactory;
import javax.wsdl.xml.WSDLReader;
import javax.wsdl.xml.WSDLWriter;
import javax.xml.namespace.QName;
import org.springframework.core.io.ClassPathResource;
import org.springframework.xml.sax.SaxUtils;
import org.custommonkey.xmlunit.XMLTestCase;
import org.w3c.dom.Document;
public class DefaultBindingVisitorTest extends XMLTestCase {
private DefaultBindingVisitor visitor;
private Definition definition;
private Definition expected;
private WSDLFactory factory;
protected void setUp() throws Exception {
factory = WSDLFactory.newInstance();
definition = factory.newDefinition();
visitor = new DefaultBindingVisitor();
WSDLReader reader = factory.newWSDLReader();
definition = reader.readWSDL(null,
SaxUtils.createInputSource(new ClassPathResource("defaultBindingVisitorTest-input.wsdl", getClass())));
expected = reader.readWSDL(null,
SaxUtils.createInputSource(new ClassPathResource("defaultBindingVisitorTest-expected.wsdl", getClass())));
}
public void testDefaultBindingVisitor() throws Exception {
visitor.startDefinition(definition);
PortType portType = definition.getPortType(new QName("http://springframework.org/spring-ws", "PortType"));
visitor.startPortType(portType);
for (Iterator operationIter = portType.getOperations().iterator(); operationIter.hasNext();) {
Operation operation = (Operation) operationIter.next();
visitor.startOperation(operation);
if (operation.getInput() != null) {
visitor.input(operation.getInput());
}
if (operation.getOutput() != null) {
visitor.output(operation.getOutput());
}
for (Iterator faultIter = operation.getFaults().values().iterator(); faultIter.hasNext();) {
Fault fault = (Fault) faultIter.next();
visitor.fault(fault);
}
visitor.endOperation(operation);
}
visitor.endPortType(portType);
visitor.endDefinition(definition);
WSDLWriter writer = factory.newWSDLWriter();
Document resultDocument = writer.getDocument(definition);
Document expectedDocument = writer.getDocument(expected);
assertXMLEqual("Invalid WSDL generated", expectedDocument, resultDocument);
}
}

View File

@@ -1,67 +0,0 @@
/*
* Copyright ${YEAR} the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.xml.xsd.commons;
import javax.xml.transform.dom.DOMResult;
import junit.framework.TestCase;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.xml.xsd.AbstractXsdSchemaTestCase;
import org.springframework.xml.xsd.XsdSchema;
import org.springframework.xml.sax.SaxUtils;
import org.w3c.dom.Document;
public class CommonsXsdSchemaCollectionTest extends TestCase {
private CommonsXsdSchemaCollection collection;
protected void setUp() throws Exception {
collection = new CommonsXsdSchemaCollection();
}
public void testSingle() throws Exception {
Resource resource = new ClassPathResource("single.xsd", AbstractXsdSchemaTestCase.class);
collection.setXsds(new Resource[]{resource});
collection.afterPropertiesSet();
assertEquals("Invalid amount of XSDs loaded", 1, collection.getXsdSchemas().length);
}
public void testIncludes() throws Exception {
Resource resource = new ClassPathResource("including.xsd", AbstractXsdSchemaTestCase.class);
collection.setXsds(new Resource[] { resource});
collection.afterPropertiesSet();
assertEquals("Invalid amount of XSDs loaded", 2, collection.getXsdSchemas().length);
}
public void testImports() throws Exception {
Resource resource = new ClassPathResource("importing.xsd", AbstractXsdSchemaTestCase.class);
collection.setXsds(new Resource[] { resource});
collection.afterPropertiesSet();
assertEquals("Invalid amount of XSDs loaded", 2, collection.getXsdSchemas().length);
}
public void testDuplicates() throws Exception {
Resource resource = new ClassPathResource("single.xsd", AbstractXsdSchemaTestCase.class);
collection.setXsds(new Resource[] { resource, resource});
collection.afterPropertiesSet();
assertEquals("Invalid amount of XSDs loaded", 1, collection.getXsdSchemas().length);
}
}

View File

@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="urn:1"
xmlns:tns="urn:1" elementFormDefault="qualified"
attributeFormDefault="unqualified">
<xsd:include schemaLocation="B.xsd"/>
<xsd:simpleType name="A">
<xsd:restriction base="tns:B"/>
</xsd:simpleType>
</xsd:schema>

View File

@@ -0,0 +1,16 @@
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:ns0="urn:2" xmlns:tns="urn:1"
attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="urn:1">
<xsd:import namespace="urn:2" schemaLocation="D.xsd"/>
<xsd:simpleType name="A">
<xsd:restriction base="tns:B"/>
</xsd:simpleType>
<xsd:complexType name="B">
<xsd:sequence>
<xsd:element name="c" type="tns:C"/>
<xsd:element name="d" type="ns0:D"/>
</xsd:sequence>
</xsd:complexType>
<xsd:simpleType name="C">
<xsd:restriction base="xsd:string"/>
</xsd:simpleType>
</xsd:schema>

View File

@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="urn:1"
xmlns="urn:1"
xmlns:imported="urn:2" elementFormDefault="qualified">
<xsd:include schemaLocation="C.xsd"/>
<xsd:import schemaLocation="D.xsd" namespace="urn:2"/>
<xsd:complexType name="B">
<xsd:sequence>
<xsd:element type="C" name="c"/>
<xsd:element type="imported:D" name="d"/>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>

View File

@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.springframework.org/spring-ws/schema"
xmlns="http://www.springframework.org/spring-ws/schema" elementFormDefault="qualified"
attributeFormDefault="unqualified">
<xsd:simpleType name="customType">
<xsd:restriction base="xsd:string"/>
</xsd:simpleType>
<xsd:element name="GetOrderRequest">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="child" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="GetOrderResponse">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="child" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="GetOrderFault">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="child" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>

View File

@@ -1,13 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:tns="http://springframework.org/spring-ws"
name="wsdlDefinition"
targetNamespace="http://springframework.org/spring-ws">
<wsdl:portType name="PortType">
<wsdl:operation name="Operation">
<wsdl:input/>
<wsdl:output/>
<wsdl:fault name="Fault"/>
</wsdl:operation>
</wsdl:portType>
</wsdl:definitions>

View File

@@ -1,37 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:tns="http://springframework.org/spring-ws"
targetNamespace="http://springframework.org/spring-ws">
<wsdl:types>
<schema xmlns="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified"
targetNamespace="http://springframework.org/spring-ws">
<element name="Element" type="string"/>
</schema>
</wsdl:types>
<wsdl:message name="Message">
<wsdl:part element="tns:string" name="Message"/>
</wsdl:message>
<wsdl:portType name="PortType">
<wsdl:operation name="OneWay">
<wsdl:input message="tns:Message"/>
</wsdl:operation>
<wsdl:operation name="RequestResponse">
<wsdl:input message="tns:Message"/>
<wsdl:output message="tns:Message"/>
<wsdl:fault name="Fault" message="tns:Message"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="PortTypeBinding" type="tns:PortType">
<wsdl:operation name="OneWay">
<wsdl:input/>
</wsdl:operation>
<wsdl:operation name="RequestResponse">
<wsdl:input/>
<wsdl:output/>
<wsdl:fault name="Fault"/>
</wsdl:operation>
</wsdl:binding>
</wsdl:definitions>

View File

@@ -1,27 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:tns="http://springframework.org/spring-ws"
targetNamespace="http://springframework.org/spring-ws">
<wsdl:types>
<schema xmlns="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified"
targetNamespace="http://springframework.org/spring-ws">
<element name="Element" type="string"/>
</schema>
</wsdl:types>
<wsdl:message name="Message">
<wsdl:part element="tns:string" name="Message"/>
</wsdl:message>
<wsdl:portType name="PortType">
<wsdl:operation name="OneWay">
<wsdl:input message="tns:Message"/>
</wsdl:operation>
<wsdl:operation name="RequestResponse">
<wsdl:input message="tns:Message"/>
<wsdl:output message="tns:Message"/>
<wsdl:fault name="Fault" message="tns:Message"/>
</wsdl:operation>
</wsdl:portType>
</wsdl:definitions>