Search in sources :

Example 1 with TestMediator

use of org.apache.synapse.mediators.TestMediator 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);
    }
}
Also used : MutableInt(org.apache.commons.lang.mutable.MutableInt) TestMediateHandler(org.apache.synapse.mediators.TestMediateHandler) TestMediator(org.apache.synapse.mediators.TestMediator) MessageContext(org.apache.synapse.MessageContext)

Example 2 with TestMediator

use of org.apache.synapse.mediators.TestMediator 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);
}
Also used : SynapseXPath(org.apache.synapse.util.xpath.SynapseXPath) SwitchCase(org.apache.synapse.config.xml.SwitchCase) TestMediateHandler(org.apache.synapse.mediators.TestMediateHandler) AnonymousListMediator(org.apache.synapse.config.xml.AnonymousListMediator) TestMediator(org.apache.synapse.mediators.TestMediator) Mediator(org.apache.synapse.Mediator) AnonymousListMediator(org.apache.synapse.config.xml.AnonymousListMediator) TestMediator(org.apache.synapse.mediators.TestMediator) MessageContext(org.apache.synapse.MessageContext)

Example 3 with TestMediator

use of org.apache.synapse.mediators.TestMediator in project wso2-synapse by wso2.

the class DebugManagerTest method testDebugManagerProcessCommandSetSkipInboundErrorSequence.

public void testDebugManagerProcessCommandSetSkipInboundErrorSequence() throws Exception {
    InboundEndpoint inboundEndpoint = new InboundEndpoint();
    inboundEndpoint.setName("test_inbound_4");
    TestMediator in1 = new TestMediator();
    TestMediator in2 = new TestMediator();
    TestMediator in3 = new TestMediator();
    SequenceMediator dispatchSeq = new SequenceMediator();
    dispatchSeq.addChild(in1);
    dispatchSeq.addChild(in2);
    dispatchSeq.addChild(in3);
    TestMediator out1 = new TestMediator();
    TestMediator out2 = new TestMediator();
    TestMediator out3 = new TestMediator();
    SequenceMediator errorSeq = new SequenceMediator();
    errorSeq.addChild(out1);
    errorSeq.addChild(out2);
    errorSeq.addChild(out3);
    synConfig.addSequence("dispatch_4", dispatchSeq);
    inboundEndpoint.setInjectingSeq("dispatch_4");
    synConfig.addSequence("error_4", errorSeq);
    inboundEndpoint.setOnErrorSeq("error_4");
    synConfig.addInboundEndpoint(inboundEndpoint.getName(), inboundEndpoint);
    String debug_command = "{\"command\":\"set\",\"command-argument\":\"skip\",\"mediation-component\":\"sequence\"," + "\"sequence\":{\"inbound\":{\"inbound-key\":\"test_inbound_4\",\"sequence-type\":\"inbound_faultseq\",\"mediator-position\":\"0\"}}}";
    dm.processDebugCommand(debug_command);
    assertTrue(((AbstractMediator) errorSeq.getChild(0)).isSkipEnabled());
}
Also used : InboundEndpoint(org.apache.synapse.inbound.InboundEndpoint) TestMediator(org.apache.synapse.mediators.TestMediator) SequenceMediator(org.apache.synapse.mediators.base.SequenceMediator)

Example 4 with TestMediator

use of org.apache.synapse.mediators.TestMediator in project wso2-synapse by wso2.

the class DebugManagerTest method testDebugManagerProcessCommandClearSkipTemplate.

public void testDebugManagerProcessCommandClearSkipTemplate() throws Exception {
    TestMediator t1 = new TestMediator();
    TestMediator t2 = new TestMediator();
    TestMediator t3 = new TestMediator();
    TemplateMediator temp = new TemplateMediator();
    temp.addChild(t1);
    temp.addChild(t2);
    temp.addChild(t3);
    temp.setName("test_sequence_template_4");
    synConfig.addSequenceTemplate(temp.getName(), temp);
    String debug_command = "{\"command\":\"set\",\"command-argument\":\"skip\"," + "\"mediation-component\":\"template\",\"template\":{\"template-key\":\"test_sequence_template_4\"," + "\"mediator-position\": \"0\"}}";
    dm.processDebugCommand(debug_command);
    debug_command = "{\"command\":\"clear\",\"command-argument\":\"skip\",\"mediation-component\":\"template\"," + "\"template\":{\"template-key\":\"test_sequence_template_4\",\"mediator-position\": \"0\"}}";
    dm.processDebugCommand(debug_command);
    assertTrue(!((AbstractMediator) temp.getChild(0)).isSkipEnabled());
}
Also used : TemplateMediator(org.apache.synapse.mediators.template.TemplateMediator) TestMediator(org.apache.synapse.mediators.TestMediator) AbstractMediator(org.apache.synapse.mediators.AbstractMediator)

Example 5 with TestMediator

use of org.apache.synapse.mediators.TestMediator in project wso2-synapse by wso2.

the class DebugManagerTest method testDebugManagerProcessCommandSetBreakPointSequence.

public void testDebugManagerProcessCommandSetBreakPointSequence() throws Exception {
    TestMediator t1 = new TestMediator();
    TestMediator t2 = new TestMediator();
    TestMediator t3 = new TestMediator();
    SequenceMediator seq = new SequenceMediator();
    seq.addChild(t1);
    seq.addChild(t2);
    seq.addChild(t3);
    synConfig.addSequence("test_sequence_1", seq);
    String debug_command = "{\"command\":\"set\",\"command-argument\":\"breakpoint\"," + "\"mediation-component\":\"sequence\",\"sequence\":{\"sequence-key\":\"test_sequence_1\"," + "\"sequence-type\": \"named\",\"mediator-position\": \"0\"}}";
    dm.processDebugCommand(debug_command);
    assertTrue(((AbstractMediator) seq.getChild(0)).isBreakPoint());
}
Also used : TestMediator(org.apache.synapse.mediators.TestMediator) SequenceMediator(org.apache.synapse.mediators.base.SequenceMediator)

Aggregations

TestMediator (org.apache.synapse.mediators.TestMediator)29 SequenceMediator (org.apache.synapse.mediators.base.SequenceMediator)18 MessageContext (org.apache.synapse.MessageContext)9 TestMediateHandler (org.apache.synapse.mediators.TestMediateHandler)9 ProxyService (org.apache.synapse.core.axis2.ProxyService)8 AbstractMediator (org.apache.synapse.mediators.AbstractMediator)8 TemplateMediator (org.apache.synapse.mediators.template.TemplateMediator)6 InboundEndpoint (org.apache.synapse.inbound.InboundEndpoint)4 ConfigurationContext (org.apache.axis2.context.ConfigurationContext)3 AxisConfiguration (org.apache.axis2.engine.AxisConfiguration)3 MutableInt (org.apache.commons.lang.mutable.MutableInt)1 Mediator (org.apache.synapse.Mediator)1 SynapseException (org.apache.synapse.SynapseException)1 SynapseConfiguration (org.apache.synapse.config.SynapseConfiguration)1 AnonymousListMediator (org.apache.synapse.config.xml.AnonymousListMediator)1 SwitchCase (org.apache.synapse.config.xml.SwitchCase)1 Axis2SynapseEnvironment (org.apache.synapse.core.axis2.Axis2SynapseEnvironment)1 SynapseMessageReceiver (org.apache.synapse.core.axis2.SynapseMessageReceiver)1 SynapseXPath (org.apache.synapse.util.xpath.SynapseXPath)1