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);
}
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));
}
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);
}
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"));
}
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"));
}
Aggregations