Search in sources :

Example 21 with Mediator

use of org.apache.synapse.Mediator 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 22 with Mediator

use of org.apache.synapse.Mediator 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 23 with Mediator

use of org.apache.synapse.Mediator in project wso2-synapse by wso2.

the class POJOCommandMediatorTest method testPojoWithPropertiesCommandImpl.

public void testPojoWithPropertiesCommandImpl() throws Exception {
    Mediator pcm = MediatorFactoryFinder.getInstance().getMediator(createOMElement("<pojoCommand name='org.apache.synapse.mediators.ext.POJOCommandTestImplementedMediator' " + "xmlns='http://ws.apache.org/ns/synapse'><property name=\"testProp\" " + "expression=\"fn:concat('XPATH ', 'FUNC')\" action=\"ReadMessage\"/></pojoCommand>"), new Properties());
    POJOCommandTestHelper.reset();
    TestMessageContext msgContext = new TestMessageContext();
    msgContext.setEnvironment(new Axis2SynapseEnvironment(new SynapseConfiguration()));
    pcm.mediate(msgContext);
    assertEquals("XPATH FUNC", POJOCommandTestHelper.getInstance().getChangedProperty());
    assertTrue(POJOCommandTestHelper.getInstance().isExecuted());
}
Also used : Axis2SynapseEnvironment(org.apache.synapse.core.axis2.Axis2SynapseEnvironment) TestMessageContext(org.apache.synapse.TestMessageContext) Mediator(org.apache.synapse.Mediator) Properties(java.util.Properties) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration)

Example 24 with Mediator

use of org.apache.synapse.Mediator in project wso2-synapse by wso2.

the class POJOCommandMediatorTest method testPojoWithoutPropertiesCommandImpl.

public void testPojoWithoutPropertiesCommandImpl() throws Exception {
    Mediator pcm = MediatorFactoryFinder.getInstance().getMediator(createOMElement("<pojoCommand name='org.apache.synapse.mediators.ext.POJOCommandTestImplementedMediator' " + "xmlns='http://ws.apache.org/ns/synapse'/>"), new Properties());
    POJOCommandTestHelper.reset();
    TestMessageContext msgContext = new TestMessageContext();
    msgContext.setEnvironment(new Axis2SynapseEnvironment(new SynapseConfiguration()));
    pcm.mediate(msgContext);
    assertTrue(POJOCommandTestHelper.getInstance().isExecuted());
}
Also used : Axis2SynapseEnvironment(org.apache.synapse.core.axis2.Axis2SynapseEnvironment) TestMessageContext(org.apache.synapse.TestMessageContext) Mediator(org.apache.synapse.Mediator) Properties(java.util.Properties) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration)

Example 25 with Mediator

use of org.apache.synapse.Mediator in project wso2-synapse by wso2.

the class POJOCommandMediatorTest method testPojoWithoutPropertiesNotCommandImpl.

public void testPojoWithoutPropertiesNotCommandImpl() throws Exception {
    Mediator pcm = MediatorFactoryFinder.getInstance().getMediator(createOMElement("<pojoCommand name='org.apache.synapse.mediators.ext.POJOCommandTestMediator' " + "xmlns='http://ws.apache.org/ns/synapse'/>"), new Properties());
    POJOCommandTestHelper.reset();
    TestMessageContext msgContext = new TestMessageContext();
    msgContext.setEnvironment(new Axis2SynapseEnvironment(new SynapseConfiguration()));
    pcm.mediate(msgContext);
    assertTrue(POJOCommandTestHelper.getInstance().isExecuted());
}
Also used : Axis2SynapseEnvironment(org.apache.synapse.core.axis2.Axis2SynapseEnvironment) TestMessageContext(org.apache.synapse.TestMessageContext) Mediator(org.apache.synapse.Mediator) Properties(java.util.Properties) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration)

Aggregations

Mediator (org.apache.synapse.Mediator)108 Properties (java.util.Properties)30 SequenceMediator (org.apache.synapse.mediators.base.SequenceMediator)24 OMElement (org.apache.axiom.om.OMElement)22 AbstractMediator (org.apache.synapse.mediators.AbstractMediator)22 MessageContext (org.apache.synapse.MessageContext)16 SynapseLog (org.apache.synapse.SynapseLog)16 FlowContinuableMediator (org.apache.synapse.mediators.FlowContinuableMediator)13 SynapseException (org.apache.synapse.SynapseException)12 TestMessageContext (org.apache.synapse.TestMessageContext)12 SynapseConfiguration (org.apache.synapse.config.SynapseConfiguration)12 Axis2SynapseEnvironment (org.apache.synapse.core.axis2.Axis2SynapseEnvironment)12 TemplateMediator (org.apache.synapse.mediators.template.TemplateMediator)12 Test (org.junit.Test)10 AbstractListMediator (org.apache.synapse.mediators.AbstractListMediator)9 SynapseSequenceType (org.apache.synapse.debug.constructs.SynapseSequenceType)8 SequenceMediationFlowPoint (org.apache.synapse.debug.constructs.SequenceMediationFlowPoint)6 ForEachMediatorFactory (org.apache.synapse.config.xml.ForEachMediatorFactory)5 MediatorFactory (org.apache.synapse.config.xml.MediatorFactory)5 MediatorFaultHandler (org.apache.synapse.mediators.MediatorFaultHandler)5