use of org.apache.synapse.MessageContext 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.MessageContext 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);
}
use of org.apache.synapse.MessageContext in project wso2-synapse by wso2.
the class ValidateMediatorTest method test.
private void test(ValidateMediator validate, MessageContext synCtx, boolean expectFail) {
final MutableInt onFailInvoked = new MutableInt();
TestMediator testMediator = new TestMediator();
testMediator.setHandler(new TestMediateHandler() {
public void handle(MessageContext synCtx) {
onFailInvoked.setValue(1);
}
});
// set dummy mediator to be called on fail
validate.addChild(testMediator);
validate.mediate(synCtx);
if (expectFail) {
assertTrue("Expected ValidateMediator to trigger on-fail sequence", onFailInvoked.intValue() == 1);
} else {
assertTrue("ValidateMediator unexpectedly triggered on-fail sequence", onFailInvoked.intValue() == 0);
}
}
use of org.apache.synapse.MessageContext in project wso2-synapse by wso2.
the class ValidateMediatorTest method testValidateMediatorInvalidCaseTwoSchemas.
public void testValidateMediatorInvalidCaseTwoSchemas() 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(INVALID_ENVELOPE_TWO_SCHEMAS).build();
// test validate mediator, with static enveope
test(validate, synCtx, true);
}
use of org.apache.synapse.MessageContext in project wso2-synapse by wso2.
the class ValidateMediatorTest method testValidateMediatorInvalidCaseNoNS.
public void testValidateMediatorInvalidCaseNoNS() 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_NO_NS).build();
// test validate mediator, with static enveope
test(validate, synCtx, true);
}
Aggregations