This is an automated email from the ASF dual-hosted git repository. lburgazzoli pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel-k-runtime.git
commit 76c64d88932a2090f8f832fc48475b06de0be5c4 Author: Pasquale Congiusti <pasquale.congiu...@gmail.com> AuthorDate: Tue Apr 13 14:56:16 2021 +0200 fix(core): SourceType enum order --- .../api/src/main/java/org/apache/camel/k/SourceType.java | 4 ++-- .../java/org/apache/camel/k/listener/SourcesConfigurer.java | 6 +++--- .../main/java/org/apache/camel/k/support/SourcesSupport.java | 12 ++++++------ .../org/apache/camel/k/listener/SourceConfigurerTest.java | 9 ++++----- 4 files changed, 15 insertions(+), 16 deletions(-) diff --git a/camel-k-core/api/src/main/java/org/apache/camel/k/SourceType.java b/camel-k-core/api/src/main/java/org/apache/camel/k/SourceType.java index 243a7b8..c06250a 100644 --- a/camel-k-core/api/src/main/java/org/apache/camel/k/SourceType.java +++ b/camel-k-core/api/src/main/java/org/apache/camel/k/SourceType.java @@ -19,6 +19,6 @@ package org.apache.camel.k; public enum SourceType { // Order matters. We want the sources to be loaded following this enum order. errorHandler, - source, - template + template, + source } diff --git a/camel-k-core/support/src/main/java/org/apache/camel/k/listener/SourcesConfigurer.java b/camel-k-core/support/src/main/java/org/apache/camel/k/listener/SourcesConfigurer.java index db0fb24..cbaae05 100644 --- a/camel-k-core/support/src/main/java/org/apache/camel/k/listener/SourcesConfigurer.java +++ b/camel-k-core/support/src/main/java/org/apache/camel/k/listener/SourcesConfigurer.java @@ -16,6 +16,8 @@ */ package org.apache.camel.k.listener; +import java.util.Arrays; + import org.apache.camel.k.Runtime; import org.apache.camel.k.SourceDefinition; import org.apache.camel.k.SourceType; @@ -25,8 +27,6 @@ import org.apache.camel.k.support.SourcesSupport; import org.apache.camel.spi.Configurer; import org.apache.camel.util.ObjectHelper; -import java.util.Arrays; - @Configurer public class SourcesConfigurer extends AbstractPhaseListener { public static final String CAMEL_K_PREFIX = "camel.k."; @@ -99,7 +99,7 @@ public class SourcesConfigurer extends AbstractPhaseListener { if (sources == null) { return; } - // We must ensure the following source type order: errorHandler, source, template + // We must ensure the source order as defined in SourceType enum Arrays.sort(sources, (a, b) -> { if (a.getType() == null) { diff --git a/camel-k-core/support/src/main/java/org/apache/camel/k/support/SourcesSupport.java b/camel-k-core/support/src/main/java/org/apache/camel/k/support/SourcesSupport.java index c98744d..397dcb8 100644 --- a/camel-k-core/support/src/main/java/org/apache/camel/k/support/SourcesSupport.java +++ b/camel-k-core/support/src/main/java/org/apache/camel/k/support/SourcesSupport.java @@ -16,6 +16,10 @@ */ package org.apache.camel.k.support; +import java.lang.reflect.Field; +import java.util.Collection; +import java.util.List; + import org.apache.camel.ExtendedCamelContext; import org.apache.camel.RoutesBuilder; import org.apache.camel.RuntimeCamelException; @@ -35,10 +39,6 @@ import org.apache.camel.util.ObjectHelper; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.lang.reflect.Field; -import java.util.Collection; -import java.util.List; - public final class SourcesSupport { private static final Logger LOGGER = LoggerFactory.getLogger(SourcesConfigurer.class); @@ -148,7 +148,7 @@ public final class SourcesSupport { throw new IllegalArgumentException("There should not be any template, got " + templates.size()); } - if (existErrorHandler(builder)) { + if (hasErrorHandlerBuilder(builder)) { LOGGER.debug("Setting default error handler builder factory as {}", builder.getErrorHandlerBuilder()); runtime.getCamelContext().adapt(ExtendedCamelContext.class).setErrorHandlerFactory(builder.getErrorHandlerBuilder()); } @@ -173,7 +173,7 @@ public final class SourcesSupport { } } - static boolean existErrorHandler(RouteBuilder builder) { + static boolean hasErrorHandlerBuilder(RouteBuilder builder) { //return builder.hasErrorHandlerBuilder(); // TODO We need to replace the following workaround with the statement above once we switch to camel-3.10.0 or above try { diff --git a/camel-k-core/support/src/test/java/org/apache/camel/k/listener/SourceConfigurerTest.java b/camel-k-core/support/src/test/java/org/apache/camel/k/listener/SourceConfigurerTest.java index 44f9f7c..2aae80e 100644 --- a/camel-k-core/support/src/test/java/org/apache/camel/k/listener/SourceConfigurerTest.java +++ b/camel-k-core/support/src/test/java/org/apache/camel/k/listener/SourceConfigurerTest.java @@ -35,7 +35,7 @@ public class SourceConfigurerTest { "camel.k.sources[0].location", "classpath:MyTemplate1.java", "camel.k.sources[0].type", "template", "camel.k.sources[1].name", "err1", - "camel.k.sources[1.location", "classpath:MyTemplate2.java", + "camel.k.sources[1].location", "classpath:MyTemplate2.java", "camel.k.sources[2].name", "err2", "camel.k.sources[2].location", "classpath:Err2.java", "camel.k.sources[2].type", "errorHandler" @@ -60,7 +60,7 @@ public class SourceConfigurerTest { "camel.k.sources[0].location", "classpath:MyTemplate1.java", "camel.k.sources[0].type", "template", "camel.k.sources[1].name", "err1", - "camel.k.sources[1.location", "classpath:Err1.java", + "camel.k.sources[1].location", "classpath:Err1.java", "camel.k.sources[1].type", "errorHandler", "camel.k.sources[2].name", "err2", "camel.k.sources[2].location", "classpath:Err2.java", @@ -104,12 +104,11 @@ public class SourceConfigurerTest { SourcesConfigurer.sortSources(configuration.getSources()); assertThat(configuration.getSources().length).isEqualTo(4); - assertThat(configuration.getSources()[0].getName()).isEqualTo("errorHandler1"); + assertThat(configuration.getSources()[1].getName()).isEqualTo("template1"); // Order for the same type does not matter - assertThat(configuration.getSources()[1].getName()).contains("source"); assertThat(configuration.getSources()[2].getName()).contains("source"); - assertThat(configuration.getSources()[3].getName()).isEqualTo("template1"); + assertThat(configuration.getSources()[3].getName()).contains("source"); } @Test