Search in sources :

Example 6 with TestMediateHandler

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);
}
Also used : AxisConfiguration(org.apache.axis2.engine.AxisConfiguration) ConfigurationContext(org.apache.axis2.context.ConfigurationContext) TestMediateHandler(org.apache.synapse.mediators.TestMediateHandler) TestMediator(org.apache.synapse.mediators.TestMediator) MessageContext(org.apache.synapse.MessageContext) SequenceMediator(org.apache.synapse.mediators.base.SequenceMediator)

Example 7 with TestMediateHandler

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()));
}
Also used : TestMediateHandler(org.apache.synapse.mediators.TestMediateHandler) TestMediator(org.apache.synapse.mediators.TestMediator) MessageContext(org.apache.synapse.MessageContext) SequenceMediator(org.apache.synapse.mediators.base.SequenceMediator)

Example 8 with TestMediateHandler

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

the class DebugManagerTest method testSkipTemplate.

public void testSkipTemplate() 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_5");
    temp.setParameters(new HashSet<TemplateParam>());
    synConfig.addSequenceTemplate(temp.getName(), temp);
    String debug_command = "{\"command\":\"set\",\"command-argument\":\"skip\",\"mediation-component\":\"template\"," + "\"template\":{\"template-key\":\"test_sequence_template_5\",\"mediator-position\": \"0\"}}";
    dm.processDebugCommand(debug_command);
    debug_command = "{\"command\":\"set\",\"command-argument\":\"skip\",\"mediation-component\":\"template\"," + "\"template\":{\"template-key\":\"test_sequence_template_5\",\"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);
    temp.mediate(synCtx);
    assertTrue("T3".equals(result.toString()));
    synEnv.setDebugEnabled(false);
}
Also used : AxisConfiguration(org.apache.axis2.engine.AxisConfiguration) ConfigurationContext(org.apache.axis2.context.ConfigurationContext) TestMediator(org.apache.synapse.mediators.TestMediator) TemplateMediator(org.apache.synapse.mediators.template.TemplateMediator) TestMediateHandler(org.apache.synapse.mediators.TestMediateHandler) MessageContext(org.apache.synapse.MessageContext) TemplateParam(org.apache.synapse.mediators.template.TemplateParam)

Example 9 with TestMediateHandler

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

the class FilterMediatorTest method setUp.

public void setUp() {
    testMediator = new TestMediator();
    testMediator.setHandler(new TestMediateHandler() {

        public void handle(MessageContext synCtx) {
            setFilterConditionPassed(true);
        }
    });
}
Also used : TestMediateHandler(org.apache.synapse.mediators.TestMediateHandler) TestMediator(org.apache.synapse.mediators.TestMediator) MessageContext(org.apache.synapse.MessageContext)

Aggregations

MessageContext (org.apache.synapse.MessageContext)9 TestMediateHandler (org.apache.synapse.mediators.TestMediateHandler)9 TestMediator (org.apache.synapse.mediators.TestMediator)9 ConfigurationContext (org.apache.axis2.context.ConfigurationContext)3 AxisConfiguration (org.apache.axis2.engine.AxisConfiguration)3 SequenceMediator (org.apache.synapse.mediators.base.SequenceMediator)2 TemplateMediator (org.apache.synapse.mediators.template.TemplateMediator)2 TemplateParam (org.apache.synapse.mediators.template.TemplateParam)2 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