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);
}
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);
}
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"));
}
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}&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}&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&user=john@Günter", messageContext.getTo().getAddress().toString());
}
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));
}
Aggregations