use of org.apache.camel.k.ContextCustomizer in project camel-k-runtime by apache.
the class RuntimeSupportTest method testLoadCustomizersWithPropertiesFlags.
@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).isEmpty();
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);
}
use of org.apache.camel.k.ContextCustomizer in project camel-k-runtime by apache.
the class RuntimeSupport method lookupCustomizers.
public static Map<String, ContextCustomizer> lookupCustomizers(CamelContext context) {
Map<String, ContextCustomizer> customizers = new ConcurrentHashMap<>();
Properties properties = context.getPropertiesComponent().loadProperties(n -> n.startsWith(Constants.CUSTOMIZER_PREFIX) || n.startsWith(Constants.CUSTOMIZER_PREFIX_FALLBACK));
if (properties != null) {
//
for (String customizerId : lookupCustomizerIDs(context)) {
customizers.computeIfAbsent(customizerId, id -> lookupCustomizerByID(context, id));
}
Pattern pattern = Pattern.compile(Constants.ENABLE_CUSTOMIZER_PATTERN);
properties.entrySet().stream().filter(entry -> entry.getKey() instanceof String).filter(entry -> entry.getValue() != null).forEach(entry -> {
final String key = (String) entry.getKey();
final Object val = entry.getValue();
final Matcher matcher = pattern.matcher(key);
if (matcher.matches()) {
String customizerId = null;
if (matcher.groupCount() == 1) {
customizerId = matcher.group(1);
} else if (matcher.groupCount() == 2) {
customizerId = matcher.group(2);
}
if (customizerId != null && Boolean.parseBoolean(String.valueOf(val))) {
//
// Do not override customizers eventually found
// in the registry
//
customizers.computeIfAbsent(customizerId, id -> lookupCustomizerByID(context, id));
}
}
});
}
return customizers;
}
Aggregations