geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r767090 [2/2] - in /geronimo/sandbox/blueprint: blueprint-core/src/main/java/org/apache/geronimo/blueprint/ blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/ blueprint-core/src/main/java/org/apache/geronimo/blueprint/utils...
Date Tue, 21 Apr 2009 09:46:41 GMT
Added: geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/utils/DynamicCollectionTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/utils/DynamicCollectionTest.java?rev=767090&view=auto
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/utils/DynamicCollectionTest.java
(added)
+++ geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/utils/DynamicCollectionTest.java
Tue Apr 21 09:46:41 2009
@@ -0,0 +1,124 @@
+/*
+ * 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.geronimo.blueprint.utils;
+
+import java.util.Iterator;
+
+import junit.framework.TestCase;
+
+public class DynamicCollectionTest extends TestCase {
+
+    protected static final Object O0 = new Object();
+    protected static final Object O1 = new Object();
+    protected static final Object O2 = new Object();
+    protected static final Object O3 = new Object();
+
+    protected DynamicCollection<Object> collection;
+
+    protected void setUp() {
+        collection = new DynamicCollection<Object>();
+    }
+
+    public void testAddRemove() throws Exception {
+        assertEquals(0, collection.size());
+        assertTrue(collection.isEmpty());
+        collection.add(O0);
+        assertEquals(1, collection.size());
+        assertFalse(collection.isEmpty());
+        assertTrue(collection.contains(O0));
+        assertFalse(collection.contains(O1));
+        collection.clear();
+        assertEquals(0, collection.size());
+        collection.add(O0);
+        collection.add(O0);
+        assertEquals(2, collection.size());
+        assertTrue(collection.remove(O0));
+        assertEquals(1, collection.size());
+        assertTrue(collection.remove(O0));
+        assertEquals(0, collection.size());
+    }
+
+    public void testSimpleIterator() throws Exception {
+        collection.add(O0);
+
+        Iterator iterator = collection.iterator();
+        assertTrue(iterator.hasNext());
+        assertEquals(O0, iterator.next());
+        assertFalse(iterator.hasNext());
+    }
+
+    public void testAddWhileIterating() throws Exception {
+        Iterator iterator = collection.iterator();
+        assertFalse(iterator.hasNext());
+
+        collection.add(O0);
+        assertTrue(iterator.hasNext());
+        assertEquals(O0, iterator.next());
+        assertFalse(iterator.hasNext());
+    }
+
+    public void testRemoveElementWhileIterating() throws Exception {
+        collection.add(O0);
+        collection.add(O1);
+
+        Iterator iterator = collection.iterator();
+        assertTrue(iterator.hasNext());
+        collection.remove(O0);
+        assertEquals(O0, iterator.next());
+        assertTrue(iterator.hasNext());
+        assertEquals(O1, iterator.next());
+        assertFalse(iterator.hasNext());
+    }
+
+    public void testRemoveElementAfterWhileIterating() throws Exception {
+        collection.add(O0);
+        collection.add(O1);
+
+        Iterator iterator = collection.iterator();
+        assertTrue(iterator.hasNext());
+        assertEquals(O0, iterator.next());
+        collection.remove(O1);
+        assertFalse(iterator.hasNext());
+    }
+
+    public void testRemoveElementBeforeWhileIterating() throws Exception {
+        collection.add(O0);
+        collection.add(O1);
+
+        Iterator iterator = collection.iterator();
+        assertTrue(iterator.hasNext());
+        assertEquals(O0, iterator.next());
+        collection.remove(O0);
+        assertTrue(iterator.hasNext());
+        assertEquals(O1, iterator.next());
+        assertFalse(iterator.hasNext());
+    }
+
+    public void testIteratorRemove() throws Exception {
+        collection.add(O0);
+
+        Iterator iterator = collection.iterator();
+        assertTrue(iterator.hasNext());
+        assertEquals(O0, iterator.next());
+        iterator.remove();
+        assertFalse(iterator.hasNext());
+        assertTrue(collection.isEmpty());
+        assertFalse(iterator.hasNext());
+    }
+}

Modified: geronimo/sandbox/blueprint/blueprint-itests/src/test/java/org/apache/geronimo/blueprint/itests/TestReferences.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-itests/src/test/java/org/apache/geronimo/blueprint/itests/TestReferences.java?rev=767090&r1=767089&r2=767090&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-itests/src/test/java/org/apache/geronimo/blueprint/itests/TestReferences.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-itests/src/test/java/org/apache/geronimo/blueprint/itests/TestReferences.java
Tue Apr 21 09:46:41 2009
@@ -21,6 +21,7 @@
 import java.net.URLDecoder;
 import java.util.Properties;
 import java.util.Hashtable;
+import java.util.List;
 
 import org.apache.servicemix.kernel.testing.support.AbstractIntegrationTest;
 import org.apache.geronimo.blueprint.sample.Foo;
@@ -89,6 +90,32 @@
         }
     }
 
+    public void testListReferences() throws Exception {
+        ModuleContext moduleContext = getOsgiService(ModuleContext.class, 5000);
+        assertNotNull(moduleContext);
+
+        BindingListener listener = (BindingListener) moduleContext.getComponent("listBindingListener");
+        assertNull(listener.getA());
+        assertNull(listener.getReference());
+
+        List refs = (List) moduleContext.getComponent("ref-list");
+        assertNotNull(refs);
+        assertTrue(refs.isEmpty());
+
+        ServiceRegistration reg1 = bundleContext.registerService(InterfaceA.class.getName(),
new InterfaceA() {
+            public String hello(String msg) {
+                return "Hello " + msg + "!";
+            }
+        }, null);
+        assertNotNull(listener.getA());
+        assertNotNull(listener.getReference());
+        assertEquals(1, refs.size());
+        InterfaceA a = (InterfaceA) refs.get(0);
+        assertNotNull(a);
+        assertEquals("Hello world!", a.hello("world"));
+
+    }
+
     /**
 	 * The manifest to use for the "virtual bundle" created
 	 * out of the test classes and resources in this project

Modified: geronimo/sandbox/blueprint/blueprint-sample/src/main/resources/OSGI-INF/blueprint/config.xml
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-sample/src/main/resources/OSGI-INF/blueprint/config.xml?rev=767090&r1=767089&r2=767090&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-sample/src/main/resources/OSGI-INF/blueprint/config.xml
(original)
+++ geronimo/sandbox/blueprint/blueprint-sample/src/main/resources/OSGI-INF/blueprint/config.xml
Tue Apr 21 09:46:41 2009
@@ -54,5 +54,11 @@
 
     <component id="bindingListener" class="org.apache.geronimo.blueprint.sample.BindingListener"/>
 
+    <ref-list id="ref-list" interface="org.apache.geronimo.blueprint.sample.InterfaceA">
+        <listener bind-method="bind" unbind-method="unbind" ref="listBindingListener"
/>
+    </ref-list>
+
+    <component id="listBindingListener" class="org.apache.geronimo.blueprint.sample.BindingListener"/>
+
 </components>
 



Mime
View raw message