use of org.apache.synapse.util.xpath.SynapseXPath in project wso2-synapse by wso2.
the class PayloadFactoryMediatorTest method testWithExpressionsAsArguments.
/**
* Test payloadFactory Mediator with dynamic expressions set
* @throws Exception in case of argument evaluation issue
*/
public void testWithExpressionsAsArguments() throws Exception {
PayloadFactoryMediator payloadFactoryMediator = new PayloadFactoryMediator();
payloadFactoryMediator.setFormat(format);
// prepare arguments
Argument argument1 = new Argument();
argument1.setExpression(new SynapseXPath("//name"));
Argument argument2 = new Argument();
argument2.setExpression(new SynapseXPath("get-property('SYSTEM_DATE', 'yyyy.MM.dd')"));
Argument argument3 = new Argument();
argument3.setExpression(new SynapseXPath("//tpNumber"));
Argument argument4 = new Argument();
argument4.setExpression(new SynapseXPath("//address"));
// add arguments
payloadFactoryMediator.addPathArgument(argument1);
payloadFactoryMediator.addPathArgument(argument2);
payloadFactoryMediator.addPathArgument(argument3);
payloadFactoryMediator.addPathArgument(argument4);
// do mediation
MessageContext synCtx = TestUtils.getAxis2MessageContext(inputPayload, null);
payloadFactoryMediator.mediate(synCtx);
String expectedEnvelope = "<soapenv:Body xmlns:soapenv=\"http://schemas.xmlsoap" + ".org/soap/envelope/\"><p:addCustomer xmlns:p=\"http://ws.wso2.org/dataservice\">\n" + " <xs:name xmlns:xs=\"http://ws.wso2.org/dataservice\">Smith</xs:name>\n" + " <xs:request_time xmlns:xs=\"http://ws.wso2.org/dataservice\">" + new SimpleDateFormat("yyyy.MM.dd").format(Calendar.getInstance().getTime()) + "</xs:request_time>\n" + " <xs:tp_number xmlns:xs=\"http://ws.wso2.org/dataservice\">0834558649</xs:tp_number>\n" + " <xs:address xmlns:xs=\"http://ws.wso2.org/dataservice\">No. 456, Gregory Road, Los " + "Angeles</xs:address>\n" + " </p:addCustomer></soapenv:Body>";
assertEquals("PayloadFactory mediator has not " + "set expected format", expectedEnvelope, synCtx.getEnvelope().getBody().toString());
}
use of org.apache.synapse.util.xpath.SynapseXPath in project wso2-synapse by wso2.
the class SynapseXPathTest method testStringXPath2.
public void testStringXPath2() throws Exception {
SynapseXPath xpath = SynapseXPath.parseXPathString("$body//{http://somens}test/{http://someother}another");
MessageContext ctx = TestUtils.getTestContext("<m0:test xmlns:m0=\"http://somens\"><m1:another xmlns:m1=\"http://someother\">" + message + "</m1:another></m0:test>");
assertEquals(message, xpath.stringValueOf(ctx));
}
use of org.apache.synapse.util.xpath.SynapseXPath in project wso2-synapse by wso2.
the class SynapseXPathTest method testCustomVariables.
public void testCustomVariables() throws Exception {
SynapseXPath xpath = new SynapseXPath("$myvar");
SimpleVariableContext variableContext = new SimpleVariableContext();
variableContext.setVariableValue("myvar", "myvalue");
xpath.setVariableContext(variableContext);
assertEquals("myvalue", xpath.evaluate(TestUtils.getTestContext("<test/>")));
}
use of org.apache.synapse.util.xpath.SynapseXPath in project wso2-synapse by wso2.
the class SynapseXPathTest method testBodyRelativeXPath.
public void testBodyRelativeXPath() throws Exception {
SynapseXPath xpath = new SynapseXPath("$body/test");
MessageContext ctx = TestUtils.getTestContext("<test>" + message + "</test>");
assertEquals(message, xpath.stringValueOf(ctx));
Object node = xpath.selectSingleNode(ctx);
assertTrue(node instanceof OMElement);
assertEquals(message, ((OMElement) node).getText());
}
use of org.apache.synapse.util.xpath.SynapseXPath in project wso2-synapse by wso2.
the class SynapseXPathTest method testTransportHeaders.
public void testTransportHeaders() throws Exception {
Axis2MessageContext synCtx = TestUtils.getAxis2MessageContext("<test/>", null);
org.apache.axis2.context.MessageContext axis2MessageCtx = synCtx.getAxis2MessageContext();
Object headers = axis2MessageCtx.getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS);
String name = "MyHeader";
String resultValue = "TestValue";
if (headers != null && headers instanceof Map) {
Map headersMap = (Map) headers;
headersMap.put(name, resultValue);
}
if (headers == null) {
Map headersMap = new HashMap();
headersMap.put(name, resultValue);
axis2MessageCtx.setProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS, headersMap);
}
assertEquals(resultValue, new SynapseXPath("$trp:" + name).evaluate(synCtx));
}
Aggregations