Package org.apache.synapse

Examples of org.apache.synapse.TestMessageContext


    }

    public static TestMessageContext getTestContextForXSLTMediatorUsingFile(String path, Map props) throws Exception {

        // create a test synapse context
        TestMessageContext synCtx = new TestMessageContext();
        SynapseConfiguration testConfig = new SynapseConfiguration();
        testConfig.setRegistry(new SimpleURLRegistry());

        if (props != null) {
            Iterator iter = props.keySet().iterator();
            while (iter.hasNext()) {
                String key = (String) iter.next();
                testConfig.addEntry(key, (Entry) props.get(key));
            }
        }
        synCtx.setConfiguration(testConfig);

        SOAPEnvelope envelope = OMAbstractFactory.getSOAP11Factory().getDefaultEnvelope();
        OMDocument omDoc = OMAbstractFactory.getSOAP11Factory().createOMDocument();
        omDoc.addChild(envelope);

        //XMLStreamReader parser = XMLInputFactory.newInstance().
        //        createXMLStreamReader(new FileReader(path));
        StAXOMBuilder builder = new StAXOMBuilder(path);

        // set a dummy static message
        OMFactory fac = OMAbstractFactory.getOMFactory();
        envelope.getBody().addChild(fac.createOMText("first text child "));
        envelope.getBody().addChild(builder.getDocumentElement());
        envelope.getBody().addChild(fac.createOMText("second text child "));

        synCtx.setEnvelope(envelope);
        return synCtx;
    }
View Full Code Here


    }

    public static TestMessageContext getTestContextForXSLTMediator(String bodyText, Map props) throws Exception {

        // create a test synapse context
        TestMessageContext synCtx = new TestMessageContext();
        SynapseConfiguration testConfig = new SynapseConfiguration();
        testConfig.setRegistry(new SimpleURLRegistry());

        if (props != null) {
            Iterator iter = props.keySet().iterator();
            while (iter.hasNext()) {
                String key = (String) iter.next();
                testConfig.addEntry(key, (Entry) props.get(key));
            }
        }
        synCtx.setConfiguration(testConfig);

        SOAPEnvelope envelope = OMAbstractFactory.getSOAP11Factory().getDefaultEnvelope();
        OMDocument omDoc = OMAbstractFactory.getSOAP11Factory().createOMDocument();
        omDoc.addChild(envelope);

        XMLStreamReader parser = XMLInputFactory.newInstance().
                createXMLStreamReader(new StringReader(bodyText));
        StAXOMBuilder builder = new StAXOMBuilder(parser);

        // set a dummy static message
        OMFactory fac = OMAbstractFactory.getOMFactory();
        envelope.getBody().addChild(fac.createOMText("first text child "));
        envelope.getBody().addChild(builder.getDocumentElement());
        envelope.getBody().addChild(fac.createOMText("second text child "));

        synCtx.setEnvelope(envelope);
        return synCtx;
    }
View Full Code Here

    }

    public static TestMessageContext getTestContextForXSLTMediatorUsingFile(String path, Map props) throws Exception {

        // create a test synapse context
        TestMessageContext synCtx = new TestMessageContext();
        SynapseConfiguration testConfig = new SynapseConfiguration();
        testConfig.setRegistry(new SimpleURLRegistry());

        if (props != null) {
            Iterator iter = props.keySet().iterator();
            while (iter.hasNext()) {
                String key = (String) iter.next();
                testConfig.addEntry(key, (Entry) props.get(key));
            }
        }
        synCtx.setConfiguration(testConfig);

        SOAPEnvelope envelope = OMAbstractFactory.getSOAP11Factory().getDefaultEnvelope();
        OMDocument omDoc = OMAbstractFactory.getSOAP11Factory().createOMDocument();
        omDoc.addChild(envelope);

        //XMLStreamReader parser = XMLInputFactory.newInstance().
        //        createXMLStreamReader(new FileReader(path));
        StAXOMBuilder builder = new StAXOMBuilder(path);

        // set a dummy static message
        OMFactory fac = OMAbstractFactory.getOMFactory();
        envelope.getBody().addChild(fac.createOMText("first text child "));
        envelope.getBody().addChild(builder.getDocumentElement());
        envelope.getBody().addChild(fac.createOMText("second text child "));

        synCtx.setEnvelope(envelope);
        return synCtx;
    }
View Full Code Here

public class TestUtils {

