Search in sources :

Example 31 with ComponentConfiguration

use of org.apache.camel.ComponentConfiguration in project camel by apache.

the class ComponentConfigurationTest method testConfigureAnExistingSedaEndpoint.

/**
     * Shows how we can use the configuration to get and set parameters directly on the endpoint
     * for a {@link UriEndpointComponent}
     */
@Test
public void testConfigureAnExistingSedaEndpoint() throws Exception {
    SedaEndpoint endpoint = context.getEndpoint("seda:cheese?concurrentConsumers=5", SedaEndpoint.class);
    SedaComponent component = endpoint.getComponent();
    ComponentConfiguration configuration = component.createComponentConfiguration();
    assertEquals("concurrentConsumers", 5, endpoint.getConcurrentConsumers());
    assertEquals("concurrentConsumers", 5, configuration.getEndpointParameter(endpoint, "concurrentConsumers"));
    // lets try set and get some valid parameters
    configuration.setEndpointParameter(endpoint, "concurrentConsumers", 10);
    Object concurrentConsumers = configuration.getEndpointParameter(endpoint, "concurrentConsumers");
    assertEquals("endpoint.concurrentConsumers", 10, concurrentConsumers);
    configuration.setEndpointParameter(endpoint, "size", 1000);
    Object size = configuration.getEndpointParameter(endpoint, "size");
    assertEquals("endpoint.size", 1000, size);
    // lets try set an invalid parameter
    try {
        configuration.setEndpointParameter(endpoint, "doesNotExist", 1000);
        fail("Should have got InvalidPropertyException thrown!");
    } catch (InvalidPropertyException e) {
        LOG.info("Got expected exception: " + e);
    }
}
Also used : ComponentConfiguration(org.apache.camel.ComponentConfiguration) SedaComponent(org.apache.camel.component.seda.SedaComponent) SedaEndpoint(org.apache.camel.component.seda.SedaEndpoint) InvalidPropertyException(org.apache.camel.InvalidPropertyException) Test(org.junit.Test)

Aggregations

ComponentConfiguration (org.apache.camel.ComponentConfiguration)31 Test (org.junit.Test)29 EndpointConfiguration (org.apache.camel.EndpointConfiguration)16 Component (org.apache.camel.Component)14 SedaComponent (org.apache.camel.component.seda.SedaComponent)11 InvalidPropertyException (org.apache.camel.InvalidPropertyException)4 Map (java.util.Map)2 SortedMap (java.util.SortedMap)2 MSPTest (org.apache.camel.component.salesforce.dto.generated.MSPTest)2 SedaEndpoint (org.apache.camel.component.seda.SedaEndpoint)2 ParameterConfiguration (org.apache.camel.impl.ParameterConfiguration)2 ArrayList (java.util.ArrayList)1 ResolveEndpointFailedException (org.apache.camel.ResolveEndpointFailedException)1 BeanComponent (org.apache.camel.component.bean.BeanComponent)1 BrowseComponent (org.apache.camel.component.browse.BrowseComponent)1 ControlBusComponent (org.apache.camel.component.controlbus.ControlBusComponent)1 DataFormatComponent (org.apache.camel.component.dataformat.DataFormatComponent)1 DataSetComponent (org.apache.camel.component.dataset.DataSetComponent)1 DirectComponent (org.apache.camel.component.direct.DirectComponent)1 DirectVmComponent (org.apache.camel.component.directvm.DirectVmComponent)1