Search in sources :

Example 46 with MessageContext

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);
}
Also used : TestMessageContextBuilder(org.apache.synapse.TestMessageContextBuilder) MessageContext(org.apache.synapse.MessageContext)

Example 47 with MessageContext

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);
}
Also used : TestMessageContextBuilder(org.apache.synapse.TestMessageContextBuilder) MessageContext(org.apache.synapse.MessageContext)

Example 48 with MessageContext

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);
    }
}
Also used : MutableInt(org.apache.commons.lang.mutable.MutableInt) TestMediateHandler(org.apache.synapse.mediators.TestMediateHandler) TestMediator(org.apache.synapse.mediators.TestMediator) MessageContext(org.apache.synapse.MessageContext)

Example 49 with MessageContext

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);
}
Also used : TestMessageContextBuilder(org.apache.synapse.TestMessageContextBuilder) MessageContext(org.apache.synapse.MessageContext)

Example 50 with MessageContext

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);
}
Also used : TestMessageContextBuilder(org.apache.synapse.TestMessageContextBuilder) MessageContext(org.apache.synapse.MessageContext)

Aggregations

MessageContext (org.apache.synapse.MessageContext)220 Axis2MessageContext (org.apache.synapse.core.axis2.Axis2MessageContext)86 SynapseConfiguration (org.apache.synapse.config.SynapseConfiguration)54 SynapseException (org.apache.synapse.SynapseException)29 TestMessageContextBuilder (org.apache.synapse.TestMessageContextBuilder)26 ArrayList (java.util.ArrayList)24 Axis2SynapseEnvironment (org.apache.synapse.core.axis2.Axis2SynapseEnvironment)24 SynapseXPath (org.apache.synapse.util.xpath.SynapseXPath)24 ConfigurationContext (org.apache.axis2.context.ConfigurationContext)18 SynapseEnvironment (org.apache.synapse.core.SynapseEnvironment)18 OMElement (org.apache.axiom.om.OMElement)17 AxisConfiguration (org.apache.axis2.engine.AxisConfiguration)17 HashMap (java.util.HashMap)16 Mediator (org.apache.synapse.Mediator)16 TestMessageContext (org.apache.synapse.TestMessageContext)16 Map (java.util.Map)15 Properties (java.util.Properties)15 Test (org.junit.Test)15 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)14 QName (javax.xml.namespace.QName)13