Search in sources :

Example 66 with SynapseXPath

use of org.apache.synapse.util.xpath.SynapseXPath in project wso2-synapse by wso2.

the class FilterMediatorTest method testFilterConditionTrueRegex.

public void testFilterConditionTrueRegex() 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 IBM
    Pattern regex = Pattern.compile("IBM");
    filter.setRegex(regex);
    // set dummy mediator to be called on success
    filter.addChild(testMediator);
    // 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)

Example 67 with SynapseXPath

use of org.apache.synapse.util.xpath.SynapseXPath in project wso2-synapse by wso2.

the class FilterMediatorTest method testFilterConditionFalseRegex.

public void testFilterConditionFalseRegex() 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);
    // set dummy mediator to be called on success
    filter.addChild(testMediator);
    // 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)

Example 68 with SynapseXPath

use of org.apache.synapse.util.xpath.SynapseXPath 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

SynapseXPath (org.apache.synapse.util.xpath.SynapseXPath)68 MessageContext (org.apache.synapse.MessageContext)24 JaxenException (org.jaxen.JaxenException)20 Axis2MessageContext (org.apache.synapse.core.axis2.Axis2MessageContext)15 OMElement (org.apache.axiom.om.OMElement)14 OMAttribute (org.apache.axiom.om.OMAttribute)11 Value (org.apache.synapse.mediators.Value)9 TestMessageContext (org.apache.synapse.TestMessageContext)8 Pattern (java.util.regex.Pattern)6 Iterator (java.util.Iterator)5 QName (javax.xml.namespace.QName)5 EndpointReference (org.apache.axis2.addressing.EndpointReference)4 SynapseException (org.apache.synapse.SynapseException)4 TestMessageContextBuilder (org.apache.synapse.TestMessageContextBuilder)4 SynapseJsonPath (org.apache.synapse.util.xpath.SynapseJsonPath)4 Method (java.lang.reflect.Method)3 Map (java.util.Map)3 MediatorProperty (org.apache.synapse.mediators.MediatorProperty)3 Field (java.lang.reflect.Field)2 List (java.util.List)2