use of org.apache.synapse.rest.version.DefaultStrategy in project wso2-synapse by wso2.
the class APIDispatcherTest method testAPIDefaultVersionBasedDispatch.
public void testAPIDefaultVersionBasedDispatch() throws Exception {
API api = new API(TEST_API, "/test");
api.setVersionStrategy(new DefaultStrategy(api));
SynapseConfiguration synapseConfig = new SynapseConfiguration();
synapseConfig.addAPI(api.getName(), api);
RESTRequestHandler handler = new RESTRequestHandler();
// Messages with '/test' context should ne dispatched
MessageContext synCtx = getMessageContext(synapseConfig, false, "/test", "GET");
handler.process(synCtx);
assertEquals(TEST_API, synCtx.getProperty(RESTConstants.SYNAPSE_REST_API));
assertEquals("", synCtx.getProperty(RESTConstants.SYNAPSE_REST_API_VERSION));
synCtx = getMessageContext(synapseConfig, false, "/test/", "GET");
handler.process(synCtx);
assertEquals(TEST_API, synCtx.getProperty(RESTConstants.SYNAPSE_REST_API));
assertEquals("", synCtx.getProperty(RESTConstants.SYNAPSE_REST_API_VERSION));
synCtx = getMessageContext(synapseConfig, false, "/test/foo/bar?a=5", "GET");
handler.process(synCtx);
assertEquals(TEST_API, synCtx.getProperty(RESTConstants.SYNAPSE_REST_API));
assertEquals("", synCtx.getProperty(RESTConstants.SYNAPSE_REST_API_VERSION));
synCtx = getMessageContext(synapseConfig, false, "/test?a=5", "GET");
handler.process(synCtx);
assertEquals(TEST_API, synCtx.getProperty(RESTConstants.SYNAPSE_REST_API));
assertEquals("", 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));
synCtx = getMessageContext(synapseConfig, false, "/test1/bar?a=5", "GET");
handler.process(synCtx);
assertNull(synCtx.getProperty(RESTConstants.SYNAPSE_REST_API));
assertNull(synCtx.getProperty(RESTConstants.SYNAPSE_REST_API_VERSION));
}
Aggregations