CAMEL-8000: Need the clear for testing purposes.

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

Branch: refs/heads/master
Commit: b306a54163f39b2c789e5109e4bfdf383358e7f3
Parents: 0148123
Author: Claus Ibsen <davscl...@apache.org>
Authored: Fri Nov 14 17:16:49 2014 +0100
Committer: Claus Ibsen <davscl...@apache.org>
Committed: Fri Nov 14 17:22:28 2014 +0100

----------------------------------------------------------------------
 .../camel/impl/DefaultCamelContextRegistry.java |  5 ++
 .../apache/camel/spi/CamelContextRegistry.java  |  5 ++
 .../camel/impl/CamelContextRegistryTest.java    | 77 ++++++++++++++++++++
 .../camel/spi/CamelContextRegistryTest.java     | 75 -------------------
 4 files changed, 87 insertions(+), 75 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/b306a541/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContextRegistry.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContextRegistry.java
 
b/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContextRegistry.java
index 75a2f5f..6d65441 100644
--- 
a/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContextRegistry.java
+++ 
b/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContextRegistry.java
@@ -128,4 +128,9 @@ public final class DefaultCamelContextRegistry implements 
CamelContextRegistry {
         return it.hasNext() ? it.next() : null;
     }
 
+    @Override
+    public synchronized void clear() {
+        contexts.clear();
+        listeners.clear();
+    }
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/b306a541/camel-core/src/main/java/org/apache/camel/spi/CamelContextRegistry.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/main/java/org/apache/camel/spi/CamelContextRegistry.java 
b/camel-core/src/main/java/org/apache/camel/spi/CamelContextRegistry.java
index 78d10ca..164fa91 100644
--- a/camel-core/src/main/java/org/apache/camel/spi/CamelContextRegistry.java
+++ b/camel-core/src/main/java/org/apache/camel/spi/CamelContextRegistry.java
@@ -96,4 +96,9 @@ public interface CamelContextRegistry {
      */
     CamelContext getContext(String name);
 
+    /**
+     * Needed for testing purposes.
+     */
+    void clear();
+
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/b306a541/camel-core/src/test/java/org/apache/camel/impl/CamelContextRegistryTest.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/test/java/org/apache/camel/impl/CamelContextRegistryTest.java 
b/camel-core/src/test/java/org/apache/camel/impl/CamelContextRegistryTest.java
new file mode 100644
index 0000000..222556d
--- /dev/null
+++ 
b/camel-core/src/test/java/org/apache/camel/impl/CamelContextRegistryTest.java
@@ -0,0 +1,77 @@
+/**
+ * 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.impl;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import junit.framework.TestCase;
+import org.apache.camel.CamelContext;
+import org.apache.camel.spi.CamelContextRegistry;
+
+public class CamelContextRegistryTest extends TestCase {
+
+    private final class MyListener extends CamelContextRegistry.Listener {
+
+        private List<String> names = new ArrayList<String>();
+
+        @Override
+        public void contextAdded(CamelContext camelContext) {
+            names.add(camelContext.getName());
+        }
+
+        @Override
+        public void contextRemoved(CamelContext camelContext) {
+            names.remove(camelContext.getName());
+        }
+    }
+
+    public void testContainerSet() throws Exception {
+
+        // must clear for testing purpose
+        CamelContextRegistry.INSTANCE.clear();
+
+        MyListener listener = new MyListener();
+
+        CamelContext camel1 = new DefaultCamelContext();
+        CamelContext camel2 = new DefaultCamelContext();
+
+        assertEquals(0, listener.names.size());
+
+        try {
+            CamelContextRegistry.INSTANCE.addListener(listener, true);
+               
+            // after we set, then we should manage the 2 pending contexts
+            assertEquals(2, listener.names.size());
+
+            CamelContext camel3 = new DefaultCamelContext();
+            assertEquals(3, listener.names.size());
+            assertEquals(camel1.getName(), listener.names.get(0));
+            assertEquals(camel2.getName(), listener.names.get(1));
+            assertEquals(camel3.getName(), listener.names.get(2));
+
+            camel1.stop();
+            camel2.stop();
+            camel3.stop();
+
+            assertEquals(0, listener.names.size());
+            
+        } finally {
+            CamelContextRegistry.INSTANCE.removeListener(listener, true);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/b306a541/camel-core/src/test/java/org/apache/camel/spi/CamelContextRegistryTest.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/test/java/org/apache/camel/spi/CamelContextRegistryTest.java 
b/camel-core/src/test/java/org/apache/camel/spi/CamelContextRegistryTest.java
deleted file mode 100644
index a702254..0000000
--- 
a/camel-core/src/test/java/org/apache/camel/spi/CamelContextRegistryTest.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/**
- * 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.spi;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import junit.framework.TestCase;
-
-import org.apache.camel.CamelContext;
-import org.apache.camel.impl.DefaultCamelContext;
-
-public class CamelContextRegistryTest extends TestCase {
-
-    private final class MyListener extends CamelContextRegistry.Listener {
-
-        private List<String> names = new ArrayList<String>();
-
-        @Override
-        public void contextAdded(CamelContext camelContext) {
-            names.add(camelContext.getName());
-        }
-
-        @Override
-        public void contextRemoved(CamelContext camelContext) {
-            names.remove(camelContext.getName());
-        }
-    }
-
-    public void testContainerSet() throws Exception {
-
-        MyListener listener = new MyListener();
-
-        CamelContext camel1 = new DefaultCamelContext();
-        CamelContext camel2 = new DefaultCamelContext();
-
-        assertEquals(0, listener.names.size());
-
-        try {
-            CamelContextRegistry.INSTANCE.addListener(listener, true);
-               
-            // after we set, then we should manage the 2 pending contexts
-            assertEquals(2, listener.names.size());
-
-            CamelContext camel3 = new DefaultCamelContext();
-            assertEquals(3, listener.names.size());
-            assertEquals(camel1.getName(), listener.names.get(0));
-            assertEquals(camel2.getName(), listener.names.get(1));
-            assertEquals(camel3.getName(), listener.names.get(2));
-
-            camel1.stop();
-            camel2.stop();
-            camel3.stop();
-
-            assertEquals(0, listener.names.size());
-            
-        } finally {
-            CamelContextRegistry.INSTANCE.removeListener(listener, true);
-        }
-    }
-}

Reply via email to