/** * 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); }
/** * Create a RecipientListEndpoint by config and test sending a message * @throws Exception on an issue sending out the message */ @Test public void testSendToEndpointList() throws Exception { OMElement omBody = AXIOMUtil.stringToOM("<endpoint><recipientlist xmlns=\"http://ws.apache.org/ns/synapse\">\n" + " <endpoint xmlns=\"http://ws.apache.org/ns/synapse\">\n" + " <address uri=\"http://localhost:9000/services/SimpleStockQuoteService\"/>\n" + " </endpoint>\n" + " <endpoint xmlns=\"http://ws.apache.org/ns/synapse\">\n" + " <address uri=\"http://localhost:9001/services/SimpleStockQuoteService\"/>\n" + " </endpoint>\n" + "</recipientlist></endpoint>"); RecipientListEndpoint recipientListEndpoint = (RecipientListEndpoint) EndpointFactory. getEndpointFromElement(omBody,true, null); Axis2SynapseEnvironment synapseEnvironment = getMockedSynapseEnvironment(); Mockito.when(synapseEnvironment.createMessageContext()).thenReturn(createMessageContext()); //test send message String samplePayload = "<test><a>WSO2</a></test>"; Axis2MessageContext messageContext = getMessageContext(samplePayload); //message will be sent to EP using this env (which is mocked and do nothing) messageContext.setEnvironment(synapseEnvironment); recipientListEndpoint.init(synapseEnvironment); recipientListEndpoint.sendMessage(messageContext); }
/** * 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); }