Search in sources :

Example 31 with Component

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

the class PubsubComponentTest method testComponentConfiguration.

@Test
public void testComponentConfiguration() throws Exception {
    Component contextComponent = context.hasComponent("google-pubsub");
    assertNotNull(contextComponent);
    assertTrue(contextComponent instanceof GooglePubsubComponent);
    GooglePubsubComponent pubsubComponent = (GooglePubsubComponent) contextComponent;
    assertEquals(SERVICE_ACCOUNT, pubsubComponent.getConnectionFactory().getServiceAccount());
    assertEquals(SERVICE_KEY, pubsubComponent.getConnectionFactory().getServiceAccountKey());
}
Also used : GooglePubsubComponent(org.apache.camel.component.google.pubsub.GooglePubsubComponent) Component(org.apache.camel.Component) GooglePubsubComponent(org.apache.camel.component.google.pubsub.GooglePubsubComponent) Test(org.junit.Test)

Example 32 with Component

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

the class SalesforceComponentConfigurationIntegrationTest method testConfiguration.

@Test
public void testConfiguration() throws Exception {
    Component component = context().getComponent(componentName);
    ComponentConfiguration configuration = component.createComponentConfiguration();
    SortedMap<String, ParameterConfiguration> parameterConfigurationMap = configuration.getParameterConfigurationMap();
    if (verbose) {
        Set<Map.Entry<String, ParameterConfiguration>> entries = parameterConfigurationMap.entrySet();
        for (Map.Entry<String, ParameterConfiguration> entry : entries) {
            String name = entry.getKey();
            ParameterConfiguration config = entry.getValue();
            LOG.info("Has name: {} with type {}", name, config.getParameterType().getName());
        }
    }
    assertParameterConfig(configuration, "format", PayloadFormat.class);
    assertParameterConfig(configuration, "sObjectName", String.class);
    assertParameterConfig(configuration, "sObjectFields", String.class);
    assertParameterConfig(configuration, "updateTopic", boolean.class);
    configuration.setParameter("format", PayloadFormat.XML);
    configuration.setParameter("sObjectName", "Merchandise__c");
    configuration.setParameter("sObjectFields", "Description__c,Total_Inventory__c");
    configuration.setParameter("updateTopic", false);
    // operation name is base uri
    configuration.setBaseUri(componentName + ":getSObject");
    SalesforceEndpoint endpoint = assertIsInstanceOf(SalesforceEndpoint.class, configuration.createEndpoint());
    final SalesforceEndpointConfig endpointConfig = endpoint.getConfiguration();
    assertEquals("endpoint.format", PayloadFormat.XML, endpointConfig.getFormat());
    assertEquals("endpoint.sObjectName", "Merchandise__c", endpointConfig.getSObjectName());
    assertEquals("endpoint.sObjectFields", "Description__c,Total_Inventory__c", endpointConfig.getSObjectFields());
    assertEquals("endpoint.updateTopic", false, endpointConfig.isUpdateTopic());
}
Also used : ComponentConfiguration(org.apache.camel.ComponentConfiguration) Component(org.apache.camel.Component) ParameterConfiguration(org.apache.camel.impl.ParameterConfiguration) Map(java.util.Map) SortedMap(java.util.SortedMap) Test(org.junit.Test) MSPTest(org.apache.camel.component.salesforce.dto.generated.MSPTest)

Example 33 with Component

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

the class RouteBuilder method propertyInject.

/**
     * Injects a property placeholder value with the given key converted to the given type.
     *
     * @param key  the property key
     * @param type the type to convert the value as
     * @return the value, or <tt>null</tt> if value is empty
     * @throws Exception is thrown if property with key not found or error converting to the given type.
     */
public <T> T propertyInject(String key, Class<T> type) throws Exception {
    ObjectHelper.notEmpty(key, "key");
    ObjectHelper.notNull(type, "Class type");
    // the properties component is mandatory
    Component component = getContext().hasComponent("properties");
    if (component == null) {
        throw new IllegalArgumentException("PropertiesComponent with name properties must be defined" + " in CamelContext to support property placeholders in expressions");
    }
    PropertiesComponent pc = getContext().getTypeConverter().mandatoryConvertTo(PropertiesComponent.class, component);
    // enclose key with {{ }} to force parsing
    Object value = pc.parseUri(pc.getPrefixToken() + key + pc.getSuffixToken());
    if (value != null) {
        return getContext().getTypeConverter().mandatoryConvertTo(type, value);
    } else {
        return null;
    }
}
Also used : Component(org.apache.camel.Component) PropertiesComponent(org.apache.camel.component.properties.PropertiesComponent) PropertiesComponent(org.apache.camel.component.properties.PropertiesComponent)

Example 34 with Component

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

the class BlueprintComponentResolverTest method testOsgiResolverFindLanguageDoubleFallbackTest.

@Test
public void testOsgiResolverFindLanguageDoubleFallbackTest() throws Exception {
    SimpleRegistry registry = new SimpleRegistry();
    registry.put("allstar", new SampleComponent(false));
    registry.put("allstar-component", new SampleComponent(true));
    CamelContext camelContext = new DefaultCamelContext(registry);
    BlueprintComponentResolver resolver = new BlueprintComponentResolver(null);
    Component component = resolver.resolveComponent("allstar", camelContext);
    assertNotNull("We should find the super component", component);
    assertTrue("We should get the super component here", component instanceof SampleComponent);
    assertFalse("We should NOT find the fallback component", ((SampleComponent) component).isFallback());
}
Also used : CamelContext(org.apache.camel.CamelContext) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) SimpleRegistry(org.apache.camel.impl.SimpleRegistry) Component(org.apache.camel.Component) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) Test(org.junit.Test)

Example 35 with Component

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

the class BlueprintComponentResolverTest method testOsgiResolverFindComponentFallbackTest.

@Test
public void testOsgiResolverFindComponentFallbackTest() throws Exception {
    SimpleRegistry registry = new SimpleRegistry();
    registry.put("allstar-component", new SampleComponent(true));
    CamelContext camelContext = new DefaultCamelContext(registry);
    BlueprintComponentResolver resolver = new BlueprintComponentResolver(null);
    Component component = resolver.resolveComponent("allstar", camelContext);
    assertNotNull("We should find the super component", component);
    assertTrue("We should get the super component here", component instanceof SampleComponent);
}
Also used : CamelContext(org.apache.camel.CamelContext) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) SimpleRegistry(org.apache.camel.impl.SimpleRegistry) Component(org.apache.camel.Component) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) 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