use of org.apache.synapse.TestMessageContextBuilder in project wso2-synapse by wso2.
the class XSLTMediatorTest method testTransformXSLTCustomSource.
public void testTransformXSLTCustomSource() throws Exception {
// create a new XSLT mediator
XSLTMediator transformMediator = new XSLTMediator();
// set xpath condition to select source
SynapseXPath xpath = new SynapseXPath("//m0:CheckPriceRequest");
xpath.addNamespace("m0", "http://services.samples/xsd");
transformMediator.setSource(xpath);
// 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 ValidateMediatorTest method makeValidInvocation.
private void makeValidInvocation(ValidateMediator validate) throws Exception {
// set the schema url, source xpath and any name spaces
validate.setSchemaKeys(createKeyListFromStaticKey("xsd-key-1"));
validate.setSource(createXPath("//m0:CheckPriceRequest"));
MessageContext synCtx = new TestMessageContextBuilder().setRequireAxis2MessageContext(true).addFileEntry("xsd-key-1", "./../../repository/conf/sample/resources/validate/validate.xsd").setBodyFromString(VALID_ENVELOPE).build();
// test validate mediator, with static enveope
test(validate, synCtx, false);
}
use of org.apache.synapse.TestMessageContextBuilder in project wso2-synapse by wso2.
the class ValidateMediatorTest method testValidateMediatorValidCaseTwoSchemas.
public void testValidateMediatorValidCaseTwoSchemas() throws Exception {
// create a validate mediator
ValidateMediator validate = new ValidateMediator();
// set the schema url, source xpath and any name spaces
validate.setSchemaKeys(createKeyListFromMoreKeys("xsd-key-1", "xsd-key-2"));
validate.setSource(createXPath("//m1:Outer"));
MessageContext synCtx = new TestMessageContextBuilder().setRequireAxis2MessageContext(true).addFileEntry("xsd-key-1", "./../../repository/conf/sample/resources/validate/validate.xsd").addFileEntry("xsd-key-2", "./../../repository/conf/sample/resources/validate/validate2.xsd").setBodyFromString(VALID_ENVELOPE_TWO_SCHEMAS).build();
// test validate mediator, with static envelope
test(validate, synCtx, false);
}
use of org.apache.synapse.TestMessageContextBuilder in project wso2-synapse by wso2.
the class ValidateMediatorTest method testValidateMediatorJSONSchemaValidCase.
public void testValidateMediatorJSONSchemaValidCase() throws Exception {
// create a validate mediator
ValidateMediator validate = new ValidateMediator();
// set the schema url, source xpath and any name spaces
validate.setSchemaKeys(createKeyListFromStaticKey("JSON-key"));
validate.setSource(createJSONPath("$.msg"));
MessageContext synCtx = new TestMessageContextBuilder().setRequireAxis2MessageContext(true).addFileEntry("JSON-key", "./../../repository/conf/sample/resources/validate/StockQuoteSchema.json").setJsonBodyFromString(VALID_JSON_MESSAGE1).build();
// test validate mediator, with static enveope
test(validate, synCtx, false);
}
use of org.apache.synapse.TestMessageContextBuilder in project wso2-synapse by wso2.
the class ValidateMediatorTest method testValidateMediatorInvalidCase.
public void testValidateMediatorInvalidCase() throws Exception {
// create a validate mediator
ValidateMediator validate = new ValidateMediator();
// set the schema url, source xpath and any name spaces
validate.setSchemaKeys(createKeyListFromStaticKey("xsd-key-1"));
validate.setSource(createXPath("//m0:CheckPriceRequest"));
MessageContext synCtx = new TestMessageContextBuilder().setRequireAxis2MessageContext(true).addFileEntry("xsd-key-1", "./../../repository/conf/sample/resources/validate/validate.xsd").setBodyFromString(IN_VALID_ENVELOPE).build();
// test validate mediator, with static enveope
test(validate, synCtx, true);
}
Aggregations