Search in sources :

Example 11 with TestMessageContext

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

the class TracingDataCollectionHelperTest method testCollectPayloadNone.

/**
 * Test CollectPayload exception condition.
 */
@Test
public void testCollectPayloadNone() {
    MessageContext messageContext = new TestMessageContext();
    String payload = TracingDataCollectionHelper.collectPayload(messageContext);
    Assert.assertEquals("should return NONE for invalid message context", "NONE", payload);
}
Also used : TestMessageContext(org.apache.synapse.TestMessageContext) TestMessageContext(org.apache.synapse.TestMessageContext) MessageContext(org.apache.synapse.MessageContext) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext) Test(org.junit.Test)

Example 12 with TestMessageContext

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

the class DynamicEndpointTest method testContextProperties.

public void testContextProperties() throws Exception {
    SynapseXPath xpath = new SynapseXPath("$ctx:timeout");
    AbstractEndpoint endpoint = new AddressEndpoint();
    EndpointDefinition definition = new EndpointDefinition();
    endpoint.setDefinition(definition);
    definition.setDynamicTimeoutExpression(xpath);
    MessageContext synCtx = new TestMessageContext();
    synCtx.setProperty("timeout", "90000");
    assertEquals(Long.valueOf((String) xpath.evaluate(synCtx)).longValue(), endpoint.getDefinition().evaluateDynamicEndpointTimeout(synCtx));
}
Also used : SynapseXPath(org.apache.synapse.util.xpath.SynapseXPath) AbstractEndpoint(org.apache.synapse.endpoints.AbstractEndpoint) AddressEndpoint(org.apache.synapse.endpoints.AddressEndpoint) TestMessageContext(org.apache.synapse.TestMessageContext) EndpointDefinition(org.apache.synapse.endpoints.EndpointDefinition) TestMessageContext(org.apache.synapse.TestMessageContext) MessageContext(org.apache.synapse.MessageContext)

Example 13 with TestMessageContext

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

the class EventPublisherMediatorTest method testMediate.

/**
 * Testing eventPublisherMediator with mocked event source.
 */
@Test
public void testMediate() {
    final String EventSourceName = "testEventStore";
    SynapseEnvironment synapseEnvironment = Mockito.mock(SynapseEnvironment.class);
    MessageContext messageContext = new TestMessageContext();
    messageContext.setEnvironment(synapseEnvironment);
    SynapseConfiguration synapseConfiguration = new SynapseConfiguration();
    SynapseEventSource synapseEventSource = Mockito.mock(SynapseEventSource.class);
    Mockito.doNothing().when(synapseEventSource).dispatchEvents(Mockito.any(MessageContext.class));
    Map<String, SynapseEventSource> eventStoreMap = new HashMap<>();
    eventStoreMap.put(EventSourceName, synapseEventSource);
    synapseConfiguration.setEventSources(eventStoreMap);
    messageContext.setConfiguration(synapseConfiguration);
    eventPublisherMediator.setEventSourceName(EventSourceName);
    Assert.assertTrue("mediation successful", eventPublisherMediator.mediate(messageContext));
}
Also used : TestMessageContext(org.apache.synapse.TestMessageContext) SynapseEventSource(org.apache.synapse.eventing.SynapseEventSource) HashMap(java.util.HashMap) SynapseEnvironment(org.apache.synapse.core.SynapseEnvironment) TestMessageContext(org.apache.synapse.TestMessageContext) MessageContext(org.apache.synapse.MessageContext) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration) Test(org.junit.Test)

Example 14 with TestMessageContext

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

the class ClassMediatorTest method testMediationWithoutProperties.

public void testMediationWithoutProperties() throws Exception {
    Mediator cm = MediatorFactoryFinder.getInstance().getMediator(createOMElement("<class name='org.apache.synapse.mediators.ext.ClassMediatorTestMediator' " + "xmlns='http://ws.apache.org/ns/synapse'/>"), new Properties());
    TestMessageContext msgContext = new TestMessageContext();
    msgContext.setEnvironment(new Axis2SynapseEnvironment(new SynapseConfiguration()));
    cm.mediate(msgContext);
    assertTrue(ClassMediatorTestMediator.invoked);
}
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 15 with TestMessageContext

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

the class ClassMediatorTest method testDestroy.

public void testDestroy() throws Exception {
    Mediator cm = MediatorFactoryFinder.getInstance().getMediator(createOMElement("<class name='org.apache.synapse.mediators.ext.ClassMediatorTestMediator' " + "xmlns='http://ws.apache.org/ns/synapse'/>"), new Properties());
    TestMessageContext msgContext = new TestMessageContext();
    msgContext.setEnvironment(new Axis2SynapseEnvironment(new SynapseConfiguration()));
    cm.mediate(msgContext);
    assertTrue(ClassMediatorTestMediator.invoked);
    ((ManagedLifecycle) cm).destroy();
    assertTrue(ClassMediatorTestMediator.destroyed);
}
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) ManagedLifecycle(org.apache.synapse.ManagedLifecycle)

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