From jbossws-commits at lists.jboss.org Thu Feb 11 09:05:57 2010 Content-Type: multipart/mixed; boundary="===============0936979577707965004==" MIME-Version: 1.0 From: jbossws-commits at lists.jboss.org To: jbossws-commits at lists.jboss.org Subject: [jbossws-commits] JBossWS SVN: r11578 - framework/trunk/testsuite/test/java/org/jboss/test/ws/jaxws/endpointReference. Date: Thu, 11 Feb 2010 09:05:56 -0500 Message-ID: <201002111405.o1BE5uN8000912@svn01.web.mwc.hst.phx2.redhat.com> --===============0936979577707965004== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Author: richard.opalka(a)jboss.com Date: 2010-02-11 09:05:56 -0500 (Thu, 11 Feb 2010) New Revision: 11578 Added: framework/trunk/testsuite/test/java/org/jboss/test/ws/jaxws/endpointRefe= rence/EndpointReferenceBuilderTestCase.java Log: [JBWS-2914] providing EndpointReferenceBuilder test Added: framework/trunk/testsuite/test/java/org/jboss/test/ws/jaxws/endpoint= Reference/EndpointReferenceBuilderTestCase.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- framework/trunk/testsuite/test/java/org/jboss/test/ws/jaxws/endpointRef= erence/EndpointReferenceBuilderTestCase.java (rev 0) +++ framework/trunk/testsuite/test/java/org/jboss/test/ws/jaxws/endpointRef= erence/EndpointReferenceBuilderTestCase.java 2010-02-11 14:05:56 UTC (rev 1= 1578) @@ -0,0 +1,157 @@ +/* + * JBoss, Home of Professional Open Source. + * Copyright 2010, Red Hat Middleware LLC, and individual contributors + * as indicated by the @author tags. See the copyright.txt file in the + * distribution for a full listing of individual contributors. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.jboss.test.ws.jaxws.endpointReference; + +import java.io.ByteArrayOutputStream; +import java.io.PrintWriter; + +import javax.xml.namespace.QName; +import javax.xml.transform.dom.DOMResult; +import javax.xml.ws.wsaddressing.W3CEndpointReference; +import javax.xml.ws.wsaddressing.W3CEndpointReferenceBuilder; + +import org.jboss.ws.Constants; +import org.jboss.wsf.common.DOMUtils; +import org.jboss.wsf.common.DOMWriter; +import org.jboss.wsf.test.JBossWSTest; +import org.w3c.dom.Element; +import org.w3c.dom.Node; + +/** + * W3CEndpointReferenceBuilder test. + * + * @author Richard Opalka + */ +public final class EndpointReferenceBuilderTestCase extends JBossWSTest +{ + private static final String URL =3D "http://localhost:8080/hello"; + private static final String WSDL_URL =3D URL + "?wsdl"; + private static final String XML_INTERFACE_NAME =3D "myns:Hello"; + private static final String XML_REF_PARAM1 =3D "Hello"; + private static final String XML_REF_PARAM2 =3D "World"; + private static final String MY_NS =3D "http://helloservice.org/wsdl"; + private static final String SERVICE_NAME =3D "HelloService"; + private static final String PORT_NAME =3D "HelloPort"; + private static final String PORT_TYPE_NAME =3D "Hello"; + private static final String WSA_NS =3D "http://www.w3.org/2005/08/addre= ssing"; + private static final String WSAM_NS =3D "http://www.w3.org/2007/05/addr= essing/metadata"; + private static final String WSAM_PREFIX =3D "wsam"; + private static final String MY_PREFIX =3D "myns"; + private static final QName PARAM1_QNAME =3D new QName("http://helloserv= ice.org/param1", "param1", "ns1"); + private static final QName PARAM2_QNAME =3D new QName("http://helloserv= ice.org/param2", "param2", "ns2"); + private static final QName WSAM_SERVICE_QNAME =3D new QName(WSAM_NS, "S= erviceName"); + private static final QName WSAM_INTERFACE_QNAME =3D new QName(WSAM_NS, = "InterfaceName"); + private static final QName METADATA_QNAME =3D new QName(WSA_NS, "Metada= ta"); + private static final QName SERVICE_QNAME =3D new QName(MY_NS, SERVICE_N= AME, MY_PREFIX); + private static final QName PORT_QNAME =3D new QName(MY_NS, PORT_NAME, M= Y_PREFIX); + private static final QName PORT_TYPE_QNAME =3D new QName(MY_NS, PORT_TY= PE_NAME, MY_PREFIX); + + public void testParsedInterfaceName() throws Exception + { + W3CEndpointReferenceBuilder builder =3D new W3CEndpointReferenceBuil= der(); = + builder =3D builder.address(URL); + Element element =3D DOMUtils.parse(XML_INTERFACE_NAME); + builder =3D builder.metadata(element); + builder =3D builder.serviceName(SERVICE_QNAME); + builder =3D builder.endpointName(PORT_QNAME); + builder =3D builder.wsdlDocumentLocation(WSDL_URL); + element =3D DOMUtils.parse(XML_REF_PARAM1); + builder =3D builder.referenceParameter(element); + element =3D DOMUtils.parse(XML_REF_PARAM2); + builder =3D builder.referenceParameter(element); + W3CEndpointReference epr =3D builder.build(); + DOMResult dr =3D new DOMResult(); = + epr.writeTo(dr); + Node endpointReferenceElement =3D dr.getNode(); + System.out.println(getXml(endpointReferenceElement)); + assertMetaData(endpointReferenceElement); + assertRefParam(endpointReferenceElement, PARAM1_QNAME, "Hello"); + assertRefParam(endpointReferenceElement, PARAM2_QNAME, "World"); + } + = + public void testConstructedInterfaceName() throws Exception + { + W3CEndpointReferenceBuilder builder =3D new W3CEndpointReferenceBuil= der(); = + builder =3D builder.address(URL); + builder =3D builder.serviceName(SERVICE_QNAME); + builder =3D builder.endpointName(PORT_QNAME); + builder =3D builder.interfaceName(PORT_TYPE_QNAME); + builder =3D builder.wsdlDocumentLocation(WSDL_URL); + Element element =3D DOMUtils.parse(XML_REF_PARAM1); + builder =3D builder.referenceParameter(element); + element =3D DOMUtils.parse(XML_REF_PARAM2); + builder =3D builder.referenceParameter(element); + W3CEndpointReference epr =3D builder.build(); + DOMResult dr =3D new DOMResult(); = + epr.writeTo(dr); + Node endpointReferenceElement =3D dr.getNode(); + System.out.println(getXml(endpointReferenceElement)); + assertMetaData(endpointReferenceElement); + assertRefParam(endpointReferenceElement, PARAM1_QNAME, "Hello"); + assertRefParam(endpointReferenceElement, PARAM2_QNAME, "World"); + } + + private static String getXml(final Node node) throws Exception + { + ByteArrayOutputStream baos =3D new ByteArrayOutputStream(); + PrintWriter pw =3D new PrintWriter(baos); + new DOMWriter(pw, Constants.DEFAULT_XML_CHARSET).setPrettyprint(true= ).print(node); + return baos.toString("utf-8"); + } + = + private static void assertRefParam(final Node root, final QName nodeNam= e, final String refParamValue) + { + Element e =3D (Element)DOMUtils.getFirstChildElement(root, nodeName,= true); + assertNotNull("Reference parameter " + nodeName + " not found", e); + String actual =3D DOMUtils.getTextContent(e); + if ((actual =3D=3D null) || (!actual.equals(refParamValue))) + { + fail("Reference parameter " + nodeName + " expected value is " + = refParamValue); + } + } + = + private static void assertMetaData(final Node root) + { + Element metadataElement =3D (Element)DOMUtils.getFirstChildElement(r= oot, METADATA_QNAME, true); + assertEquals("wsdlLocation mismatch", metadataElement.getAttribute("= wsdlLocation"), WSDL_URL); + Element serviceNameElement =3D (Element)DOMUtils.getFirstChildElemen= t(metadataElement, WSAM_SERVICE_QNAME); + assertNamespaces(serviceNameElement); + assertEquals("wrong text content in ServiceName element", "myns:Hell= oService", DOMUtils.getTextContent(serviceNameElement)); + String endpointNameValue =3D DOMUtils.getAttributeValue(serviceNameE= lement, "EndpointName"); + assertNotNull("cannot find endpointName attribute value", endpointNa= meValue); + assertEquals("wrong endpointName attribute value", endpointNameValue= , "myns:HelloPort"); + Element interfaceNameElement =3D (Element)DOMUtils.getFirstChildElem= ent(metadataElement, WSAM_INTERFACE_QNAME); + assertNamespaces(interfaceNameElement); + assertEquals("wrong text content in InterfaceName element", "myns:He= llo", DOMUtils.getTextContent(interfaceNameElement)); + } + = + private static void assertNamespaces(final Element e) + { + String myNamespace =3D e.lookupNamespaceURI(MY_PREFIX); + assertNotNull("namespace is null for prefix " + MY_PREFIX + ", isn't= xalan in endorsed directory?", myNamespace); + assertEquals("namespace mismatch", myNamespace, MY_NS); + String wsamNamespace =3D e.lookupNamespaceURI(WSAM_PREFIX); + assertNotNull("namespace is null for prefix " + WSAM_PREFIX + ", isn= 't xalan in endorsed directory?", wsamNamespace); + assertEquals("namespace mismatch", wsamNamespace, WSAM_NS); + } +} + --===============0936979577707965004==--