use of org.apache.synapse.core.SynapseEnvironment in project wso2-synapse by wso2.
the class TemplateDeployerTest method testUpdateForSequence.
/**
* Test updating an endpoint
*
* @throws Exception
*/
@Test
public void testUpdateForSequence() 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);
templateDeployer.deploySynapseArtifact(inputElement, "sampleFile", null);
String inputUpdateXML = "<template name = \"TestTemplateUpdated\" xmlns=\"http://ws.apache.org/ns/synapse\">" + " <sequence name=\"TestSequenceUpdated\" xmlns=\"http://ws.apache.org/ns/synapse\">" + " <log/>" + " </sequence>" + " </template>";
OMElement updatedElement = AXIOMUtil.stringToOM(inputUpdateXML);
String response = templateDeployer.updateSynapseArtifact(updatedElement, "sampleUpdateFile", "TestTemplate", null);
Assert.assertEquals("Sequence template not updated!", "TestTemplateUpdated", response);
}
use of org.apache.synapse.core.SynapseEnvironment in project wso2-synapse by wso2.
the class TemplateDeployerTest method testUpdateForEndpoint.
/**
* Test updating an endpoint
*
* @throws Exception
*/
@Test
public void testUpdateForEndpoint() 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);
String inputUpdateXML = "<template name = \"TestTemplateUpdated\" xmlns=\"http://ws.apache.org/ns/synapse\">" + " <endpoint name = \"sampleEP\" >" + " <address uri=\"http://localhost:9000/services/SimpleStockQuoteService\" >" + "</address>" + " </endpoint>" + " </template>";
OMElement updatedElement = AXIOMUtil.stringToOM(inputUpdateXML);
String response = templateDeployer.updateSynapseArtifact(updatedElement, "sampleUpdateFile", "TestTemplate", null);
Assert.assertEquals("Endpoint template not updated!", "TestTemplateUpdated", response);
}
use of org.apache.synapse.core.SynapseEnvironment in project wso2-synapse by wso2.
the class TemplateDeployerTest method testDeployForEndpoint.
/**
* Testing the deployment of an endpoint template
*
* @throws Exception
*/
@Test
public void testDeployForEndpoint() 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);
String response = templateDeployer.deploySynapseArtifact(inputElement, "sampleFile", null);
Assert.assertEquals("Endpoint template not deployed!", "TestTemplate", response);
}
use of org.apache.synapse.core.SynapseEnvironment in project wso2-synapse by wso2.
the class DynamicLoadBalanceEndpointTest method testSend.
/**
* Test sending a message to a load balance EP
*
* @throws AxisFault on an issue sending message to DynamicLoadBalanceEndpoint
*/
@Test
public void testSend() throws AxisFault {
DynamicLoadbalanceEndpoint dynamicLoadbalanceEndpoint = new DynamicLoadbalanceEndpoint();
SynapseEnvironment synapseEnvironment = getMockedSynapseEnvironment();
dynamicLoadbalanceEndpoint.init(synapseEnvironment);
MessageContext messageContext = createMessageContext();
// Mock a LoadBalanceMembershipHandler and set
LoadBalanceMembershipHandler loadBalanceMembershipHandler = PowerMockito.mock(LoadBalanceMembershipHandler.class);
Member member1 = new Member("localhost", 9000);
Mockito.when(loadBalanceMembershipHandler.getNextApplicationMember(any(AlgorithmContext.class))).thenReturn(member1);
dynamicLoadbalanceEndpoint.setLoadBalanceMembershipHandler(loadBalanceMembershipHandler);
// set mocked SynapseEnvironment to message context
((Axis2MessageContext) messageContext).getAxis2MessageContext().getConfigurationContext().getAxisConfiguration().addParameter(SynapseConstants.SYNAPSE_ENV, synapseEnvironment);
messageContext.setEnvironment(synapseEnvironment);
// send message
dynamicLoadbalanceEndpoint.send(messageContext);
Assert.assertNotNull("SynapseConstants.LAST_ENDPOINT should return a not null value", messageContext.getProperty(SynapseConstants.LAST_ENDPOINT));
}
use of org.apache.synapse.core.SynapseEnvironment in project wso2-synapse by wso2.
the class EndpointViewTest method createEndPointView.
/**
* Creates a basic EndpointView with a given number of children added to the endpoint.
*
* @param numberOfChildren the child endpoints inside the endpoint attached to the end point view. If
* specified as 0, the children list will be null
* @return the created end point view
*/
private EndpointView createEndPointView(int numberOfChildren) {
AbstractEndpoint endpoint = new AddressEndpoint();
MessageContext synCtx = new TestMessageContext();
synCtx.setConfiguration(new SynapseConfiguration());
SynapseEnvironment environment = new Axis2SynapseEnvironment(new ConfigurationContext(new AxisConfiguration()), synCtx.getConfiguration());
if (numberOfChildren > 0) {
List<Endpoint> children = new ArrayList<>(numberOfChildren);
for (int i = 0; i < numberOfChildren; i++) {
AbstractEndpoint child = new AddressEndpoint();
child.init(environment);
child.setEnableMBeanStats(true);
child.setName("endpoint" + i);
children.add(child);
}
endpoint.setChildren(children);
}
endpoint.init(environment);
return new EndpointView("endpoint", endpoint);
}
Aggregations