Search in sources :

Example 56 with SynapseConfiguration

use of org.apache.synapse.config.SynapseConfiguration in project wso2-synapse by wso2.

the class SynapseXMLConfigurationSerializerTest method testSerializeConfiguration2.

/**
 * Test serializeConfigurationMethod with registry set for SynapseConfiguration and assert OMElement returned
 */
@Test
public void testSerializeConfiguration2() {
    SynapseXMLConfigurationSerializer serializer = new SynapseXMLConfigurationSerializer();
    SynapseConfiguration synapseConfiguration = new SynapseConfiguration();
    Map<String, OMNode> data = new HashMap<>();
    data.put(KEY_DYNAMIC_ENDPOINT_1, TestUtils.createOMElement(DYNAMIC_ENDPOINT_1));
    data.put(KEY_DYNAMIC_SEQUENCE_1, TestUtils.createOMElement(DYNAMIC_SEQUENCE_1));
    Registry registry = new SimpleInMemoryRegistry(data, 8000L);
    synapseConfiguration.setRegistry(registry);
    OMElement element = serializer.serializeConfiguration(synapseConfiguration);
    Assert.assertNotNull("OMElement is not returned", element);
    Assert.assertEquals("definitions", element.getLocalName());
    Assert.assertTrue("Registry added is not serialized.", element.getChildren().next().toString().contains("registry"));
}
Also used : OMNode(org.apache.axiom.om.OMNode) HashMap(java.util.HashMap) SimpleInMemoryRegistry(org.apache.synapse.registry.SimpleInMemoryRegistry) OMElement(org.apache.axiom.om.OMElement) Registry(org.apache.synapse.registry.Registry) SimpleInMemoryRegistry(org.apache.synapse.registry.SimpleInMemoryRegistry) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration) Test(org.junit.Test)

Example 57 with SynapseConfiguration

use of org.apache.synapse.config.SynapseConfiguration in project wso2-synapse by wso2.

the class MultiXMLConfigurationSerializerTest method testSerialize4.

/**
 * Test serialize method with taskManager set for SynapseConfiguration and assert synapse.xml is created.
 */
@Test
public void testSerialize4() {
    MultiXMLConfigurationSerializer serializer = new MultiXMLConfigurationSerializer(TEST_DIRECTORY_NAME);
    SynapseConfiguration configuration = new SynapseConfiguration();
    configuration.setTaskManager(new QuartzTaskManager());
    serializer.serialize(configuration);
    Assert.assertTrue("Error in serializing Synapse configuration.", new File(TEST_DIRECTORY_NAME + File.separator + SYNAPSE_XML).exists());
    removeTestFolder(TEST_DIRECTORY_NAME);
}
Also used : QuartzTaskManager(org.apache.synapse.startup.quartz.QuartzTaskManager) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration) File(java.io.File) Test(org.junit.Test)

Example 58 with SynapseConfiguration

use of org.apache.synapse.config.SynapseConfiguration in project wso2-synapse by wso2.

the class MultiXMLConfigurationSerializerTest method testSerializeSynapseXML2.

/**
 * Test serializeSynapseXML method with taskManager set for SynapseConfiguration and assert synapse.xml is created.
 */
@Test
public void testSerializeSynapseXML2() throws Exception {
    MultiXMLConfigurationSerializer serializer = new MultiXMLConfigurationSerializer(TEST_DIRECTORY_NAME);
    SynapseConfiguration configuration = new SynapseConfiguration();
    configuration.setTaskManager(new QuartzTaskManager());
    serializer.serializeSynapseXML(configuration);
    Assert.assertTrue("Error in serializing Synapse configuration.", new File(TEST_DIRECTORY_NAME + File.separator + SYNAPSE_XML).exists());
    removeTestFolder(TEST_DIRECTORY_NAME);
}
Also used : QuartzTaskManager(org.apache.synapse.startup.quartz.QuartzTaskManager) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration) File(java.io.File) Test(org.junit.Test)

Example 59 with SynapseConfiguration

use of org.apache.synapse.config.SynapseConfiguration in project wso2-synapse by wso2.

