Search in sources :

Example 61 with SynapseEnvironment

use of org.apache.synapse.core.SynapseEnvironment in project wso2-synapse by wso2.

the class SequenceDeployerTest method testDeploy.

/**
 * Testing the deployment of a sequence
 *
 * @throws Exception
 */
@Test
public void testDeploy() throws Exception {
    String inputXML = "<sequence name=\"TestSequence\" xmlns=\"http://ws.apache.org/ns/synapse\">" + "             <log/>" + "         </sequence>";
    OMElement inputElement = AXIOMUtil.stringToOM(inputXML);
    SequenceDeployer sequenceDeployer = new SequenceDeployer();
    SynapseConfiguration synapseConfiguration = new SynapseConfiguration();
    AxisConfiguration axisConfiguration = synapseConfiguration.getAxisConfiguration();
    ConfigurationContext cfgCtx = new ConfigurationContext(axisConfiguration);
    SynapseEnvironment synapseEnvironment = new Axis2SynapseEnvironment(cfgCtx, synapseConfiguration);
    axisConfiguration.addParameter(new Parameter(SynapseConstants.SYNAPSE_ENV, synapseEnvironment));
    axisConfiguration.addParameter(new Parameter(SynapseConstants.SYNAPSE_CONFIG, synapseConfiguration));
    cfgCtx.setAxisConfiguration(axisConfiguration);
    sequenceDeployer.init(cfgCtx);
    String response = sequenceDeployer.deploySynapseArtifact(inputElement, "sampleFile", null);
    Assert.assertEquals("Sequence not deployed!", "TestSequence", response);
}
Also used : AxisConfiguration(org.apache.axis2.engine.AxisConfiguration) ConfigurationContext(org.apache.axis2.context.ConfigurationContext) Axis2SynapseEnvironment(org.apache.synapse.core.axis2.Axis2SynapseEnvironment) SynapseEnvironment(org.apache.synapse.core.SynapseEnvironment) Axis2SynapseEnvironment(org.apache.synapse.core.axis2.Axis2SynapseEnvironment) Parameter(org.apache.axis2.description.Parameter) OMElement(org.apache.axiom.om.OMElement) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration) Test(org.junit.Test)

Example 62 with SynapseEnvironment

use of org.apache.synapse.core.SynapseEnvironment in project wso2-synapse by wso2.

the class TemplateDeployerTest method testDeployForSequence.

/**
 * Testing the deployment of a sequence template
 *
 * @throws Exception
 */
@Test
public void testDeployForSequence() throws Exception {
    String inputXML = "<template name = \"TestTemplate\" xmlns=\"http://ws.apache.org/ns/synapse\">" + "              <sequence name=\"TestSequenceUpdated\" xmlns=\"http://ws.apache.org/ns/synapse\">" + "                  <log/>" + "              </sequence>" + "          </template>";
    OMElement inputElement = AXIOMUtil.stringToOM(inputXML);
    TemplateDeployer templateDeployer = new TemplateDeployer();
    SynapseConfiguration synapseConfiguration = new SynapseConfiguration();
    AxisConfiguration axisConfiguration = synapseConfiguration.getAxisConfiguration();
    ConfigurationContext cfgCtx = new ConfigurationContext(axisConfiguration);
    SynapseEnvironment synapseEnvironment = new Axis2SynapseEnvironment(cfgCtx, synapseConfiguration);
    axisConfiguration.addParameter(new Parameter(SynapseConstants.SYNAPSE_ENV, synapseEnvironment));
    axisConfiguration.addParameter(new Parameter(SynapseConstants.SYNAPSE_CONFIG, synapseConfiguration));
    cfgCtx.setAxisConfiguration(axisConfiguration);
    templateDeployer.init(cfgCtx);
    String response = templateDeployer.deploySynapseArtifact(inputElement, "sampleFile", null);
    Assert.assertEquals("Sequence template not deployed!", "TestTemplate", response);
}
Also used : AxisConfiguration(org.apache.axis2.engine.AxisConfiguration) ConfigurationContext(org.apache.axis2.context.ConfigurationContext) Axis2SynapseEnvironment(org.apache.synapse.core.axis2.Axis2SynapseEnvironment) SynapseEnvironment(org.apache.synapse.core.SynapseEnvironment) Axis2SynapseEnvironment(org.apache.synapse.core.axis2.Axis2SynapseEnvironment) Parameter(org.apache.axis2.description.Parameter) OMElement(org.apache.axiom.om.OMElement) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration) Test(org.junit.Test)

