use of org.apache.synapse.TestMessageContextBuilder in project wso2-synapse by wso2.
the class ValidateMediatorTest method testValidateMediatorJSONSchemaWithoutSourceValidCase.
public void testValidateMediatorJSONSchemaWithoutSourceValidCase() 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"));
MessageContext synCtx = new TestMessageContextBuilder().setRequireAxis2MessageContext(true).addFileEntry("JSON-key", "./../../repository/conf/sample/resources/validate/StockQuoteSchema.json").setJsonBodyFromString(VALID_JSON_MESSAGE2).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 testValidateMediatorInvalidSource.
/**
* This method tests the mediator when an invalid source xpath is given.
* Test gets passed if mediator invokes on-fail sequence.
* @throws Exception
*/
public void testValidateMediatorInvalidSource() throws Exception {
// create a validate mediator
ValidateMediator validate = new ValidateMediator();
// set the schema url, invalid source xpath and any name spaces
validate.setSchemaKeys(createKeyListFromStaticKey("xsd-key-1"));
validate.setSource(createXPath("//m0:CheckPriceRequest/m0:price"));
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 envelope
test(validate, synCtx, true);
}
use of org.apache.synapse.TestMessageContextBuilder in project wso2-synapse by wso2.
the class ValidateMediatorTest method testValidateMediatorJSONSchemaWithoutSourceInValidCase.
public void testValidateMediatorJSONSchemaWithoutSourceInValidCase() 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"));
MessageContext synCtx = new TestMessageContextBuilder().setRequireAxis2MessageContext(true).addFileEntry("JSON-key", "./../../repository/conf/sample/resources/validate/StockQuoteSchema.json").setJsonBodyFromString(INVALID_JSON_MESSAGE2).build();
// test validate mediator, with static enveope
test(validate, synCtx, true);
}
use of org.apache.synapse.TestMessageContextBuilder in project wso2-synapse by wso2.
the class TestUtils method getAxis2MessageContext.
public static Axis2MessageContext getAxis2MessageContext(String bodyText, Map<String, Entry> props) throws Exception {
TestMessageContextBuilder builder = new TestMessageContextBuilder();
builder.setRequireAxis2MessageContext(true);
builder.setBodyFromString(bodyText);
if (props != null) {
for (Map.Entry<String, Entry> mapEntry : props.entrySet()) {
builder.addEntry(mapEntry.getKey(), mapEntry.getValue());
}
}
return (Axis2MessageContext) builder.build();
}
Aggregations