001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.servicemix.soap.handlers.addressing;
018:
019: import javax.xml.namespace.QName;
020:
021: import org.apache.servicemix.jbi.util.WSAddressingConstants;
022: import org.apache.servicemix.soap.Context;
023: import org.apache.servicemix.soap.marshalers.SoapMessage;
024: import org.w3c.dom.DocumentFragment;
025:
026: import junit.framework.TestCase;
027:
028: public class AddressingHandlerTest extends TestCase {
029:
030: private AddressingHandler handler;
031:
032: public AddressingHandlerTest(String name) {
033: super (name);
034: }
035:
036: protected void setUp() throws Exception {
037: this .handler = new AddressingHandler();
038: }
039:
040: public void testCreateHeader() throws Exception {
041: QName messageIdQN = new QName(
042: WSAddressingConstants.WSA_NAMESPACE_200408,
043: WSAddressingConstants.EL_MESSAGE_ID,
044: WSAddressingConstants.WSA_PREFIX);
045: String messageId = "uuid:1234567890";
046: DocumentFragment wsaMessageId = this .handler.createHeader(
047: messageIdQN, messageId);
048:
049: assertNotNull("DocumentFragment is null", wsaMessageId);
050: assertEquals("messageId", messageId, wsaMessageId
051: .getTextContent());
052:
053: }
054:
055: public void testWSAEmptyPrefix() throws Exception {
056: // setup
057: QName messageIdQN = new QName(
058: WSAddressingConstants.WSA_NAMESPACE_200408,
059: WSAddressingConstants.EL_MESSAGE_ID, "");
060: QName relatesToQN = new QName(
061: WSAddressingConstants.WSA_NAMESPACE_200408,
062: WSAddressingConstants.EL_RELATES_TO, "");
063:
064: // create messages and add them to the context
065: Context msgContext = new Context();
066: SoapMessage inMessage = new SoapMessage();
067: SoapMessage outMessage = new SoapMessage();
068: msgContext.setInMessage(inMessage);
069: msgContext.setOutMessage(outMessage);
070:
071: // add wsa MessageID header to in message
072: String messageId = "uuid:1234567890";
073: DocumentFragment wsaMessageId = this .handler.createHeader(
074: messageIdQN, messageId);
075: inMessage.addHeader(messageIdQN, wsaMessageId);
076:
077: // run handler
078: this .handler.onReply(msgContext);
079:
080: // verify relates-to
081: DocumentFragment wsaRelatesTo = (DocumentFragment) outMessage
082: .getHeaders().get(relatesToQN);
083: assertNotNull("No RelatesTo header", wsaRelatesTo);
084: assertEquals("Value", messageId, wsaRelatesTo.getTextContent());
085: }
086:
087: public void testWSAPrefix() throws Exception {
088: // setup
089: QName messageIdQN = new QName(
090: WSAddressingConstants.WSA_NAMESPACE_200408,
091: WSAddressingConstants.EL_MESSAGE_ID,
092: WSAddressingConstants.WSA_PREFIX);
093: QName relatesToQN = new QName(
094: WSAddressingConstants.WSA_NAMESPACE_200408,
095: WSAddressingConstants.EL_RELATES_TO,
096: WSAddressingConstants.WSA_PREFIX);
097:
098: // create messages and add them to the context
099: Context msgContext = new Context();
100: SoapMessage inMessage = new SoapMessage();
101: SoapMessage outMessage = new SoapMessage();
102: msgContext.setInMessage(inMessage);
103: msgContext.setOutMessage(outMessage);
104:
105: // add wsa MessageID header to in message
106: String messageId = "uuid:1234567890";
107: DocumentFragment wsaMessageId = this .handler.createHeader(
108: messageIdQN, messageId);
109: inMessage.addHeader(messageIdQN, wsaMessageId);
110:
111: // run handler
112: this .handler.onReply(msgContext);
113:
114: // verify relates-to
115: DocumentFragment wsaRelatesTo = (DocumentFragment) outMessage
116: .getHeaders().get(relatesToQN);
117: assertNotNull("No RelatesTo header", wsaRelatesTo);
118: assertEquals("Value", messageId, wsaRelatesTo.getTextContent());
119: }
120:
121: }
|