the class ThrottleMediatorTest method testMediate.

public void testMediate() throws Exception {
    ByteArrayInputStream in = new ByteArrayInputStream(POLICY.getBytes());
    StAXOMBuilder builde = new StAXOMBuilder(in);
    ThrottleTestMediator throttleMediator = new ThrottleTestMediator();
    throttleMediator.setPolicyKey("throttlepolicy");
    MessageContext synCtx = createLightweightSynapseMessageContext("<empty/>");
    synCtx.setProperty(REMOTE_ADDR, "192.168.8.212");
    SynapseConfiguration synCfg = new SynapseConfiguration();
    Entry prop = new Entry();
    prop.setKey("throttlepolicy");
    prop.setType(Entry.INLINE_XML);
    prop.setValue(builde.getDocumentElement());
    synCfg.addEntry("throttlepolicy", prop);
    synCtx.setConfiguration(synCfg);
    for (int i = 0; i < 6; i++) {
        try {
            throttleMediator.mediate(synCtx);
            Thread.sleep(1000);
        } catch (Exception e) {
            if (i == 3) {
                assertTrue(e.getMessage().lastIndexOf("IP_BASE") > 0);
            }
            if (i == 4) {
                assertTrue(e.getMessage().lastIndexOf("IP_BASE") > 0);
            }
            if (i == 5) {
                assertTrue(e.getMessage().lastIndexOf("IP_BASE") > 0);
            }
        }
    }
}
Also used : Entry(org.apache.synapse.config.Entry) ByteArrayInputStream(java.io.ByteArrayInputStream) StAXOMBuilder(org.apache.axiom.om.impl.builder.StAXOMBuilder) MessageContext(org.apache.synapse.MessageContext) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration) XMLStreamException(javax.xml.stream.XMLStreamException) SynapseException(org.apache.synapse.SynapseException)

Example 60 with SynapseConfiguration

use of org.apache.synapse.config.SynapseConfiguration in project wso2-synapse by wso2.

the class HessianMessageBuilderTest method testProcessDocumentWithSynEnv.

public void testProcessDocumentWithSynEnv() throws IOException {
    SynapseEnvironment synEnv = new Axis2SynapseEnvironment(new ConfigurationContext(new AxisConfiguration()), new SynapseConfiguration());
    testProcessDocument(synEnv);
}
Also used : Axis2SynapseEnvironment(org.apache.synapse.core.axis2.Axis2SynapseEnvironment) ConfigurationContext(org.apache.axis2.context.ConfigurationContext) AxisConfiguration(org.apache.axis2.engine.AxisConfiguration) Axis2SynapseEnvironment(org.apache.synapse.core.axis2.Axis2SynapseEnvironment) SynapseEnvironment(org.apache.synapse.core.SynapseEnvironment) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration)

Aggregations

SynapseConfiguration (org.apache.synapse.config.SynapseConfiguration)145 Axis2SynapseEnvironment (org.apache.synapse.core.axis2.Axis2SynapseEnvironment)64 AxisConfiguration (org.apache.axis2.engine.AxisConfiguration)59 MessageContext (org.apache.synapse.MessageContext)56 Test (org.junit.Test)56 ConfigurationContext (org.apache.axis2.context.ConfigurationContext)50 SynapseEnvironment (org.apache.synapse.core.SynapseEnvironment)49 OMElement (org.apache.axiom.om.OMElement)41 Parameter (org.apache.axis2.description.Parameter)29 Axis2MessageContext (org.apache.synapse.core.axis2.Axis2MessageContext)27 TestMessageContext (org.apache.synapse.TestMessageContext)16 Properties (java.util.Properties)15 SynapseException (org.apache.synapse.SynapseException)13 Mediator (org.apache.synapse.Mediator)12 AddressEndpoint (org.apache.synapse.endpoints.AddressEndpoint)11 File (java.io.File)10 ArrayList (java.util.ArrayList)10 HashMap (java.util.HashMap)9 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)7 Endpoint (org.apache.synapse.endpoints.Endpoint)7