Search in sources :

Example 26 with TestMessageContextBuilder

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

Example 27 with TestMessageContextBuilder

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

Example 28 with TestMessageContextBuilder

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

Example 29 with TestMessageContextBuilder

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();
}
Also used : Entry(org.apache.synapse.config.Entry) TestMessageContextBuilder(org.apache.synapse.TestMessageContextBuilder) Map(java.util.Map) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext)

Aggregations

TestMessageContextBuilder (org.apache.synapse.TestMessageContextBuilder)29 MessageContext (org.apache.synapse.MessageContext)26 SynapseXPath (org.apache.synapse.util.xpath.SynapseXPath)4 Map (java.util.Map)3 Entry (org.apache.synapse.config.Entry)3 QName (javax.xml.namespace.QName)2 Value (org.apache.synapse.mediators.Value)2 SynapseException (org.apache.synapse.SynapseException)1 Axis2MessageContext (org.apache.synapse.core.axis2.Axis2MessageContext)1