Search in sources :

Example 36 with Mediator

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

the class PayloadFactoryMediatorSerializerTest method testSerializeSpecificMediator4.

/**
 * Test SerializeSpecificMediator method with PathArgument added for payloadFactory mediator
 * and assert that argument is added.
 */
@Test
public void testSerializeSpecificMediator4() throws JaxenException {
    PayloadFactoryMediatorSerializer serializer = new PayloadFactoryMediatorSerializer();
    PayloadFactoryMediator payloadFactoryMediator = new PayloadFactoryMediator();
    Argument argument = new Argument();
    argument.setValue("TestArgument1");
    payloadFactoryMediator.addPathArgument(argument);
    payloadFactoryMediator.setFormat(format);
    OMElement element = serializer.serializeSpecificMediator(payloadFactoryMediator);
    MediatorFactory mediatorFactory = new PayloadFactoryMediatorFactory();
    Mediator mediator = mediatorFactory.createMediator(element, null);
    Assert.assertNotNull(element);
    Assert.assertEquals("Path argument added is not serialized", "TestArgument1", ((PayloadFactoryMediator) mediator).getPathArgumentList().get(0).getValue());
}
Also used : Argument(org.apache.synapse.mediators.transform.Argument) PayloadFactoryMediator(org.apache.synapse.mediators.transform.PayloadFactoryMediator) OMElement(org.apache.axiom.om.OMElement) PayloadFactoryMediator(org.apache.synapse.mediators.transform.PayloadFactoryMediator) Mediator(org.apache.synapse.Mediator) Test(org.junit.Test)

Example 37 with Mediator

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

the class PayloadFactoryMediatorSerializerTest method testSerializeSpecificMediator3.

/**
 * Test SerializeSpecificMediator method with Dynamic format added for payloadFactory mediator
 * and assert that dynamic format is set.
 */
@Test
public void testSerializeSpecificMediator3() {
    PayloadFactoryMediatorSerializer serializer = new PayloadFactoryMediatorSerializer();
    PayloadFactoryMediator payloadFactoryMediator = new PayloadFactoryMediator();
    payloadFactoryMediator.setFormat(format);
    payloadFactoryMediator.setFormatDynamic(true);
    payloadFactoryMediator.setFormatKey(new Value("testKey"));
    OMElement element = serializer.serializeSpecificMediator(payloadFactoryMediator);
    Assert.assertNotNull(element);
    MediatorFactory mediatorFactory = new PayloadFactoryMediatorFactory();
    Mediator mediator = mediatorFactory.createMediator(element, null);
    Assert.assertTrue("Dynamic Format set for Mediator is not serialized", ((PayloadFactoryMediator) mediator).isFormatDynamic());
}
Also used : PayloadFactoryMediator(org.apache.synapse.mediators.transform.PayloadFactoryMediator) Value(org.apache.synapse.mediators.Value) OMElement(org.apache.axiom.om.OMElement) PayloadFactoryMediator(org.apache.synapse.mediators.transform.PayloadFactoryMediator) Mediator(org.apache.synapse.Mediator) Test(org.junit.Test)

Example 38 with Mediator

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

the class EventPublisherMediatorSerializerTest method testCreateEventSource.

/**
 * Passing unsupported mediator.
 */
@Test(expected = SynapseException.class)
public void testCreateEventSource() {
    EventPublisherMediatorSerializer mediatorSerializer = new EventPublisherMediatorSerializer();
    Mediator mediator = new CallMediator();
    mediatorSerializer.serializeSpecificMediator(mediator);
}
Also used : EventPublisherMediator(org.apache.synapse.mediators.eventing.EventPublisherMediator) Mediator(org.apache.synapse.Mediator) CallMediator(org.apache.synapse.mediators.builtin.CallMediator) CallMediator(org.apache.synapse.mediators.builtin.CallMediator) Test(org.junit.Test)

Example 39 with Mediator

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

the class AbstractTestCase method serialization.

protected boolean serialization(String inputXml, MediatorFactory mediatorFactory, MediatorSerializer mediatorSerializer) {
    OMElement inputOM = createOMElement(inputXml);
    Mediator mediator = mediatorFactory.createMediator(inputOM, new Properties());
    OMElement resultOM = mediatorSerializer.serializeMediator(null, mediator);
    try {
        assertXMLEqual(resultOM.toString(), inputXml);
        return true;
    } catch (SAXException e) {
        log.error(e);
    } catch (IOException e) {
        log.error(e);
    }
    return false;
}
Also used : OMElement(org.apache.axiom.om.OMElement) TemplateMediator(org.apache.synapse.mediators.template.TemplateMediator) Mediator(org.apache.synapse.Mediator) IOException(java.io.IOException) Properties(java.util.Properties) SAXException(org.xml.sax.SAXException)

Example 40 with Mediator

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

the class BeanMediatorFactoryTest method testCreateSpecificMediator2.

/**
 * Setting property of BeanMediator and asserting the action.
 *
 * @throws XMLStreamException - XMLStreamException.
 */
@Test
public void testCreateSpecificMediator2() throws XMLStreamException {
    BeanMediatorFactory beanMediatorFactory = new BeanMediatorFactory();
    String inputXML = "<bean action=\"SET_PROPERTY\" property=\"latitude\" value=\"{//latitude}\" var=\"loc\" " + "xmlns:ns3=\"http://org.apache.synapse/xsd\"             " + "xmlns:ns=\"http://org.apache.synapse/xsd\"></bean>\n";
    OMElement element = AXIOMUtil.stringToOM(inputXML);
    Mediator mediator = beanMediatorFactory.createSpecificMediator(element, null);
    Assert.assertTrue("BeanMediator is not created successfully.", mediator instanceof BeanMediator);
    BeanMediator beanMediator = (BeanMediator) mediator;
    Assert.assertEquals("SET_PROPERTY action is not set", BeanMediator.Action.SET_PROPERTY, beanMediator.getAction());
}
Also used : OMElement(org.apache.axiom.om.OMElement) Mediator(org.apache.synapse.Mediator) BeanMediator(org.apache.synapse.mediators.bean.BeanMediator) BeanMediator(org.apache.synapse.mediators.bean.BeanMediator) Test(org.junit.Test)

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