use of org.apache.synapse.mediators.template.TemplateMediator in project wso2-synapse by wso2.
the class DebugManagerTest method testBreakPointTemplate.
public void testBreakPointTemplate() throws Exception {
TestMediator t1 = new TestMediator();
t1.setHandler(new TestMediateHandler() {
public void handle(MessageContext synCtx) {
result.append("T1.");
}
});
TestMediator t2 = new TestMediator();
t2.setHandler(new TestMediateHandler() {
public void handle(MessageContext synCtx) {
result.append("T2.");
}
});
TestMediator t3 = new TestMediator();
t3.setHandler(new TestMediateHandler() {
public void handle(MessageContext synCtx) {
result.append("T3");
}
});
TemplateMediator temp = new TemplateMediator();
temp.addChild(t1);
temp.addChild(t2);
temp.addChild(t3);
temp.setName("test_sequence_template_6");
temp.setParameters(new HashSet<String>());
synConfig.addSequenceTemplate(temp.getName(), temp);
String debug_command = "{\"command\":\"set\",\"command-argument\":\"breakpoint\",\"mediation-component\":" + "\"template\",\"template\":{\"template-key\":\"test_sequence_template_6\",\"mediator-position\": \"0\"}}";
dm.processDebugCommand(debug_command);
debug_command = "{\"command\":\"set\",\"command-argument\":\"breakpoint\",\"mediation-component\":\"template\"," + "\"template\":{\"template-key\":\"test_sequence_template_6\",\"mediator-position\": \"1\"}}";
dm.processDebugCommand(debug_command);
MessageContext synCtx = TestUtils.getTestContext("<empty/>");
synEnv.setDebugEnabled(false);
temp.mediate(synCtx);
assertTrue("T1.T2.T3".equals(result.toString()));
}
use of org.apache.synapse.mediators.template.TemplateMediator in project wso2-synapse by wso2.
the class SynapseXMLConfigurationSerializerTest method testSerializeConfiguration5.
/**
* Test serializeConfigurationMethod with TemplateMediator added for SynapseConfiguration
* and assert OMElement returned
*/
@Test
public void testSerializeConfiguration5() {
SynapseXMLConfigurationSerializer serializer = new SynapseXMLConfigurationSerializer();
SynapseConfiguration synapseConfiguration = new SynapseConfiguration();
org.apache.synapse.mediators.TestMediator t1 = new org.apache.synapse.mediators.TestMediator();
org.apache.synapse.mediators.TestMediator t2 = new org.apache.synapse.mediators.TestMediator();
org.apache.synapse.mediators.TestMediator t3 = new org.apache.synapse.mediators.TestMediator();
TemplateMediator templateMediator = new TemplateMediator();
templateMediator.addChild(t1);
templateMediator.addChild(t2);
templateMediator.addChild(t3);
synapseConfiguration.addSequence("testSequence", templateMediator);
OMElement element = serializer.serializeConfiguration(synapseConfiguration);
Assert.assertNotNull("OMElement is not returned", element);
Assert.assertEquals("definitions", element.getLocalName());
Assert.assertTrue("Template added is not serialized.", element.getChildren().next().toString().contains("template"));
}
use of org.apache.synapse.mediators.template.TemplateMediator in project wso2-synapse by wso2.
the class XMLToTemplateMapperTest method testGetObjectFromOMNodeSequence.
/**
* Test getObjectFromOMNode by parsing a XML with sequence tag.
*
* @throws XMLStreamException
*/
@Test
public void testGetObjectFromOMNodeSequence() throws XMLStreamException {
String input = "<template xmlns=\"http://ws.apache.org/ns/synapse\" name=\"" + NAME + "\">\n" + " <sequence>\n" + " <log level=\"full\">\n" + " <property xmlns:ns2=\"http://org.apache.synapse/xsd\" name=\"message\" " + "expression=\"$func:message\"></property>\n" + " </log>\n" + " </sequence>\n" + "</template>";
OMElement element = AXIOMUtil.stringToOM(input);
TemplateMediator templateMediator = (TemplateMediator) mapper.getObjectFromOMNode(element, properties);
Assert.assertEquals("name should be parsed into the element", NAME, templateMediator.getName());
}
use of org.apache.synapse.mediators.template.TemplateMediator in project wso2-synapse by wso2.
the class SynapseObserverTest method testSimpleObserver.
public void testSimpleObserver() {
SynapseConfiguration synapseConfig = new SynapseConfiguration();
synapseConfig.setAxisConfiguration(new AxisConfiguration());
synapseConfig.registerObserver(observer);
Endpoint epr = new AddressEndpoint();
epr.setName("endpoint1");
synapseConfig.addEndpoint(epr.getName(), epr);
assertItemAdded(epr.getName(), ENDPOINT);
synapseConfig.removeEndpoint(epr.getName());
assertItemRemoved(epr.getName(), ENDPOINT);
SequenceMediator seq = new SequenceMediator();
seq.setName("sequence1");
synapseConfig.addSequence(seq.getName(), seq);
assertItemAdded(seq.getName(), SEQUENCE);
synapseConfig.removeSequence(seq.getName());
assertItemRemoved(seq.getName(), SEQUENCE);
TemplateMediator template = new TemplateMediator();
template.setName("template1");
synapseConfig.addSequenceTemplate(template.getName(), template);
assertItemAdded(template.getName(), SEQUENCE_TEMPLATE);
synapseConfig.removeSequenceTemplate(template.getName());
assertItemRemoved(template.getName(), SEQUENCE_TEMPLATE);
Entry entry = new Entry();
entry.setKey("entry1");
synapseConfig.addEntry(entry.getKey(), entry);
assertItemAdded(entry.getKey(), ENTRY);
synapseConfig.removeEntry(entry.getKey());
assertItemRemoved(entry.getKey(), ENTRY);
ProxyService proxy = new ProxyService("proxy1");
synapseConfig.addProxyService(proxy.getName(), proxy);
assertItemAdded(proxy.getName(), PROXY);
synapseConfig.removeProxyService(proxy.getName());
assertItemRemoved(proxy.getName(), PROXY);
Startup startup = new StartUpController();
startup.setName("startup1");
synapseConfig.addStartup(startup);
assertItemAdded(startup.getName(), STARTUP);
synapseConfig.removeStartup(startup.getName());
assertItemRemoved(startup.getName(), STARTUP);
SynapseEventSource eventSrc = new SynapseEventSource("eventSrc1");
synapseConfig.addEventSource(eventSrc.getName(), eventSrc);
assertItemAdded(eventSrc.getName(), EVENT_SRC);
synapseConfig.removeEventSource(eventSrc.getName());
assertItemRemoved(eventSrc.getName(), EVENT_SRC);
PriorityExecutor exec = new PriorityExecutor();
exec.setName("exec1");
synapseConfig.addPriorityExecutor(exec.getName(), exec);
assertItemAdded(exec.getName(), EXECUTOR);
synapseConfig.removeExecutor(exec.getName());
assertItemRemoved(exec.getName(), EXECUTOR);
}
use of org.apache.synapse.mediators.template.TemplateMediator in project wso2-synapse by wso2.
the class TestMessageContext method getSequenceTemplate.
public Mediator getSequenceTemplate(String key) {
Object o = localEntries.get(key);
if (o != null && o instanceof Mediator) {
return (Mediator) o;
} else {
Mediator m = getConfiguration().getSequence(key);
if (m instanceof TemplateMediator) {
TemplateMediator templateMediator = (TemplateMediator) m;
synchronized (m) {
if (!templateMediator.isInitialized()) {
templateMediator.init(synEnv);
}
}
}
localEntries.put(key, m);
return m;
}
}
Aggregations