RuntimeSupport { public static List<ContextCustomizer> configureContextCustomizers(HasCamelContext hasCamelContext) { return configureContextCustomizers(hasCamelContext.getCamelContext()); } private  RuntimeSupport(); static List<ContextCustomizer> configureContextCustomizers(HasCamelContext hasCamelContext); static List<ContextCustomizer> configureContextCustomizers(CamelContext context); static Map<String, ContextCustomizer> lookupCustomizers(CamelContext context); static ContextCustomizer lookupCustomizerByID(CamelContext context, String customizerId); static Set<String> lookupCustomizerIDs(CamelContext context); static SourceLoader loaderFor(CamelContext context, Source source); static SourceLoader lookupLoaderById(CamelContext context, String loaderId); static SourceLoader lookupLoaderByLanguage(CamelContext context, String loaderId); static SourceLoader lookupLoaderFromResource(CamelContext context, String loaderId); static List<SourceLoader.Interceptor> loadInterceptors(CamelContext context, Source source); static String getRuntimeVersion();  }
@Test public void testLoadCustomizersWithPropertiesFlags() { CamelContext context = new DefaultCamelContext(); NameCustomizer customizer = new NameCustomizer("from-registry"); context.getRegistry().bind("name", customizer); List<ContextCustomizer> customizers = RuntimeSupport.configureContextCustomizers(context); assertThat(context.getName()).isNotEqualTo("from-registry"); assertThat(context.getName()).isNotEqualTo("default"); assertThat(customizers).hasSize(0); Properties properties = new Properties(); properties.setProperty("camel.k.customizer.name.enabled", "true"); context.getPropertiesComponent().setInitialProperties(properties); customizers = RuntimeSupport.configureContextCustomizers(context); assertThat(context.getName()).isEqualTo("from-registry"); assertThat(customizers).hasSize(1); }
@Test public void testLoadCustomizersWithList() { CamelContext context = new DefaultCamelContext(); NameCustomizer customizer = new NameCustomizer("from-registry"); context.getRegistry().bind("name", customizer); List<ContextCustomizer> customizers = RuntimeSupport.configureContextCustomizers(context); assertThat(context.getName()).isNotEqualTo("from-registry"); assertThat(context.getName()).isNotEqualTo("default"); assertThat(customizers).hasSize(0); Properties properties = new Properties(); properties.setProperty(Constants.PROPERTY_CAMEL_K_CUSTOMIZER, "name"); context.getPropertiesComponent().setInitialProperties(properties); customizers = RuntimeSupport.configureContextCustomizers(context); assertThat(context.getName()).isEqualTo("from-registry"); assertThat(customizers).hasSize(1); }
@Test public void testLoadCustomizers() { CamelContext context = new DefaultCamelContext(); context.getRegistry().bind("converters", (ContextCustomizer)camelContext -> camelContext.setLoadTypeConverters(true)); List<ContextCustomizer> customizers = RuntimeSupport.configureContextCustomizers(context); assertThat(context.getName()).isNotEqualTo("from-registry"); assertThat(context.getName()).isNotEqualTo("default"); assertThat(context.isLoadTypeConverters()).isFalse(); assertThat(customizers).hasSize(0); Properties properties = new Properties(); properties.setProperty("camel.k.customizer.name.enabled", "true"); context.getPropertiesComponent().setInitialProperties(properties); customizers = RuntimeSupport.configureContextCustomizers(context); assertThat(context.getName()).isEqualTo("default"); assertThat(customizers).hasSize(1); properties.setProperty("camel.k.customizer.converters.enabled", "true"); context.getPropertiesComponent().setInitialProperties(properties); customizers = RuntimeSupport.configureContextCustomizers(context); assertThat(context.getName()).isEqualTo("default"); assertThat(context.isLoadTypeConverters()).isTrue(); assertThat(customizers).hasSize(2); }
@Test public void testLoadCustomizersFallback() { CamelContext context = new DefaultCamelContext(); context.getRegistry().bind("converters", (ContextCustomizer)camelContext -> camelContext.setLoadTypeConverters(true)); List<ContextCustomizer> customizers = RuntimeSupport.configureContextCustomizers(context); assertThat(context.getName()).isNotEqualTo("from-registry"); assertThat(context.getName()).isNotEqualTo("default"); assertThat(context.isLoadTypeConverters()).isFalse(); assertThat(customizers).hasSize(0); Properties properties = new Properties(); properties.setProperty("customizer.name.enabled", "true"); context.getPropertiesComponent().setInitialProperties(properties); customizers = RuntimeSupport.configureContextCustomizers(context); assertThat(context.getName()).isEqualTo("default"); assertThat(customizers).hasSize(1); properties.setProperty("customizer.converters.enabled", "true"); properties.setProperty("customizer.converters.enabled", "true"); context.getPropertiesComponent().setInitialProperties(properties); customizers = RuntimeSupport.configureContextCustomizers(context); assertThat(context.getName()).isEqualTo("default"); assertThat(context.isLoadTypeConverters()).isTrue(); assertThat(customizers).hasSize(2); }
@Test public void testLoadCustomizerOrder() { DefaultCamelContext context = new DefaultCamelContext(); context.setName("camel"); context.getRegistry().bind("c1", new ContextCustomizer() { @Override public int getOrder() { return Ordered.LOWEST; } @Override public void apply(CamelContext camelContext) { camelContext.setNameStrategy(new ExplicitCamelContextNameStrategy(camelContext.getName() + "-c1")); } }); context.getRegistry().bind("c2", new ContextCustomizer() { @Override public int getOrder() { return Ordered.HIGHEST; } @Override public void apply(CamelContext camelContext) { camelContext.setNameStrategy(new ExplicitCamelContextNameStrategy(camelContext.getName() + "-c2")); } }); context.getRegistry().bind("c3", new ContextCustomizer() { @Override public void apply(CamelContext camelContext) { camelContext.setNameStrategy(new ExplicitCamelContextNameStrategy(camelContext.getName() + "-c3")); } }); Properties properties = new Properties(); properties.setProperty("camel.k.customizer.c1.enabled", "true"); properties.setProperty("camel.k.customizer.c2.enabled", "true"); properties.setProperty("camel.k.customizer.c3.enabled", "true"); context.getPropertiesComponent().setInitialProperties(properties); List<ContextCustomizer> customizers = RuntimeSupport.configureContextCustomizers(context); assertThat(customizers).hasSize(3); assertThat(context.getName()).isEqualTo("camel-c2-c3-c1"); }