use of org.apache.synapse.util.xpath.SynapseXPath in project wso2-synapse by wso2.
the class PropertyMediatorTest method testMediatorPropertiesExpression.
public void testMediatorPropertiesExpression() throws Exception {
// set a local property to the synapse context
PropertyMediator propMediator = new PropertyMediator();
propMediator.setName("name");
propMediator.setValue("value");
MessageContext synCtx = TestUtils.getTestContext("<empty/>");
propMediator.mediate(synCtx);
// read property through a mediator property
MediatorProperty medProp = new MediatorProperty();
medProp.setExpression(new SynapseXPath("synapse:get-property('name')"));
assertTrue("value".equals(medProp.getEvaluatedExpression(synCtx)));
}
use of org.apache.synapse.util.xpath.SynapseXPath in project wso2-synapse by wso2.
the class FilterMediatorTest method testFilterConditionTrueXPath.
public void testFilterConditionTrueXPath() throws Exception {
setFilterConditionPassed(false);
// create a new filter mediator
FilterMediator filter = new FilterMediator();
// set xpath condition to IBM
SynapseXPath xpath = new SynapseXPath("//*[wsx:symbol='IBM']");
xpath.addNamespace("wsx", "http://www.webserviceX.NET/");
filter.setXpath(xpath);
// set dummy mediator to be called on success
filter.addChild(testMediator);
// test validate mediator, with static enveope
filter.mediate(TestUtils.getTestContext(REQ));
assertTrue(filterConditionPassed);
}
use of org.apache.synapse.util.xpath.SynapseXPath in project wso2-synapse by wso2.
the class FilterMediatorTest method testFilterConditionFalseXPath.
public void testFilterConditionFalseXPath() throws Exception {
setFilterConditionPassed(false);
// create a new filter mediator
FilterMediator filter = new FilterMediator();
// set xpath condition to MSFT
SynapseXPath xpath = new SynapseXPath("//*[wsx:symbol='MSFT']");
xpath.addNamespace("wsx", "http://www.webserviceX.NET/");
filter.setXpath(xpath);
// set dummy mediator to be called on success
filter.addChild(testMediator);
// test validate mediator, with static enveope
filter.mediate(TestUtils.getTestContext(REQ));
assertTrue(!filterConditionPassed);
}
use of org.apache.synapse.util.xpath.SynapseXPath 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.util.xpath.SynapseXPath in project wso2-synapse by wso2.
the class HeaderMediatorTest method testSimpleHeaderXPathSetAndRemove.
public void testSimpleHeaderXPathSetAndRemove() throws Exception {
HeaderMediator headerMediator = new HeaderMediator();
headerMediator.setQName(new QName(SynapseConstants.HEADER_TO));
headerMediator.setExpression(new SynapseXPath("concat('http://','server','/path')"));
// invoke transformation, with static enveope
MessageContext synCtx = TestUtils.getTestContext("<empty/>");
headerMediator.mediate(synCtx);
assertTrue(TEST_HEADER.equals(synCtx.getTo().getAddress()));
// set the header mediator as a remove-header
headerMediator.setAction(HeaderMediator.ACTION_REMOVE);
headerMediator.mediate(synCtx);
assertTrue(synCtx.getTo() == null);
}
Aggregations