Search in sources :

Example 6 with TestMessageContext

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);
}
Also used : Axis2SynapseEnvironment(org.apache.synapse.core.axis2.Axis2SynapseEnvironment) TestMessageContext(org.apache.synapse.TestMessageContext) Mediator(org.apache.synapse.Mediator) Properties(java.util.Properties) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration) ManagedLifecycle(org.apache.synapse.ManagedLifecycle)

Example 7 with TestMessageContext

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"));
}
Also used : Axis2SynapseEnvironment(org.apache.synapse.core.axis2.Axis2SynapseEnvironment) TestMessageContext(org.apache.synapse.TestMessageContext) Mediator(org.apache.synapse.Mediator) Properties(java.util.Properties) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration)

Example 8 with TestMessageContext

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));
}
Also used : AxisConfiguration(org.apache.axis2.engine.AxisConfiguration) TestMessageContext(org.apache.synapse.TestMessageContext) AddressEndpoint(org.apache.synapse.endpoints.AddressEndpoint) EndpointDefinition(org.apache.synapse.endpoints.EndpointDefinition) MessageContext(org.apache.synapse.MessageContext) TestMessageContext(org.apache.synapse.TestMessageContext) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration) URI(java.net.URI)

Example 9 with TestMessageContext

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);
}
Also used : AxisConfiguration(org.apache.axis2.engine.AxisConfiguration) ConfigurationContext(org.apache.axis2.context.ConfigurationContext) MediatorFaultHandler(org.apache.synapse.mediators.MediatorFaultHandler) TestMessageContext(org.apache.synapse.TestMessageContext) SynapseEnvironment(org.apache.synapse.core.SynapseEnvironment) MessageContext(org.apache.synapse.MessageContext) TestMessageContext(org.apache.synapse.TestMessageContext) SequenceMediator(org.apache.synapse.mediators.base.SequenceMediator) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration)

Example 10 with TestMessageContext

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);
}
Also used : ConfigurationContext(org.apache.axis2.context.ConfigurationContext) AxisConfiguration(org.apache.axis2.engine.AxisConfiguration) SynapseEnvironment(org.apache.synapse.core.SynapseEnvironment) Axis2SynapseEnvironment(org.apache.synapse.core.axis2.Axis2SynapseEnvironment) ArrayList(java.util.ArrayList) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration) Axis2SynapseEnvironment(org.apache.synapse.core.axis2.Axis2SynapseEnvironment) TestMessageContext(org.apache.synapse.TestMessageContext) TestMessageContext(org.apache.synapse.TestMessageContext) MessageContext(org.apache.synapse.MessageContext)

Aggregations

TestMessageContext (org.apache.synapse.TestMessageContext)20 SynapseConfiguration (org.apache.synapse.config.SynapseConfiguration)16 Axis2SynapseEnvironment (org.apache.synapse.core.axis2.Axis2SynapseEnvironment)13 Properties (java.util.Properties)12 Mediator (org.apache.synapse.Mediator)12 MessageContext (org.apache.synapse.MessageContext)10 SynapseEnvironment (org.apache.synapse.core.SynapseEnvironment)4 AxisConfiguration (org.apache.axis2.engine.AxisConfiguration)3 ConfigurationContext (org.apache.axis2.context.ConfigurationContext)2 ManagedLifecycle (org.apache.synapse.ManagedLifecycle)2 Axis2MessageContext (org.apache.synapse.core.axis2.Axis2MessageContext)2 AddressEndpoint (org.apache.synapse.endpoints.AddressEndpoint)2 EndpointDefinition (org.apache.synapse.endpoints.EndpointDefinition)2 SynapseXPath (org.apache.synapse.util.xpath.SynapseXPath)2 Test (org.junit.Test)2 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)1 AbstractEndpoint (org.apache.synapse.endpoints.AbstractEndpoint)1