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/16 03:55:30 UTC

(camel) branch main updated (e844404abe3 -> 427c19faa5d)

This is an automated email from the ASF dual-hosted git repository.

orpiske pushed a change to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git


    from e844404abe3 camel-salesforce: Document CLIENT_CREDENTIALS auth type.
     new 042c9797bc9 (chores) camel-test-junit5: decouple the hasAnnotationCheck
     new cc07a915dd4 (chores) camel-test-junit5: remove SpringBootTest from the applyCamelPostProcessor
     new 46b33293bd8 (chores) camel-test-junit5: move the JUnitPropertiesSource to a separate class
     new 75ff061a6db (chores) camel-test-junit5: decouple the logging from the base class
     new 427c19faa5d (chores) camel-test-junit5: decouple supported/unsupported check

The 5 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../apache/camel/test/junit5/CamelTestSupport.java |  88 +++++------------
 .../camel/test/junit5/JunitPropertiesSource.java}  |  28 +++---
 .../camel/test/junit5/util/ExtensionHelper.java    | 108 +++++++++++++++++++++
 .../junit5/util/RouteCoverageDumperExtension.java  |  54 +++++++++++
 4 files changed, 196 insertions(+), 82 deletions(-)
 copy components/{camel-fastjson/src/test/java/org/apache/camel/component/fastjson/TestPojo.java => camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/JunitPropertiesSource.java} (64%)
 create mode 100644 components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/util/ExtensionHelper.java
 create mode 100644 components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/util/RouteCoverageDumperExtension.java


(camel) 05/05: (chores) camel-test-junit5: decouple supported/unsupported check

Posted by or...@apache.org.
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 427c19faa5d2e5a3534f244e30355ec7134422e5
Author: Otavio Rodolfo Piske <an...@gmail.com>
AuthorDate: Tue May 14 17:42:22 2024 +0200

    (chores) camel-test-junit5: decouple supported/unsupported check
---
 .../apache/camel/test/junit5/CamelTestSupport.java | 18 +++++-----
 .../camel/test/junit5/util/ExtensionHelper.java    | 41 ++++++++++++++++++++--
 2 files changed, 48 insertions(+), 11 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 79bc99244fa..bd54b3196d7 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
