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: */
019: package org.apache.axis2.engine;
020:
021: import junit.framework.TestCase;
022: import org.apache.axis2.context.MessageContext;
023: import org.apache.axis2.context.ConfigurationContext;
024: import org.apache.axis2.description.AxisOperation;
025: import org.apache.axis2.description.AxisService;
026: import org.apache.axis2.description.InOnlyAxisOperation;
027: import org.apache.axis2.dispatchers.SOAPActionBasedDispatcher;
028:
029: import javax.xml.namespace.QName;
030:
031: public class SOAPActionBasedDispatcherTest extends TestCase {
032:
033: public void testFindOperation() throws Exception {
034: ConfigurationContext cc = new ConfigurationContext(
035: new AxisConfiguration());
036: MessageContext messageContext = cc.createMessageContext();
037: AxisService as = new AxisService("Service1");
038: messageContext.setAxisService(as);
039:
040: AxisOperation operation1 = new InOnlyAxisOperation(new QName(
041: "operation1"));
042: operation1
043: .setSoapAction("urn:org.apache.axis2.dispatchers.test:operation1");
044:
045: AxisOperation operation2 = new InOnlyAxisOperation(new QName(
046: "operation2"));
047: operation2
048: .setSoapAction("urn:org.apache.axis2.dispatchers.test:operation2");
049:
050: as.addOperation(operation1);
051: as.addOperation(operation2);
052:
053: messageContext
054: .setSoapAction("urn:org.apache.axis2.dispatchers.test:operation1");
055:
056: SOAPActionBasedDispatcher soapActionDispatcher = new SOAPActionBasedDispatcher();
057: soapActionDispatcher.invoke(messageContext);
058: assertEquals(operation1, messageContext.getAxisOperation());
059: }
060:
061: public void testEmptyAction() throws Exception {
062: // We shouldn't be able to route on an emtpy-string action.
063: MessageContext messageContext = new MessageContext();
064: AxisService as = new AxisService("Service1");
065: messageContext.setAxisService(as);
066:
067: AxisOperation operation1 = new InOnlyAxisOperation(new QName(
068: "operation1"));
069: operation1.setSoapAction("");
070:
071: AxisOperation operation2 = new InOnlyAxisOperation(new QName(
072: "operation2"));
073: operation2.setSoapAction("");
074:
075: as.addOperation(operation1);
076: as.addOperation(operation2);
077:
078: messageContext.setSoapAction("");
079:
080: SOAPActionBasedDispatcher soapActionDispatcher = new SOAPActionBasedDispatcher();
081: soapActionDispatcher.invoke(messageContext);
082: assertNull(messageContext.getAxisOperation());
083: }
084:
085: public void testNullAction() throws Exception {
086: // We shouldn't be able to route on a null action.
087: MessageContext messageContext = new MessageContext();
088: AxisService as = new AxisService("Service1");
089: messageContext.setAxisService(as);
090:
091: AxisOperation operation1 = new InOnlyAxisOperation(new QName(
092: "operation1"));
093: operation1.setSoapAction(null);
094:
095: AxisOperation operation2 = new InOnlyAxisOperation(new QName(
096: "operation2"));
097: operation2.setSoapAction(null);
098:
099: as.addOperation(operation1);
100: as.addOperation(operation2);
101:
102: messageContext.setSoapAction(null);
103:
104: SOAPActionBasedDispatcher soapActionDispatcher = new SOAPActionBasedDispatcher();
105: soapActionDispatcher.invoke(messageContext);
106: assertNull(messageContext.getAxisOperation());
107: }
108:
109: public void testDuplicateAction() throws Exception {
110: // We shouldn't be able to route on a SOAPAction that is a duplicate.
111: MessageContext messageContext = new MessageContext();
112: AxisService as = new AxisService("Service1");
113: messageContext.setAxisService(as);
114:
115: AxisOperation operation1 = new InOnlyAxisOperation(new QName(
116: "operation1"));
117: operation1
118: .setSoapAction("urn:org.apache.axis2.dispatchers.test:operation1");
119:
120: AxisOperation operation2 = new InOnlyAxisOperation(new QName(
121: "operation2"));
122: operation2
123: .setSoapAction("urn:org.apache.axis2.dispatchers.test:operation2");
124:
125: as.addOperation(operation1);
126: as.addOperation(operation2);
127:
128: messageContext
129: .setSoapAction("urn:org.apache.axis2.dispatchers.test:operation2");
130:
131: SOAPActionBasedDispatcher soapActionDispatcher = new SOAPActionBasedDispatcher();
132: soapActionDispatcher.invoke(messageContext);
133: assertEquals(operation2, messageContext.getAxisOperation());
134:
135: // Now add a duplicate action, then validate we can't route on it anymore.
136: AxisOperation operation3 = new InOnlyAxisOperation(new QName(
137: "operation3"));
138: // Note that the SOAPAction is intentionally duplicated with operation 2 above.
139: operation3
140: .setSoapAction("urn:org.apache.axis2.dispatchers.test:operation2");
141: as.addOperation(operation3);
142:
143: messageContext = new MessageContext();
144: messageContext.setAxisService(as);
145: messageContext
146: .setSoapAction("urn:org.apache.axis2.dispatchers.test:operation2");
147: soapActionDispatcher.invoke(messageContext);
148: assertNull(messageContext.getAxisOperation());
149:
150: // Now verify that adding another operation with the duplicate SOAPAction
151: // doesn't somehow get it added back into the valid alias map
152: AxisOperation operation4 = new InOnlyAxisOperation(new QName(
153: "operation4"));
154: // Note that the SOAPAction is intentionally duplicated with operation 2 above.
155: operation3
156: .setSoapAction("urn:org.apache.axis2.dispatchers.test:operation2");
157: as.addOperation(operation3);
158:
159: messageContext = new MessageContext();
160: messageContext.setAxisService(as);
161: messageContext
162: .setSoapAction("urn:org.apache.axis2.dispatchers.test:operation2");
163: soapActionDispatcher.invoke(messageContext);
164: assertNull(messageContext.getAxisOperation());
165:
166: // And finally, verify that after all the above, we can still route on a valid
167: // SOAPAction for operation 1 (whose SOAPAction was never duplicated, so should still be
168: // valid)
169: messageContext = new MessageContext();
170: messageContext.setAxisService(as);
171: messageContext
172: .setSoapAction("urn:org.apache.axis2.dispatchers.test:operation1");
173: soapActionDispatcher.invoke(messageContext);
174: assertEquals(operation1, messageContext.getAxisOperation());
175:
176: }
177:
178: }
|