Search in sources :

Example 76 with Mediator

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

the class PayloadFactoryMediatorSerializerTest method testSerializeSpecificMediator5.

/**
 * Test SerializeSpecificMediator method with PathArgument with expression added for payloadFactory mediator
 * and assert that expression is added.
 */
@Test
public void testSerializeSpecificMediator5() throws JaxenException {
    PayloadFactoryMediatorSerializer serializer = new PayloadFactoryMediatorSerializer();
    PayloadFactoryMediator payloadFactoryMediator = new PayloadFactoryMediator();
    Argument argument = new Argument();
    argument.setExpression(new SynapseXPath("//name"));
    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("Expression added for path argument is not serialized", "//name", ((PayloadFactoryMediator) mediator).getPathArgumentList().get(0).getExpression().toString());
}
Also used : SynapseXPath(org.apache.synapse.util.xpath.SynapseXPath) 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 77 with Mediator

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

the class AbstractTestCase method serialization.

protected boolean serialization(String inputXml, MediatorSerializer mediatorSerializer) {
    OMElement inputOM = createOMElement(inputXml);
    Mediator mediator = MediatorFactoryFinder.getInstance().getMediator(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 78 with Mediator

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

the class BeanMediatorFactoryTest method testCreateSpecificMediator.

/**
 * Creating a bean mediator and asserting it is created successfully.
 *
 * @throws XMLStreamException - XMLStreamException.
 */
@Test
public void testCreateSpecificMediator() throws XMLStreamException {
    BeanMediatorFactory beanMediatorFactory = new BeanMediatorFactory();
    String inputXML = "<bean action=\"CREATE\" class=\"org.apache.synapse.util.TestTask\" " + "var=\"loc\"></bean>";
    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("CREATE action is not set", BeanMediator.Action.CREATE, 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)

Example 79 with Mediator

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

the class BeanMediatorFactoryTest method testCreateSpecificMediator4.

/**
 * Removing the property of BeanMediator and asserting the action.
 *
 * @throws XMLStreamException - XMLStreamException.
 */
@Test
public void testCreateSpecificMediator4() throws XMLStreamException {
    BeanMediatorFactory beanMediatorFactory = new BeanMediatorFactory();
    String inputXML = "<bean action=\"REMOVE\" 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("REMOVE action is not set", BeanMediator.Action.REMOVE, 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)

Example 80 with Mediator

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

the class EJBMediatorFactoryTest method testCreateSpecificMediator.

/**
 * Test createSpecificMediator method and checked the returned mediator benStalkName.
 *
 * @throws XMLStreamException - XMLStreamException
 */
@Test
public void testCreateSpecificMediator() throws XMLStreamException {
    EJBMediatorFactory factory = new EJBMediatorFactory();
    String inputXML = "<ejb xmlns=\"http://ws.apache.org/ns/synapse\" beanstalk=\"jack\" class=\"org.apache.synapse" + ".mediators.bean.enterprise.EJBMediator\" method=\"setMethod\" target=\"store\" " + "jndiName=\"ejb:/EJBDemo/StoreRegisterBean!org.ejb.wso2.test.StoreRegister\">" + "<args><arg value=\"{get-property('loc_id')}\"/></args></ejb>";
    OMElement inputElement = AXIOMUtil.stringToOM(inputXML);
    Mediator mediator = factory.createSpecificMediator(inputElement, null);
    EJBMediatorSerializer serializer = new EJBMediatorSerializer();
    OMElement outputElement = serializer.serializeSpecificMediator(mediator);
    Assert.assertEquals("EJB Mediator with beanstalk name jack is not returned", "jack", ((EJBMediator) mediator).getBeanstalkName());
    Assert.assertTrue("Input XML and serialized output XMLs are not same", compare(inputElement, outputElement));
}
Also used : OMElement(org.apache.axiom.om.OMElement) Mediator(org.apache.synapse.Mediator) EJBMediator(org.apache.synapse.mediators.bean.enterprise.EJBMediator) 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