Search in sources :

Example 6 with SynapseConfiguration

use of org.apache.synapse.config.SynapseConfiguration in project wso2-synapse by wso2.

the class DBReportMediatorTest method suite.

public static Test suite() {
    return new TestSetup(new TestSuite(DBReportMediatorTest.class)) {

        @Override
        protected void setUp() throws Exception {
            String baseDir = System.getProperty("basedir");
            if (baseDir == null) {
                baseDir = ".";
            }
            report = (DBReportMediator) new DBReportMediatorFactory().createMediator(createOMElement("<dblookup xmlns=\"http://ws.apache.org/ns/synapse\">\n" + "  <connection>\n" + "    <pool>\n" + "      <driver>org.apache.derby.jdbc.EmbeddedDriver</driver>\n" + "      <url>jdbc:derby:" + baseDir + "/target/derbyDB;create=true</url>\n" + "      <user>user</user>\n" + "      <password>pass</password>\n" + "      <property name=\"initialsize\" value=\"2\"/>\n" + "      <property name=\"isolation\" value=\"Connection.TRANSACTION_SERIALIZABLE\"/>\n" + "    </pool>\n" + "  </connection>\n" + "  <statement>\n" + "    <sql>insert into audit values(?, ?, ?, ?)</sql>\n" + "    <parameter expression=\"//from\" type=\"VARCHAR\"/>\n" + "    <parameter expression=\"//count\" type=\"INTEGER\"/>\n" + "    <parameter expression=\"//to\" type=\"VARCHAR\"/>\n" + "    <parameter value=\"GOLD\" type=\"VARCHAR\"/>\n" + "  </statement>\n" + "</dblookup>"), new Properties());
            report.init(new Axis2SynapseEnvironment(new SynapseConfiguration()));
            java.sql.Statement s = report.getDataSource().getConnection().createStatement();
            try {
                s.execute("drop table audit");
            } catch (SQLException ignore) {
            }
            s.execute("create table audit(fromepr varchar(10), cnt int, toepr varchar(10), category varchar(10))");
            s.close();
        }

        @Override
        protected void tearDown() throws Exception {
        }
    };
}
Also used : TestSetup(junit.extensions.TestSetup) Axis2SynapseEnvironment(org.apache.synapse.core.axis2.Axis2SynapseEnvironment) TestSuite(junit.framework.TestSuite) SQLException(java.sql.SQLException) Properties(java.util.Properties) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration) DBReportMediatorFactory(org.apache.synapse.config.xml.DBReportMediatorFactory)

Example 7 with SynapseConfiguration

use of org.apache.synapse.config.SynapseConfiguration in project wso2-synapse by wso2.

the class APIDispatcherTest method testGeneralAPIDispatch.

public void testGeneralAPIDispatch() throws Exception {
    API api = new API(TEST_API, "/");
    SynapseConfiguration synapseConfig = new SynapseConfiguration();
    synapseConfig.addAPI(TEST_API, api);
    RESTRequestHandler handler = new RESTRequestHandler();
    MessageContext synCtx = getMessageContext(synapseConfig, false, "/test", "GET");
    handler.process(synCtx);
    assertEquals(TEST_API, synCtx.getProperty(RESTConstants.SYNAPSE_REST_API));
    synCtx = getMessageContext(synapseConfig, false, "/", "GET");
    handler.process(synCtx);
    assertEquals(TEST_API, synCtx.getProperty(RESTConstants.SYNAPSE_REST_API));
    synCtx = getMessageContext(synapseConfig, false, "/foo/bar?a=5", "GET");
    handler.process(synCtx);
    assertEquals(TEST_API, synCtx.getProperty(RESTConstants.SYNAPSE_REST_API));
}
Also used : MessageContext(org.apache.synapse.MessageContext) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration)

Example 8 with SynapseConfiguration

use of org.apache.synapse.config.SynapseConfiguration in project wso2-synapse by wso2.

the class APIDispatcherTest method testResponseDispatch.

