Search in sources :

Example 1 with AnonymousListMediator

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);
}
Also used : SynapseXPath(org.apache.synapse.util.xpath.SynapseXPath) SwitchCase(org.apache.synapse.config.xml.SwitchCase) TestMediateHandler(org.apache.synapse.mediators.TestMediateHandler) AnonymousListMediator(org.apache.synapse.config.xml.AnonymousListMediator) TestMediator(org.apache.synapse.mediators.TestMediator) Mediator(org.apache.synapse.Mediator) AnonymousListMediator(org.apache.synapse.config.xml.AnonymousListMediator) TestMediator(org.apache.synapse.mediators.TestMediator) MessageContext(org.apache.synapse.MessageContext)

Example 2 with AnonymousListMediator

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);
}
Also used : SynapseXPath(org.apache.synapse.util.xpath.SynapseXPath) Pattern(java.util.regex.Pattern) AnonymousListMediator(org.apache.synapse.config.xml.AnonymousListMediator)

Aggregations

AnonymousListMediator (org.apache.synapse.config.xml.AnonymousListMediator)2 SynapseXPath (org.apache.synapse.util.xpath.SynapseXPath)2 Pattern (java.util.regex.Pattern)1 Mediator (org.apache.synapse.Mediator)1 MessageContext (org.apache.synapse.MessageContext)1 SwitchCase (org.apache.synapse.config.xml.SwitchCase)1 TestMediateHandler (org.apache.synapse.mediators.TestMediateHandler)1 TestMediator (org.apache.synapse.mediators.TestMediator)1