Search in sources :

Example 1 with SourcesConfigurer

use of org.apache.camel.k.listener.SourcesConfigurer in project camel-k-runtime by apache.

the class PropertiesSupportTest method propertiesAreBoundToSourcesConfigurer.

@Test
public void propertiesAreBoundToSourcesConfigurer() {
    CamelContext context = new DefaultCamelContext();
    context.getPropertiesComponent().setInitialProperties(asProperties("camel.k.sources[0].name", "MyRoutesWithBeans", "camel.k.sources[0].location", "classpath:MyRoutesWithBeans.java", "camel.k.sources[1].name", "MyRoutesConfig", "camel.k.sources[1].location", "classpath:MyRoutesConfig.java", "camel.k.sources[1].property-names[0]", "foo", "camel.k.sources[1].property-names[1]", "bar"));
    SourcesConfigurer configuration = new SourcesConfigurer();
    PropertiesSupport.bindProperties(context, configuration, k -> k.startsWith(SourcesConfigurer.CAMEL_K_SOURCES_PREFIX), SourcesConfigurer.CAMEL_K_PREFIX);
    assertThat(configuration.getSources()).hasSize(2).anyMatch(byNameAndLocation("MyRoutesWithBeans", "classpath:MyRoutesWithBeans.java").and(d -> d.getPropertyNames() == null)).anyMatch(byNameAndLocation("MyRoutesConfig", "classpath:MyRoutesConfig.java").and(d -> d.getPropertyNames() != null && d.getPropertyNames().containsAll(List.of("foo", "bar"))));
}
Also used : CamelContext(org.apache.camel.CamelContext) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) Objects(java.util.Objects) Test(org.junit.jupiter.api.Test) CamelContext(org.apache.camel.CamelContext) List(java.util.List) SourcesConfigurer(org.apache.camel.k.listener.SourcesConfigurer) SourceDefinition(org.apache.camel.k.SourceDefinition) CamelKTestSupport.asProperties(org.apache.camel.k.test.CamelKTestSupport.asProperties) Predicate(java.util.function.Predicate) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) SourcesConfigurer(org.apache.camel.k.listener.SourcesConfigurer) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) Test(org.junit.jupiter.api.Test)

Example 2 with SourcesConfigurer

use of org.apache.camel.k.listener.SourcesConfigurer in project camel-k-runtime by apache.

the class PropertiesSupportTest method propertiesWithGapsAreBoundToSourcesConfigurer.

@Test
public void propertiesWithGapsAreBoundToSourcesConfigurer() {
    CamelContext context = new DefaultCamelContext();
    context.getPropertiesComponent().setInitialProperties(asProperties("camel.k.sources[0].name", "MyRoutesWithBeans", "camel.k.sources[0].location", "classpath:MyRoutesWithBeans.java", "camel.k.sources[2].name", "MyRoutesConfig", "camel.k.sources[2].location", "classpath:MyRoutesConfig.java"));
    SourcesConfigurer configuration = new SourcesConfigurer();
    PropertiesSupport.bindProperties(context, configuration, k -> k.startsWith(SourcesConfigurer.CAMEL_K_SOURCES_PREFIX), SourcesConfigurer.CAMEL_K_PREFIX);
    assertThat(configuration.getSources()).hasSize(3).filteredOn(Objects::nonNull).hasSize(2).anyMatch(byNameAndLocation("MyRoutesWithBeans", "classpath:MyRoutesWithBeans.java")).anyMatch(byNameAndLocation("MyRoutesConfig", "classpath:MyRoutesConfig.java"));
}
Also used : CamelContext(org.apache.camel.CamelContext) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) SourcesConfigurer(org.apache.camel.k.listener.SourcesConfigurer) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) Test(org.junit.jupiter.api.Test)

Aggregations

CamelContext (org.apache.camel.CamelContext)2 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)2 SourcesConfigurer (org.apache.camel.k.listener.SourcesConfigurer)2 Test (org.junit.jupiter.api.Test)2 List (java.util.List)1 Objects (java.util.Objects)1 Predicate (java.util.function.Predicate)1 SourceDefinition (org.apache.camel.k.SourceDefinition)1 CamelKTestSupport.asProperties (org.apache.camel.k.test.CamelKTestSupport.asProperties)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1