Search in sources :

Example 16 with TestMessageContext

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

the class POJOCommandMediatorTest method testPojoWithContextR$UPropertiesCommandImpl.

public void testPojoWithContextR$UPropertiesCommandImpl() 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=\"ctxTest\" " + "context-name=\"testCtxProp\" action=\"ReadAndUpdateContext\"/></pojoCommand>"), new Properties());
    POJOCommandTestHelper.reset();
    MessageContext ctx = new TestMessageContext();
    ctx.setProperty("testCtxProp", "test");
    ctx.setEnvironment(new Axis2SynapseEnvironment(new SynapseConfiguration()));
    pcm.mediate(ctx);
    assertEquals("testcommand", ctx.getProperty("testCtxProp").toString());
    assertTrue(POJOCommandTestHelper.getInstance().isExecuted());
}
Also used : Axis2SynapseEnvironment(org.apache.synapse.core.axis2.Axis2SynapseEnvironment) TestMessageContext(org.apache.synapse.TestMessageContext) Mediator(org.apache.synapse.Mediator) TestMessageContext(org.apache.synapse.TestMessageContext) MessageContext(org.apache.synapse.MessageContext) Properties(java.util.Properties) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration)

Example 17 with TestMessageContext

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

the class POJOCommandMediatorTest method testPojoWithMessagePropertiesCommandImpl.

public void testPojoWithMessagePropertiesCommandImpl() 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\" " + "value=\"TestProperty\" expression=\"//testNode\"/></pojoCommand>"), new Properties());
    POJOCommandTestHelper.reset();
    MessageContext ctx = new TestMessageContext();
    SOAPEnvelope envelope = OMAbstractFactory.getSOAP11Factory().getDefaultEnvelope();
    envelope.getBody().addChild(createOMElement("<original><testNode/></original>"));
    ctx.setEnvelope(envelope);
    ctx.setEnvironment(new Axis2SynapseEnvironment(new SynapseConfiguration()));
    pcm.mediate(ctx);
    assertEquals("TestProperty", POJOCommandTestHelper.getInstance().getChangedProperty());
    assertEquals("<original>TestProperty</original>", ctx.getEnvelope().getBody().getFirstOMChild().toString());
    assertTrue(POJOCommandTestHelper.getInstance().isExecuted());
}
Also used : Axis2SynapseEnvironment(org.apache.synapse.core.axis2.Axis2SynapseEnvironment) TestMessageContext(org.apache.synapse.TestMessageContext) Mediator(org.apache.synapse.Mediator) TestMessageContext(org.apache.synapse.TestMessageContext) MessageContext(org.apache.synapse.MessageContext) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) Properties(java.util.Properties) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration)

Example 18 with TestMessageContext

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

the class POJOCommandMediatorTest method testPojoWithPropertiesNotCommandImpl.

public void testPojoWithPropertiesNotCommandImpl() throws Exception {
    Mediator pcm = MediatorFactoryFinder.getInstance().getMediator(createOMElement("<pojoCommand name='org.apache.synapse.mediators.ext.POJOCommandTestMediator' " + "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 19 with TestMessageContext

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

the class POJOCommandMediatorTest method testPojoWithContextPropertiesCommandImpl.

public void testPojoWithContextPropertiesCommandImpl() 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\" " + "value=\"Test Property\" context-name=\"testPropInMC\"/></pojoCommand>"), new Properties());
    POJOCommandTestHelper.reset();
    MessageContext ctx = new TestMessageContext();
    ctx.setEnvironment(new Axis2SynapseEnvironment(new SynapseConfiguration()));
    pcm.mediate(ctx);
    assertEquals("Test Property", POJOCommandTestHelper.getInstance().getChangedProperty());
    assertEquals("Test Property", ctx.getProperty("testPropInMC"));
    assertTrue(POJOCommandTestHelper.getInstance().isExecuted());
}
Also used : Axis2SynapseEnvironment(org.apache.synapse.core.axis2.Axis2SynapseEnvironment) TestMessageContext(org.apache.synapse.TestMessageContext) Mediator(org.apache.synapse.Mediator) TestMessageContext(org.apache.synapse.TestMessageContext) MessageContext(org.apache.synapse.MessageContext) Properties(java.util.Properties) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration)

Example 20 with TestMessageContext

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

the class BeanMediatorTest method init.

/**
 * Initializing bean mediator by creating an initial bean in messageContext
 */
@BeforeClass
public static void init() {
    SynapseEnvironment synapseEnvironment = Mockito.mock(SynapseEnvironment.class);
    messageContext = new TestMessageContext();
    beanMediator.setReplace(true);
    beanMediator.setDescription(DESCRIPTION);
    beanMediator.setBreakPoint(true);
    beanMediator.setSkipEnabled(true);
    beanMediator.setMediatorPosition(1);
    beanMediator.setPropertyName(PROPERTY_NAME);
    Value value = new Value(VALUE_TEXT);
    beanMediator.setValue(value);
    Target target = new Target(ATTRIBUTE, TestUtils.createOMElement(XML));
    beanMediator.setTarget(target);
    beanMediator.setAction(BeanMediator.Action.CREATE);
    beanMediator.setClazz(SampleBean.class);
    beanMediator.setVarName(VAR_NAME);
    messageContext.setEnvironment(synapseEnvironment);
    beanMediator.mediate(messageContext);
}
Also used : TestMessageContext(org.apache.synapse.TestMessageContext) SynapseEnvironment(org.apache.synapse.core.SynapseEnvironment) Value(org.apache.synapse.mediators.Value) BeforeClass(org.junit.BeforeClass)

Aggregations

TestMessageContext (org.apache.synapse.TestMessageContext)20 SynapseConfiguration (org.apache.synapse.config.SynapseConfiguration)16 Axis2SynapseEnvironment (org.apache.synapse.core.axis2.Axis2SynapseEnvironment)13 Properties (java.util.Properties)12 Mediator (org.apache.synapse.Mediator)12 MessageContext (org.apache.synapse.MessageContext)10 SynapseEnvironment (org.apache.synapse.core.SynapseEnvironment)4 AxisConfiguration (org.apache.axis2.engine.AxisConfiguration)3 ConfigurationContext (org.apache.axis2.context.ConfigurationContext)2 ManagedLifecycle (org.apache.synapse.ManagedLifecycle)2 Axis2MessageContext (org.apache.synapse.core.axis2.Axis2MessageContext)2 AddressEndpoint (org.apache.synapse.endpoints.AddressEndpoint)2 EndpointDefinition (org.apache.synapse.endpoints.EndpointDefinition)2 SynapseXPath (org.apache.synapse.util.xpath.SynapseXPath)2 Test (org.junit.Test)2 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)1 AbstractEndpoint (org.apache.synapse.endpoints.AbstractEndpoint)1