use of org.apache.synapse.mediators.TestMediateHandler in project wso2-synapse by wso2.
the class ValidateMediatorTest method test.
private void test(ValidateMediator validate, MessageContext synCtx, boolean expectFail) {
final MutableInt onFailInvoked = new MutableInt();
TestMediator testMediator = new TestMediator();
testMediator.setHandler(new TestMediateHandler() {
public void handle(MessageContext synCtx) {
onFailInvoked.setValue(1);
}
});
// set dummy mediator to be called on fail
validate.addChild(testMediator);
validate.mediate(synCtx);
if (expectFail) {
assertTrue("Expected ValidateMediator to trigger on-fail sequence", onFailInvoked.intValue() == 1);
} else {
assertTrue("ValidateMediator unexpectedly triggered on-fail sequence", onFailInvoked.intValue() == 0);
}
}
use of org.apache.synapse.mediators.TestMediateHandler in project wso2-synapse by wso2.
the class SwitchMediatorTest method setUp.
public void setUp() throws Exception {
ibmMediator = new TestMediator();
ibmMediator.setHandler(new TestMediateHandler() {
public void handle(MessageContext synCtx) {
setExecutedCase("IBM");
}
});
msftMediator = new TestMediator();
msftMediator.setHandler(new TestMediateHandler() {
public void handle(MessageContext synCtx) {
setExecutedCase("MSFT");
}
});
defaultMediator = new TestMediator();
defaultMediator.setHandler(new TestMediateHandler() {
public void handle(MessageContext synCtx) {
setExecutedCase("DEFAULT");
}
});
// create a new switch mediator
switchMediator = new SwitchMediator();
// set xpath condition to select symbol
SynapseXPath xpath = new SynapseXPath("//wsx:symbol");
xpath.addNamespace("wsx", "http://www.webserviceX.NET/");
switchMediator.setSource(xpath);
SwitchCase caseOne = new SwitchCase();
caseOne.setRegex(Pattern.compile("IBM"));
AnonymousListMediator mediatorOne = new AnonymousListMediator();
mediatorOne.addAll(Arrays.asList(new Mediator[] { ibmMediator }));
caseOne.setCaseMediator(mediatorOne);
SwitchCase caseTwo = new SwitchCase();
caseTwo.setRegex(Pattern.compile("MSFT"));
AnonymousListMediator mediatorTwo = new AnonymousListMediator();
mediatorTwo.addAll(Arrays.asList(new Mediator[] { msftMediator }));
caseTwo.setCaseMediator(mediatorTwo);
SwitchCase caseDefault = new SwitchCase();
AnonymousListMediator mediatorDefault = new AnonymousListMediator();
mediatorDefault.addAll(Arrays.asList(new Mediator[] { defaultMediator }));
caseDefault.setCaseMediator(mediatorDefault);
// set ibm mediator to be called for IBM, msft for MSFT and default for others..
switchMediator.addCase(caseOne);
switchMediator.addCase(caseTwo);
switchMediator.setDefaultCase(caseDefault);
}
use of org.apache.synapse.mediators.TestMediateHandler 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.TestMediateHandler in project wso2-synapse by wso2.
the class DebugManagerTest method testSkipSequence.
public void testSkipSequence() 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");
}
});
SequenceMediator seq = new SequenceMediator();
seq.addChild(t1);
seq.addChild(t2);
seq.addChild(t3);
synConfig.addSequence("test_sequence_5", seq);
String debug_command = "{\"command\":\"set\",\"command-argument\":\"skip\"," + "\"mediation-component\":\"sequence\",\"sequence\":{\"sequence-key\":\"test_sequence_5\"," + "\"sequence-type\": \"named\",\"mediator-position\": \"0\"}}";
dm.processDebugCommand(debug_command);
debug_command = "{\"command\":\"set\",\"command-argument\":\"skip\"," + "\"mediation-component\":\"sequence\",\"sequence\":{\"sequence-key\":\"test_sequence_5\"," + "\"sequence-type\": \"named\",\"mediator-position\": \"1\"}}";
dm.processDebugCommand(debug_command);
synEnv.setDebugEnabled(true);
MessageContextCreatorForAxis2.setSynConfig(synConfig);
MessageContextCreatorForAxis2.setSynEnv(synEnv);
org.apache.axis2.context.MessageContext mc = new org.apache.axis2.context.MessageContext();
AxisConfiguration axisConfig = synConfig.getAxisConfiguration();
if (axisConfig == null) {
axisConfig = new AxisConfiguration();
synConfig.setAxisConfiguration(axisConfig);
}
ConfigurationContext cfgCtx = new ConfigurationContext(axisConfig);
mc.setConfigurationContext(cfgCtx);
mc.setEnvelope(TestUtils.getTestContext("<empty/>").getEnvelope());
MessageContext synCtx = MessageContextCreatorForAxis2.getSynapseMessageContext(mc);
seq.mediate(synCtx);
assertTrue("T3".equals(result.toString()));
synEnv.setDebugEnabled(false);
}
use of org.apache.synapse.mediators.TestMediateHandler in project wso2-synapse by wso2.
the class DebugManagerTest method testBreakPointSequence.
public void testBreakPointSequence() 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");
}
});
SequenceMediator seq = new SequenceMediator();
seq.addChild(t1);
seq.addChild(t2);
seq.addChild(t3);
synConfig.addSequence("test_sequence_6", seq);
String debug_command = "{\"command\":\"set\",\"command-argument\":\"breakpoint\"," + "\"mediation-component\":\"sequence\",\"sequence\":{\"sequence-key\":\"test_sequence_6\"," + "\"sequence-type\": \"named\",\"mediator-position\": \"0\"}}";
dm.processDebugCommand(debug_command);
debug_command = "{\"command\":\"set\",\"command-argument\":\"breakpoint\"," + "\"mediation-component\":\"sequence\",\"sequence\":{\"sequence-key\":\"test_sequence_6\"," + "\"sequence-type\": \"named\",\"mediator-position\": \"1\"}}";
dm.processDebugCommand(debug_command);
MessageContext synCtx = TestUtils.getTestContext("<empty/>");
seq.mediate(synCtx);
assertTrue("T1.T2.T3".equals(result.toString()));
}
Aggregations