You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by co...@apache.org on 2014/06/23 13:42:42 UTC
[3/3] git commit: [CXF-5817] - Adding unit test
[CXF-5817] - Adding unit test
Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/fdd9c970
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/fdd9c970
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/fdd9c970
Branch: refs/heads/2.7.x-fixes
Commit: fdd9c970719cb73084dc442068658d53641d05b2
Parents: b86d56a
Author: Colm O hEigeartaigh <co...@apache.org>
Authored: Mon Jun 23 12:41:46 2014 +0100
Committer: Colm O hEigeartaigh <co...@apache.org>
Committed: Mon Jun 23 12:42:30 2014 +0100
----------------------------------------------------------------------
.../cxf/ws/security/sts/STSClientTest.java | 67 +
.../org/apache/cxf/ws/security/sts/wcf.wsdl | 1344 ++++++++++++++++++
2 files changed, 1411 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cxf/blob/fdd9c970/rt/ws/security/src/test/java/org/apache/cxf/ws/security/sts/STSClientTest.java
----------------------------------------------------------------------
diff --git a/rt/ws/security/src/test/java/org/apache/cxf/ws/security/sts/STSClientTest.java b/rt/ws/security/src/test/java/org/apache/cxf/ws/security/sts/STSClientTest.java
index ec58016..96363dd 100644
--- a/rt/ws/security/src/test/java/org/apache/cxf/ws/security/sts/STSClientTest.java
+++ b/rt/ws/security/src/test/java/org/apache/cxf/ws/security/sts/STSClientTest.java
@@ -19,19 +19,35 @@
package org.apache.cxf.ws.security.sts;
import java.io.InputStream;
+import java.util.ArrayList;
import java.util.HashSet;
+import java.util.List;
import java.util.Set;
+import javax.wsdl.Definition;
+import javax.wsdl.Types;
+import javax.wsdl.extensions.ExtensibilityElement;
+import javax.wsdl.extensions.schema.Schema;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.Unmarshaller;
import javax.xml.namespace.QName;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
import org.apache.cxf.Bus;
import org.apache.cxf.BusFactory;
import org.apache.cxf.common.jaxb.JAXBContextCache;
+import org.apache.cxf.databinding.source.SourceDataBinding;
+import org.apache.cxf.helpers.DOMUtils;
+import org.apache.cxf.service.Service;
+import org.apache.cxf.staxutils.StaxUtils;
import org.apache.cxf.ws.addressing.EndpointReferenceType;
import org.apache.cxf.ws.security.trust.STSClient;
+import org.apache.cxf.wsdl.WSDLManager;
+import org.apache.cxf.wsdl11.WSDLServiceFactory;
import org.junit.Assert;
import org.junit.Test;
@@ -62,4 +78,55 @@ public class STSClientTest extends Assert {
assertEquals(new QName("http://docs.oasis-open.org/ws-sx/ws-trust/200512/", "UT_Port"),
client.getEndpointQName());
}
+
+ // A unit test to make sure that we can parse a WCF wsdl properly. See CXF-5817.
+ @Test
+ public void testWCFWsdl() throws Exception {
+ Bus bus = BusFactory.getThreadDefaultBus();
+
+ // Load WSDL
+ InputStream inStream = getClass().getResourceAsStream("wcf.wsdl");
+ Document doc = StaxUtils.read(inStream);
+
+
+ NodeList metadataSections =
+ doc.getElementsByTagNameNS("http://schemas.xmlsoap.org/ws/2004/09/mex", "MetadataSection");
+ Element wsdlDefinition = null;
+ List<Element> schemas = new ArrayList<Element>();
+ for (int i = 0; i < metadataSections.getLength(); i++) {
+ Node node = metadataSections.item(i);
+ if (node instanceof Element) {
+ Element element = (Element)node;
+ String dialect = element.getAttributeNS(null, "Dialect");
+ if ("http://schemas.xmlsoap.org/wsdl/".equals(dialect)) {
+ wsdlDefinition = DOMUtils.getFirstElement(element);
+ } else if ("http://www.w3.org/2001/XMLSchema".equals(dialect)) {
+ schemas.add(DOMUtils.getFirstElement(element));
+ }
+ }
+ }
+
+ assertNotNull(wsdlDefinition);
+ assertTrue(!schemas.isEmpty());
+
+ WSDLManager wsdlManager = bus.getExtension(WSDLManager.class);
+ Definition definition = wsdlManager.getDefinition(wsdlDefinition);
+
+ for (Element schemaElement : schemas) {
+ QName schemaName =
+ new QName(schemaElement.getNamespaceURI(), schemaElement.getLocalName());
+ ExtensibilityElement
+ exElement = wsdlManager.getExtensionRegistry().createExtension(Types.class, schemaName);
+ ((Schema)exElement).setElement(schemaElement);
+ definition.getTypes().addExtensibilityElement(exElement);
+ }
+
+ WSDLServiceFactory factory = new WSDLServiceFactory(bus, definition);
+ SourceDataBinding dataBinding = new SourceDataBinding();
+ factory.setDataBinding(dataBinding);
+ Service service = factory.create();
+ service.setDataBinding(dataBinding);
+
+ }
+
}