use of org.apache.synapse.config.xml.MediatorFactory in project wso2-synapse by wso2.
the class ForEachMediatorTest method testSequenceValidity.
/**
* Testing validity of reference sequence. Other cases : inline sequence
* is covered in ForEachMediatorFactory
*
* @throws Exception
*/
public void testSequenceValidity() throws Exception {
// Clear envelope
if (testCtx.getEnvelope().getBody().getFirstElement() != null) {
testCtx.getEnvelope().getBody().getFirstElement().detach();
}
testCtx.getEnvelope().getBody().addChild(createOMElement("<original>" + "<itr>test-split-context-itr1-body</itr>" + "<itr>test-split-context-itr2-body</itr>" + "</original>"));
MediatorFactory fac = new ForEachMediatorFactory();
Mediator foreachInvalid = fac.createMediator(createOMElement("<foreach expression=\"//original/itr\" sequence=\"seqRefInvalid\" />"), new Properties());
String result = null;
try {
foreachInvalid.mediate(testCtx);
result = testCtx.getEnvelope().getBody().getFirstElement().toString();
} catch (SynapseException ex) {
result = ex.getMessage();
}
assertTrue(result.contains("Referred sequence cannot contain Call"));
// Clear envelope
if (testCtx.getEnvelope().getBody().getFirstElement() != null) {
testCtx.getEnvelope().getBody().getFirstElement().detach();
}
testCtx.getEnvelope().getBody().addChild(createOMElement("<original>" + "<itr>test-split-context-itr1-body</itr>" + "<itr>test-split-context-itr2-body</itr>" + "</original>"));
Mediator foreachValid = fac.createMediator(createOMElement("<foreach " + "expression=\"//original/itr\" sequence=\"seqRef\" />"), new Properties());
boolean successValid = foreachValid.mediate(testCtx);
assertEquals(true, successValid);
}
Aggregations