Search in sources :

Example 1 with ForEachMediatorFactory

use of org.apache.synapse.config.xml.ForEachMediatorFactory in project wso2-synapse by wso2.

the class ForEachMediatorTest method testForEachXpathNodeRelativePath.

/**
 * Testing when the xpath returns only one element
 *
 * @throws Exception
 */
public void testForEachXpathNodeRelativePath() throws Exception {
    // Clear envelope
    if (testCtx.getEnvelope().getBody().getFirstElement() != null) {
        testCtx.getEnvelope().getBody().getFirstElement().detach();
    }
    testCtx.getEnvelope().getBody().addChild(createOMElement("<original>" + "<itr id=\"one\">test-split-context-itr1-body</itr>" + "<itr>test-split-context-itr2-body</itr>" + "</original>"));
    MediatorFactory fac = new ForEachMediatorFactory();
    Mediator foreach = fac.createMediator(createOMElement("<foreach " + "expression=\"//itr[@id='one']\" sequence=\"seqRef\" />"), new Properties());
    helperMediator.clearMediatedContexts();
    foreach.mediate(testCtx);
    assertEquals(1, helperMediator.getMsgCount());
    assertEquals("<itr id=\"one\">test-split-context-itr1-body</itr>", helperMediator.getMediatedContext(0).getEnvelope().getBody().getFirstElement().toString());
}
Also used : ForEachMediatorFactory(org.apache.synapse.config.xml.ForEachMediatorFactory) ForEachMediatorFactory(org.apache.synapse.config.xml.ForEachMediatorFactory) MediatorFactory(org.apache.synapse.config.xml.MediatorFactory) Mediator(org.apache.synapse.Mediator) SequenceMediator(org.apache.synapse.mediators.base.SequenceMediator) Properties(java.util.Properties)

Example 2 with ForEachMediatorFactory

use of org.apache.synapse.config.xml.ForEachMediatorFactory in project wso2-synapse by wso2.

the class ForEachMediatorTest method testForEachXpathList.

/**
 * Testing when the xpath returns a list of elements
 *
 * @throws Exception
 */
public void testForEachXpathList() 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 foreach = fac.createMediator(createOMElement("<foreach expression=\"//original/itr\" sequence=\"seqRef\" />"), new Properties());
    helperMediator.clearMediatedContexts();
    foreach.mediate(testCtx);
    assertEquals(2, helperMediator.getMsgCount());
    assertEquals("<itr>test-split-context-itr1-body</itr>", helperMediator.getMediatedContext(0).getEnvelope().getBody().getFirstElement().toString());
    assertEquals("<itr>test-split-context-itr2-body</itr>", helperMediator.getMediatedContext(1).getEnvelope().getBody().getFirstElement().toString());
}
Also used : ForEachMediatorFactory(org.apache.synapse.config.xml.ForEachMediatorFactory) ForEachMediatorFactory(org.apache.synapse.config.xml.ForEachMediatorFactory) MediatorFactory(org.apache.synapse.config.xml.MediatorFactory) Mediator(org.apache.synapse.Mediator) SequenceMediator(org.apache.synapse.mediators.base.SequenceMediator) Properties(java.util.Properties)

Example 3 with ForEachMediatorFactory

use of org.apache.synapse.config.xml.ForEachMediatorFactory in project wso2-synapse by wso2.

the class ForEachMediatorTest method testForEachXpathNode.

/**
 * Testing when the xpath returns only one element
 *
 * @throws Exception
 */
public void testForEachXpathNode() throws Exception {
    // Clear envelope
    if (testCtx.getEnvelope().getBody().getFirstElement() != null) {
        testCtx.getEnvelope().getBody().getFirstElement().detach();
    }
    testCtx.getEnvelope().getBody().addChild(createOMElement("<original>" + "<itr id=\"one\">test-split-context-itr1-body</itr>" + "<itr>test-split-context-itr2-body</itr>" + "</original>"));
    MediatorFactory fac = new ForEachMediatorFactory();
    Mediator foreach = fac.createMediator(createOMElement("<foreach " + "expression=\"//original/itr[@id='one']\" sequence=\"seqRef\" />"), new Properties());
    helperMediator.clearMediatedContexts();
    foreach.mediate(testCtx);
    assertEquals(1, helperMediator.getMsgCount());
    assertEquals("<itr id=\"one\">test-split-context-itr1-body</itr>", helperMediator.getMediatedContext(0).getEnvelope().getBody().getFirstElement().toString());
}
Also used : ForEachMediatorFactory(org.apache.synapse.config.xml.ForEachMediatorFactory) ForEachMediatorFactory(org.apache.synapse.config.xml.ForEachMediatorFactory) MediatorFactory(org.apache.synapse.config.xml.MediatorFactory) Mediator(org.apache.synapse.Mediator) SequenceMediator(org.apache.synapse.mediators.base.SequenceMediator) Properties(java.util.Properties)

Example 4 with ForEachMediatorFactory

use of org.apache.synapse.config.xml.ForEachMediatorFactory in project wso2-synapse by wso2.

the class ForEachMediatorTest method testForEachXpathListRelativePath.

/**
 * Testing when the relative xpath returns a list of elements
 *
 * @throws Exception
 */
public void testForEachXpathListRelativePath() 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 foreach = fac.createMediator(createOMElement("<foreach " + "expression=\"//itr\" sequence=\"seqRef\" />"), new Properties());
    helperMediator.clearMediatedContexts();
    foreach.mediate(testCtx);
    assertEquals(2, helperMediator.getMsgCount());
    assertEquals("<itr>test-split-context-itr1-body</itr>", helperMediator.getMediatedContext(0).getEnvelope().getBody().getFirstElement().toString());
    assertEquals("<itr>test-split-context-itr2-body</itr>", helperMediator.getMediatedContext(1).getEnvelope().getBody().getFirstElement().toString());
}
Also used : ForEachMediatorFactory(org.apache.synapse.config.xml.ForEachMediatorFactory) ForEachMediatorFactory(org.apache.synapse.config.xml.ForEachMediatorFactory) MediatorFactory(org.apache.synapse.config.xml.MediatorFactory) Mediator(org.apache.synapse.Mediator) SequenceMediator(org.apache.synapse.mediators.base.SequenceMediator) Properties(java.util.Properties)

Example 5 with ForEachMediatorFactory

use of org.apache.synapse.config.xml.ForEachMediatorFactory 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);
}
Also used : SynapseException(org.apache.synapse.SynapseException) ForEachMediatorFactory(org.apache.synapse.config.xml.ForEachMediatorFactory) ForEachMediatorFactory(org.apache.synapse.config.xml.ForEachMediatorFactory) MediatorFactory(org.apache.synapse.config.xml.MediatorFactory) Mediator(org.apache.synapse.Mediator) SequenceMediator(org.apache.synapse.mediators.base.SequenceMediator) Properties(java.util.Properties)

Aggregations

Properties (java.util.Properties)5 Mediator (org.apache.synapse.Mediator)5 ForEachMediatorFactory (org.apache.synapse.config.xml.ForEachMediatorFactory)5 MediatorFactory (org.apache.synapse.config.xml.MediatorFactory)5 SequenceMediator (org.apache.synapse.mediators.base.SequenceMediator)5 SynapseException (org.apache.synapse.SynapseException)1