use of org.apache.synapse.core.axis2.Axis2SynapseEnvironment in project wso2-synapse by wso2.
the class HttpEndpointTest method getMockedSynapseEnvironment.
/**
* Create a mock SynapseEnvironment object
*
* @return Axis2SynapseEnvironment instance
* @throws AxisFault on creating/mocking object
*/
private Axis2SynapseEnvironment getMockedSynapseEnvironment() throws AxisFault {
Axis2SynapseEnvironment synapseEnvironment = PowerMockito.mock(Axis2SynapseEnvironment.class);
ConfigurationContext axis2ConfigurationContext = new ConfigurationContext(new AxisConfiguration());
axis2ConfigurationContext.getAxisConfiguration().addParameter(SynapseConstants.SYNAPSE_ENV, synapseEnvironment);
Mockito.when(synapseEnvironment.getAxis2ConfigurationContext()).thenReturn(axis2ConfigurationContext);
return synapseEnvironment;
}
use of org.apache.synapse.core.axis2.Axis2SynapseEnvironment in project wso2-synapse by wso2.
the class RecipientListEndpointTest method testSendMessageToMembers.
/**
* Test on Sending messages to different members using RecipientListEndpoint
*/
@Test
public void testSendMessageToMembers() throws Exception {
// perform init
Axis2SynapseEnvironment synapseEnvironment = getMockedSynapseEnvironment();
RecipientListEndpoint recipientListEndpoint = new RecipientListEndpoint();
recipientListEndpoint.init(synapseEnvironment);
Mockito.when(synapseEnvironment.createMessageContext()).thenReturn(createMessageContext());
// set members
Member member1 = new Member("localhost", 9000);
Member member2 = new Member("localhost", 9001);
ArrayList<Member> members = new ArrayList<>(2);
members.add(member1);
members.add(member2);
recipientListEndpoint.setMembers(members);
// test send message
String samplePayload = "<test>value</test>";
Axis2MessageContext messageContext = getMessageContext(samplePayload);
// message will be sent to EP using this env (which is mocked and do nothing)
messageContext.setEnvironment(synapseEnvironment);
messageContext.setTo(new EndpointReference("http://localhost:9000/services/SimpleStockQuoteService"));
recipientListEndpoint.sendMessage(messageContext);
}
use of org.apache.synapse.core.axis2.Axis2SynapseEnvironment in project wso2-synapse by wso2.
the class RecipientListEndpointTest method createMessageContext.
/**
* Create a empty message context
*
* @return A context with empty message
* @throws AxisFault on an error creating a context
*/
private MessageContext createMessageContext() throws AxisFault {
Axis2SynapseEnvironment synapseEnvironment = new Axis2SynapseEnvironment(new SynapseConfiguration());
org.apache.axis2.context.MessageContext axis2MC = new org.apache.axis2.context.MessageContext();
axis2MC.setConfigurationContext(new ConfigurationContext(new AxisConfiguration()));
ServiceContext svcCtx = new ServiceContext();
OperationContext opCtx = new OperationContext(new InOutAxisOperation(), svcCtx);
axis2MC.setServiceContext(svcCtx);
axis2MC.setOperationContext(opCtx);
MessageContext mc = new Axis2MessageContext(axis2MC, new SynapseConfiguration(), synapseEnvironment);
mc.setMessageID(UIDGenerator.generateURNString());
mc.setEnvelope(OMAbstractFactory.getSOAP12Factory().createSOAPEnvelope());
mc.getEnvelope().addChild(OMAbstractFactory.getSOAP12Factory().createSOAPBody());
return mc;
}
use of org.apache.synapse.core.axis2.Axis2SynapseEnvironment in project wso2-synapse by wso2.
the class RecipientListEndpointTest method testSendToDynamicMembers.
/**
* Test on Sending messages to a dynamic EP based on an expression
*
* @throws Exception on test failure
*/
@Test
public void testSendToDynamicMembers() throws Exception {
// perform init
Axis2SynapseEnvironment synapseEnvironment = getMockedSynapseEnvironment();
RecipientListEndpoint recipientListEndpoint = new RecipientListEndpoint(2);
recipientListEndpoint.init(synapseEnvironment);
Mockito.when(synapseEnvironment.createMessageContext()).thenReturn(createMessageContext());
// add dynamic EPs
Value dynamicEPs = new Value(new SynapseXPath("//endpoints"));
recipientListEndpoint.setDynamicEnpointSet(dynamicEPs);
// test send message
String samplePayload = "<test><endpoints>http://localhost:9000/services/SimpleStockQuoteService," + "http://localhost:9001/services/SimpleStockQuoteService" + "</endpoints><body>wso2</body></test>";
Axis2MessageContext messageContext = getMessageContext(samplePayload);
// message will be sent to EP using this env (which is mocked and do nothing)
messageContext.setEnvironment(synapseEnvironment);
// messageContext.setTo(new EndpointReference("http://localhost:9000/services/SimpleStockQuoteService"));
recipientListEndpoint.sendMessage(messageContext);
}
use of org.apache.synapse.core.axis2.Axis2SynapseEnvironment 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);
}
Aggregations