Search in sources :

Example 16 with TestMessageContextBuilder

use of org.apache.synapse.TestMessageContextBuilder in project wso2-synapse by wso2.

the class TestUtils method getTestContext.

public static MessageContext getTestContext(String bodyText, Map<String, Entry> props) throws Exception {
    TestMessageContextBuilder builder = new TestMessageContextBuilder();
    builder.setBodyFromString(bodyText);
    if (props != null) {
        for (Map.Entry<String, Entry> mapEntry : props.entrySet()) {
            builder.addEntry(mapEntry.getKey(), mapEntry.getValue());
        }
    }
    return builder.build();
}
Also used : Entry(org.apache.synapse.config.Entry) TestMessageContextBuilder(org.apache.synapse.TestMessageContextBuilder) Map(java.util.Map)

Example 17 with TestMessageContextBuilder

use of org.apache.synapse.TestMessageContextBuilder in project wso2-synapse by wso2.

the class XSLTMediatorTest method testInvalidStylesheet.

// Test for SYNAPSE-307
public void testInvalidStylesheet() throws Exception {
    XSLTMediator transformMediator = new XSLTMediator();
    setXsltTransformationURL(transformMediator, "xslt-key");
    MessageContext mc = new TestMessageContextBuilder().addEntry("xslt-key", getClass().getResource("invalid.xslt")).setBodyFromString("<root/>").build();
    try {
        transformMediator.mediate(mc);
        fail("Expected a SynapseException to be thrown");
    } catch (SynapseException ex) {
    // this is what is expected
    }
}
Also used : SynapseException(org.apache.synapse.SynapseException) TestMessageContextBuilder(org.apache.synapse.TestMessageContextBuilder) MessageContext(org.apache.synapse.MessageContext)

Example 18 with TestMessageContextBuilder

use of org.apache.synapse.TestMessageContextBuilder in project wso2-synapse by wso2.

the class XSLTMediatorTest method testTransformXSLTDefaultSource.

/**
 * If a source element for transformation is not found, default to soap body
 * @throws Exception if there is an error in test
 */
public void testTransformXSLTDefaultSource() throws Exception {
    // create a new xslt mediator
    XSLTMediator transformMediator = new XSLTMediator();
    // set XSLT transformation URL
    setXsltTransformationURL(transformMediator, "xslt-key");
    MessageContext synCtx = new TestMessageContextBuilder().addFileEntry("xslt-key", "../../repository/conf/sample/resources/transform/transform_unittest.xslt").setBodyFromString(SOURCE).addTextAroundBody().build();
    transformMediator.mediate(synCtx);
    // validate result
    assertQuoteElement(synCtx.getEnvelope().getBody().getFirstOMChild().getNextOMSibling());
}
Also used : TestMessageContextBuilder(org.apache.synapse.TestMessageContextBuilder) MessageContext(org.apache.synapse.MessageContext)

Example 19 with TestMessageContextBuilder

use of org.apache.synapse.TestMessageContextBuilder in project wso2-synapse by wso2.

the class XSLTMediatorTest method testWithCDATA.

/**
 * Test that the XSLT mediator is able to handle CDATA sections in the
 * source AXIOM tree.
 * This tests for regression against WSCOMMONS-338. It should work with
 * AXIOM versions above 1.2.7.
 *
 * @throws Exception in case of an error in tests
 */
public void testWithCDATA() throws Exception {
    XSLTMediator transformMediator = new XSLTMediator();
    setXsltTransformationURL(transformMediator, "xslt-key");
    MessageContext mc = new TestMessageContextBuilder().addEntry("xslt-key", getClass().getResource("cdata.xslt")).build();
    OMFactory factory = OMAbstractFactory.getOMFactory();
    OMElement in = factory.createOMElement(new QName(null, "in"));
    factory.createOMText(in, "test", OMNode.CDATA_SECTION_NODE);
    mc.getEnvelope().getBody().addChild(in);
    transformMediator.mediate(mc);
    OMElement out = mc.getEnvelope().getBody().getFirstElement();
    assertEquals("out", out.getLocalName());
    assertEquals("test", out.getText());
}
Also used : TestMessageContextBuilder(org.apache.synapse.TestMessageContextBuilder) QName(javax.xml.namespace.QName) MessageContext(org.apache.synapse.MessageContext)

Example 20 with TestMessageContextBuilder

use of org.apache.synapse.TestMessageContextBuilder in project wso2-synapse by wso2.

the class XSLTMediatorTest method testTransformXSLTLargeMessagesXML.

public void testTransformXSLTLargeMessagesXML() throws Exception {
    // create a new switch mediator
    XSLTMediator transformMediator = new XSLTMediator();
    // set XSLT transformation URL
    setXsltTransformationURL(transformMediator, "xslt-key");
    for (int i = 0; i < 2; i++) {
        // invoke transformation, with static enveope
        MessageContext synCtx = new TestMessageContextBuilder().addFileEntry("xslt-key", "../../repository/conf/sample/resources/transform/transform_load_3.xml").setBodyFromFile("../../repository/conf/sample/resources/transform/message.xml").addTextAroundBody().build();
        // MessageContext synCtx = TestUtils.getTestContextForXSLTMediator(SOURCE, props);
        transformMediator.mediate(synCtx);
    // System.gc();
    // System.out.println("done : " + i + " :: " + Runtime.getRuntime().freeMemory());
    }
}
Also used : TestMessageContextBuilder(org.apache.synapse.TestMessageContextBuilder) MessageContext(org.apache.synapse.MessageContext)

Aggregations

TestMessageContextBuilder (org.apache.synapse.TestMessageContextBuilder)29 MessageContext (org.apache.synapse.MessageContext)26 SynapseXPath (org.apache.synapse.util.xpath.SynapseXPath)4 Map (java.util.Map)3 Entry (org.apache.synapse.config.Entry)3 QName (javax.xml.namespace.QName)2 Value (org.apache.synapse.mediators.Value)2 SynapseException (org.apache.synapse.SynapseException)1 Axis2MessageContext (org.apache.synapse.core.axis2.Axis2MessageContext)1