001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */package org.apache.cxf.ws.rm;
019:
020: import org.apache.cxf.message.Exchange;
021: import org.apache.cxf.message.Message;
022: import org.apache.cxf.ws.addressing.AddressingProperties;
023: import org.apache.cxf.ws.addressing.AddressingPropertiesImpl;
024: import org.apache.cxf.ws.addressing.JAXWSAConstants;
025: import org.easymock.classextension.EasyMock;
026: import org.easymock.classextension.IMocksControl;
027: import org.junit.After;
028: import org.junit.Assert;
029: import org.junit.Before;
030: import org.junit.Test;
031:
032: /**
033: *
034: */
035: public class RMContextUtilsTest extends Assert {
036:
037: private IMocksControl control;
038:
039: @Before
040: public void setUp() {
041: control = EasyMock.createNiceControl();
042: }
043:
044: @After
045: public void tearDown() {
046: control.verify();
047: }
048:
049: @Test
050: public void testCtor() {
051: control.replay();
052: assertNotNull(new RMContextUtils());
053: }
054:
055: @Test
056: public void testGenerateUUID() {
057: control.replay();
058: assertNotNull(RMContextUtils.generateUUID());
059: }
060:
061: @Test
062: public void testIsServerSide() {
063: Message msg = control.createMock(Message.class);
064: Exchange ex = control.createMock(Exchange.class);
065: EasyMock.expect(msg.getExchange()).andReturn(ex);
066: EasyMock.expect(ex.getDestination()).andReturn(null);
067: control.replay();
068: assertTrue(!RMContextUtils.isServerSide(msg));
069: }
070:
071: @Test
072: public void testIsRmPrtocolMessage() {
073: control.replay();
074: String action = null;
075: assertTrue(!RMContextUtils.isRMProtocolMessage(action));
076: action = "";
077: assertTrue(!RMContextUtils.isRMProtocolMessage(action));
078: action = "greetMe";
079: assertTrue(!RMContextUtils.isRMProtocolMessage(action));
080: action = RMConstants.getCreateSequenceAction();
081: assertTrue(RMContextUtils.isRMProtocolMessage(action));
082: }
083:
084: @Test
085: public void testRetrieveOutboundRMProperties() {
086: Message msg = control.createMock(Message.class);
087: RMProperties rmps = control.createMock(RMProperties.class);
088: EasyMock.expect(
089: msg.get(RMMessageConstants.RM_PROPERTIES_OUTBOUND))
090: .andReturn(rmps);
091: control.replay();
092: assertSame(rmps, RMContextUtils.retrieveRMProperties(msg, true));
093: }
094:
095: @Test
096: public void testRetrieveInboundRMPropertiesFromOutboundMessage() {
097: Message outMsg = control.createMock(Message.class);
098: Exchange ex = control.createMock(Exchange.class);
099: EasyMock.expect(outMsg.getExchange()).andReturn(ex).times(3);
100: EasyMock.expect(ex.getOutMessage()).andReturn(outMsg);
101: Message inMsg = control.createMock(Message.class);
102: EasyMock.expect(ex.getInMessage()).andReturn(null);
103: EasyMock.expect(ex.getInFaultMessage()).andReturn(inMsg);
104: RMProperties rmps = control.createMock(RMProperties.class);
105: EasyMock.expect(
106: inMsg.get(RMMessageConstants.RM_PROPERTIES_INBOUND))
107: .andReturn(rmps);
108: control.replay();
109: assertSame(rmps, RMContextUtils.retrieveRMProperties(outMsg,
110: false));
111: }
112:
113: @Test
114: public void testRetrieveInboundRMPropertiesFromInboundMessage() {
115: Message inMsg = control.createMock(Message.class);
116: Exchange ex = control.createMock(Exchange.class);
117: EasyMock.expect(inMsg.getExchange()).andReturn(ex);
118: EasyMock.expect(ex.getOutMessage()).andReturn(null);
119: EasyMock.expect(ex.getOutFaultMessage()).andReturn(null);
120: RMProperties rmps = control.createMock(RMProperties.class);
121: EasyMock.expect(
122: inMsg.get(RMMessageConstants.RM_PROPERTIES_INBOUND))
123: .andReturn(rmps);
124: control.replay();
125: assertSame(rmps, RMContextUtils.retrieveRMProperties(inMsg,
126: false));
127: }
128:
129: @Test
130: public void testStoreRMProperties() {
131: Message msg = control.createMock(Message.class);
132: RMProperties rmps = control.createMock(RMProperties.class);
133: EasyMock
134: .expect(
135: msg
136: .put(
137: RMMessageConstants.RM_PROPERTIES_INBOUND,
138: rmps)).andReturn(null);
139: control.replay();
140: RMContextUtils.storeRMProperties(msg, rmps, false);
141: }
142:
143: @Test
144: public void testRetrieveMAPs() {
145: Message msg = control.createMock(Message.class);
146: EasyMock.expect(msg.get(Message.REQUESTOR_ROLE)).andReturn(
147: Boolean.TRUE);
148: AddressingPropertiesImpl maps = control
149: .createMock(AddressingPropertiesImpl.class);
150: EasyMock
151: .expect(
152: msg
153: .get(JAXWSAConstants.CLIENT_ADDRESSING_PROPERTIES_OUTBOUND))
154: .andReturn(maps);
155: control.replay();
156: assertSame(maps, RMContextUtils.retrieveMAPs(msg, false, true));
157: }
158:
159: @Test
160: public void testStoreMAPs() {
161: Message msg = control.createMock(Message.class);
162: AddressingProperties maps = control
163: .createMock(AddressingProperties.class);
164: EasyMock
165: .expect(
166: msg
167: .put(
168: JAXWSAConstants.CLIENT_ADDRESSING_PROPERTIES_OUTBOUND,
169: maps)).andReturn(null);
170: control.replay();
171: RMContextUtils.storeMAPs(maps, msg, true, true);
172: }
173:
174: }
|