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:
20: package org.apache.synapse.mediators.ext;
21:
22: import org.apache.synapse.ManagedLifecycle;
23: import org.apache.synapse.Mediator;
24: import org.apache.synapse.TestMessageContext;
25: import org.apache.synapse.config.SynapseConfiguration;
26: import org.apache.synapse.config.xml.MediatorFactoryFinder;
27: import org.apache.synapse.core.axis2.Axis2SynapseEnvironment;
28: import org.apache.synapse.mediators.AbstractMediatorTestCase;
29:
30: /**
31: * Tests the class mediator instantiation and setting of literal and
32: * XPath parameters at runtime.
33: */
34: public class ClassMediatorTest extends AbstractMediatorTestCase {
35:
36: public void testMediationWithoutProperties() throws Exception {
37: Mediator cm = MediatorFactoryFinder
38: .getInstance()
39: .getMediator(
40: createOMElement("<class name='org.apache.synapse.mediators.ext.ClassMediatorTestMediator' "
41: + "xmlns='http://ws.apache.org/ns/synapse'/>"));
42: cm.mediate(new TestMessageContext());
43: assertTrue(ClassMediatorTestMediator.invoked);
44: }
45:
46: public void testMediationWithLiteralProperties() throws Exception {
47: Mediator cm = MediatorFactoryFinder
48: .getInstance()
49: .getMediator(
50: createOMElement("<class name='org.apache.synapse.mediators.ext.ClassMediatorTestMediator' "
51: + "xmlns='http://ws.apache.org/ns/synapse'><property name='testProp' value='testValue'/></class>"));
52: cm.mediate(new TestMessageContext());
53: assertTrue(ClassMediatorTestMediator.invoked);
54: assertTrue(ClassMediatorTestMediator.testProp
55: .equals("testValue"));
56: }
57:
58: public void testInitializationAndMedition() throws Exception {
59: Mediator cm = MediatorFactoryFinder
60: .getInstance()
61: .getMediator(
62: createOMElement("<class name='org.apache.synapse.mediators.ext.ClassMediatorTestMediator' "
63: + "xmlns='http://ws.apache.org/ns/synapse'/>"));
64: ((ManagedLifecycle) cm).init(new Axis2SynapseEnvironment(
65: new SynapseConfiguration()));
66: assertTrue(ClassMediatorTestMediator.initialized);
67: cm.mediate(new TestMessageContext());
68: assertTrue(ClassMediatorTestMediator.invoked);
69: }
70:
71: public void testDestroy() throws Exception {
72: Mediator cm = MediatorFactoryFinder
73: .getInstance()
74: .getMediator(
75: createOMElement("<class name='org.apache.synapse.mediators.ext.ClassMediatorTestMediator' "
76: + "xmlns='http://ws.apache.org/ns/synapse'/>"));
77: cm.mediate(new TestMessageContext());
78: assertTrue(ClassMediatorTestMediator.invoked);
79: ((ManagedLifecycle) cm).destroy();
80: assertTrue(ClassMediatorTestMediator.destroyed);
81: }
82:
83: // public void testCreationWithXPathProperties() throws Exception {
84: // ClassMediator cm = new ClassMediator();
85: // MediatorProperty mp = new MediatorProperty();
86: // mp.setName("testProp");
87: // mp.setExpression(new SynapseXPath("concat('XPath ','is ','FUN!')"));
88: // cm.addProperty(mp);
89: // cm.setClazz(ClassMediatorTestMediator.class);
90: // cm.mediate(new TestMessageContext());
91: // assertTrue(ClassMediatorTestMediator.testProp.equals("XPath is FUN!"));
92: // }
93:
94: }
|