use of org.apache.synapse.config.SynapseConfiguration in project wso2-synapse by wso2.
the class URITemplateBasedDispatcherTest method testBasicTemplateDispatch2.
public void testBasicTemplateDispatch2() throws Exception {
API api = new API("TestAPI", "/");
Resource resource = new Resource();
resource.setDispatcherHelper(new URITemplateHelper("/dictionary/{char}/{word}"));
resource.setInSequence(getTestSequence(PROP_NAME, PROP_VALUE));
api.addResource(resource);
SynapseConfiguration synapseConfig = new SynapseConfiguration();
synapseConfig.addAPI(api.getName(), api);
RESTRequestHandler handler = new RESTRequestHandler();
MessageContext synCtx = getMessageContext(synapseConfig, false, "/dictionary/c/cat", "GET");
handler.process(synCtx);
assertEquals(PROP_VALUE, synCtx.getProperty(PROP_NAME));
assertEquals("c", synCtx.getProperty(RESTConstants.REST_URI_VARIABLE_PREFIX + "char"));
assertEquals("cat", synCtx.getProperty(RESTConstants.REST_URI_VARIABLE_PREFIX + "word"));
synCtx = getMessageContext(synapseConfig, false, "/dictionary/d/dog/", "GET");
handler.process(synCtx);
assertEquals(PROP_VALUE, synCtx.getProperty(PROP_NAME));
assertEquals("d", synCtx.getProperty(RESTConstants.REST_URI_VARIABLE_PREFIX + "char"));
assertEquals("dog", synCtx.getProperty(RESTConstants.REST_URI_VARIABLE_PREFIX + "word"));
synCtx = getMessageContext(synapseConfig, false, "/test/c/cat", "GET");
handler.process(synCtx);
assertNull(synCtx.getProperty(PROP_NAME));
synCtx = getMessageContext(synapseConfig, false, "/dictionary/c", "GET");
handler.process(synCtx);
assertNull(synCtx.getProperty(PROP_NAME));
/* With ESBJAVA-4260 we now support optional query parameters for URITemplates */
synCtx = getMessageContext(synapseConfig, false, "/dictionary/c/cat?a=5", "GET");
handler.process(synCtx);
assertEquals(PROP_VALUE, synCtx.getProperty(PROP_NAME));
assertEquals("c", synCtx.getProperty(RESTConstants.REST_URI_VARIABLE_PREFIX + "char"));
assertEquals("cat", synCtx.getProperty(RESTConstants.REST_URI_VARIABLE_PREFIX + "word"));
}
use of org.apache.synapse.config.SynapseConfiguration in project wso2-synapse by wso2.
the class POJOCommandMediatorTest method testPojoWithPropertiesCommandImpl.
public void testPojoWithPropertiesCommandImpl() throws Exception {
Mediator pcm = MediatorFactoryFinder.getInstance().getMediator(createOMElement("<pojoCommand name='org.apache.synapse.mediators.ext.POJOCommandTestImplementedMediator' " + "xmlns='http://ws.apache.org/ns/synapse'><property name=\"testProp\" " + "expression=\"fn:concat('XPATH ', 'FUNC')\" action=\"ReadMessage\"/></pojoCommand>"), new Properties());
POJOCommandTestHelper.reset();
TestMessageContext msgContext = new TestMessageContext();
msgContext.setEnvironment(new Axis2SynapseEnvironment(new SynapseConfiguration()));
pcm.mediate(msgContext);
assertEquals("XPATH FUNC", POJOCommandTestHelper.getInstance().getChangedProperty());
assertTrue(POJOCommandTestHelper.getInstance().isExecuted());
}
use of org.apache.synapse.config.SynapseConfiguration in project wso2-synapse by wso2.
the class POJOCommandMediatorTest method testPojoWithoutPropertiesCommandImpl.
public void testPojoWithoutPropertiesCommandImpl() throws Exception {
Mediator pcm = MediatorFactoryFinder.getInstance().getMediator(createOMElement("<pojoCommand name='org.apache.synapse.mediators.ext.POJOCommandTestImplementedMediator' " + "xmlns='http://ws.apache.org/ns/synapse'/>"), new Properties());
POJOCommandTestHelper.reset();
TestMessageContext msgContext = new TestMessageContext();
msgContext.setEnvironment(new Axis2SynapseEnvironment(new SynapseConfiguration()));
pcm.mediate(msgContext);
assertTrue(POJOCommandTestHelper.getInstance().isExecuted());
}
use of org.apache.synapse.config.SynapseConfiguration in project wso2-synapse by wso2.
the class POJOCommandMediatorTest method testPojoWithoutPropertiesNotCommandImpl.
public void testPojoWithoutPropertiesNotCommandImpl() throws Exception {
Mediator pcm = MediatorFactoryFinder.getInstance().getMediator(createOMElement("<pojoCommand name='org.apache.synapse.mediators.ext.POJOCommandTestMediator' " + "xmlns='http://ws.apache.org/ns/synapse'/>"), new Properties());
POJOCommandTestHelper.reset();
TestMessageContext msgContext = new TestMessageContext();
msgContext.setEnvironment(new Axis2SynapseEnvironment(new SynapseConfiguration()));
pcm.mediate(msgContext);
assertTrue(POJOCommandTestHelper.getInstance().isExecuted());
}
use of org.apache.synapse.config.SynapseConfiguration in project wso2-synapse by wso2.
the class POJOCommandMediatorTest method testPojoWithStaticPropertiesCommandImpl.
public void testPojoWithStaticPropertiesCommandImpl() throws Exception {
Mediator pcm = MediatorFactoryFinder.getInstance().getMediator(createOMElement("<pojoCommand name='org.apache.synapse.mediators.ext.POJOCommandTestImplementedMediator' " + "xmlns='http://ws.apache.org/ns/synapse'><property name=\"testProp\" " + "value=\"Test Property\"/></pojoCommand>"), new Properties());
POJOCommandTestHelper.reset();
TestMessageContext msgContext = new TestMessageContext();
msgContext.setEnvironment(new Axis2SynapseEnvironment(new SynapseConfiguration()));
pcm.mediate(msgContext);
assertEquals("Test Property", POJOCommandTestHelper.getInstance().getChangedProperty());
assertTrue(POJOCommandTestHelper.getInstance().isExecuted());
}
Aggregations