@@ -343,8 +343,7 @@ public abstract class CamelTestSupport
     public void setUp() throws Exception {
         testStartHeader(getClass(), currentTestName);
 
-        doSpringBootCheck();
-        doQuarkusCheck();
+        ExtensionHelper.hasUnsupported(getClass());
 
         if (isCreateCamelContextPerClass()) {
             createCamelContextPerClass();
@@ -360,8 +359,6 @@ public abstract class CamelTestSupport
         watch.restart();
     }
 
-
-
     private void createCamelContextPerClass() throws Exception {
         INSTANCE.set(this);
         AtomicInteger v = TESTS.get();
@@ -372,7 +369,6 @@ public abstract class CamelTestSupport
         if (v.getAndIncrement() == 0) {
             LOG.debug("Setup CamelContext before running first test");
             // test is per class, so only setup once (the first time)
-            doSpringBootCheck();
             setupResources();
             doPreSetup();
             doSetUp();
@@ -401,10 +397,12 @@ public abstract class CamelTestSupport
 
     /**
      * Detects if this is a Spring-Boot test and throws an exception, as these base classes is not intended for testing
-     * Camel on Spring Boot.
+     * Camel on Spring Boot. Use ExtensionHelper.hasClassAnnotation instead
      */
+    @Deprecated(since = "4.7.0")
     protected void doSpringBootCheck() {
-        boolean springBoot = ExtensionHelper.hasClassAnnotation(getClass(),"org.springframework.boot.test.context.SpringBootTest");
+        boolean springBoot
+                = ExtensionHelper.hasClassAnnotation(getClass(), "org.springframework.boot.test.context.SpringBootTest");
         if (springBoot) {
             throw new RuntimeException(
                     "Spring Boot detected: The CamelTestSupport/CamelSpringTestSupport class is not intended for Camel testing with Spring Boot.");
@@ -413,10 +411,12 @@ public abstract class CamelTestSupport
 
     /**
      * Detects if this is a Camel-quarkus test and throw an exception, as these base classes is not intended for testing
-     * Camel onQuarkus.
+     * Camel onQuarkus. Use ExtensionHelper.hasClassAnnotation instead.
      */
+    @Deprecated(since = "4.7.0")
     protected void doQuarkusCheck() {
-        boolean quarkus = ExtensionHelper.hasClassAnnotation(getClass(), "io.quarkus.test.junit.QuarkusTest", "org.apache.camel.quarkus.test.CamelQuarkusTest");
+        boolean quarkus = ExtensionHelper.hasClassAnnotation(getClass(), "io.quarkus.test.junit.QuarkusTest",
+                "org.apache.camel.quarkus.test.CamelQuarkusTest");
         if (quarkus) {
             throw new RuntimeException(
                     "Quarkus detected: The CamelTestSupport/CamelSpringTestSupport class is not intended for Camel testing with Quarkus.");
diff --git a/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/util/ExtensionHelper.java b/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/util/ExtensionHelper.java
index 9b8bddfe0f9..f1d3a2b1762 100644
--- a/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/util/ExtensionHelper.java
+++ b/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/util/ExtensionHelper.java
@@ -18,6 +18,7 @@
 package org.apache.camel.test.junit5.util;
 
 import java.lang.annotation.Annotation;
+import java.util.function.Consumer;
 
 import org.apache.camel.util.TimeUtils;
 import org.slf4j.Logger;
@@ -26,11 +27,46 @@ import org.slf4j.LoggerFactory;
 public final class ExtensionHelper {
     private static final Logger LOG = LoggerFactory.getLogger(ExtensionHelper.class);
     public static final String SEPARATOR = "*".repeat(80);
+    private static final String SPRING_BOOT_TEST = "org.springframework.boot.test.context.SpringBootTest";
+    private static final String QUARKUS_TEST = "io.quarkus.test.junit.QuarkusTest";
+    private static final String CAMEL_QUARKUS_TEST = "org.apache.camel.quarkus.test.CamelQuarkusTest";
+
+    private static void throwUnsupportedClassException(String name) {
+        switch (name) {
+            case SPRING_BOOT_TEST:
+                throw new RuntimeException(
+                        "Spring Boot detected: The CamelTestSupport/CamelSpringTestSupport class is not intended for Camel testing with Spring Boot.");
+            case QUARKUS_TEST:
+            case CAMEL_QUARKUS_TEST: {
+                throw new RuntimeException(
+                        "Quarkus detected: The CamelTestSupport/CamelSpringTestSupport class is not intended for Camel testing with Quarkus.");
+            }
+        }
+
+        throw new RuntimeException(
+                "Unspecified class detected: The " + name + " class is not intended for Camel testing");
+    }
+
+    public static boolean hasUnsupported(Class<?> clazz) {
+        hasClassAnnotation(clazz, ExtensionHelper::throwUnsupportedClassException, SPRING_BOOT_TEST, QUARKUS_TEST,
+                CAMEL_QUARKUS_TEST);
+        return true;
+    }
 
     /**
      * Does the test class have any of the following annotations on the class-level?
-     * @return true if has or false otherwise
      */
+    public static void hasClassAnnotation(Class<?> clazz, Consumer<String> classConsumer, String... names) {
+        for (String name : names) {
+            for (Annotation ann : clazz.getAnnotations()) {
+                String annName = ann.annotationType().getName();
+                if (annName.equals(name)) {
+                    classConsumer.accept(name);
+                }
+            }
+        }
+    }
+
     public static boolean hasClassAnnotation(Class<?> clazz, String... names) {
         for (String name : names) {
             for (Annotation ann : clazz.getAnnotations()) {
@@ -56,7 +92,8 @@ public final class ExtensionHelper {
         LOG.info(SEPARATOR);
     }
 
-    public static void testEndFooter(Class<?> testClass, String currentTestName, long time, RouteCoverageDumperExtension routeCoverageWrapper)
+    public static void testEndFooter(
+            Class<?> testClass, String currentTestName, long time, RouteCoverageDumperExtension routeCoverageWrapper)
             throws Exception {
         LOG.info(SEPARATOR);
         LOG.info("Testing done: {} ({})", currentTestName, testClass.getName());


(camel) 04/05: (chores) camel-test-junit5: decouple the logging from the base class

Posted by or...@apache.org.
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 75ff061a6dba466085c40e1e865bf5f20331bfee
Author: Otavio Rodolfo Piske <an...@gmail.com>
AuthorDate: Tue May 14 17:22:09 2024 +0200

    (chores) camel-test-junit5: decouple the logging from the base class
---
 .../apache/camel/test/junit5/CamelTestSupport.java | 46 +++++-------------
 .../camel/test/junit5/util/ExtensionHelper.java    | 32 +++++++++++++
 .../junit5/util/RouteCoverageDumperExtension.java  | 54 ++++++++++++++++++++++
 3 files changed, 97 insertions(+), 35 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 c35fc26ce9b..79bc99244fa 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
@@ -16,7 +16,6 @@
  */
 package org.apache.camel.test.junit5;
 
-import java.lang.annotation.Annotation;
 import java.net.URISyntaxException;
 import java.util.HashMap;
 import java.util.Map;
@@ -40,8 +39,6 @@ import org.apache.camel.RoutesBuilder;
 import org.apache.camel.RuntimeCamelException;
 import org.apache.camel.Service;
 import org.apache.camel.ServiceStatus;
-import org.apache.camel.api.management.ManagedCamelContext;
-import org.apache.camel.api.management.mbean.ManagedCamelContextMBean;
 import org.apache.camel.builder.AdviceWith;
 import org.apache.camel.builder.AdviceWithRouteBuilder;
 import org.apache.camel.builder.RouteBuilder;
@@ -55,16 +52,14 @@ import org.apache.camel.model.ProcessorDefinition;
 import org.apache.camel.spi.CamelBeanPostProcessor;
 import org.apache.camel.spi.Language;
 import org.apache.camel.spi.PropertiesComponent;
-import org.apache.camel.spi.PropertiesSource;
 import org.apache.camel.spi.Registry;
 import org.apache.camel.support.BreakpointSupport;
 import org.apache.camel.support.EndpointHelper;
 import org.apache.camel.support.PluginHelper;
-import org.apache.camel.test.CamelRouteCoverageDumper;
 import org.apache.camel.test.junit5.util.ExtensionHelper;
+import org.apache.camel.test.junit5.util.RouteCoverageDumperExtension;
 import org.apache.camel.util.StopWatch;
 import org.apache.camel.util.StringHelper;
-import org.apache.camel.util.TimeUtils;
 import org.apache.camel.util.URISupport;
 import org.junit.jupiter.api.AfterEach;
 import org.junit.jupiter.api.BeforeEach;
@@ -81,6 +76,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import static org.apache.camel.test.junit5.TestSupport.isCamelDebugPresent;
+import static org.apache.camel.test.junit5.util.ExtensionHelper.testStartHeader;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
 
 /**
@@ -103,7 +99,7 @@ public abstract class CamelTestSupport
     private static final ThreadLocal<FluentProducerTemplate> THREAD_FLUENT_TEMPLATE = new ThreadLocal<>();
     private static final ThreadLocal<ConsumerTemplate> THREAD_CONSUMER = new ThreadLocal<>();
     private static final ThreadLocal<Service> THREAD_SERVICE = new ThreadLocal<>();
-    public static final String SEPARATOR = "********************************************************************************";
+
     protected Properties extra;
     protected volatile ModelCamelContext context;
     protected volatile ProducerTemplate template;
@@ -120,7 +116,7 @@ public abstract class CamelTestSupport
     private static final ThreadLocal<CamelTestSupport> INSTANCE = new ThreadLocal<>();
     private String currentTestName;
     private boolean isCreateCamelContextPerClass = false;
-    private final CamelRouteCoverageDumper routeCoverageDumper = new CamelRouteCoverageDumper();
+
     private ExtensionContext.Store globalStore;
 
     @Override
@@ -133,6 +129,7 @@ public abstract class CamelTestSupport
         watch.restart();
     }
 
+    @Deprecated(since = "4.7.0")
     public long timeTaken() {
         return watch.taken();
     }
@@ -344,9 +341,7 @@ public abstract class CamelTestSupport
 
     @BeforeEach
     public void setUp() throws Exception {
-        LOG.info(SEPARATOR);
-        LOG.info("Testing: {} ({})", currentTestName, getClass().getName());
-        LOG.info(SEPARATOR);
+        testStartHeader(getClass(), currentTestName);
 
         doSpringBootCheck();
         doQuarkusCheck();
@@ -365,6 +360,8 @@ public abstract class CamelTestSupport
         watch.restart();
     }
 
+
+
     private void createCamelContextPerClass() throws Exception {
         INSTANCE.set(this);
         AtomicInteger v = TESTS.get();
@@ -590,15 +587,11 @@ public abstract class CamelTestSupport
     public void tearDown() throws Exception {
         long time = watch.taken();
 
-        LOG.info(SEPARATOR);
-        LOG.info("Testing done: {} ({})", currentTestName, getClass().getName());
-        LOG.info("Took: {} ({} millis)", TimeUtils.printDuration(time, true), time);
-
-        // if we should dump route stats, then write that to a file
         if (isRouteCoverageEnabled()) {
-            dumpRouteCoverage();
+            ExtensionHelper.testEndFooter(getClass(), currentTestName, time, new RouteCoverageDumperExtension(context));
+        } else {
+            ExtensionHelper.testEndFooter(getClass(), currentTestName, time);
         }
-        LOG.info(SEPARATOR);
 
         if (isCreateCamelContextPerClass()) {
             // will tear down test specially in afterAll callback
@@ -613,23 +606,6 @@ public abstract class CamelTestSupport
 
     }
 
-    private void dumpRouteCoverage() throws Exception {
-        String className = this.getClass().getSimpleName();
-        String dir = "target/camel-route-coverage";
-        String name = className + "-" + StringHelper.before(currentTestName, "(") + ".xml";
-
-        ManagedCamelContext mc
-                = context != null ? context.getCamelContextExtension().getContextPlugin(ManagedCamelContext.class) : null;
-        ManagedCamelContextMBean managedCamelContext = mc != null ? mc.getManagedCamelContext() : null;
-        if (managedCamelContext == null) {
-            LOG.warn("Cannot dump route coverage to file as JMX is not enabled. "
-                     + "Add camel-management JAR as dependency and/or override useJmx() method to enable JMX in the unit test classes.");
-        } else {
-            routeCoverageDumper.dump(managedCamelContext, context, dir, name, getClass().getName(), currentTestName,
-                    timeTaken());
-        }
-    }
-
     void tearDownCreateCamelContextPerClass() throws Exception {
         LOG.debug("tearDownCreateCamelContextPerClass()");
         TESTS.remove();
diff --git a/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/util/ExtensionHelper.java b/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/util/ExtensionHelper.java
index 64f356b78ac..9b8bddfe0f9 100644
--- a/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/util/ExtensionHelper.java
+++ b/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/util/ExtensionHelper.java
@@ -19,7 +19,13 @@ package org.apache.camel.test.junit5.util;
 
 import java.lang.annotation.Annotation;
 
+import org.apache.camel.util.TimeUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
 public final class ExtensionHelper {
+    private static final Logger LOG = LoggerFactory.getLogger(ExtensionHelper.class);
+    public static final String SEPARATOR = "*".repeat(80);
 
     /**
      * Does the test class have any of the following annotations on the class-level?
@@ -36,4 +42,30 @@ public final class ExtensionHelper {
         }
         return false;
     }
+
+    public static void testStartHeader(Class<?> testClass, String currentTestName) {
+        LOG.info(SEPARATOR);
+        LOG.info("Testing: {} ({})", currentTestName, testClass.getName());
+        LOG.info(SEPARATOR);
+    }
+
+    public static void testEndFooter(Class<?> testClass, String currentTestName, long time) {
+        LOG.info(SEPARATOR);
+        LOG.info("Testing done: {} ({})", currentTestName, testClass.getName());
+        LOG.info("Took: {} ({} millis)", TimeUtils.printDuration(time, true), time);
+        LOG.info(SEPARATOR);
+    }
+
+    public static void testEndFooter(Class<?> testClass, String currentTestName, long time, RouteCoverageDumperExtension routeCoverageWrapper)
+            throws Exception {
+        LOG.info(SEPARATOR);
+        LOG.info("Testing done: {} ({})", currentTestName, testClass.getName());
+        LOG.info("Took: {} ({} millis)", TimeUtils.printDuration(time, true), time);
+
+        if (routeCoverageWrapper != null) {
+            routeCoverageWrapper.dumpRouteCoverage(testClass, currentTestName, time);
+        }
+
+        LOG.info(SEPARATOR);
+    }
 }
diff --git a/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/util/RouteCoverageDumperExtension.java b/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/util/RouteCoverageDumperExtension.java
new file mode 100644
index 00000000000..6d0ac31a8d5
--- /dev/null
+++ b/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/util/RouteCoverageDumperExtension.java
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.camel.test.junit5.util;
+
+import org.apache.camel.api.management.ManagedCamelContext;
+import org.apache.camel.api.management.mbean.ManagedCamelContextMBean;
+import org.apache.camel.model.ModelCamelContext;
+import org.apache.camel.test.CamelRouteCoverageDumper;
+import org.apache.camel.util.StringHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class RouteCoverageDumperExtension {
+    private static final Logger LOG = LoggerFactory.getLogger(RouteCoverageDumperExtension.class);
+    private final ModelCamelContext context;
+
+    public RouteCoverageDumperExtension(ModelCamelContext context) {
+        this.context = context;
+    }
+
+    public void dumpRouteCoverage(Class<?> testClass, String currentTestName, long taken) throws Exception {
+        String className = testClass.getSimpleName();
+        String dir = "target/camel-route-coverage";
+        String name = className + "-" + StringHelper.before(currentTestName, "(") + ".xml";
+
+        CamelRouteCoverageDumper routeCoverageDumper = new CamelRouteCoverageDumper();
+
+        ManagedCamelContext mc
+                = context != null ? context.getCamelContextExtension().getContextPlugin(ManagedCamelContext.class) : null;
+        ManagedCamelContextMBean managedCamelContext = mc != null ? mc.getManagedCamelContext() : null;
+        if (managedCamelContext == null) {
+            LOG.warn("Cannot dump route coverage to file as JMX is not enabled. "
+                     + "Add camel-management JAR as dependency and/or override useJmx() method to enable JMX in the unit test classes.");
+        } else {
+            routeCoverageDumper.dump(managedCamelContext, context, dir, name, getClass().getName(), currentTestName,
+                    taken);
+        }
+    }
+}


(camel) 01/05: (chores) camel-test-junit5: decouple the hasAnnotationCheck

Posted by or...@apache.org.
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 042c9797bc94b6863c69e1779965fab6617cadf0
Author: Otavio Rodolfo Piske <an...@gmail.com>
AuthorDate: Tue May 14 16:54:30 2024 +0200

    (chores) camel-test-junit5: decouple the hasAnnotationCheck
---
 .../apache/camel/test/junit5/CamelTestSupport.java | 19 ++++-------
 .../camel/test/junit5/util/ExtensionHelper.java    | 39 ++++++++++++++++++++++
 2 files changed, 45 insertions(+), 13 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 4aae8bc3962..4f565b8c195 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
@@ -61,6 +61,7 @@ import org.apache.camel.support.BreakpointSupport;
 import org.apache.camel.support.EndpointHelper;
 import org.apache.camel.support.PluginHelper;
 import org.apache.camel.test.CamelRouteCoverageDumper;
+import org.apache.camel.test.junit5.util.ExtensionHelper;
 import org.apache.camel.util.StopWatch;
 import org.apache.camel.util.StringHelper;
 import org.apache.camel.util.TimeUtils;
@@ -406,7 +407,7 @@ public abstract class CamelTestSupport
      * Camel on Spring Boot.
      */
     protected void doSpringBootCheck() {
-        boolean springBoot = hasClassAnnotation("org.springframework.boot.test.context.SpringBootTest");
+        boolean springBoot = ExtensionHelper.hasClassAnnotation(getClass(),"org.springframework.boot.test.context.SpringBootTest");
         if (springBoot) {
             throw new RuntimeException(
                     "Spring Boot detected: The CamelTestSupport/CamelSpringTestSupport class is not intended for Camel testing with Spring Boot.");
@@ -418,8 +419,7 @@ public abstract class CamelTestSupport
      * Camel onQuarkus.
      */
     protected void doQuarkusCheck() {
-        boolean quarkus = hasClassAnnotation("io.quarkus.test.junit.QuarkusTest") ||
-                hasClassAnnotation("org.apache.camel.quarkus.test.CamelQuarkusTest");
+        boolean quarkus = ExtensionHelper.hasClassAnnotation(getClass(), "io.quarkus.test.junit.QuarkusTest", "org.apache.camel.quarkus.test.CamelQuarkusTest");
         if (quarkus) {
             throw new RuntimeException(
                     "Quarkus detected: The CamelTestSupport/CamelSpringTestSupport class is not intended for Camel testing with Quarkus.");
@@ -727,7 +727,7 @@ public abstract class CamelTestSupport
     protected void applyCamelPostProcessor() throws Exception {
         // use the bean post processor if the test class is not dependency
         // injected already by Spring Framework
-        boolean spring = hasClassAnnotation("org.springframework.boot.test.context.SpringBootTest",
+        boolean spring = ExtensionHelper.hasClassAnnotation(getClass(), "org.springframework.boot.test.context.SpringBootTest",
                 "org.springframework.context.annotation.ComponentScan");
         if (!spring) {
             PluginHelper.getBeanPostProcessor(context).postProcessBeforeInitialization(this,
@@ -740,16 +740,9 @@ public abstract class CamelTestSupport
     /**
      * Does this test class have any of the following annotations on the class-level.
      */
+    @Deprecated
     protected boolean hasClassAnnotation(String... names) {
-        for (String name : names) {
-            for (Annotation ann : getClass().getAnnotations()) {
-                String annName = ann.annotationType().getName();
-                if (annName.equals(name)) {
-                    return true;
-                }
-            }
-        }
-        return false;
+        return ExtensionHelper.hasClassAnnotation(getClass(), names);
     }
 
     protected void stopCamelContext() throws Exception {
diff --git a/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/util/ExtensionHelper.java b/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/util/ExtensionHelper.java
new file mode 100644
index 00000000000..64f356b78ac
--- /dev/null
+++ b/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/util/ExtensionHelper.java
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.camel.test.junit5.util;
+
+import java.lang.annotation.Annotation;
+
+public final class ExtensionHelper {
+
+    /**
+     * Does the test class have any of the following annotations on the class-level?
+     * @return true if has or false otherwise
+     */
+    public static boolean hasClassAnnotation(Class<?> clazz, String... names) {
+        for (String name : names) {
+            for (Annotation ann : clazz.getAnnotations()) {
+                String annName = ann.annotationType().getName();
+                if (annName.equals(name)) {
+                    return true;
+                }
+            }
+        }
+        return false;
+    }
+}


(camel) 03/05: (chores) camel-test-junit5: move the JUnitPropertiesSource to a separate class

Posted by or...@apache.org.
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 46b33293bd840aaf59947147f6530a5b1ff62c36
Author: Otavio Rodolfo Piske <an...@gmail.com>
AuthorDate: Tue May 14 17:03:10 2024 +0200

    (chores) camel-test-junit5: move the JUnitPropertiesSource to a separate class
---
 .../apache/camel/test/junit5/CamelTestSupport.java | 12 +------
 .../camel/test/junit5/JunitPropertiesSource.java   | 39 ++++++++++++++++++++++
 2 files changed, 40 insertions(+), 11 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 60d8103ff03..c35fc26ce9b 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
@@ -539,17 +539,7 @@ public abstract class CamelTestSupport
         if (extra != null && !extra.isEmpty()) {
             pc.setOverrideProperties(extra);
         }
-        pc.addPropertiesSource(new PropertiesSource() {
-            @Override
-            public String getName() {
-                return "junit-store";
-            }
-
-            @Override
-            public String getProperty(String name) {
-                return globalStore.get(name, String.class);
-            }
-        });
+        pc.addPropertiesSource(new JunitPropertiesSource(globalStore));
         Boolean ignore = ignoreMissingLocationWithPropertiesComponent();
         if (ignore != null) {
             pc.setIgnoreMissingLocation(ignore);
diff --git a/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/JunitPropertiesSource.java b/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/JunitPropertiesSource.java
new file mode 100644
index 00000000000..e52c4637891
--- /dev/null
+++ b/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/JunitPropertiesSource.java
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.camel.test.junit5;
+
+import org.apache.camel.spi.PropertiesSource;
+import org.junit.jupiter.api.extension.ExtensionContext;
+
+class JunitPropertiesSource implements PropertiesSource {
+    private final ExtensionContext.Store globalStore;
+
+    JunitPropertiesSource(ExtensionContext.Store globalStore) {
+        this.globalStore = globalStore;
+    }
+
+    @Override
+    public String getName() {
+        return "junit-store";
+    }
+
+    @Override
+    public String getProperty(String name) {
+        return globalStore.get(name, String.class);
+    }
+}


(camel) 02/05: (chores) camel-test-junit5: remove SpringBootTest from the applyCamelPostProcessor

Posted by or...@apache.org.
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 cc07a915dd42456908ed65e6afd108ec8a99c33a
Author: Otavio Rodolfo Piske <an...@gmail.com>
AuthorDate: Tue May 14 17:01:30 2024 +0200

    (chores) camel-test-junit5: remove SpringBootTest from the applyCamelPostProcessor
    
    This class is blocked in setup and, therefore, unsupported for testing
---
 .../src/main/java/org/apache/camel/test/junit5/CamelTestSupport.java   | 3 +--
 1 file changed, 1 insertion(+), 2 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 4f565b8c195..60d8103ff03 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
@@ -727,8 +727,7 @@ public abstract class CamelTestSupport
     protected void applyCamelPostProcessor() throws Exception {
         // use the bean post processor if the test class is not dependency
         // injected already by Spring Framework
-        boolean spring = ExtensionHelper.hasClassAnnotation(getClass(), "org.springframework.boot.test.context.SpringBootTest",
-                "org.springframework.context.annotation.ComponentScan");
+        boolean spring = ExtensionHelper.hasClassAnnotation(getClass(), "org.springframework.context.annotation.ComponentScan");
         if (!spring) {
             PluginHelper.getBeanPostProcessor(context).postProcessBeforeInitialization(this,
                     getClass().getName());