Search in sources :

Example 1 with InvalidPropertyException

use of org.apache.camel.InvalidPropertyException 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 2 with InvalidPropertyException

use of org.apache.camel.InvalidPropertyException 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 3 with InvalidPropertyException

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

the class ComponentConfigurationTest method testConfigureAnExistingDefaultEndpoint.

/**
     * Shows how we can use the configuration to get and set parameters directly on the endpoint
     * which is typesafe and performs validation even if the component is not a {@link UriEndpointComponent}
     */
@Test
public void testConfigureAnExistingDefaultEndpoint() throws Exception {
    NonUriEndpoint endpoint = context.getEndpoint("cheese:somePath?bar=123&foo=something", NonUriEndpoint.class);
    Component component = endpoint.getComponent();
    ComponentConfiguration configuration = component.createComponentConfiguration();
    assertEquals("bar", 123, endpoint.getBar());
    assertEquals("bar", 123, configuration.getEndpointParameter(endpoint, "bar"));
    // lets try set and get some valid parameters
    configuration.setEndpointParameter(endpoint, "bar", 10);
    Object bar = configuration.getEndpointParameter(endpoint, "bar");
    assertEquals("endpoint.bar", 10, bar);
    configuration.setEndpointParameter(endpoint, "foo", "anotherThing");
    Object foo = configuration.getEndpointParameter(endpoint, "foo");
    assertEquals("endpoint.foo", "anotherThing", foo);
    // 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) InvalidPropertyException(org.apache.camel.InvalidPropertyException) Component(org.apache.camel.Component) SedaComponent(org.apache.camel.component.seda.SedaComponent) Test(org.junit.Test)

Example 4 with InvalidPropertyException

use of org.apache.camel.InvalidPropertyException 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)4 InvalidPropertyException (org.apache.camel.InvalidPropertyException)4 SedaComponent (org.apache.camel.component.seda.SedaComponent)4 Test (org.junit.Test)4 Component (org.apache.camel.Component)3 SedaEndpoint (org.apache.camel.component.seda.SedaEndpoint)2 ResolveEndpointFailedException (org.apache.camel.ResolveEndpointFailedException)1