Search in sources :

Example 6 with Component

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

the class ComponentConfigurationTest method testCreateNewDefaultComponentEndpoint.

@Test
public void testCreateNewDefaultComponentEndpoint() throws Exception {
    Component component = context.getComponent("cheese");
    ComponentConfiguration configuration = component.createComponentConfiguration();
    assertNotNull("Should have created a ComponentConfiguration for component " + component, configuration);
    // configure the base URI properties
    configuration.setBaseUri("something");
    // lets try set and get a valid parameter
    configuration.setParameter("foo", "xyz");
    configuration.setParameter("bar", 5);
    NonUriEndpoint endpoint = TestSupport.assertIsInstanceOf(NonUriEndpoint.class, configuration.createEndpoint());
    assertEquals("foo", "xyz", endpoint.getFoo());
    assertEquals("bar", 5, endpoint.getBar());
    LOG.info("Created endpoint " + endpoint + " on URI " + endpoint.getEndpointUri());
    // lets try configure a parameter
    configuration.setEndpointParameter(endpoint, "bar", 6);
    assertEquals("bar", 6, endpoint.getBar());
    // lets try configure an invalid parameter
    try {
        configuration.setEndpointParameter(endpoint, "doesNotExist", 1000);
        fail("Should have got InvalidPropertyException thrown!");
    } catch (InvalidPropertyException e) {
        LOG.info("Got expected exception: " + e);
    }
    ComponentConfiguration badConfiguration = component.createComponentConfiguration();
    badConfiguration.setBaseUri(configuration.getBaseUri());
    badConfiguration.setParameters(configuration.getParameters());
    // lets try set an invalid parameter on a configuration
    // there is no way to validate on non UriEndpoint unless the endpoint
    // creates its own configuration object so this always works...
    badConfiguration.setParameter("doesNotExist", 1000);
    // however it fails if we now try create an
    try {
        badConfiguration.createEndpoint();
        fail("Should have got ResolveEndpointFailedException thrown!");
    } catch (ResolveEndpointFailedException e) {
        LOG.info("Got expected exception: " + e);
    }
}
Also used : ComponentConfiguration(org.apache.camel.ComponentConfiguration) ResolveEndpointFailedException(org.apache.camel.ResolveEndpointFailedException) InvalidPropertyException(org.apache.camel.InvalidPropertyException) Component(org.apache.camel.Component) SedaComponent(org.apache.camel.component.seda.SedaComponent) Test(org.junit.Test)

Example 7 with Component

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

the class ComponentConfigurationTest method testCreateNewSedaUriEndpoint.

/**
     * Use the {@link ComponentConfiguration}, set some parameters then lets turn it into an endpoint
     */
@Test
public void testCreateNewSedaUriEndpoint() throws Exception {
    Component component = context.getComponent("seda");
    ComponentConfiguration configuration = component.createComponentConfiguration();
    assertNotNull("Should have created a ComponentConfiguration for component " + component, configuration);
    // configure the base URI properties
    configuration.setBaseUri("foo");
    // lets try set and get a valid parameter
    configuration.setParameter("concurrentConsumers", 5);
    configuration.setParameter("size", 1000);
    // lets try set an invalid parameter
    try {
        configuration.setParameter("doesNotExist", 1000);
        fail("Should have got InvalidPropertyException thrown!");
    } catch (InvalidPropertyException e) {
        LOG.info("Got expected exception: " + e);
    }
    SedaEndpoint endpoint = TestSupport.assertIsInstanceOf(SedaEndpoint.class, configuration.createEndpoint());
    assertEquals("concurrentConsumers", 5, endpoint.getConcurrentConsumers());
    assertEquals("size", 1000, endpoint.getSize());
    assertEquals("endpoint uri", "foo?concurrentConsumers=5&size=1000", endpoint.getEndpointUri());
    // lets try configure a parameter
    configuration.setEndpointParameter(endpoint, "concurrentConsumers", 6);
    assertEquals("concurrentConsumers", 6, endpoint.getConcurrentConsumers());
    // 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) SedaEndpoint(org.apache.camel.component.seda.SedaEndpoint) InvalidPropertyException(org.apache.camel.InvalidPropertyException) Component(org.apache.camel.Component) SedaComponent(org.apache.camel.component.seda.SedaComponent) Test(org.junit.Test)

Example 8 with Component

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

the class ComponentConfigurationTest method testSetParametersFromUriStringOnDefaultComponent.

/**
     * Tests that parameters can be used on non-{@link UriEndpointComponent} implementations
     * but that their types tend to be String until we try to create an Endpoint
     */
@Test
public void testSetParametersFromUriStringOnDefaultComponent() throws Exception {
    Component component = context.getComponent("cheese");
    ComponentConfiguration configuration = component.createComponentConfiguration();
    assertNotNull("Should have created a ComponentConfiguration for component " + component, configuration);
    // configure the uri and query parameters
    configuration.setUriString("somePath?foo=something&bar=123");
    // notice the parameters are all Strings since we don't use UriEndpointComponent
    assertEquals("foo", "something", configuration.getParameter("foo"));
    assertEquals("bar", "123", configuration.getParameter("bar"));
    configuration.setUriString("somePath?foo=another&bar=456");
    assertEquals("foo", "another", configuration.getParameter("foo"));
    assertEquals("bar", "456", configuration.getParameter("bar"));
}
Also used : ComponentConfiguration(org.apache.camel.ComponentConfiguration) Component(org.apache.camel.Component) SedaComponent(org.apache.camel.component.seda.SedaComponent) Test(org.junit.Test)

Example 9 with Component

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

the class DefaultCamelContextResolverTest method testComponentWithBothNames.

@Test
public void testComponentWithBothNames() throws Exception {
    Component component = context.getComponent("yellow");
    assertNotNull("Component not found in registry", component);
    assertTrue("Wrong instance type of the Component", component instanceof SampleComponent);
    assertFalse("Here we should NOT have the fallback Component", ((SampleComponent) component).isFallback());
}
Also used : Component(org.apache.camel.Component) Test(org.junit.Test)

Example 10 with Component

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

the class DefaultCamelContextResolverTest method testNullLookupComponent.

@Test
public void testNullLookupComponent() throws Exception {
    Component component = context.getComponent("xxxxxxxxx");
    assertNull("Non-existent Component should be null", component);
}
Also used : Component(org.apache.camel.Component) Test(org.junit.Test)

Aggregations

Component (org.apache.camel.Component)52 Test (org.junit.Test)24 ComponentConfiguration (org.apache.camel.ComponentConfiguration)14 PropertiesComponent (org.apache.camel.component.properties.PropertiesComponent)9 SedaComponent (org.apache.camel.component.seda.SedaComponent)9 Map (java.util.Map)7 CamelContext (org.apache.camel.CamelContext)7 NoFactoryAvailableException (org.apache.camel.NoFactoryAvailableException)7 IOException (java.io.IOException)6 Endpoint (org.apache.camel.Endpoint)6 NoSuchEndpointException (org.apache.camel.NoSuchEndpointException)6 ResolveEndpointFailedException (org.apache.camel.ResolveEndpointFailedException)6 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)5 LinkedHashMap (java.util.LinkedHashMap)4 MalformedObjectNameException (javax.management.MalformedObjectNameException)4 FailedToStartRouteException (org.apache.camel.FailedToStartRouteException)4 NoSuchBeanException (org.apache.camel.NoSuchBeanException)4 RuntimeCamelException (org.apache.camel.RuntimeCamelException)4 VetoCamelContextStartException (org.apache.camel.VetoCamelContextStartException)4 DirectComponent (org.apache.camel.component.direct.DirectComponent)4