use of org.apache.synapse.config.xml.AnonymousListMediator in project wso2-synapse by wso2.
the class SwitchMediatorTest method setUp.
public void setUp() throws Exception {
ibmMediator = new TestMediator();
ibmMediator.setHandler(new TestMediateHandler() {
public void handle(MessageContext synCtx) {
setExecutedCase("IBM");
}
});
msftMediator = new TestMediator();
msftMediator.setHandler(new TestMediateHandler() {
public void handle(MessageContext synCtx) {
setExecutedCase("MSFT");
}
});
defaultMediator = new TestMediator();
defaultMediator.setHandler(new TestMediateHandler() {
public void handle(MessageContext synCtx) {
setExecutedCase("DEFAULT");
}
});
// create a new switch mediator
switchMediator = new SwitchMediator();
// set xpath condition to select symbol
SynapseXPath xpath = new SynapseXPath("//wsx:symbol");
xpath.addNamespace("wsx", "http://www.webserviceX.NET/");
switchMediator.setSource(xpath);
SwitchCase caseOne = new SwitchCase();
caseOne.setRegex(Pattern.compile("IBM"));
AnonymousListMediator mediatorOne = new AnonymousListMediator();
mediatorOne.addAll(Arrays.asList(new Mediator[] { ibmMediator }));
caseOne.setCaseMediator(mediatorOne);
SwitchCase caseTwo = new SwitchCase();
caseTwo.setRegex(Pattern.compile("MSFT"));
AnonymousListMediator mediatorTwo = new AnonymousListMediator();
mediatorTwo.addAll(Arrays.asList(new Mediator[] { msftMediator }));
caseTwo.setCaseMediator(mediatorTwo);
SwitchCase caseDefault = new SwitchCase();
AnonymousListMediator mediatorDefault = new AnonymousListMediator();
mediatorDefault.addAll(Arrays.asList(new Mediator[] { defaultMediator }));
caseDefault.setCaseMediator(mediatorDefault);
// set ibm mediator to be called for IBM, msft for MSFT and default for others..
switchMediator.addCase(caseOne);
switchMediator.addCase(caseTwo);
switchMediator.setDefaultCase(caseDefault);
}
use of org.apache.synapse.config.xml.AnonymousListMediator in project wso2-synapse by wso2.
the class FilterMediatorTest method testFilterConditionWithThenElse.
public void testFilterConditionWithThenElse() 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);
AnonymousListMediator seq = new AnonymousListMediator();
seq.addChild(testMediator);
filter.setElseMediator(seq);
// test validate mediator, with static enveope
filter.mediate(TestUtils.getTestContext(REQ));
assertTrue(filterConditionPassed);
}
Aggregations