Search in sources :

Example 51 with MessageContext

use of org.apache.synapse.MessageContext 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 52 with MessageContext

use of org.apache.synapse.MessageContext 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 53 with MessageContext

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

the class DBLookupMediatorTest method testLookupMediator1.

public void testLookupMediator1() throws Exception {
    MessageContext synCtx = TestUtils.getTestContext("<dummy><source>5</source></dummy>");
    assertTrue(lookup.mediate(synCtx));
    assertEquals(synCtx.getProperty("targetProp"), "svr1");
    assertEquals(synCtx.getProperty("categoryProp"), "A");
}
Also used : MessageContext(org.apache.synapse.MessageContext)

Example 54 with MessageContext

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

the class DBLookupMediatorTest method testLookupMediator2.

public void testLookupMediator2() throws Exception {
    MessageContext synCtx = TestUtils.getTestContext("<dummy><source>6</source></dummy>");
    assertTrue(lookup.mediate(synCtx));
    assertEquals(synCtx.getProperty("targetProp"), "svr3");
    assertEquals(synCtx.getProperty("categoryProp"), "B");
}
Also used : MessageContext(org.apache.synapse.MessageContext)

Example 55 with MessageContext

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

the class DBReportMediatorTest method testLookupMediator1.

public void testLookupMediator1() throws Exception {
    MessageContext synCtx = TestUtils.getTestContext("<dummy><from>me</from><count>5</count><to>you</to><category>GOLD</category></dummy>");
    assertTrue(report.mediate(synCtx));
    Connection con = report.getDataSource().getConnection();
    ResultSet rs = con.createStatement().executeQuery("select fromepr, cnt, toepr, category from audit");
    if (rs.next()) {
        assertEquals("me", rs.getString("fromepr"));
        assertEquals(5, rs.getInt("cnt"));
        assertEquals("you", rs.getString("toepr"));
        assertEquals("GOLD", rs.getString("category"));
    } else {
        fail("DB report failed");
    }
}
Also used : Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) 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