Search in sources :

Example 46 with SynapseEnvironment

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

the class ProxyServiceTest method testStart.

/**
 * Tests starting a proxy service with correct axis configuration provided.
 *
 * @throws Exception if an exception occurs while configuring the axis configuration
 */
public void testStart() throws Exception {
    String proxyServiceName = "TestStartProxy";
    SynapseConfiguration synCfg = new SynapseConfiguration();
    AxisConfiguration axisCfg = new AxisConfiguration();
    SynapseEnvironment synEnv = new Axis2SynapseEnvironment(new ConfigurationContext(axisCfg), synCfg);
    axisCfg.addParameter(SynapseConstants.SYNAPSE_ENV, synEnv);
    synCfg.setAxisConfiguration(axisCfg);
    ProxyService proxyService = new ProxyService(proxyServiceName);
    AxisService axisServiceForActivation = new AxisService();
    axisServiceForActivation.setName(proxyServiceName);
    axisCfg.addToAllServicesMap(axisServiceForActivation);
    proxyService.setTargetInLineInSequence(new SequenceMediator());
    proxyService.setTargetInLineOutSequence(new SequenceMediator());
    proxyService.setTargetInLineFaultSequence(new SequenceMediator());
    proxyService.start(synCfg);
    Assert.assertTrue("Underlying Axis service is not activated", axisServiceForActivation.isActive());
    Assert.assertTrue("Proxy service is not running", proxyService.isRunning());
    proxyService.stop(synCfg);
}
Also used : AxisConfiguration(org.apache.axis2.engine.AxisConfiguration) ConfigurationContext(org.apache.axis2.context.ConfigurationContext) SynapseEnvironment(org.apache.synapse.core.SynapseEnvironment) AxisService(org.apache.axis2.description.AxisService) SequenceMediator(org.apache.synapse.mediators.base.SequenceMediator) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration)

Example 47 with SynapseEnvironment

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

the class ProxyServiceTest method testBuildAxisServiceWithPinnedServers.

/**
 * Configures pinned servers for the proxy server and asserts if the proxy gets built correctly with and without
 * correct pinned servers.
 *
 * @throws Exception is an error occurs while adding the synapse environment to the axis configuration
 */
public void testBuildAxisServiceWithPinnedServers() throws Exception {
    String pinnedServer = "localhost";
    SynapseConfiguration synCfg = new SynapseConfiguration();
    AxisConfiguration axisCfg = new AxisConfiguration();
    ServerConfigurationInformation serverConfigurationInformation = Mockito.mock(ServerConfigurationInformation.class);
    ServerContextInformation serverContextInformation = new ServerContextInformation(serverConfigurationInformation);
    SynapseEnvironment synEnv = new Axis2SynapseEnvironment(new ConfigurationContext(axisCfg), synCfg, serverContextInformation);
    axisCfg.addParameter(SynapseConstants.SYNAPSE_ENV, synEnv);
    ProxyService proxyService = new ProxyService("testBuildAxisServiceWithPinnedServersProxy");
    List<String> pinnedServersList = new ArrayList<>();
    pinnedServersList.add(pinnedServer);
    proxyService.setPinnedServers(pinnedServersList);
    // Tests with incorrect pinned servers
    Mockito.when(synEnv.getServerContextInformation().getServerConfigurationInformation().getServerName()).thenReturn("10.10.10.1");
    AxisService axisService = proxyService.buildAxisService(synCfg, axisCfg);
    Assert.assertNull("Axis service built with incorrect pinned servers should be null", axisService);
    // Asserts with correct pinned servers
    Mockito.when(synEnv.getServerContextInformation().getServerConfigurationInformation().getServerName()).thenReturn(pinnedServer);
    Assert.assertNotNull("Axis service should be built with correct pinned servers", proxyService.buildAxisService(synCfg, axisCfg));
}
Also used : AxisConfiguration(org.apache.axis2.engine.AxisConfiguration) ConfigurationContext(org.apache.axis2.context.ConfigurationContext) ServerContextInformation(org.apache.synapse.ServerContextInformation) SynapseEnvironment(org.apache.synapse.core.SynapseEnvironment) AxisService(org.apache.axis2.description.AxisService) ArrayList(java.util.ArrayList) ServerConfigurationInformation(org.apache.synapse.ServerConfigurationInformation) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration)

Example 48 with SynapseEnvironment

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

the class APIDeployerTest method testDeploy.

/**
 * Testing the deployment of an API
 *
 * @throws Exception
 */
@Test
public void testDeploy() throws Exception {
    String inputXML = "<api name=\"TestAPI\" context=\"/order\" xmlns=\"http://ws.apache.org/ns/synapse\">" + "<resource url-mapping=\"/list\" inSequence=\"seq1\" outSequence=\"seq2\" xmlns=\"http://ws.apache.org/ns/synapse\"/>" + "</api>";
    OMElement inputElement = AXIOMUtil.stringToOM(inputXML);
    APIDeployer apiDeployer = new APIDeployer();
    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);
    apiDeployer.init(cfgCtx);
    String response = apiDeployer.deploySynapseArtifact(inputElement, "sampleFile", null);
    Assert.assertEquals("API not deployed!", "TestAPI", 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 49 with SynapseEnvironment

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

the class APIDeployerTest method testUndeploy.

/**
 * Test undeploying an API
 *
 * @throws Exception
 */
@Test
public void testUndeploy() throws Exception {
    String inputXML = "<api name=\"TestAPI\" context=\"/order\" xmlns=\"http://ws.apache.org/ns/synapse\">" + "<resource url-mapping=\"/list\" inSequence=\"seq1\" outSequence=\"seq2\" xmlns=\"http://ws.apache.org/ns/synapse\"/>" + "</api>";
    OMElement inputElement = AXIOMUtil.stringToOM(inputXML);
    APIDeployer apiDeployer = new APIDeployer();
    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);
    apiDeployer.init(cfgCtx);
    apiDeployer.deploySynapseArtifact(inputElement, "sampleFile", null);
    Assert.assertNotNull("API not deployed!", synapseConfiguration.getAPI("TestAPI"));
    apiDeployer.undeploySynapseArtifact("TestAPI");
    Assert.assertNull("Api cannot be undeployed!", synapseConfiguration.getAPI("TestAPI"));
}
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 50 with SynapseEnvironment

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

the class EndpointDeployerTest method testUndeploy.

/**
 * Test undeploying an endpoint
 *
 * @throws Exception
 */
@Test
public void testUndeploy() throws Exception {
    String inputXML = "<endpoint name = \"sampleEP\" xmlns=\"http://ws.apache.org/ns/synapse\">" + "<address uri=\"http://localhost:9000/services/SimpleStockQuoteService\" >" + "</address>" + "</endpoint>";
    OMElement inputElement = AXIOMUtil.stringToOM(inputXML);
    EndpointDeployer endpointDeployer = new EndpointDeployer();
    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);
    endpointDeployer.init(cfgCtx);
    endpointDeployer.deploySynapseArtifact(inputElement, "sampleFile", null);
    Assert.assertNotNull("Endpoint not deployed!", synapseConfiguration.getEndpoint("sampleEP"));
    endpointDeployer.undeploySynapseArtifact("sampleEP");
    Assert.assertNull("Endpoint cannot be undeployed", synapseConfiguration.getEndpoint("sampleEP"));
}
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)

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