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 {
}
};
}
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));
}
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));
}
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));
}
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));
}
Aggregations