Search in sources :

Example 11 with TestMessageContextBuilder

use of org.apache.synapse.TestMessageContextBuilder 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 12 with TestMessageContextBuilder

use of org.apache.synapse.TestMessageContextBuilder 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)

Example 13 with TestMessageContextBuilder

use of org.apache.synapse.TestMessageContextBuilder in project wso2-synapse by wso2.

the class ValidateMediatorTest method testValidateMediatorValidCaseNoNS.

public void testValidateMediatorValidCaseNoNS() 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(VALID_ENVELOPE_NO_NS).build();
    // test validate mediator, with static enveope
    test(validate, synCtx, false);
}
Also used : TestMessageContextBuilder(org.apache.synapse.TestMessageContextBuilder) MessageContext(org.apache.synapse.MessageContext)

Example 14 with TestMessageContextBuilder

use of org.apache.synapse.TestMessageContextBuilder in project wso2-synapse by wso2.

the class ValidateMediatorTest method testValidateMediatorValidCase.

public void testValidateMediatorValidCase() 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"));
    validate.setSource(createXPath("//m0:CheckPriceRequest"));
    MessageContext synCtx = new TestMessageContextBuilder().setRequireAxis2MessageContext(true).addFileEntry("xsd-key", "./../../repository/conf/sample/resources/validate/validate.xsd").setBodyFromString(VALID_ENVELOPE).build();
    // test validate mediator, with static enveope
    test(validate, synCtx, false);
}
Also used : TestMessageContextBuilder(org.apache.synapse.TestMessageContextBuilder) MessageContext(org.apache.synapse.MessageContext)

Example 15 with TestMessageContextBuilder

use of org.apache.synapse.TestMessageContextBuilder in project wso2-synapse by wso2.

the class TestUtils method getTestContextJson.

public static MessageContext getTestContextJson(String bodyText, Map<String, Entry> props) throws Exception {
    TestMessageContextBuilder builder = new TestMessageContextBuilder();
    builder.setRequireAxis2MessageContext(true);
    builder.setJsonBodyFromString(bodyText);
    if (props != null) {
        for (Map.Entry<String, Entry> mapEntry : props.entrySet()) {
            builder.addEntry(mapEntry.getKey(), mapEntry.getValue());
        }
    }
    return builder.build();
}
Also used : Entry(org.apache.synapse.config.Entry) TestMessageContextBuilder(org.apache.synapse.TestMessageContextBuilder) Map(java.util.Map)

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