From 95c83c38d814e6dbcceb9efdcd4b62d60a16c051 Mon Sep 17 00:00:00 2001 From: rfeng Date: Fri, 31 Oct 2008 04:01:44 +0000 Subject: Resolve a lot of OSGi access violations. More to be fixed. git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@709339 13f79535-47bb-0310-9956-ffa450edef68 --- .../interfacedef/wsdl/AbstractWSDLTestCase.java | 68 ++++++++++++ .../WSDLInterfaceIntrospectorTestCase.java | 83 +++++++++++++++ .../WSDLOperationIntrospectorTestCase.java | 117 +++++++++++++++++++++ ...licyAnnotatedInterfaceIntrospectorTestCase.java | 87 +++++++++++++++ .../introspect/WrapperStyleOperationTestCase.java | 70 ++++++++++++ 5 files changed, 425 insertions(+) create mode 100644 branches/sca-equinox/modules/interface-wsdl/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/AbstractWSDLTestCase.java create mode 100644 branches/sca-equinox/modules/interface-wsdl/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/introspect/WSDLInterfaceIntrospectorTestCase.java create mode 100644 branches/sca-equinox/modules/interface-wsdl/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/introspect/WSDLOperationIntrospectorTestCase.java create mode 100644 branches/sca-equinox/modules/interface-wsdl/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/introspect/WSDLPolicyAnnotatedInterfaceIntrospectorTestCase.java create mode 100644 branches/sca-equinox/modules/interface-wsdl/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/introspect/WrapperStyleOperationTestCase.java (limited to 'branches/sca-equinox/modules/interface-wsdl/src/test') diff --git a/branches/sca-equinox/modules/interface-wsdl/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/AbstractWSDLTestCase.java b/branches/sca-equinox/modules/interface-wsdl/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/AbstractWSDLTestCase.java new file mode 100644 index 0000000000..8ed7ba395b --- /dev/null +++ b/branches/sca-equinox/modules/interface-wsdl/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/AbstractWSDLTestCase.java @@ -0,0 +1,68 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.apache.tuscany.sca.interfacedef.wsdl; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.contribution.Contribution; +import org.apache.tuscany.sca.contribution.ContributionFactory; +import org.apache.tuscany.sca.contribution.processor.ExtensibleURLArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.contribution.resolver.ExtensibleModelResolver; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.contribution.resolver.ModelResolverExtensionPoint; +import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.FactoryExtensionPoint; +import org.apache.tuscany.sca.xsd.XSDFactory; + +/** + * Test case for WSDLOperation. + * + * @version $Rev$ $Date$ + */ +public abstract class AbstractWSDLTestCase extends TestCase { + protected URLArtifactProcessor documentProcessor; + protected ModelResolver resolver; + protected WSDLFactory wsdlFactory; + protected XSDFactory xsdFactory; + + /** + * @see junit.framework.TestCase#setUp() + */ + @Override + protected void setUp() throws Exception { + ExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); + FactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(FactoryExtensionPoint.class); + wsdlFactory = modelFactories.getFactory(WSDLFactory.class); + xsdFactory = modelFactories.getFactory(XSDFactory.class); + + ContributionFactory contributionFactory = modelFactories.getFactory(ContributionFactory.class); + Contribution contribution = contributionFactory.createContribution(); + ModelResolverExtensionPoint modelResolvers = extensionPoints.getExtensionPoint(ModelResolverExtensionPoint.class); + resolver = new ExtensibleModelResolver(contribution, modelResolvers, modelFactories); + contribution.setModelResolver(resolver); + + URLArtifactProcessorExtensionPoint documentProcessors = extensionPoints.getExtensionPoint(URLArtifactProcessorExtensionPoint.class); + documentProcessor = new ExtensibleURLArtifactProcessor(documentProcessors, null); + } + +} diff --git a/branches/sca-equinox/modules/interface-wsdl/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/introspect/WSDLInterfaceIntrospectorTestCase.java b/branches/sca-equinox/modules/interface-wsdl/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/introspect/WSDLInterfaceIntrospectorTestCase.java new file mode 100644 index 0000000000..dc7e1ced38 --- /dev/null +++ b/branches/sca-equinox/modules/interface-wsdl/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/introspect/WSDLInterfaceIntrospectorTestCase.java @@ -0,0 +1,83 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.apache.tuscany.sca.interfacedef.wsdl.introspect; + +import java.net.URI; +import java.net.URL; +import java.util.List; + +import javax.wsdl.PortType; +import javax.xml.namespace.QName; + +import junit.framework.Assert; + +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.InvalidInterfaceException; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.util.XMLType; +import org.apache.tuscany.sca.interfacedef.wsdl.AbstractWSDLTestCase; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLDefinition; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLInterface; + +/** + * Test case for InterfaceWSDLIntrospectorImpl. + * + * @version $Rev$ $Date$ + */ +public class WSDLInterfaceIntrospectorTestCase extends AbstractWSDLTestCase { + private static final QName PORTTYPE_NAME = new QName("http://example.com/stockquote.wsdl", "StockQuotePortType"); + + private PortType portType; + private WSDLDefinition definition; + + /** + * @see junit.framework.TestCase#setUp() + */ + @Override + protected void setUp() throws Exception { + super.setUp(); + + URL url = getClass().getResource("../xml/stockquote.wsdl"); + definition = (WSDLDefinition)documentProcessor.read(null, new URI("stockquote.wsdl"), url); + resolver.addModel(definition); + definition = resolver.resolveModel(WSDLDefinition.class, definition); + portType = definition.getDefinition().getPortType(PORTTYPE_NAME); + } + + @SuppressWarnings("unchecked") + public final void testIntrospectPortType() throws InvalidInterfaceException { + WSDLInterface contract = wsdlFactory.createWSDLInterface(portType, definition, resolver); + Assert.assertEquals(contract.getName().getLocalPart(), "StockQuotePortType"); + List operations = contract.getOperations(); + Assert.assertEquals(1, operations.size()); + Operation operation = operations.get(0); + Assert.assertEquals("getLastTradePrice", operation.getName()); + DataType> inputType = operation.getInputType(); + Assert.assertEquals(1, inputType.getLogical().size()); + DataType returnType = operation.getOutputType(); + Assert.assertNotNull(returnType); + Assert.assertEquals(0, operation.getFaultTypes().size()); + // Assert.assertEquals(1, + // operation.getWrapper().getInputChildElements().size()); + // Assert.assertEquals(1, + // operation.getWrapper().getOutputChildElements().size()); + } + +} diff --git a/branches/sca-equinox/modules/interface-wsdl/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/introspect/WSDLOperationIntrospectorTestCase.java b/branches/sca-equinox/modules/interface-wsdl/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/introspect/WSDLOperationIntrospectorTestCase.java new file mode 100644 index 0000000000..c392b92f8a --- /dev/null +++ b/branches/sca-equinox/modules/interface-wsdl/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/introspect/WSDLOperationIntrospectorTestCase.java @@ -0,0 +1,117 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.apache.tuscany.sca.interfacedef.wsdl.introspect; + +import java.net.URI; +import java.net.URL; +import java.util.List; + +import javax.wsdl.Operation; +import javax.wsdl.PortType; +import javax.xml.namespace.QName; + +import junit.framework.Assert; + +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.InvalidInterfaceException; +import org.apache.tuscany.sca.interfacedef.util.XMLType; +import org.apache.tuscany.sca.interfacedef.wsdl.AbstractWSDLTestCase; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLDefinition; +import org.apache.tuscany.sca.interfacedef.wsdl.impl.WSDLOperationIntrospectorImpl; + +/** + * Test case for WSDLOperation. + * + * @version $Rev$ $Date$ + */ +public class WSDLOperationIntrospectorTestCase extends AbstractWSDLTestCase { + private static final QName PORTTYPE_NAME = + new QName("http://example.com/stockquote.wsdl", "StockQuotePortType"); + + + @SuppressWarnings("unchecked") + public final void testWrappedOperation() throws Exception { + URL url = getClass().getResource("../xml/stockquote.wsdl"); + WSDLDefinition definition = (WSDLDefinition)documentProcessor.read(null, new URI("stockquote.wsdl"), url); + resolver.addModel(definition); + definition = resolver.resolveModel(WSDLDefinition.class, definition); + PortType portType = definition.getDefinition().getPortType(PORTTYPE_NAME); + Operation operation = portType.getOperation("getLastTradePrice", null, null); + + WSDLOperationIntrospectorImpl op = new WSDLOperationIntrospectorImpl(xsdFactory, operation, definition, "org.w3c.dom.Node", resolver); + + DataType> inputType = op.getInputType(); + Assert.assertEquals(1, inputType.getLogical().size()); + DataType type = inputType.getLogical().get(0); + Assert.assertEquals(new QName("http://example.com/stockquote.xsd", "getLastTradePrice"), type.getLogical().getElementName()); + + DataType outputType = op.getOutputType(); + Assert.assertEquals(new QName("http://example.com/stockquote.xsd", "getLastTradePriceResponse"), + outputType.getLogical().getElementName()); + Assert.assertTrue(op.isWrapperStyle()); + + DataType> unwrappedInputType = op.getWrapper().getWrapperInfo().getUnwrappedInputType(); + List childTypes = unwrappedInputType.getLogical(); + Assert.assertEquals(1, childTypes.size()); + DataType childType = childTypes.get(0); + Assert.assertEquals(new QName(null, "tickerSymbol"), childType.getLogical().getElementName()); + + childType = op.getWrapper().getWrapperInfo().getUnwrappedOutputType(); + Assert.assertEquals(new QName(null, "price"), childType.getLogical().getElementName()); + } + + public final void testUnwrappedOperation() throws Exception { + URL url = getClass().getResource("../xml/unwrapped-stockquote.wsdl"); + WSDLDefinition definition = (WSDLDefinition)documentProcessor.read(null, new URI("unwrapped-stockquote.wsdl"), url); + resolver.addModel(definition); + definition = resolver.resolveModel(WSDLDefinition.class, definition); + PortType portType = definition.getDefinition().getPortType(PORTTYPE_NAME); + + Operation operation = portType.getOperation("getLastTradePrice1", null, null); + WSDLOperationIntrospectorImpl op = new WSDLOperationIntrospectorImpl(xsdFactory, operation, definition, "org.w3c.dom.Node", resolver); + Assert.assertFalse(op.isWrapperStyle()); + Assert.assertEquals(1, op.getInputType().getLogical().size()); + + operation = portType.getOperation("getLastTradePrice2", null, null); + op = new WSDLOperationIntrospectorImpl(xsdFactory, operation, definition, "org.w3c.dom.Node", resolver); + Assert.assertFalse(op.isWrapperStyle()); + Assert.assertEquals(2, op.getInputType().getLogical().size()); + } + + public final void testInvalidWSDL() throws Exception { + URL url = getClass().getResource("../xml/invalid-stockquote.wsdl"); + WSDLDefinition definition = (WSDLDefinition)documentProcessor.read(null, new URI("invalid-stockquote.wsdl"), url); + resolver.addModel(definition); + definition = resolver.resolveModel(WSDLDefinition.class, definition); + PortType portType = definition.getDefinition().getPortType(PORTTYPE_NAME); + + Operation operation = portType.getOperation("getLastTradePrice", null, null); + WSDLOperationIntrospectorImpl op = new WSDLOperationIntrospectorImpl(xsdFactory, operation, definition, "org.w3c.dom.Node", resolver); + + try { + op.isWrapperStyle(); + fail("InvalidWSDLException should have been thrown"); + } catch (InvalidInterfaceException e) { + // Expected + } + + } + +} diff --git a/branches/sca-equinox/modules/interface-wsdl/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/introspect/WSDLPolicyAnnotatedInterfaceIntrospectorTestCase.java b/branches/sca-equinox/modules/interface-wsdl/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/introspect/WSDLPolicyAnnotatedInterfaceIntrospectorTestCase.java new file mode 100644 index 0000000000..cf379a1b11 --- /dev/null +++ b/branches/sca-equinox/modules/interface-wsdl/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/introspect/WSDLPolicyAnnotatedInterfaceIntrospectorTestCase.java @@ -0,0 +1,87 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.apache.tuscany.sca.interfacedef.wsdl.introspect; + +import java.net.URI; +import java.net.URL; + +import javax.wsdl.PortType; +import javax.xml.namespace.QName; + +import junit.framework.Assert; + +import org.apache.tuscany.sca.interfacedef.ConversationSequence; +import org.apache.tuscany.sca.interfacedef.InvalidInterfaceException; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.wsdl.AbstractWSDLTestCase; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLDefinition; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLInterface; +import org.apache.tuscany.sca.policy.Intent; + +/** + * Test case for InterfaceWSDLIntrospectorImpl. + * + * @version $Rev$ $Date$ + */ +public class WSDLPolicyAnnotatedInterfaceIntrospectorTestCase extends AbstractWSDLTestCase { + private static final QName PORTTYPE_NAME = new QName("http://example.com/stockquote.wsdl", "StockQuotePortType"); + private static final QName INTENT = new QName("http://example.com/stockquote.wsdl", "PolicyIntent"); + + private PortType portType; + private WSDLDefinition definition; + + /** + * @see junit.framework.TestCase#setUp() + */ + @Override + protected void setUp() throws Exception { + super.setUp(); + + URL url = getClass().getResource("/policy/stockquote_policy.wsdl"); + definition = (WSDLDefinition)documentProcessor.read(null, new URI("stockquote.wsdl"), url); + resolver.addModel(definition); + definition = resolver.resolveModel(WSDLDefinition.class, definition); + portType = definition.getDefinition().getPortType(PORTTYPE_NAME); + } + + @SuppressWarnings("unchecked") + public final void testIntrospectPortType() throws InvalidInterfaceException { + WSDLInterface contract = wsdlFactory.createWSDLInterface(portType, definition, resolver); + Assert.assertEquals(contract.getName().getLocalPart(), "StockQuotePortType"); + Assert.assertTrue(contract.isConversational()); + + boolean foundIntent = false; + + for(Intent intent : contract.getRequiredIntents()) { + if(INTENT.equals(intent.getName())) { + foundIntent = true; + } + } + + Assert.assertTrue(foundIntent); + + for(Operation operation : contract.getOperations()) { + if(operation.getName().equals("cancel")) { + Assert.assertEquals(operation.getConversationSequence(), ConversationSequence.CONVERSATION_END); + } + } + + } +} diff --git a/branches/sca-equinox/modules/interface-wsdl/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/introspect/WrapperStyleOperationTestCase.java b/branches/sca-equinox/modules/interface-wsdl/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/introspect/WrapperStyleOperationTestCase.java new file mode 100644 index 0000000000..ff18c65c69 --- /dev/null +++ b/branches/sca-equinox/modules/interface-wsdl/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/introspect/WrapperStyleOperationTestCase.java @@ -0,0 +1,70 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.apache.tuscany.sca.interfacedef.wsdl.introspect; + +import java.net.URI; +import java.net.URL; + +import javax.wsdl.Operation; +import javax.wsdl.PortType; +import javax.xml.namespace.QName; + +import junit.framework.Assert; + +import org.apache.tuscany.sca.interfacedef.wsdl.AbstractWSDLTestCase; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLDefinition; +import org.apache.tuscany.sca.interfacedef.wsdl.impl.WSDLOperationIntrospectorImpl; + +/** + * Test case for WSDLOperation. + * + * @version $Rev$ $Date$ + */ +public class WrapperStyleOperationTestCase extends AbstractWSDLTestCase { + private static final QName PORTTYPE_NAME = new QName("http://example.com/stockquote.wsdl", "StockQuotePortType"); + + public final void testWrappedOperation() throws Exception { + URL url = getClass().getResource("../xml/stockquote.wsdl"); + WSDLDefinition definition = (WSDLDefinition)documentProcessor.read(null, new URI("stockquote.wsdl"), url); + resolver.addModel(definition); + definition = resolver.resolveModel(WSDLDefinition.class, definition); + PortType portType = definition.getDefinition().getPortType(PORTTYPE_NAME); + Operation operation = portType.getOperation("getLastTradePrice", null, null); + WSDLOperationIntrospectorImpl op = new WSDLOperationIntrospectorImpl(xsdFactory, operation, definition, "org.w3c.dom.Node", resolver); + Assert.assertTrue(op.isWrapperStyle()); + Assert.assertEquals(1, op.getWrapper().getInputChildElements().size()); + Assert.assertEquals(1, op.getWrapper().getOutputChildElements().size()); + } + + public final void testUnwrappedOperation() throws Exception { + URL url = getClass().getResource("../xml/unwrapped-stockquote.wsdl"); + WSDLDefinition definition = (WSDLDefinition)documentProcessor.read(null, new URI("unwrapped-stockquote.wsdl"), url); + resolver.addModel(definition); + definition = resolver.resolveModel(WSDLDefinition.class, definition); + PortType portType = definition.getDefinition().getPortType(PORTTYPE_NAME); + Operation operation = portType.getOperation("getLastTradePrice1", null, null); + WSDLOperationIntrospectorImpl op = new WSDLOperationIntrospectorImpl(xsdFactory, operation, definition, "org.w3c.dom.Node", resolver); + Assert.assertFalse(op.isWrapperStyle()); + operation = portType.getOperation("getLastTradePrice2", null, null); + op = new WSDLOperationIntrospectorImpl(xsdFactory, operation, definition, "org.w3c.dom.Node", resolver); + Assert.assertFalse(op.isWrapperStyle()); + } + +} -- cgit v1.2.3