Search in sources :

Example 26 with TestMediator

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

the class DebugManagerTest method testDebugManagerProcessCommandSetSkipProxyInSequence.

public void testDebugManagerProcessCommandSetSkipProxyInSequence() throws Exception {
    ProxyService ps = new ProxyService("test_proxy_5");
    TestMediator in1 = new TestMediator();
    TestMediator in2 = new TestMediator();
    TestMediator in3 = new TestMediator();
    SequenceMediator inSeq = new SequenceMediator();
    inSeq.addChild(in1);
    inSeq.addChild(in2);
    inSeq.addChild(in3);
    TestMediator out1 = new TestMediator();
    TestMediator out2 = new TestMediator();
    TestMediator out3 = new TestMediator();
    SequenceMediator outSeq = new SequenceMediator();
    outSeq.addChild(out1);
    outSeq.addChild(out2);
    outSeq.addChild(out3);
    ps.setTargetInLineInSequence(inSeq);
    ps.setTargetInLineOutSequence(inSeq);
    synConfig.addProxyService(ps.getName(), ps);
    String debug_command = "{\"command\":\"set\",\"command-argument\":\"skip\",\"mediation-component\":\"sequence\"," + "\"sequence\":{\"proxy\":{\"proxy-key\":\"test_proxy_5\",\"sequence-type\":\"proxy_inseq\"," + "\"mediator-position\":\"0\"}}}";
    dm.processDebugCommand(debug_command);
    assertTrue(((AbstractMediator) ps.getTargetInLineInSequence().getChild(0)).isSkipEnabled());
}
Also used : ProxyService(org.apache.synapse.core.axis2.ProxyService) TestMediator(org.apache.synapse.mediators.TestMediator) SequenceMediator(org.apache.synapse.mediators.base.SequenceMediator)

Example 27 with TestMediator

use of org.apache.synapse.mediators.TestMediator 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)

Example 28 with TestMediator

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

the class SequenceMediatorTest method testSequenceMediator.

public void testSequenceMediator() 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);
    // invoke transformation, with static enveope
    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)

Example 29 with TestMediator

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

the class SequenceMediatorTest method testErrorHandling.

public void testErrorHandling() 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.");
            throw new SynapseException("test");
        }
    });
    TestMediator t3 = new TestMediator();
    t3.setHandler(new TestMediateHandler() {

        public void handle(MessageContext synCtx) {
            result.append("T3.");
        }
    });
    TestMediator t4 = new TestMediator();
    t4.setHandler(new TestMediateHandler() {

        public void handle(MessageContext synCtx) {
            result.append("T4");
            assertEquals("test", synCtx.getProperty(SynapseConstants.ERROR_MESSAGE));
        }
    });
    SequenceMediator seq = new SequenceMediator();
    seq.addChild(t1);
    seq.addChild(t2);
    seq.addChild(t3);
    seq.setErrorHandler("myErrorHandler");
    SequenceMediator seqErr = new SequenceMediator();
    seqErr.setName("myErrorHandler");
    seqErr.addChild(t4);
    // invoke transformation, with static enveope
    SynapseConfiguration synConfig = new SynapseConfiguration();
    synConfig.addSequence("myErrorHandler", seqErr);
    synConfig.addSequence(SynapseConstants.MAIN_SEQUENCE_KEY, seq);
    MessageContextCreatorForAxis2.setSynConfig(synConfig);
    MessageContextCreatorForAxis2.setSynEnv(new Axis2SynapseEnvironment(synConfig));
    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());
    new SynapseMessageReceiver().receive(mc);
    assertTrue("T1.T2.T4".equals(result.toString()));
}
Also used : AxisConfiguration(org.apache.axis2.engine.AxisConfiguration) ConfigurationContext(org.apache.axis2.context.ConfigurationContext) SynapseException(org.apache.synapse.SynapseException) TestMediator(org.apache.synapse.mediators.TestMediator) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration) Axis2SynapseEnvironment(org.apache.synapse.core.axis2.Axis2SynapseEnvironment) TestMediateHandler(org.apache.synapse.mediators.TestMediateHandler) MessageContext(org.apache.synapse.MessageContext) SynapseMessageReceiver(org.apache.synapse.core.axis2.SynapseMessageReceiver)

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