aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From csie...@apache.org
Subject svn commit: r1784748 - /aries/trunk/component-dsl/itests/src/main/java/org/apache/aries/osgi/functional/test/DSLTest.java
Date Tue, 28 Feb 2017 14:48:57 GMT
Author: csierra
Date: Tue Feb 28 14:48:57 2017
New Revision: 1784748

URL: http://svn.apache.org/viewvc?rev=1784748&view=rev
Log:
Add test to show programmatic dependencies

Modified:
    aries/trunk/component-dsl/itests/src/main/java/org/apache/aries/osgi/functional/test/DSLTest.java

Modified: aries/trunk/component-dsl/itests/src/main/java/org/apache/aries/osgi/functional/test/DSLTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/component-dsl/itests/src/main/java/org/apache/aries/osgi/functional/test/DSLTest.java?rev=1784748&r1=1784747&r2=1784748&view=diff
==============================================================================
--- aries/trunk/component-dsl/itests/src/main/java/org/apache/aries/osgi/functional/test/DSLTest.java
(original)
+++ aries/trunk/component-dsl/itests/src/main/java/org/apache/aries/osgi/functional/test/DSLTest.java
Tue Feb 28 14:48:57 2017
@@ -31,11 +31,13 @@ import org.osgi.service.cm.Configuration
 import org.osgi.service.cm.ManagedServiceFactory;
 
 import java.io.IOException;
+import java.util.Arrays;
 import java.util.Dictionary;
 import java.util.HashMap;
 import java.util.Hashtable;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.concurrent.atomic.AtomicInteger;
 import java.util.concurrent.atomic.AtomicReference;
 
@@ -45,7 +47,9 @@ import static org.apache.aries.osgi.func
 import static org.apache.aries.osgi.functional.OSGi.onClose;
 import static org.apache.aries.osgi.functional.OSGi.register;
 import static org.apache.aries.osgi.functional.OSGi.serviceReferences;
+import static org.apache.aries.osgi.functional.OSGi.services;
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
@@ -425,6 +429,75 @@ public class DSLTest {
         bundleContext.ungetService(serviceReference);
     }
 
+    @Test
+    public void testProgrammaticDependencies() {
+        AtomicBoolean executed = new AtomicBoolean(false);
+        AtomicBoolean closed = new AtomicBoolean(false);
+
+        String[] filters = {
+            "(key=service one)",
+            "(key=service two)",
+            "(key=service three)"
+        };
+
+        OSGi<?> program =
+            onClose(() -> closed.set(true)).foreach(
+            ign -> executed.set(true)
+        );
+
+        for (String filter : filters) {
+            program = services(filter).then(program);
+        }
+
+        OSGiResult<?> result = program.run(bundleContext);
+
+        try {
+            assertFalse(closed.get());
+            assertFalse(executed.get());
+
+            ServiceRegistration<Service> serviceRegistrationOne =
+                bundleContext.registerService(
+                    Service.class, new Service(),
+                    new Hashtable<String, Object>() {{
+                        put("key", "service one");
+                    }});
+
+            assertFalse(closed.get());
+            assertFalse(executed.get());
+
+            ServiceRegistration<Service> serviceRegistrationTwo =
+                bundleContext.registerService(
+                    Service.class, new Service(),
+                    new Hashtable<String, Object>() {{
+                        put("key", "service two");
+                    }});
+
+            assertFalse(closed.get());
+            assertFalse(executed.get());
+
+            ServiceRegistration<Service> serviceRegistrationThree =
+                bundleContext.registerService(
+                    Service.class, new Service(),
+                    new Hashtable<String, Object>() {{
+                        put("key", "service three");
+                    }});
+
+            assertFalse(closed.get());
+            assertTrue(executed.get());
+
+            serviceRegistrationOne.unregister();
+
+            assertTrue(closed.get());
+
+            serviceRegistrationTwo.unregister();
+            serviceRegistrationThree.unregister();
+        }
+        finally {
+            result.close();
+        }
+
+    }
+
     private class Service {}
 
 }



Mime
View raw message