use of org.apache.synapse.util.xpath.SynapseXPath in project wso2-synapse by wso2.
the class SynapseXPathTest method testHeaderRelativeXPath.
public void testHeaderRelativeXPath() throws Exception {
MessageContext ctx = TestUtils.getTestContext("<test>" + message + "</test>");
OMFactory fac = ctx.getEnvelope().getOMFactory();
OMNamespace ns = fac.createOMNamespace("http://test", "t");
ctx.getEnvelope().getHeader().addHeaderBlock("test", ns).setText(message);
ctx.getEnvelope().getHeader().addHeaderBlock("test2", ns);
SynapseXPath xpath = new SynapseXPath("$header/t:test");
xpath.addNamespace(ns);
assertEquals(message, xpath.stringValueOf(ctx));
xpath = new SynapseXPath("$header/*");
assertEquals(2, xpath.selectNodes(ctx).size());
}
use of org.apache.synapse.util.xpath.SynapseXPath in project wso2-synapse by wso2.
the class SynapseXPathTest method testContextProperties.
public void testContextProperties() throws Exception {
SynapseXPath xpath = new SynapseXPath("$ctx:test");
MessageContext synCtx = new TestMessageContext();
synCtx.setProperty("test", message);
assertEquals(xpath.evaluate(synCtx), message);
}
use of org.apache.synapse.util.xpath.SynapseXPath in project wso2-synapse by wso2.
the class Axis2MessageContextTest method testMessageContextGetStringValueEnvelope.
public void testMessageContextGetStringValueEnvelope() throws Exception {
SynapseXPath axiomXpath = new SynapseXPath("/s11:Envelope/s11:Body/ns1:a/ns1:c");
axiomXpath.addNamespace("s11", nsSoapEnv);
axiomXpath.addNamespace("ns1", nsNamespace1);
MessageContext synCtx = TestUtils.getTestContext(sampleBody);
String result = axiomXpath.stringValueOf(synCtx);
assertEquals("second", result);
}
use of org.apache.synapse.util.xpath.SynapseXPath in project wso2-synapse by wso2.
the class EventFilterTest method testTopicBasedEventFilter.
public void testTopicBasedEventFilter() {
String status = "snow";
try {
MessageContext msgCtx = TestUtils.getAxis2MessageContext("<weatherCondition>" + status + "</weatherCondition>", null).getAxis2MessageContext();
Event<MessageContext> event = new Event<MessageContext>();
event.setMessage(msgCtx);
TopicBasedEventFilter filter = new TopicBasedEventFilter();
filter.setResultValue(status);
filter.setSourceXpath(new SynapseXPath("//weatherCondition"));
assertTrue(filter.match(event));
filter.setResultValue("rain");
assertFalse(filter.match(event));
} catch (Exception e) {
fail("Error while constructing the test message context: " + e.getMessage());
}
}
use of org.apache.synapse.util.xpath.SynapseXPath in project wso2-synapse by wso2.
the class EventFilterTest method testXPathBasedEventFilter.
public void testXPathBasedEventFilter() {
String status = "snow";
try {
org.apache.synapse.MessageContext msgCtx = TestUtils.createLightweightSynapseMessageContext("<weatherCondition>" + status + "</weatherCondition>");
XPathBasedEventFilter filter = new XPathBasedEventFilter();
filter.setResultValue(status);
filter.setSourceXpath(new SynapseXPath("//weatherCondition"));
assertTrue(filter.isSatisfied(msgCtx));
filter.setResultValue("rain");
assertFalse(filter.isSatisfied(msgCtx));
} catch (Exception e) {
e.printStackTrace();
fail("Error while constructing the test message context: " + e.getMessage());
}
}
Aggregations