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();
}
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
}
}
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());
}
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());
}
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());
}
}
Aggregations