    public static TestMessageContext getTestContext(String bodyText, Map props) throws Exception {

        // create a test synapse context
        TestMessageContext synCtx = new TestMessageContext();
        SynapseConfiguration testConfig = new SynapseConfiguration();
        testConfig.setRegistry(new SimpleURLRegistry());
        synCtx.setEnvironment(new Axis2SynapseEnvironment(testConfig));       

        if (props != null) {
            Iterator iter = props.keySet().iterator();
            while (iter.hasNext()) {
                String key = (String) iter.next();
                testConfig.addEntry(key, (Entry) props.get(key));
            }
        }
        synCtx.setConfiguration(testConfig);
        synCtx.setEnvironment(new Axis2SynapseEnvironment(
            new ConfigurationContext(new AxisConfiguration()), testConfig));

        SOAPEnvelope envelope = OMAbstractFactory.getSOAP11Factory().getDefaultEnvelope();
        OMDocument omDoc = OMAbstractFactory.getSOAP11Factory().createOMDocument();
        omDoc.addChild(envelope);

        XMLStreamReader parser = XMLInputFactory.newInstance().
                createXMLStreamReader(new StringReader(bodyText));
        StAXOMBuilder builder = new StAXOMBuilder(parser);

        // set a dummy static message
        envelope.getBody().addChild(builder.getDocumentElement());

        synCtx.setEnvelope(envelope);
        return synCtx;
    }
View Full Code Here

    }

    public static TestMessageContext getTestContextForXSLTMediator(String bodyText, Map props) throws Exception {

        // create a test synapse context
        TestMessageContext synCtx = new TestMessageContext();
        SynapseConfiguration testConfig = new SynapseConfiguration();
        testConfig.setRegistry(new SimpleURLRegistry());
        SynapseEnvironment testEnv = new Axis2SynapseEnvironment(new ConfigurationContext(new AxisConfiguration()), testConfig);

        if (props != null) {
            Iterator iter = props.keySet().iterator();
            while (iter.hasNext()) {
                String key = (String) iter.next();
                testConfig.addEntry(key, (Entry) props.get(key));
            }
        }
        synCtx.setConfiguration(testConfig);
        synCtx.setEnvironment(testEnv);

        SOAPEnvelope envelope = OMAbstractFactory.getSOAP11Factory().getDefaultEnvelope();
        OMDocument omDoc = OMAbstractFactory.getSOAP11Factory().createOMDocument();
        omDoc.addChild(envelope);

        XMLStreamReader parser = XMLInputFactory.newInstance().
                createXMLStreamReader(new StringReader(bodyText));
        StAXOMBuilder builder = new StAXOMBuilder(parser);

        // set a dummy static message
        OMFactory fac = OMAbstractFactory.getOMFactory();
        envelope.getBody().addChild(fac.createOMText("first text child "));
        envelope.getBody().addChild(builder.getDocumentElement());
        envelope.getBody().addChild(fac.createOMText("second text child "));

        synCtx.setEnvelope(envelope);
        return synCtx;
    }
View Full Code Here

    }

    public static TestMessageContext getTestContextForXSLTMediatorUsingFile(String path, Map props) throws Exception {

        // create a test synapse context
        TestMessageContext synCtx = new TestMessageContext();
        SynapseConfiguration testConfig = new SynapseConfiguration();
        testConfig.setRegistry(new SimpleURLRegistry());
        synCtx.setEnvironment(new Axis2SynapseEnvironment(new ConfigurationContext(new AxisConfiguration()), testConfig));

        if (props != null) {
            Iterator iter = props.keySet().iterator();
            while (iter.hasNext()) {
                String key = (String) iter.next();
                testConfig.addEntry(key, (Entry) props.get(key));
            }
        }
        synCtx.setConfiguration(testConfig);

        SOAPEnvelope envelope = OMAbstractFactory.getSOAP11Factory().getDefaultEnvelope();
        OMDocument omDoc = OMAbstractFactory.getSOAP11Factory().createOMDocument();
        omDoc.addChild(envelope);

        //XMLStreamReader parser = XMLInputFactory.newInstance().
        //        createXMLStreamReader(new FileReader(path));
        StAXOMBuilder builder = new StAXOMBuilder(path);

        // set a dummy static message
        OMFactory fac = OMAbstractFactory.getOMFactory();
        envelope.getBody().addChild(fac.createOMText("first text child "));
        envelope.getBody().addChild(builder.getDocumentElement());
        envelope.getBody().addChild(fac.createOMText("second text child "));

        synCtx.setEnvelope(envelope);
        return synCtx;
    }
View Full Code Here

        cfg.addEntry("xslt-key", xsltEntry);
       
        transformMediator = new XSLTMediator();
        transformMediator.setXsltKey("xslt-key");
       
        MessageContext mc = new TestMessageContext();
        mc.setConfiguration(cfg);
        mc.setEnvironment(new Axis2SynapseEnvironment(new ConfigurationContext(new AxisConfiguration()), cfg));
        mc.setEnvelope(new StAXSOAPModelBuilder(StAXUtils.createXMLStreamReader(new FileInputStream("./../../repository/conf/sample/resources/transform/encoding_test.xml"))).getSOAPEnvelope());
       
        transformMediator.mediate(mc);
       
        OMElement resultElement = mc.getEnvelope().getBody().getFirstElement();
        assertEquals(BaseConstants.DEFAULT_TEXT_WRAPPER, resultElement.getQName());
        assertEquals("\u00e0 peine arriv\u00e9s nous entr\u00e2mes dans sa chambre", resultElement.getText());
    }
View Full Code Here

        assertEquals(2, xpath.selectNodes(ctx).size());
    }

    public void testContextProperties() throws Exception {
        SynapseXPath xpath = new SynapseXPath("$ctx:test");
        MessageContext synCtx = new TestMessageContext();
        synCtx.setProperty("test", message);
        assertEquals(xpath.evaluate(synCtx), message);
    }
View Full Code Here

    public void testMediationWithoutProperties() throws Exception {
        Mediator cm = MediatorFactoryFinder.getInstance().getMediator(createOMElement(
                "<class name='org.apache.synapse.mediators.ext.ClassMediatorTestMediator' " +
                        "xmlns='http://ws.apache.org/ns/synapse'/>"));
        cm.mediate(new TestMessageContext());
        assertTrue(ClassMediatorTestMediator.invoked);
    }
View Full Code Here

    public void testMediationWithLiteralProperties() throws Exception {
        Mediator cm = MediatorFactoryFinder.getInstance().getMediator(createOMElement(
                "<class name='org.apache.synapse.mediators.ext.ClassMediatorTestMediator' " +
                        "xmlns='http://ws.apache.org/ns/synapse'><property name='testProp' value='testValue'/></class>"));
        cm.mediate(new TestMessageContext());
        assertTrue(ClassMediatorTestMediator.invoked);
        assertTrue(ClassMediatorTestMediator.testProp.equals("testValue"));
    }
View Full Code Here

TOP

Related Classes of org.apache.synapse.TestMessageContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.