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());
}
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());
}
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;
}
}
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());
}
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);
}
Aggregations