public void testResponseDispatch() throws Exception {
    API api = new API(TEST_API, "/test");
    SynapseConfiguration synapseConfig = new SynapseConfiguration();
    synapseConfig.addAPI(TEST_API, api);
    RESTRequestHandler handler = new RESTRequestHandler();
    // Messages with '/test' context should ne dispatched
    MessageContext synCtx = getMessageContext(synapseConfig, false, "/test", "GET");
    synCtx.setResponse(true);
    assertFalse(handler.process(synCtx));
    synCtx.setProperty(RESTConstants.SYNAPSE_REST_API, TEST_API);
    assertTrue(handler.process(synCtx));
}
Also used : MessageContext(org.apache.synapse.MessageContext) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration)

Example 9 with SynapseConfiguration

use of org.apache.synapse.config.SynapseConfiguration in project wso2-synapse by wso2.

the class APIDispatcherTest method testAPIContextVersionBasedDispatchEndingWithVersion.

public void testAPIContextVersionBasedDispatchEndingWithVersion() throws Exception {
    API api = new API(TEST_API, "/test/{version}");
    api.setVersionStrategy(new ContextVersionStrategy(api, TEST_API_VERSION, null));
    SynapseConfiguration synapseConfig = new SynapseConfiguration();
    synapseConfig.addAPI(api.getName(), api);
    RESTRequestHandler handler = new RESTRequestHandler();
    // Messages with '/test' context should NOT be dispatched
    MessageContext synCtx = getMessageContext(synapseConfig, false, "/test/", "GET");
    handler.process(synCtx);
    assertNull(synCtx.getProperty(RESTConstants.SYNAPSE_REST_API));
    assertNull(synCtx.getProperty(RESTConstants.SYNAPSE_REST_API_VERSION));
    synCtx = getMessageContext(synapseConfig, false, "/test/1.0.0", "GET");
    handler.process(synCtx);
    assertEquals(api.getName(), synCtx.getProperty(RESTConstants.SYNAPSE_REST_API));
    assertEquals(TEST_API_VERSION, synCtx.getProperty(RESTConstants.SYNAPSE_REST_API_VERSION));
    synCtx = getMessageContext(synapseConfig, false, "/test/1.0.0/", "GET");
    handler.process(synCtx);
    assertEquals(api.getName(), synCtx.getProperty(RESTConstants.SYNAPSE_REST_API));
    assertEquals(TEST_API_VERSION, synCtx.getProperty(RESTConstants.SYNAPSE_REST_API_VERSION));
    synCtx = getMessageContext(synapseConfig, false, "/test/1.0.0/foo/bar?a=5", "GET");
    handler.process(synCtx);
    assertEquals(api.getName(), synCtx.getProperty(RESTConstants.SYNAPSE_REST_API));
    assertEquals(TEST_API_VERSION, synCtx.getProperty(RESTConstants.SYNAPSE_REST_API_VERSION));
    synCtx = getMessageContext(synapseConfig, false, "/test/1.0.0?a=5", "GET");
    handler.process(synCtx);
    assertEquals(api.getName(), synCtx.getProperty(RESTConstants.SYNAPSE_REST_API));
    assertEquals(TEST_API_VERSION, synCtx.getProperty(RESTConstants.SYNAPSE_REST_API_VERSION));
    // Message with '/test' context & URL as a Query Parameter should be dispatched
    synCtx = getMessageContext(synapseConfig, false, "/test/1.0.0?a=http://localhost.com", "GET");
    handler.process(synCtx);
    assertEquals(api.getName(), synCtx.getProperty(RESTConstants.SYNAPSE_REST_API));
    assertEquals(TEST_API_VERSION, synCtx.getProperty(RESTConstants.SYNAPSE_REST_API_VERSION));
    // Messages WITHOUT the '/test' context should NOT be dispatched
    synCtx = getMessageContext(synapseConfig, false, "/foo/test/bar?a=5", "GET");
    handler.process(synCtx);
    assertNull(synCtx.getProperty(RESTConstants.SYNAPSE_REST_API));
    assertNull(synCtx.getProperty(RESTConstants.SYNAPSE_REST_API_VERSION));
    // Messages WITHOUT the '/test' context and proper version should NOT be dispatched
    synCtx = getMessageContext(synapseConfig, false, "/test/1.0.1/foo/bar?a=5", "GET");
    handler.process(synCtx);
    assertNull(synCtx.getProperty(RESTConstants.SYNAPSE_REST_API));
    assertNull(synCtx.getProperty(RESTConstants.SYNAPSE_REST_API_VERSION));
    synCtx = getMessageContext(synapseConfig, false, "/test/2.0/foo/bar?a=5", "GET");
    handler.process(synCtx);
    assertNull(synCtx.getProperty(RESTConstants.SYNAPSE_REST_API));
    assertNull(synCtx.getProperty(RESTConstants.SYNAPSE_REST_API_VERSION));
    synCtx = getMessageContext(synapseConfig, false, "/test/2.0.0.0/foo/bar?a=5", "GET");
    handler.process(synCtx);
    assertNull(synCtx.getProperty(RESTConstants.SYNAPSE_REST_API));
    assertNull(synCtx.getProperty(RESTConstants.SYNAPSE_REST_API_VERSION));
}
Also used : ContextVersionStrategy(org.apache.synapse.rest.version.ContextVersionStrategy) MessageContext(org.apache.synapse.MessageContext) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration)

