001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common Development
008: * and Distribution License("CDDL") (collectively, the "License"). You
009: * may not use this file except in compliance with the License. You can obtain
010: * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
011: * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
012: * language governing permissions and limitations under the License.
013: *
014: * When distributing the software, include this License Header Notice in each
015: * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
016: * Sun designates this particular file as subject to the "Classpath" exception
017: * as provided by Sun in the GPL Version 2 section of the License file that
018: * accompanied this code. If applicable, add the following below the License
019: * Header, with the fields enclosed by brackets [] replaced by your own
020: * identifying information: "Portions Copyrighted [year]
021: * [name of copyright owner]"
022: *
023: * Contributor(s):
024: *
025: * If you wish your version of this file to be governed by only the CDDL or
026: * only the GPL Version 2, indicate your decision by adding "[Contributor]
027: * elects to include this software in this distribution under the [CDDL or GPL
028: * Version 2] license." If you don't indicate a single choice of license, a
029: * recipient has the option to distribute your version of this file under
030: * either the CDDL, the GPL Version 2 or to extend the choice of license to
031: * its licensees as provided above. However, if you add GPL Version 2 code
032: * and therefore, elected the GPL Version 2 license, then the option applies
033: * only if the new code is made subject to such option by the copyright
034: * holder.
035: */
036:
037: package com.sun.xml.ws.tx.common;
038:
039: import com.sun.xml.ws.api.SOAPVersion;
040: import com.sun.xml.ws.api.message.Header;
041: import com.sun.xml.ws.api.message.Messages;
042: import com.sun.xml.ws.tx.coordinator.CoordinationContextInterface;
043: import java.io.StringReader;
044: import javax.xml.transform.stream.StreamSource;
045: import junit.framework.TestCase;
046:
047: /**
048: *
049: * @author Ryan.Shoemaker@Sun.COM
050: */
051: public class MessageTest extends TestCase {
052:
053: /** Creates a new instance of MessageTest */
054: public MessageTest(String name) {
055: super (name);
056: }
057:
058: private final String messageSource = "<S:Envelope xmlns:S=\"http://schemas.xmlsoap.org/soap/envelope/\">"
059: + "<S:Header>"
060: + "<To xmlns=\"http://schemas.xmlsoap.org/ws/2004/08/addressing\">http://tini.east.sun.com/WcfInterop/TransactionalService.svc</To>"
061: + "<Action xmlns=\"http://schemas.xmlsoap.org/ws/2004/08/addressing\">http://tempuri.org/ITransactionalService/Commit</Action>"
062: + "<ReplyTo xmlns=\"http://schemas.xmlsoap.org/ws/2004/08/addressing\">"
063: + "<Address>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</Address>"
064: + "</ReplyTo>"
065: + "<MessageID xmlns=\"http://schemas.xmlsoap.org/ws/2004/08/addressing\">uuid:655bd1d1-5085-4b88-832e-c813254b4d3d</MessageID>"
066: + "<CoordinationContext xmlns=\"http://schemas.xmlsoap.org/ws/2004/10/wscoor\" xmlns:ns2=\"http://schemas.xmlsoap.org/ws/2004/08/addressing\" xmlns:ns3=\"http://java.sun.com/xml/ns/wsit/coord\" xmlns:ns4=\"http://schemas.xmlsoap.org/soap/envelope/\" ns4:mustUnderstand=\"true\">"
067: + "<Identifier>uuid:WSCOOR-SUN-2</Identifier>"
068: + "<Expires>37376</Expires>"
069: + "<CoordinationType>http://schemas.xmlsoap.org/ws/2004/10/wsat</CoordinationType>"
070: + "<RegistrationService>"
071: + "<ns2:Address>https://tini.east.sun.com:8181/wstx-services/wscoor/coordinator/register</ns2:Address>"
072: + "<ns2:ReferenceParameters>"
073: + "<jaxws:objectId xmlns:jaxws=\"http://jax-ws.dev.java.net/xml/ns/\" xmlns:wsa=\"http://schemas.xmlsoap.org/ws/2004/08/addressing\">dc9cde07-108c-4d1f-9410-507867fa1dfa</jaxws:objectId>"
074: + "</ns2:ReferenceParameters>"
075: + "</RegistrationService>"
076: + "</CoordinationContext>"
077: + "</S:Header>"
078: + "<S:Body>"
079: + "<Commit xmlns=\"http://tempuri.org/\"/>"
080: + "</S:Body>"
081: + "</S:Envelope>";
082:
083: private final com.sun.xml.ws.api.message.Message jaxwsMessage = Messages
084: .create(new StreamSource(new StringReader(messageSource)),
085: SOAPVersion.SOAP_11);
086:
087: private final com.sun.xml.ws.tx.common.Message txMessage = new com.sun.xml.ws.tx.common.Message(
088: jaxwsMessage);
089:
090: public void testGetCtxHeader() throws Exception {
091: Header h = txMessage.getCoordCtxHeader();
092: assertNotNull(h);
093: assertEquals("http://schemas.xmlsoap.org/ws/2004/10/wscoor", h
094: .getNamespaceURI());
095: assertEquals("CoordinationContext", h.getLocalPart());
096: }
097:
098: public void testGetContext() throws Exception {
099: CoordinationContextInterface cc = txMessage
100: .getCoordinationContext(TxJAXBContext
101: .createUnmarshaller());
102: // we really only need to test that JAXB can unmarshal and hand us the object
103: assertEquals("http://schemas.xmlsoap.org/ws/2004/10/wsat", cc
104: .getCoordinationType());
105: assertEquals("uuid:WSCOOR-SUN-2", cc.getIdentifier());
106: assertEquals(37376l, cc.getExpires());
107: }
108:
109: public void testGetCtxHeader2() throws Exception {
110: assertNotNull(txMessage.getCoordCtxHeader(
111: Constants.WSCOOR_SOAP_NSURI,
112: Constants.COORDINATION_CONTEXT));
113: }
114: }
|