use of org.apache.synapse.mediators.Value in project wso2-synapse by wso2.
the class XSLTMediatorTest method test.
protected static void test(Class sbf, Class rbf) throws Exception {
XSLTMediator transformMediator = new XSLTMediator();
Value xsltKey = new Value("xslt-key");
transformMediator.setXsltKey(xsltKey);
MessageContext mc = new TestMessageContextBuilder().addEntry("xslt-key", XSLTMediator.class.getResource("identity.xslt")).build();
OMFactory factory = OMAbstractFactory.getOMFactory();
OMElement orgRoot = factory.createOMElement(new QName("root"));
OMElement orgElement = factory.createOMElement(new QName("urn:mynamespace", "element1"));
orgElement.setText("test");
OMAttribute orgAttribute = orgElement.addAttribute("att", "testValue", null);
orgRoot.addChild(orgElement);
mc.getEnvelope().getBody().addChild(orgRoot);
transformMediator.addAttribute(XSLTMediator.SOURCE_BUILDER_FACTORY, sbf.getName());
transformMediator.addAttribute(XSLTMediator.RESULT_BUILDER_FACTORY, rbf.getName());
transformMediator.mediate(mc);
OMElement root = mc.getEnvelope().getBody().getFirstElement();
assertEquals(orgRoot.getQName(), root.getQName());
OMElement element = (OMElement) root.getFirstOMChild();
assertEquals(orgElement.getQName(), element.getQName());
assertEquals(orgElement.getText(), element.getText());
assertEquals(orgAttribute, orgElement.getAttribute(orgAttribute.getQName()));
assertNull(element.getNextOMSibling());
}
use of org.apache.synapse.mediators.Value 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.mediators.Value 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);
}
Aggregations