Search in sources :

Example 16 with SynapseConfiguration

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"));
}
Also used : URITemplateHelper(org.apache.synapse.rest.dispatch.URITemplateHelper) MessageContext(org.apache.synapse.MessageContext) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration)

Example 17 with SynapseConfiguration

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());
}
Also used : Axis2SynapseEnvironment(org.apache.synapse.core.axis2.Axis2SynapseEnvironment) TestMessageContext(org.apache.synapse.TestMessageContext) Mediator(org.apache.synapse.Mediator) Properties(java.util.Properties) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration)

Example 18 with SynapseConfiguration

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());
}
Also used : Axis2SynapseEnvironment(org.apache.synapse.core.axis2.Axis2SynapseEnvironment) TestMessageContext(org.apache.synapse.TestMessageContext) Mediator(org.apache.synapse.Mediator) Properties(java.util.Properties) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration)

Example 19 with SynapseConfiguration

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());
}
Also used : Axis2SynapseEnvironment(org.apache.synapse.core.axis2.Axis2SynapseEnvironment) TestMessageContext(org.apache.synapse.TestMessageContext) Mediator(org.apache.synapse.Mediator) Properties(java.util.Properties) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration)

Example 20 with SynapseConfiguration

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());
}
Also used : Axis2SynapseEnvironment(org.apache.synapse.core.axis2.Axis2SynapseEnvironment) TestMessageContext(org.apache.synapse.TestMessageContext) Mediator(org.apache.synapse.Mediator) Properties(java.util.Properties) 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