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);
}
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));
}
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));
}
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);
}
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);
}
Aggregations