Example 10 with SynapseConfiguration

use of org.apache.synapse.config.SynapseConfiguration in project wso2-synapse by wso2.

the class APIDispatcherTest method testBasicAPIDispatch.

public void testBasicAPIDispatch() throws Exception {
    API api = new API(TEST_API, "/test");
    SynapseConfiguration synapseConfig = new SynapseConfiguration();
    synapseConfig.addAPI(TEST_API, api);
    RESTRequestHandler handler = new RESTRequestHandler();
    // Messages with '/test' context should be dispatched
    MessageContext synCtx = getMessageContext(synapseConfig, false, "/test", "GET");
    handler.process(synCtx);
    assertEquals(TEST_API, synCtx.getProperty(RESTConstants.SYNAPSE_REST_API));
    synCtx = getMessageContext(synapseConfig, false, "/test/", "GET");
    handler.process(synCtx);
    assertEquals(TEST_API, synCtx.getProperty(RESTConstants.SYNAPSE_REST_API));
    synCtx = getMessageContext(synapseConfig, false, "/test/foo/bar?a=5", "GET");
    handler.process(synCtx);
    assertEquals(TEST_API, synCtx.getProperty(RESTConstants.SYNAPSE_REST_API));
    synCtx = getMessageContext(synapseConfig, false, "/test?a=5", "GET");
    handler.process(synCtx);
    assertEquals(TEST_API, synCtx.getProperty(RESTConstants.SYNAPSE_REST_API));
    // Messages WITHOUT the '/test' context should NOT be dispatched
    synCtx = getMessageContext(synapseConfig, false, "/foo/test/bar?a=5", "GET");
    handler.process(synCtx);
    assertNull(synCtx.getProperty(RESTConstants.SYNAPSE_REST_API));
    synCtx = getMessageContext(synapseConfig, false, "/test1/bar?a=5", "GET");
    handler.process(synCtx);
    assertNull(synCtx.getProperty(RESTConstants.SYNAPSE_REST_API));
}
Also used : MessageContext(org.apache.synapse.MessageContext) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration)

Aggregations

SynapseConfiguration (org.apache.synapse.config.SynapseConfiguration)145 Axis2SynapseEnvironment (org.apache.synapse.core.axis2.Axis2SynapseEnvironment)64 AxisConfiguration (org.apache.axis2.engine.AxisConfiguration)59 MessageContext (org.apache.synapse.MessageContext)56 Test (org.junit.Test)56 ConfigurationContext (org.apache.axis2.context.ConfigurationContext)50 SynapseEnvironment (org.apache.synapse.core.SynapseEnvironment)49 OMElement (org.apache.axiom.om.OMElement)41 Parameter (org.apache.axis2.description.Parameter)29 Axis2MessageContext (org.apache.synapse.core.axis2.Axis2MessageContext)27 TestMessageContext (org.apache.synapse.TestMessageContext)16 Properties (java.util.Properties)15 SynapseException (org.apache.synapse.SynapseException)13 Mediator (org.apache.synapse.Mediator)12 AddressEndpoint (org.apache.synapse.endpoints.AddressEndpoint)11 File (java.io.File)10 ArrayList (java.util.ArrayList)10 HashMap (java.util.HashMap)9 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)7 Endpoint (org.apache.synapse.endpoints.Endpoint)7