Example 63 with SynapseEnvironment

use of org.apache.synapse.core.SynapseEnvironment in project wso2-synapse by wso2.

the class TemplateDeployerTest method testUndeploy.

/**
 * Test undeploying an endpoint
 *
 * @throws Exception
 */
@Test
public void testUndeploy() throws Exception {
    String inputXML = "<template name = \"TestTemplate\" xmlns=\"http://ws.apache.org/ns/synapse\">" + "              <endpoint name = \"sampleEP\" >" + "                  <address uri=\"http://localhost:9000/services/SimpleStockQuoteService\" >" + "</address>" + "              </endpoint>" + "          </template>";
    OMElement inputElement = AXIOMUtil.stringToOM(inputXML);
    TemplateDeployer templateDeployer = new TemplateDeployer();
    SynapseConfiguration synapseConfiguration = new SynapseConfiguration();
    AxisConfiguration axisConfiguration = synapseConfiguration.getAxisConfiguration();
    ConfigurationContext cfgCtx = new ConfigurationContext(axisConfiguration);
    SynapseEnvironment synapseEnvironment = new Axis2SynapseEnvironment(cfgCtx, synapseConfiguration);
    axisConfiguration.addParameter(new Parameter(SynapseConstants.SYNAPSE_ENV, synapseEnvironment));
    axisConfiguration.addParameter(new Parameter(SynapseConstants.SYNAPSE_CONFIG, synapseConfiguration));
    cfgCtx.setAxisConfiguration(axisConfiguration);
    templateDeployer.init(cfgCtx);
    templateDeployer.deploySynapseArtifact(inputElement, "sampleFile", null);
    Assert.assertNotNull("Endpoint template not deployed!", synapseConfiguration.getEndpointTemplate("TestTemplate"));
    templateDeployer.undeploySynapseArtifact("TestTemplate");
    Assert.assertNull("Endpoint template cannot be undeployed", synapseConfiguration.getEndpointTemplate("TestTemplate"));
}
Also used : AxisConfiguration(org.apache.axis2.engine.AxisConfiguration) ConfigurationContext(org.apache.axis2.context.ConfigurationContext) Axis2SynapseEnvironment(org.apache.synapse.core.axis2.Axis2SynapseEnvironment) SynapseEnvironment(org.apache.synapse.core.SynapseEnvironment) Axis2SynapseEnvironment(org.apache.synapse.core.axis2.Axis2SynapseEnvironment) Parameter(org.apache.axis2.description.Parameter) OMElement(org.apache.axiom.om.OMElement) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration) Test(org.junit.Test)

Example 64 with SynapseEnvironment

use of org.apache.synapse.core.SynapseEnvironment in project wso2-synapse by wso2.

the class HttpEndpointTest method testQueryParamsWithLegacyEncoding.

/**
 * Test usage of legacy-encoding property where encoded values will be decoded
 * @throws AxisFault
 * @throws XMLStreamException
 */
