Search in sources :

Example 1 with BeanMediator

use of org.apache.synapse.mediators.bean.BeanMediator 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)

Example 2 with BeanMediator

use of org.apache.synapse.mediators.bean.BeanMediator in project wso2-synapse by wso2.

the class BeanMediatorFactoryTest method testCreateSpecificMediator3.

/**
 * Getting the property of BeanMediator and asserting the action.
 *
 * @throws XMLStreamException - XMLStreamException.
 */
@Test
public void testCreateSpecificMediator3() throws XMLStreamException {
    BeanMediatorFactory beanMediatorFactory = new BeanMediatorFactory();
    String inputXML = "<bean action=\"GET_PROPERTY\" property=\"latitude\" value=\"{//latitude}\" var=\"loc\" " + "target=\"target\"   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("GET_PROPERTY action is not set", BeanMediator.Action.GET_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)

Example 3 with BeanMediator

use of org.apache.synapse.mediators.bean.BeanMediator in project wso2-synapse by wso2.

the class BeanMediatorSerializerTest method testSerializeSpecificMediator3.

/**
 * Test serializeSpecificMediator with GET_PROPERTY action and assert the action.
 */
@Test
public void testSerializeSpecificMediator3() {
    BeanMediatorSerializer beanMediatorSerializer = new BeanMediatorSerializer();
    BeanMediator mediator = new BeanMediator();
    mediator.setAction(BeanMediator.Action.GET_PROPERTY);
    mediator.setVarName("loc");
    mediator.setPropertyName("testProperty");
    Target target = new Target("attr", TestUtils.createOMElement("<target attr=\"testTarget\">"));
    mediator.setTarget(target);
    OMElement element = beanMediatorSerializer.serializeSpecificMediator(mediator);
    Assert.assertEquals("GET_PROPERTY action is not performed", "GET_PROPERTY", element.getAttributeValue(new QName(BeanConstants.ACTION)));
}
Also used : Target(org.apache.synapse.mediators.bean.Target) QName(javax.xml.namespace.QName) OMElement(org.apache.axiom.om.OMElement) BeanMediator(org.apache.synapse.mediators.bean.BeanMediator) Test(org.junit.Test)

Example 4 with BeanMediator

use of org.apache.synapse.mediators.bean.BeanMediator in project wso2-synapse by wso2.

the class BeanMediatorSerializerTest method testSerializeSpecificMediator4.

/**
 * Test serializeSpecificMediator with no action specified.
 */
@Test(expected = SynapseException.class)
public void testSerializeSpecificMediator4() {
    BeanMediatorSerializer beanMediatorSerializer = new BeanMediatorSerializer();
    BeanMediator mediator = new BeanMediator();
    beanMediatorSerializer.serializeSpecificMediator(mediator);
}
Also used : BeanMediator(org.apache.synapse.mediators.bean.BeanMediator) Test(org.junit.Test)

Example 5 with BeanMediator

use of org.apache.synapse.mediators.bean.BeanMediator in project wso2-synapse by wso2.

the class BeanMediatorSerializerTest method testSerializeSpecificMediator.

/**
 * Test serializeSpecificMediator with CREATE action and assert the action.
 */
@Test
public void testSerializeSpecificMediator() {
    BeanMediatorSerializer beanMediatorSerializer = new BeanMediatorSerializer();
    BeanMediator mediator = new BeanMediator();
    mediator.setAction(BeanMediator.Action.CREATE);
    mediator.setVarName("loc");
    mediator.setClazz(MockBean.class);
    OMElement element = beanMediatorSerializer.serializeSpecificMediator(mediator);
    Assert.assertEquals("CREATE action is not performed", "CREATE", element.getAttributeValue(new QName(BeanConstants.ACTION)));
}
Also used : QName(javax.xml.namespace.QName) OMElement(org.apache.axiom.om.OMElement) BeanMediator(org.apache.synapse.mediators.bean.BeanMediator) Test(org.junit.Test)

Aggregations

BeanMediator (org.apache.synapse.mediators.bean.BeanMediator)10 OMElement (org.apache.axiom.om.OMElement)8 Test (org.junit.Test)8 QName (javax.xml.namespace.QName)4 Mediator (org.apache.synapse.Mediator)4 Value (org.apache.synapse.mediators.Value)1 Target (org.apache.synapse.mediators.bean.Target)1