use of org.apache.synapse.mediators.base.SequenceMediator in project wso2-synapse by wso2.
the class FilterMediatorTest method testFilterConditionWithThenElseKey.
public void testFilterConditionWithThenElseKey() throws Exception {
setFilterConditionPassed(false);
// create a new filter mediator
FilterMediator filter = new FilterMediator();
// set source xpath condition to //symbol
SynapseXPath source = new SynapseXPath("//wsx:symbol");
source.addNamespace("wsx", "http://www.webserviceX.NET/");
filter.setSource(source);
// set regex to MSFT
Pattern regex = Pattern.compile("MSFT");
filter.setRegex(regex);
MessageContext msgCtx = TestUtils.getTestContext(REQ);
SequenceMediator seq = new SequenceMediator();
seq.setName("refSeq");
seq.addChild(testMediator);
msgCtx.getConfiguration().addSequence("refSeq", testMediator);
filter.setElseKey("refSeq");
// test validate mediator, with static enveope
filter.mediate(msgCtx);
assertTrue(filterConditionPassed);
}
use of org.apache.synapse.mediators.base.SequenceMediator in project wso2-synapse by wso2.
the class ForEachMediatorTest method setUp.
protected void setUp() throws Exception {
super.setUp();
SynapseConfiguration synCfg = new SynapseConfiguration();
AxisConfiguration config = new AxisConfiguration();
testCtx = new Axis2MessageContext(new org.apache.axis2.context.MessageContext(), synCfg, new Axis2SynapseEnvironment(new ConfigurationContext(config), synCfg));
((Axis2MessageContext) testCtx).getAxis2MessageContext().setConfigurationContext(new ConfigurationContext(config));
SOAPEnvelope envelope = OMAbstractFactory.getSOAP11Factory().getDefaultEnvelope();
testCtx.setEnvelope(envelope);
testCtx.setSoapAction("urn:test");
SequenceMediator seqMed = new SequenceMediator();
helperMediator = new ForEachHelperMediator();
helperMediator.init(testCtx.getEnvironment());
seqMed.addChild(helperMediator);
SequenceMediator seqMedInvalid = new SequenceMediator();
SendMediator sendMediator = new SendMediator();
sendMediator.init(testCtx.getEnvironment());
seqMedInvalid.addChild(sendMediator);
testCtx.getConfiguration().addSequence("seqRef", seqMed);
testCtx.getConfiguration().addSequence("seqRefInvalid", seqMedInvalid);
testCtx.getConfiguration().addSequence("main", new SequenceMediator());
testCtx.getConfiguration().addSequence("fault", new SequenceMediator());
testCtx.setEnvelope(envelope);
}
use of org.apache.synapse.mediators.base.SequenceMediator in project wso2-synapse by wso2.
the class DynamicResourceTest method testDynamicSequenceLookup.
public void testDynamicSequenceLookup() throws Exception {
System.out.println("Testing dynamic sequence lookup...");
// Phase 1
System.out.println("Testing basic registry lookup functionality...");
MessageContext synCtx = TestUtils.createLightweightSynapseMessageContext("<empty/>", config);
Mediator seq1 = synCtx.getSequence(KEY_DYNAMIC_SEQUENCE_1);
assertNotNull(seq1);
assertTrue(((SequenceMediator) seq1).isInitialized());
assertEquals(1, registry.getHitCount());
seq1.mediate(synCtx);
assertEquals("bar", synCtx.getProperty("foo"));
// Phase 2
System.out.println("Testing basic sequence caching...");
synCtx = TestUtils.createLightweightSynapseMessageContext("<empty/>", config);
Mediator seq2 = synCtx.getSequence(KEY_DYNAMIC_SEQUENCE_1);
assertNotNull(seq2);
assertTrue(((SequenceMediator) seq2).isInitialized());
assertEquals(1, registry.getHitCount());
seq2.mediate(synCtx);
assertEquals("bar", synCtx.getProperty("foo"));
assertTrue(seq1 == seq2);
// Phase 3
System.out.println("Testing advanced sequence caching...");
synCtx = TestUtils.createLightweightSynapseMessageContext("<empty/>", config);
System.out.println("Waiting for the cache to expire...");
Thread.sleep(8500L);
Mediator seq3 = synCtx.getSequence(KEY_DYNAMIC_SEQUENCE_1);
assertNotNull(seq3);
assertTrue(((SequenceMediator) seq3).isInitialized());
assertEquals(1, registry.getHitCount());
seq3.mediate(synCtx);
assertEquals("bar", synCtx.getProperty("foo"));
assertTrue(seq1 == seq3);
// Phase 4
System.out.println("Testing sequence reloading...");
registry.updateResource(KEY_DYNAMIC_SEQUENCE_1, TestUtils.createOMElement(DYNAMIC_SEQUENCE_2));
System.out.println("Waiting for the cache to expire...");
Thread.sleep(8500L);
synCtx = TestUtils.createLightweightSynapseMessageContext("<empty/>", config);
Mediator seq4 = synCtx.getSequence(KEY_DYNAMIC_SEQUENCE_1);
assertNotNull(seq4);
assertTrue(((SequenceMediator) seq4).isInitialized());
assertEquals(2, registry.getHitCount());
seq4.mediate(synCtx);
assertEquals("baz", synCtx.getProperty("foo"));
assertTrue(seq1 != seq4);
assertTrue(!((SequenceMediator) seq1).isInitialized());
// Phase 5
System.out.println("Testing for non-existing sequences...");
synCtx = TestUtils.createSynapseMessageContext("<empty/>", config);
Mediator seq5 = synCtx.getSequence("non-existing-sequence");
assertNull(seq5);
System.out.println("Dynamic sequence lookup tests were successful...");
}
use of org.apache.synapse.mediators.base.SequenceMediator in project wso2-synapse by wso2.
the class AbstractSplitMediatorTestCase method setUp.
protected void setUp() throws Exception {
super.setUp();
SynapseConfiguration synCfg = new SynapseConfiguration();
AxisConfiguration config = new AxisConfiguration();
testCtx = new Axis2MessageContext(new org.apache.axis2.context.MessageContext(), synCfg, new Axis2SynapseEnvironment(new ConfigurationContext(config), synCfg));
((Axis2MessageContext) testCtx).getAxis2MessageContext().setConfigurationContext(new ConfigurationContext(config));
SOAPEnvelope envelope = OMAbstractFactory.getSOAP11Factory().getDefaultEnvelope();
envelope.getBody().addChild(createOMElement("<original>test-split-context</original>"));
testCtx.setEnvelope(envelope);
testCtx.setSoapAction("urn:test");
SequenceMediator seqMed = new SequenceMediator();
helperMediator = new SplitTestHelperMediator();
helperMediator.init(testCtx.getEnvironment());
seqMed.addChild(helperMediator);
testCtx.getConfiguration().addSequence("seqRef", seqMed);
testCtx.getConfiguration().addSequence("main", new SequenceMediator());
testCtx.getConfiguration().addSequence("fault", new SequenceMediator());
}
Aggregations