camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [1/2] camel git commit: CAMEL-9981: camel-test-spring may register listener twice.
Date Mon, 23 May 2016 06:54:52 GMT
Repository: camel
Updated Branches:
  refs/heads/camel-2.17.x 7a57b1dae -> 0bad5b285
  refs/heads/master 739a750c0 -> 83f909bfa


CAMEL-9981: camel-test-spring may register listener twice.


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/83f909bf
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/83f909bf
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/83f909bf

Branch: refs/heads/master
Commit: 83f909bfa5f100a8b15861676edb215d925c32af
Parents: 739a750
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Mon May 23 08:50:39 2016 +0200
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Mon May 23 08:50:39 2016 +0200

----------------------------------------------------------------------
 .../test/spring/CamelSpringBootRunner.java      | 37 +++++++++-----------
 .../camel/test/spring/CamelSpringRunner.java    | 35 +++++++++---------
 2 files changed, 33 insertions(+), 39 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/83f909bf/components/camel-test-spring/src/main/java/org/apache/camel/test/spring/CamelSpringBootRunner.java
----------------------------------------------------------------------
diff --git a/components/camel-test-spring/src/main/java/org/apache/camel/test/spring/CamelSpringBootRunner.java
b/components/camel-test-spring/src/main/java/org/apache/camel/test/spring/CamelSpringBootRunner.java
index e8f8620..dbfc3e6 100644
--- a/components/camel-test-spring/src/main/java/org/apache/camel/test/spring/CamelSpringBootRunner.java
+++ b/components/camel-test-spring/src/main/java/org/apache/camel/test/spring/CamelSpringBootRunner.java
@@ -19,7 +19,6 @@ package org.apache.camel.test.spring;
 import java.util.List;
 
 import org.junit.runners.model.InitializationError;
-import org.springframework.core.OrderComparator;
 import org.springframework.test.context.TestContextManager;
 import org.springframework.test.context.TestExecutionListener;
 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@@ -59,30 +58,28 @@ public class CamelSpringBootRunner extends SpringJUnit4ClassRunner {
             // turn off auto starting spring as we need to do this later
             System.setProperty("skipStartingCamelContext", "true");
 
-            // inject Camel first, and then disable jmx and add the stop-watch
-            // (ensure to get the current list as we need to re-order that list so Camel
comes first)
-            List<TestExecutionListener> list = getTestExecutionListeners();
-            addIfMissingType(list, new CamelSpringTestContextLoaderTestExecutionListener());
-            addIfMissingType(list, new DisableJmxTestExecutionListener());
-            addIfMissingType(list, new CamelSpringBootExecutionListener());
-            addIfMissingType(list, new StopWatchTestExecutionListener());
-            OrderComparator.sort(list);
-            registerTestExecutionListeners(list);
+            // is Camel already registered
+            if (!alreadyRegistered()) {
+                // inject Camel first, and then disable jmx and add the stop-watch
+                List<TestExecutionListener> list = getTestExecutionListeners();
+                list.add(0, new CamelSpringTestContextLoaderTestExecutionListener());
+                list.add(1, new DisableJmxTestExecutionListener());
+                list.add(2, new CamelSpringBootExecutionListener());
+                list.add(3, new StopWatchTestExecutionListener());
+            }
         }
 
-        private void addIfMissingType(List<TestExecutionListener> list, TestExecutionListener
listener) {
-            String type = listener.getClass().getName();
-            boolean found = false;
-            for (TestExecutionListener current : list) {
-                if (type.equals(current.getClass().getName())) {
-                    found = true;
-                    break;
+        private boolean alreadyRegistered() {
+            List<TestExecutionListener> list = getTestExecutionListeners();
+            if (list != null) {
+                for (TestExecutionListener listener : list) {
+                    if (listener instanceof CamelSpringTestContextLoaderTestExecutionListener)
{
+                        return true;
+                    }
                 }
             }
 
-            if (!found) {
-                list.add(listener);
-            }
+            return false;
         }
 
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/83f909bf/components/camel-test-spring/src/main/java/org/apache/camel/test/spring/CamelSpringRunner.java
----------------------------------------------------------------------
diff --git a/components/camel-test-spring/src/main/java/org/apache/camel/test/spring/CamelSpringRunner.java
b/components/camel-test-spring/src/main/java/org/apache/camel/test/spring/CamelSpringRunner.java
index 4cd9935..58a6a0e 100644
--- a/components/camel-test-spring/src/main/java/org/apache/camel/test/spring/CamelSpringRunner.java
+++ b/components/camel-test-spring/src/main/java/org/apache/camel/test/spring/CamelSpringRunner.java
@@ -19,7 +19,6 @@ package org.apache.camel.test.spring;
 import java.util.List;
 
 import org.junit.runners.model.InitializationError;
-import org.springframework.core.OrderComparator;
 import org.springframework.test.context.TestContextManager;
 import org.springframework.test.context.TestExecutionListener;
 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@@ -56,29 +55,27 @@ public class CamelSpringRunner extends SpringJUnit4ClassRunner {
         public CamelTestContextManager(Class<?> testClass) {
             super(testClass);
 
-            // inject Camel first, and then disable jmx and add the stop-watch
-            // (ensure to get the current list as we need to re-order that list so Camel
comes first)
-            List<TestExecutionListener> list = getTestExecutionListeners();
-            addIfMissingType(list, new CamelSpringTestContextLoaderTestExecutionListener());
-            addIfMissingType(list, new DisableJmxTestExecutionListener());
-            addIfMissingType(list, new StopWatchTestExecutionListener());
-            OrderComparator.sort(list);
-            registerTestExecutionListeners(list);
+            // is Camel already registered
+            if (!alreadyRegistered()) {
+                // inject Camel first, and then disable jmx and add the stop-watch
+                List<TestExecutionListener> list = getTestExecutionListeners();
+                list.add(0, new CamelSpringTestContextLoaderTestExecutionListener());
+                list.add(1, new DisableJmxTestExecutionListener());
+                list.add(2, new StopWatchTestExecutionListener());
+            }
         }
 
-        private void addIfMissingType(List<TestExecutionListener> list, TestExecutionListener
listener) {
-            String type = listener.getClass().getName();
-            boolean found = false;
-            for (TestExecutionListener current : list) {
-                if (type.equals(current.getClass().getName())) {
-                    found = true;
-                    break;
+        private boolean alreadyRegistered() {
+            List<TestExecutionListener> list = getTestExecutionListeners();
+            if (list != null) {
+                for (TestExecutionListener listener : list) {
+                    if (listener instanceof CamelSpringTestContextLoaderTestExecutionListener)
{
+                        return true;
+                    }
                 }
             }
 
-            if (!found) {
-                list.add(listener);
-            }
+            return false;
         }
 
     }


Mime
View raw message