@Test
public void testQueryParamsWithLegacyEncoding() throws AxisFault, XMLStreamException {
    HTTPEndpointFactory factory = new HTTPEndpointFactory();
    OMElement em = AXIOMUtil.stringToOM("<endpoint><http method=\"GET\" uri-template=\"http://abc.com?symbol={query.param.symbol}&amp;user={query.param.user}\"/></endpoint>");
    EndpointDefinition ep1 = factory.createEndpointDefinition(em);
    HTTPEndpoint httpEndpoint = new HTTPEndpoint();
    httpEndpoint.setHttpMethod("GET");
    httpEndpoint.setLegacySupport(true);
    httpEndpoint.setDefinition(ep1);
    httpEndpoint.setUriTemplate(UriTemplate.fromTemplate("http://abc.com?symbol={query.param.symbol}&amp;user={query.param.user}"));
    SynapseEnvironment synapseEnvironment = getMockedSynapseEnvironment();
    httpEndpoint.init(getMockedSynapseEnvironment());
    MessageContext messageContext = createMessageContext();
    messageContext.setProperty("query.param.symbol", "US%3A123");
    messageContext.setProperty("query.param.user", "john%40G%C3%BCnter");
    // set mocked SynapseEnvironment to message context
    ((Axis2MessageContext) messageContext).getAxis2MessageContext().getConfigurationContext().getAxisConfiguration().addParameter(SynapseConstants.SYNAPSE_ENV, synapseEnvironment);
    messageContext.setEnvironment(synapseEnvironment);
    httpEndpoint.executeEpTypeSpecificFunctions(messageContext);
    Assert.assertEquals("With legacy encoding encoded characters need to be decoded", "http://abc.com?symbol=US:123&amp;user=john@Günter", messageContext.getTo().getAddress().toString());
}
Also used : HTTPEndpointFactory(org.apache.synapse.config.xml.endpoints.HTTPEndpointFactory) Axis2SynapseEnvironment(org.apache.synapse.core.axis2.Axis2SynapseEnvironment) SynapseEnvironment(org.apache.synapse.core.SynapseEnvironment) OMElement(org.apache.axiom.om.OMElement) MessageContext(org.apache.synapse.MessageContext) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext) Test(org.junit.Test)

Example 65 with SynapseEnvironment

use of org.apache.synapse.core.SynapseEnvironment in project wso2-synapse by wso2.

the class EventPublisherMediatorTest method testMediate.

/**
 * Testing eventPublisherMediator with mocked event source.
 */
@Test
public void testMediate() {
    final String EventSourceName = "testEventStore";
    SynapseEnvironment synapseEnvironment = Mockito.mock(SynapseEnvironment.class);
    MessageContext messageContext = new TestMessageContext();
    messageContext.setEnvironment(synapseEnvironment);
    SynapseConfiguration synapseConfiguration = new SynapseConfiguration();
    SynapseEventSource synapseEventSource = Mockito.mock(SynapseEventSource.class);
    Mockito.doNothing().when(synapseEventSource).dispatchEvents(Mockito.any(MessageContext.class));
    Map<String, SynapseEventSource> eventStoreMap = new HashMap<>();
    eventStoreMap.put(EventSourceName, synapseEventSource);
    synapseConfiguration.setEventSources(eventStoreMap);
    messageContext.setConfiguration(synapseConfiguration);
    eventPublisherMediator.setEventSourceName(EventSourceName);
    Assert.assertTrue("mediation successful", eventPublisherMediator.mediate(messageContext));
}
Also used : TestMessageContext(org.apache.synapse.TestMessageContext) SynapseEventSource(org.apache.synapse.eventing.SynapseEventSource) HashMap(java.util.HashMap) SynapseEnvironment(org.apache.synapse.core.SynapseEnvironment) TestMessageContext(org.apache.synapse.TestMessageContext) MessageContext(org.apache.synapse.MessageContext) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration) Test(org.junit.Test)

Aggregations

SynapseEnvironment (org.apache.synapse.core.SynapseEnvironment)67 Axis2SynapseEnvironment (org.apache.synapse.core.axis2.Axis2SynapseEnvironment)50 SynapseConfiguration (org.apache.synapse.config.SynapseConfiguration)49 AxisConfiguration (org.apache.axis2.engine.AxisConfiguration)44 ConfigurationContext (org.apache.axis2.context.ConfigurationContext)43 Test (org.junit.Test)40 OMElement (org.apache.axiom.om.OMElement)35 Parameter (org.apache.axis2.description.Parameter)29 MessageContext (org.apache.synapse.MessageContext)18 Axis2MessageContext (org.apache.synapse.core.axis2.Axis2MessageContext)18 ArrayList (java.util.ArrayList)8 AddressEndpoint (org.apache.synapse.endpoints.AddressEndpoint)8 Endpoint (org.apache.synapse.endpoints.Endpoint)8 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)6 HashMap (java.util.HashMap)5 OMDocument (org.apache.axiom.om.OMDocument)4 SynapseException (org.apache.synapse.SynapseException)4 TestMessageContext (org.apache.synapse.TestMessageContext)4 IOException (java.io.IOException)3 ManagedLifecycle (org.apache.synapse.ManagedLifecycle)3