You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by or...@apache.org on 2024/05/23 07:48:26 UTC
(camel) 08/11: CAMEL-20785: cleanup configurePropertiesComponent and make reusable
This is an automated email from the ASF dual-hosted git repository.
orpiske pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
commit 9ccd95d5547fd84c290fe50691048a4bed37f50a
Author: Otavio Rodolfo Piske <an...@gmail.com>
AuthorDate: Wed May 22 13:22:34 2024 +0200
CAMEL-20785: cleanup configurePropertiesComponent and make reusable
---
.../apache/camel/test/junit5/CamelTestSupport.java | 10 ++-------
.../test/junit5/util/CamelContextTestHelper.java | 24 +++++++++++++++++++++-
2 files changed, 25 insertions(+), 9 deletions(-)
diff --git a/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/CamelTestSupport.java b/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/CamelTestSupport.java
index a445b28e65b..b61b2f10e16 100644
--- a/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/CamelTestSupport.java
+++ b/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/CamelTestSupport.java
@@ -508,18 +508,12 @@ public abstract class CamelTestSupport
}
private void configurePropertiesComponent() {
- PropertiesComponent pc = context.getPropertiesComponent();
if (extra == null) {
extra = useOverridePropertiesWithPropertiesComponent();
}
- if (extra != null && !extra.isEmpty()) {
- pc.setOverrideProperties(extra);
- }
- pc.addPropertiesSource(new JunitPropertiesSource(globalStore));
+
Boolean ignore = ignoreMissingLocationWithPropertiesComponent();
- if (ignore != null) {
- pc.setIgnoreMissingLocation(ignore);
- }
+ CamelContextTestHelper.configurePropertiesComponent(context, extra, new JunitPropertiesSource(globalStore), ignore);
}
private void replaceFromEndpoints() throws Exception {
diff --git a/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/util/CamelContextTestHelper.java b/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/util/CamelContextTestHelper.java
index 73e341af417..ff889c0faeb 100644
--- a/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/util/CamelContextTestHelper.java
+++ b/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/util/CamelContextTestHelper.java
@@ -17,6 +17,8 @@
package org.apache.camel.test.junit5.util;
+import java.util.Properties;
+
import org.apache.camel.CamelContext;
import org.apache.camel.NoSuchEndpointException;
import org.apache.camel.RouteConfigurationsBuilder;
@@ -28,8 +30,8 @@ import org.apache.camel.impl.DefaultCamelContext;
import org.apache.camel.impl.debugger.DefaultDebugger;
import org.apache.camel.spi.Breakpoint;
import org.apache.camel.spi.PropertiesComponent;
+import org.apache.camel.spi.PropertiesSource;
import org.apache.camel.spi.Registry;
-import org.apache.camel.test.junit5.JunitPropertiesSource;
import org.apache.camel.test.junit5.TestSupport;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -139,4 +141,24 @@ public final class CamelContextTestHelper {
.registerEndpointCallback(new InterceptSendToMockEndpointStrategy(mockAndSkipPattern, true));
}
}
+
+ /**
+ * Configure the PropertiesComponent from the given context
+ *
+ * @param context the context with the PropertiesComponent to configure
+ * @param extra override properties to use (if any)
+ * @param propertiesSource custom properties source to use to load/lookup properties
+ * @param ignore whether to ignore missing properties locations
+ */
+ public static void configurePropertiesComponent(
+ CamelContext context, Properties extra, PropertiesSource propertiesSource, Boolean ignore) {
+ PropertiesComponent pc = context.getPropertiesComponent();
+ if (extra != null && !extra.isEmpty()) {
+ pc.setOverrideProperties(extra);
+ }
+ pc.addPropertiesSource(propertiesSource);
+ if (ignore != null) {
+ pc.setIgnoreMissingLocation(ignore);
+ }
+ }
}