use of org.apache.synapse.TestMessageContext in project wso2-synapse by wso2.
the class ClassMediatorTest method testInitializationAndMedition.
public void testInitializationAndMedition() throws Exception {
Mediator cm = MediatorFactoryFinder.getInstance().getMediator(createOMElement("<class name='org.apache.synapse.mediators.ext.ClassMediatorTestMediator' " + "xmlns='http://ws.apache.org/ns/synapse'/>"), new Properties());
((ManagedLifecycle) cm).init(new Axis2SynapseEnvironment(new SynapseConfiguration()));
assertTrue(ClassMediatorTestMediator.initialized);
TestMessageContext msgContext = new TestMessageContext();
msgContext.setEnvironment(new Axis2SynapseEnvironment(new SynapseConfiguration()));
cm.mediate(msgContext);
assertTrue(ClassMediatorTestMediator.invoked);
}
use of org.apache.synapse.TestMessageContext in project wso2-synapse by wso2.
the class ClassMediatorTest method testMediationWithLiteralProperties.
public void testMediationWithLiteralProperties() throws Exception {
Mediator cm = MediatorFactoryFinder.getInstance().getMediator(createOMElement("<class name='org.apache.synapse.mediators.ext.ClassMediatorTestMediator' " + "xmlns='http://ws.apache.org/ns/synapse'><property name='testProp' value='testValue'/></class>"), new Properties());
TestMessageContext msgContext = new TestMessageContext();
msgContext.setEnvironment(new Axis2SynapseEnvironment(new SynapseConfiguration()));
cm.mediate(msgContext);
assertTrue(ClassMediatorTestMediator.invoked);
assertTrue(ClassMediatorTestMediator.testProp.equals("testValue"));
}
use of org.apache.synapse.TestMessageContext in project wso2-synapse by wso2.
the class ProxyServiceTest method testBuildAxisServiceWithUnreachableWsdlEndpointWithPublishWSDLSafeModeEnabled.
/**
* Tests building a proxy service with an unreachable endpoint specified as the published wsdl url with the
* 'enablePublishWSDLSafeMode' set to false.
*
* @throws Exception if an error occurs when converting the URI string to a URI
*/
public void testBuildAxisServiceWithUnreachableWsdlEndpointWithPublishWSDLSafeModeEnabled() throws Exception {
MessageContext synCtx = new TestMessageContext();
SynapseConfiguration synCfg = new SynapseConfiguration();
synCtx.setConfiguration(synCfg);
AxisConfiguration axisCfg = new AxisConfiguration();
ProxyService proxyService = new ProxyService("faultyPublishWsdlEndpointProxyWithPublishWSDLSafeModeEnabled");
proxyService.setPublishWSDLEndpoint("wsdlEndPoint");
AddressEndpoint wsdlEndpoint = new AddressEndpoint();
EndpointDefinition endpointDefinition = new EndpointDefinition();
endpointDefinition.setAddress((new URI("http://localhost/SimpleStockService.wsdl")).toString());
wsdlEndpoint.setDefinition(endpointDefinition);
proxyService.addParameter("enablePublishWSDLSafeMode", true);
synCfg.addEndpoint("wsdlEndPoint", wsdlEndpoint);
Assert.assertNull("Axis service built with an unreachable wsdl endpoint be null", proxyService.buildAxisService(synCfg, axisCfg));
}
use of org.apache.synapse.TestMessageContext in project wso2-synapse by wso2.
the class ProxyServiceTest method testRegisterFaultHandler.
/**
* Tests if the correct fault handler is set when a fault handler is not explicitly set, and when set by using
* targetFaultSequence and targetInlineFaultSequence properties of the proxy.
*/
public void testRegisterFaultHandler() {
ProxyService proxyService = new ProxyService("TestRegisterFaultHandlerProxy");
MessageContext messageContext = new TestMessageContext();
SynapseConfiguration synCfg = new SynapseConfiguration();
messageContext.setConfiguration(synCfg);
SequenceMediator faultMediator = new SequenceMediator();
synCfg.addSequence("fault", faultMediator);
// test if the default fault proxy set in the message context is returned when a fault sequence is not
// explicitly set
faultMediator.setName("defaultFault");
proxyService.registerFaultHandler(messageContext);
String faultMediatorName = ((SequenceMediator) ((MediatorFaultHandler) messageContext.getFaultStack().pop()).getFaultMediator()).getName();
Assert.assertEquals("Incorrect fault handler set: " + faultMediatorName, "defaultFault", faultMediatorName);
// tests the functionality when the fault sequence is set in line in the target
faultMediator.setName("targetInLineFaultSequenceMediator");
proxyService.setTargetInLineFaultSequence(faultMediator);
proxyService.registerFaultHandler(messageContext);
faultMediatorName = ((SequenceMediator) ((MediatorFaultHandler) messageContext.getFaultStack().pop()).getFaultMediator()).getName();
Assert.assertEquals("Incorrect fault handler set: " + faultMediatorName, "targetInLineFaultSequenceMediator", faultMediatorName);
// tests the functionality when the fault sequence is set separately in the target
AxisConfiguration axisCfg = new AxisConfiguration();
SynapseEnvironment synEnv = new Axis2SynapseEnvironment(new ConfigurationContext(axisCfg), synCfg);
messageContext.setEnvironment(synEnv);
proxyService.setTargetFaultSequence("targetFaultSequence");
// when the message context does not have the correct fault sequence specified as the target fault sequence
faultMediator.setName("defaultFaultMediator");
proxyService.registerFaultHandler(messageContext);
faultMediatorName = ((SequenceMediator) ((MediatorFaultHandler) messageContext.getFaultStack().pop()).getFaultMediator()).getName();
Assert.assertEquals("Incorrect fault handler set: " + faultMediatorName, "defaultFaultMediator", faultMediatorName);
// when the message context has the correct fault sequence specified as the target fault sequence
faultMediator.setName("targetFaultSequenceMediator");
synCfg.addSequence("targetFaultSequence", faultMediator);
proxyService.registerFaultHandler(messageContext);
faultMediatorName = ((SequenceMediator) ((MediatorFaultHandler) messageContext.getFaultStack().pop()).getFaultMediator()).getName();
Assert.assertEquals("Incorrect fault handler set: " + faultMediatorName, "targetFaultSequenceMediator", faultMediatorName);
}
use of org.apache.synapse.TestMessageContext 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