01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: */
19: package org.apache.axis2.dispatchers;
20:
21: import junit.framework.TestCase;
22: import org.apache.axis2.AxisFault;
23: import org.apache.axis2.addressing.RelatesTo;
24: import org.apache.axis2.context.ConfigurationContext;
25: import org.apache.axis2.context.MessageContext;
26: import org.apache.axis2.context.OperationContext;
27: import org.apache.axis2.context.ServiceContext;
28: import org.apache.axis2.context.ServiceGroupContext;
29: import org.apache.axis2.description.AxisOperation;
30: import org.apache.axis2.description.AxisService;
31: import org.apache.axis2.description.InOnlyAxisOperation;
32: import org.apache.axis2.description.AxisServiceGroup;
33: import org.apache.axis2.engine.AxisConfiguration;
34:
35: import javax.xml.namespace.QName;
36:
37: public class RelatesToBasedServiceDispatcherTest extends TestCase {
38:
39: public void testFindService() throws AxisFault {
40:
41: MessageContext messageContext;
42:
43: AxisConfiguration ac = new AxisConfiguration();
44: ConfigurationContext cc = new ConfigurationContext(ac);
45: AxisService as1 = new AxisService("Service1");
46: AxisServiceGroup sg = new AxisServiceGroup(ac);
47: sg.addService(as1);
48: ServiceGroupContext sgc = cc.createServiceGroupContext(sg);
49:
50: ServiceContext sc1 = sgc.getServiceContext(as1);
51:
52: AxisService as2 = new AxisService("Service2");
53: sg.addService(as2);
54: ServiceContext sc2 = sgc.getServiceContext(as2);
55:
56: ac.addService(as1);
57: ac.addService(as2);
58:
59: AxisOperation operation1 = new InOnlyAxisOperation(new QName(
60: "operation1"));
61: AxisOperation operation2 = new InOnlyAxisOperation(new QName(
62: "operation2"));
63: as1.addOperation(operation1);
64: as2.addOperation(operation2);
65:
66: OperationContext oc1 = sc1.createOperationContext(operation1);
67: OperationContext oc2 = sc2.createOperationContext(operation2);
68:
69: cc.registerOperationContext(
70: "urn:org.apache.axis2.dispatchers.messageid:123", oc1);
71: cc.registerOperationContext(
72: "urn:org.apache.axis2.dispatchers.messageid:456", oc2);
73: messageContext = cc.createMessageContext();
74: messageContext.addRelatesTo(new RelatesTo(
75: "urn:org.apache.axis2.dispatchers.messageid:456"));
76:
77: RelatesToBasedServiceDispatcher ruisd = new RelatesToBasedServiceDispatcher();
78: ruisd.invoke(messageContext);
79:
80: assertEquals(as2, messageContext.getAxisService());
81: }
82:
83: }
|