aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cschnei...@apache.org
Subject svn commit: r1675287 - in /aries/trunk/blueprint/blueprint-itests/src/test: java/org/apache/aries/blueprint/itests/cm/ java/org/apache/aries/blueprint/itests/cm/service/ resources/
Date Wed, 22 Apr 2015 09:18:18 GMT
Author: cschneider
Date: Wed Apr 22 09:18:18 2015
New Revision: 1675287

URL: http://svn.apache.org/r1675287
Log:
[ARIES-1312] Reformatted

Added:
    aries/trunk/blueprint/blueprint-itests/src/test/resources/CmPropertiesTest.xml
      - copied, changed from r1675139, aries/trunk/blueprint/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/cm/service/CmPropertiesTest.xml
Removed:
    aries/trunk/blueprint/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/cm/service/CmPropertiesTest.xml
Modified:
    aries/trunk/blueprint/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/cm/ManagedServiceFactoryTest.java
    aries/trunk/blueprint/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/cm/ManagedServiceFactoryUseSystemBundleTest.java

Modified: aries/trunk/blueprint/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/cm/ManagedServiceFactoryTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/cm/ManagedServiceFactoryTest.java?rev=1675287&r1=1675286&r2=1675287&view=diff
==============================================================================
--- aries/trunk/blueprint/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/cm/ManagedServiceFactoryTest.java
(original)
+++ aries/trunk/blueprint/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/cm/ManagedServiceFactoryTest.java
Wed Apr 22 09:18:18 2015
@@ -45,46 +45,38 @@ import org.osgi.service.cm.Configuration
 import org.osgi.service.cm.ConfigurationAdmin;
 
 public class ManagedServiceFactoryTest extends AbstractBlueprintIntegrationTest {
-	@Inject
-	ConfigurationAdmin ca;
-	
-	@ProbeBuilder
-	public TestProbeBuilder probeConfiguration(TestProbeBuilder probe) {
-		probe.setHeader(Constants.EXPORT_PACKAGE, Foo.class.getPackage().getName());
-    	probe.setHeader(Constants.IMPORT_PACKAGE, Foo.class.getPackage().getName());
-		return probe;
-	}
+    @Inject
+    ConfigurationAdmin ca;
+
+    @ProbeBuilder
+    public TestProbeBuilder probeConfiguration(TestProbeBuilder probe) {
+        probe.setHeader(Constants.EXPORT_PACKAGE, Foo.class.getPackage().getName());
+        probe.setHeader(Constants.IMPORT_PACKAGE, Foo.class.getPackage().getName());
+        return probe;
+    }
 
     @org.ops4j.pax.exam.Configuration
     public Option[] config() {
-    	InputStream testBundle = TinyBundles.bundle()
-    		.add(FooInterface.class)
-    		.add(Foo.class)
-    		.add(FooFactory.class)
-    		.add("OSGI-INF/blueprint/context.xml", 
-    				getResource("ManagedServiceFactoryTest.xml"))
-    		.set(Constants.EXPORT_PACKAGE, Foo.class.getPackage().getName())
-    		.set(Constants.IMPORT_PACKAGE, Foo.class.getPackage().getName())
-    		.build(TinyBundles.withBnd());
-    	return new Option[] {
-    			baseOptions(),
-    			Helper.blueprintBundles(),
-    			CoreOptions.keepCaches(),
-    			CoreOptions.streamBundle(testBundle)
-    	};
+        InputStream testBundle = TinyBundles.bundle().add(FooInterface.class).add(Foo.class)
+            .add(FooFactory.class)
+            .add("OSGI-INF/blueprint/context.xml", getResource("ManagedServiceFactoryTest.xml"))
+            .set(Constants.EXPORT_PACKAGE, Foo.class.getPackage().getName())
+            .set(Constants.IMPORT_PACKAGE, Foo.class.getPackage().getName()).build(TinyBundles.withBnd());
+        return new Option[] {
+            baseOptions(), Helper.blueprintBundles(), CoreOptions.keepCaches(),
+            CoreOptions.streamBundle(testBundle)
+        };
     }
-    
-
 
     @Test
     public void test1() throws Exception {
         Configuration cf = ca.createFactoryConfiguration("blueprint-sample-managed-service-factory",
null);
-        Hashtable<String,String> props = new Hashtable<String,String>();
+        Hashtable<String, String> props = new Hashtable<String, String>();
         props.put("a", "5");
         cf.update(props);
-        
-		@SuppressWarnings("rawtypes")
-		ServiceReference sr = getServiceRef(Foo.class, "(key=foo1)");
+
+        @SuppressWarnings("rawtypes")
+        ServiceReference sr = getServiceRef(Foo.class, "(key=foo1)");
         Foo foo = (Foo)context().getService(sr);
         assertNotNull(foo);
         assertEquals(5, foo.getA());
@@ -92,7 +84,7 @@ public class ManagedServiceFactoryTest e
         assertEquals("5", sr.getProperty("a"));
         assertNull(sr.getProperty("b"));
 
-        props = new Hashtable<String,String>();
+        props = new Hashtable<String, String>();
         props.put("a", "5");
         props.put("b", "foo");
         cf.update(props);
@@ -110,20 +102,20 @@ public class ManagedServiceFactoryTest e
     @Test
     public void test2() throws Exception {
         Configuration cf = ca.createFactoryConfiguration("blueprint-sample-managed-service-factory2",
null);
-        Hashtable<String,String> props = new Hashtable<String,String>();
+        Hashtable<String, String> props = new Hashtable<String, String>();
         props.put("a", "5");
         cf.update(props);
 
         @SuppressWarnings("rawtypes")
-		ServiceReference sr = getServiceRef(Foo.class, "(key=foo2)");
-		Foo foo = (Foo)context().getService(sr);
+        ServiceReference sr = getServiceRef(Foo.class, "(key=foo2)");
+        Foo foo = (Foo)context().getService(sr);
         assertNotNull(foo);
         assertEquals(5, foo.getA());
         assertEquals("default", foo.getB());
         assertNull(sr.getProperty("a"));
         assertNull(sr.getProperty("b"));
 
-        props = new Hashtable<String,String>();
+        props = new Hashtable<String, String>();
         props.put("a", "5");
         props.put("b", "foo");
         cf.update(props);
@@ -138,26 +130,24 @@ public class ManagedServiceFactoryTest e
         assertNull(sr.getProperty("b"));
     }
 
-
-
     @Test
     public void test3() throws Exception {
         Configuration cf = ca.createFactoryConfiguration("blueprint-sample-managed-service-factory3",
null);
-        Hashtable<String,String> props = new Hashtable<String,String>();
+        Hashtable<String, String> props = new Hashtable<String, String>();
         props.put("a", "5");
         cf.update(props);
 
         @SuppressWarnings("rawtypes")
-		ServiceReference sr = getServiceRef(Foo.class, "(&(key=foo3)(a=5))");
+        ServiceReference sr = getServiceRef(Foo.class, "(&(key=foo3)(a=5))");
         assertNotNull(sr);
-        Foo foo = (Foo) context().getService(sr);
+        Foo foo = (Foo)context().getService(sr);
         assertNotNull(foo);
         assertEquals(5, foo.getA());
         assertEquals("default", foo.getB());
         assertEquals("5", sr.getProperty("a"));
         assertNull(sr.getProperty("b"));
 
-        props = new Hashtable<String,String>();
+        props = new Hashtable<String, String>();
         props.put("a", "5");
         props.put("b", "foo");
         cf.update(props);
@@ -174,41 +164,41 @@ public class ManagedServiceFactoryTest e
     }
 
     @SuppressWarnings("rawtypes")
-	@Test
+    @Test
     public void testCreateAndUpdate() throws Exception {
         Configuration cf = ca.createFactoryConfiguration("blueprint-sample-managed-service-factory3",
null);
-        Hashtable<String,String> props = new Hashtable<String,String>();
+        Hashtable<String, String> props = new Hashtable<String, String>();
         props.put("a", "5");
         cf.update(props);
 
         Configuration cf2 = ca.createFactoryConfiguration("blueprint-sample-managed-service-factory3",
null);
-        Hashtable<String,String> props2 = new Hashtable<String,String>();
+        Hashtable<String, String> props2 = new Hashtable<String, String>();
         props2.put("a", "7");
         cf2.update(props2);
 
         ServiceReference sr = getServiceRef(Foo.class, "(&(key=foo3)(a=5))");
         ServiceReference sr2 = getServiceRef(Foo.class, "(&(key=foo3)(a=7))");
 
-        Foo foo = (Foo) context().getService(sr);
+        Foo foo = (Foo)context().getService(sr);
         assertNotNull(foo);
         assertEquals(5, foo.getA());
         assertEquals("default", foo.getB());
         assertEquals("5", sr.getProperty("a"));
         assertNull(sr.getProperty("b"));
 
-        Foo foo2 = (Foo) context().getService(sr2);
+        Foo foo2 = (Foo)context().getService(sr2);
         assertNotNull(foo2);
         assertEquals(7, foo2.getA());
         assertEquals("default", foo2.getB());
         assertEquals("7", sr2.getProperty("a"));
         assertNull(sr2.getProperty("b"));
 
-        props = new Hashtable<String,String>();
+        props = new Hashtable<String, String>();
         props.put("a", "5");
         props.put("b", "foo");
         cf.update(props);
 
-        props2 = new Hashtable<String,String>();
+        props2 = new Hashtable<String, String>();
         props2.put("a", "7");
         props2.put("b", "foo2");
         cf2.update(props2);
@@ -233,110 +223,111 @@ public class ManagedServiceFactoryTest e
         cf2.delete();
     }
 
-  @SuppressWarnings("rawtypes")
-@Test
-  public void testCreateAndUpdateUsingUpdateMethod() throws Exception {
-    Configuration cf = ca.createFactoryConfiguration("blueprint-sample-managed-service-factory4",
null);
-    Hashtable<String, String> props = new Hashtable<String, String>();
-    props.put("a", "5");
-    cf.update(props);
-
-    Configuration cf2 = ca.createFactoryConfiguration("blueprint-sample-managed-service-factory4",
null);
-    Hashtable<String, String> props2 = new Hashtable<String, String>();
-    props2.put("a", "7");
-    cf2.update(props2);
-
-    ServiceReference sr = getServiceRef(Foo.class, "(&(key=foo4)(a=5))");
-    ServiceReference sr2 = getServiceRef(Foo.class, "(&(key=foo4)(a=7))");
-
-    Foo foo = (Foo) context().getService(sr);
-    assertNotNull(foo);
-    assertEquals(5, foo.getA());
-    assertEquals("default", foo.getB());
-    assertEquals("5", sr.getProperty("a"));
-    assertNull(sr.getProperty("b"));
-
-    Foo foo2 = (Foo) context().getService(sr2);
-    assertNotNull(foo2);
-    assertEquals(7, foo2.getA());
-    assertEquals("default", foo2.getB());
-    assertEquals("7", sr2.getProperty("a"));
-    assertNull(sr2.getProperty("b"));
-
-    props = new Hashtable<String, String>();
-    props.put("a", "5");
-    props.put("b", "foo");
-    cf.update(props);
-
-    props2 = new Hashtable<String, String>();
-    props2.put("a", "7");
-    props2.put("b", "foo2");
-    cf2.update(props2);
-
-    // Update after creation
-    Thread.sleep(500);
-    assertEquals(5, foo.getA());
-    assertEquals("foo", foo.getB());
-
-    // Update of service properties
-    assertEquals("5", sr.getProperty("a"));
-    assertEquals("foo", sr.getProperty("b"));
-
-    // 2a Update after creation
-    assertEquals(7, foo2.getA());
-    assertEquals("foo2", foo2.getB());
-
-    // 2b Update of service properties
-    assertEquals("7", sr2.getProperty("a"));
-    assertEquals("foo2", sr2.getProperty("b"));
-  }
-  
-  @Test
-  public void testFactoryCreation() throws Exception {
-    Configuration cf = ca.createFactoryConfiguration("blueprint-sample-managed-service-factory5",
null);
-    Hashtable<String, String> props = new Hashtable<String, String>();
-    props.put("a", "5");
-    cf.update(props);
+    @SuppressWarnings("rawtypes")
+    @Test
+    public void testCreateAndUpdateUsingUpdateMethod() throws Exception {
+        Configuration cf = ca.createFactoryConfiguration("blueprint-sample-managed-service-factory4",
null);
+        Hashtable<String, String> props = new Hashtable<String, String>();
+        props.put("a", "5");
+        cf.update(props);
+
+        Configuration cf2 = ca.createFactoryConfiguration("blueprint-sample-managed-service-factory4",
null);
+        Hashtable<String, String> props2 = new Hashtable<String, String>();
+        props2.put("a", "7");
+        cf2.update(props2);
+
+        ServiceReference sr = getServiceRef(Foo.class, "(&(key=foo4)(a=5))");
+        ServiceReference sr2 = getServiceRef(Foo.class, "(&(key=foo4)(a=7))");
+
+        Foo foo = (Foo)context().getService(sr);
+        assertNotNull(foo);
+        assertEquals(5, foo.getA());
+        assertEquals("default", foo.getB());
+        assertEquals("5", sr.getProperty("a"));
+        assertNull(sr.getProperty("b"));
+
+        Foo foo2 = (Foo)context().getService(sr2);
+        assertNotNull(foo2);
+        assertEquals(7, foo2.getA());
+        assertEquals("default", foo2.getB());
+        assertEquals("7", sr2.getProperty("a"));
+        assertNull(sr2.getProperty("b"));
+
+        props = new Hashtable<String, String>();
+        props.put("a", "5");
+        props.put("b", "foo");
+        cf.update(props);
+
+        props2 = new Hashtable<String, String>();
+        props2.put("a", "7");
+        props2.put("b", "foo2");
+        cf2.update(props2);
+
+        // Update after creation
+        Thread.sleep(500);
+        assertEquals(5, foo.getA());
+        assertEquals("foo", foo.getB());
+
+        // Update of service properties
+        assertEquals("5", sr.getProperty("a"));
+        assertEquals("foo", sr.getProperty("b"));
+
+        // 2a Update after creation
+        assertEquals(7, foo2.getA());
+        assertEquals("foo2", foo2.getB());
+
+        // 2b Update of service properties
+        assertEquals("7", sr2.getProperty("a"));
+        assertEquals("foo2", sr2.getProperty("b"));
+    }
+
+    @Test
+    public void testFactoryCreation() throws Exception {
+        Configuration cf = ca.createFactoryConfiguration("blueprint-sample-managed-service-factory5",
null);
+        Hashtable<String, String> props = new Hashtable<String, String>();
+        props.put("a", "5");
+        cf.update(props);
+
+        @SuppressWarnings("rawtypes")
+        ServiceReference sr = getServiceRef(Foo.class, "(key=foo5)");
+        Foo foo = (Foo)context().getService(sr);
+        assertNotNull(foo);
+        assertEquals(5, foo.getA());
+        assertEquals("default", foo.getB());
+        assertEquals("5", sr.getProperty("a"));
+        assertNull(sr.getProperty("b"));
+
+        props = new Hashtable<String, String>();
+        props.put("a", "5");
+        props.put("b", "foo");
+        cf.update(props);
+        Thread.sleep(500);
+
+        // No update of bean after creation
+        assertEquals(5, foo.getA());
+        assertEquals("default", foo.getB());
+
+        // Only initial update of service properties
+        assertEquals("5", sr.getProperty("a"));
+        assertNull(sr.getProperty("b"));
+    }
 
     @SuppressWarnings("rawtypes")
-	ServiceReference sr = getServiceRef(Foo.class, "(key=foo5)");
-    Foo foo = (Foo) context().getService(sr);
-    assertNotNull(foo);
-    assertEquals(5, foo.getA());
-    assertEquals("default", foo.getB());
-    assertEquals("5", sr.getProperty("a"));
-    assertNull(sr.getProperty("b"));
-
-    props = new Hashtable<String, String>();
-    props.put("a", "5");
-    props.put("b", "foo");
-    cf.update(props);
-    Thread.sleep(500);
-
-    // No update of bean after creation
-    assertEquals(5, foo.getA());
-    assertEquals("default", foo.getB());
-
-    // Only initial update of service properties
-    assertEquals("5", sr.getProperty("a"));
-    assertNull(sr.getProperty("b"));
-  }
-  
-	@SuppressWarnings("rawtypes")
-	private ServiceReference getServiceRef(Class serviceInterface, String filter) throws InvalidSyntaxException
{
-		int tries = 0;
-		do {
-			 ServiceReference[] srAr = bundleContext.getServiceReferences(serviceInterface.getName(),
filter);
-			 if (srAr != null && srAr.length > 0) {
-				 return (ServiceReference) srAr[0];
-			 }
-			 tries ++;
-			 try {
-				Thread.sleep(100);
-			} catch (InterruptedException e) {
-				// Ignore
-			}
-		}  while (tries < 100);
-      throw new RuntimeException("Could not find service " + serviceInterface.getName() +
", " + filter);
-	}
+    private ServiceReference getServiceRef(Class serviceInterface, String filter)
+        throws InvalidSyntaxException {
+        int tries = 0;
+        do {
+            ServiceReference[] srAr = bundleContext.getServiceReferences(serviceInterface.getName(),
filter);
+            if (srAr != null && srAr.length > 0) {
+                return (ServiceReference)srAr[0];
+            }
+            tries++;
+            try {
+                Thread.sleep(100);
+            } catch (InterruptedException e) {
+                // Ignore
+            }
+        } while (tries < 100);
+        throw new RuntimeException("Could not find service " + serviceInterface.getName()
+ ", " + filter);
+    }
 }

Modified: aries/trunk/blueprint/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/cm/ManagedServiceFactoryUseSystemBundleTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/cm/ManagedServiceFactoryUseSystemBundleTest.java?rev=1675287&r1=1675286&r2=1675287&view=diff
==============================================================================
--- aries/trunk/blueprint/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/cm/ManagedServiceFactoryUseSystemBundleTest.java
(original)
+++ aries/trunk/blueprint/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/cm/ManagedServiceFactoryUseSystemBundleTest.java
Wed Apr 22 09:18:18 2015
@@ -56,97 +56,95 @@ import org.osgi.framework.hooks.service.
 import org.osgi.service.cm.Configuration;
 import org.osgi.service.cm.ConfigurationAdmin;
 
-@SuppressWarnings({"rawtypes", "unchecked"})
+@SuppressWarnings({
+    "rawtypes", "unchecked"
+})
 public class ManagedServiceFactoryUseSystemBundleTest extends AbstractBlueprintIntegrationTest
{
-	private static final String CM_BUNDLE = "org.apache.aries.blueprint.cm";
-	private static final String TEST_BUNDLE = "org.apache.aries.blueprint.cm.test.b1";
-	@Inject
-	ConfigurationAdmin ca;
-	
-	@ProbeBuilder
-	public TestProbeBuilder probeConfiguration(TestProbeBuilder probe) {
-		probe.setHeader(Constants.EXPORT_PACKAGE, Foo.class.getPackage().getName());
-    	probe.setHeader(Constants.IMPORT_PACKAGE, Foo.class.getPackage().getName());
-		return probe;
-	}
+    private static final String CM_BUNDLE = "org.apache.aries.blueprint.cm";
+    private static final String TEST_BUNDLE = "org.apache.aries.blueprint.cm.test.b1";
+    @Inject
+    ConfigurationAdmin ca;
+
+    @ProbeBuilder
+    public TestProbeBuilder probeConfiguration(TestProbeBuilder probe) {
+        probe.setHeader(Constants.EXPORT_PACKAGE, Foo.class.getPackage().getName());
+        probe.setHeader(Constants.IMPORT_PACKAGE, Foo.class.getPackage().getName());
+        return probe;
+    }
 
     @org.ops4j.pax.exam.Configuration
     public Option[] config() {
-    	InputStream testBundle = TinyBundles.bundle()
-    		.add(FooInterface.class)
-    		.add(Foo.class)
-    		.add(FooFactory.class)
-    		.add("OSGI-INF/blueprint/context.xml", 
-    				getResource("ManagedServiceFactoryTest.xml"))
-    		.set(Constants.BUNDLE_SYMBOLICNAME, TEST_BUNDLE)
-    		.set(Constants.EXPORT_PACKAGE, Foo.class.getPackage().getName())
-    		.set(Constants.IMPORT_PACKAGE, Foo.class.getPackage().getName())
-    		.build(TinyBundles.withBnd());
-    	return new Option[] {
-    			baseOptions(),
-                CoreOptions.systemProperty("org.apache.aries.blueprint.use.system.context").value("true"),
-    			Helper.blueprintBundles(),
-    			CoreOptions.keepCaches(),
-    			CoreOptions.streamBundle(testBundle)
-    	};
-    }
-
-	ServiceRegistration eventHook;
-	ServiceRegistration findHook;
-	@Before
-	public void regiserHook() throws BundleException {
-		context().getBundleByName(CM_BUNDLE).stop();
-		final BundleContext systemContext = context().getBundle(Constants.SYSTEM_BUNDLE_LOCATION).getBundleContext();
-		eventHook = context().registerService(EventListenerHook.class, new EventListenerHook()
{
-
-			@Override
-			public void event(ServiceEvent event,
-					Map contexts) {
-				if (CM_BUNDLE.equals(event.getServiceReference().getBundle().getSymbolicName())) {
-					// hide from everything but the system bundle
-					// TODO on R6 we should be able to even try hiding from the system bundle
-					// R5 it was not clear if hooks could hide from the system bundle
-					// equinox R5 does allow hiding from system bundle
-					contexts.keySet().retainAll(Collections.singleton(systemContext));
-				}
-			}
-
-		}, null);
-		findHook = context().registerService(FindHook.class, new FindHook(){
-			@Override
-			public void find(BundleContext context, String arg1, String arg2,
-					boolean arg3, Collection references) {
-				// hide from everything but the system bundle
-				// TODO on R6 we should be able to even try hiding from the system bundle
-				// R5 it was not clear if hooks could hide from the system bundle
-				// equinox R5 does allow hiding from system bundle
-				if (!context.equals(systemContext)) {
-					for (Iterator<ServiceReference> iReferences = references.iterator(); iReferences.hasNext();)
{
-						if (CM_BUNDLE.equals(iReferences.next().getBundle().getSymbolicName())) {
-							iReferences.remove();
-						}
-					}
-				}
-			}
-			
-		}, null);
-		context().getBundleByName(CM_BUNDLE).start();
-	}
-
-	@After
-	public void unregisterHook() {
-		eventHook.unregister();
-		findHook.unregister();
-	}
+        InputStream testBundle = TinyBundles.bundle().add(FooInterface.class).add(Foo.class)
+            .add(FooFactory.class)
+            .add("OSGI-INF/blueprint/context.xml", getResource("ManagedServiceFactoryTest.xml"))
+            .set(Constants.BUNDLE_SYMBOLICNAME, TEST_BUNDLE)
+            .set(Constants.EXPORT_PACKAGE, Foo.class.getPackage().getName())
+            .set(Constants.IMPORT_PACKAGE, Foo.class.getPackage().getName()).build(TinyBundles.withBnd());
+        return new Option[] {
+            baseOptions(),
+            CoreOptions.systemProperty("org.apache.aries.blueprint.use.system.context").value("true"),
+            Helper.blueprintBundles(), CoreOptions.keepCaches(), CoreOptions.streamBundle(testBundle)
+        };
+    }
+
+    ServiceRegistration eventHook;
+    ServiceRegistration findHook;
+
+    @Before
+    public void regiserHook() throws BundleException {
+        context().getBundleByName(CM_BUNDLE).stop();
+        final BundleContext systemContext = context().getBundle(Constants.SYSTEM_BUNDLE_LOCATION)
+            .getBundleContext();
+        eventHook = context().registerService(EventListenerHook.class, new EventListenerHook()
{
+
+            @Override
+            public void event(ServiceEvent event, Map contexts) {
+                if (CM_BUNDLE.equals(event.getServiceReference().getBundle().getSymbolicName()))
{
+                    // hide from everything but the system bundle
+                    // TODO on R6 we should be able to even try hiding from the system bundle
+                    // R5 it was not clear if hooks could hide from the system bundle
+                    // equinox R5 does allow hiding from system bundle
+                    contexts.keySet().retainAll(Collections.singleton(systemContext));
+                }
+            }
+
+        }, null);
+        findHook = context().registerService(FindHook.class, new FindHook() {
+            @Override
+            public void find(BundleContext context, String arg1, String arg2, boolean arg3,
+                             Collection references) {
+                // hide from everything but the system bundle
+                // TODO on R6 we should be able to even try hiding from the system bundle
+                // R5 it was not clear if hooks could hide from the system bundle
+                // equinox R5 does allow hiding from system bundle
+                if (!context.equals(systemContext)) {
+                    for (Iterator<ServiceReference> iReferences = references.iterator();
iReferences
+                        .hasNext();) {
+                        if (CM_BUNDLE.equals(iReferences.next().getBundle().getSymbolicName()))
{
+                            iReferences.remove();
+                        }
+                    }
+                }
+            }
+
+        }, null);
+        context().getBundleByName(CM_BUNDLE).start();
+    }
+
+    @After
+    public void unregisterHook() {
+        eventHook.unregister();
+        findHook.unregister();
+    }
 
     @Test
     public void test1() throws Exception {
         Configuration cf = ca.createFactoryConfiguration("blueprint-sample-managed-service-factory",
null);
-        Hashtable<String,String> props = new Hashtable<String,String>();
+        Hashtable<String, String> props = new Hashtable<String, String>();
         props.put("a", "5");
         cf.update(props);
-        
-		ServiceReference sr = getServiceRef(Foo.class, "(key=foo1)");
+
+        ServiceReference sr = getServiceRef(Foo.class, "(key=foo1)");
         Foo foo = (Foo)context().getService(sr);
         assertNotNull(foo);
         assertEquals(5, foo.getA());
@@ -154,7 +152,7 @@ public class ManagedServiceFactoryUseSys
         assertEquals("5", sr.getProperty("a"));
         assertNull(sr.getProperty("b"));
 
-        props = new Hashtable<String,String>();
+        props = new Hashtable<String, String>();
         props.put("a", "5");
         props.put("b", "foo");
         cf.update(props);
@@ -172,19 +170,19 @@ public class ManagedServiceFactoryUseSys
     @Test
     public void test2() throws Exception {
         Configuration cf = ca.createFactoryConfiguration("blueprint-sample-managed-service-factory2",
null);
-        Hashtable<String,String> props = new Hashtable<String,String>();
+        Hashtable<String, String> props = new Hashtable<String, String>();
         props.put("a", "5");
         cf.update(props);
 
-		ServiceReference sr = getServiceRef(Foo.class, "(key=foo2)");
-		Foo foo = (Foo)context().getService(sr);
+        ServiceReference sr = getServiceRef(Foo.class, "(key=foo2)");
+        Foo foo = (Foo)context().getService(sr);
         assertNotNull(foo);
         assertEquals(5, foo.getA());
         assertEquals("default", foo.getB());
         assertNull(sr.getProperty("a"));
         assertNull(sr.getProperty("b"));
 
-        props = new Hashtable<String,String>();
+        props = new Hashtable<String, String>();
         props.put("a", "5");
         props.put("b", "foo");
         cf.update(props);
@@ -199,25 +197,23 @@ public class ManagedServiceFactoryUseSys
         assertNull(sr.getProperty("b"));
     }
 
-
-
     @Test
     public void test3() throws Exception {
         Configuration cf = ca.createFactoryConfiguration("blueprint-sample-managed-service-factory3",
null);
-        Hashtable<String,String> props = new Hashtable<String,String>();
+        Hashtable<String, String> props = new Hashtable<String, String>();
         props.put("a", "5");
         cf.update(props);
 
-		ServiceReference sr = getServiceRef(Foo.class, "(&(key=foo3)(a=5))");
+        ServiceReference sr = getServiceRef(Foo.class, "(&(key=foo3)(a=5))");
         assertNotNull(sr);
-        Foo foo = (Foo) context().getService(sr);
+        Foo foo = (Foo)context().getService(sr);
         assertNotNull(foo);
         assertEquals(5, foo.getA());
         assertEquals("default", foo.getB());
         assertEquals("5", sr.getProperty("a"));
         assertNull(sr.getProperty("b"));
 
-        props = new Hashtable<String,String>();
+        props = new Hashtable<String, String>();
         props.put("a", "5");
         props.put("b", "foo");
         cf.update(props);
@@ -233,41 +229,41 @@ public class ManagedServiceFactoryUseSys
         cf.delete();
     }
 
-	@Test
+    @Test
     public void testCreateAndUpdate() throws Exception {
         Configuration cf = ca.createFactoryConfiguration("blueprint-sample-managed-service-factory3",
null);
-        Hashtable<String,String> props = new Hashtable<String,String>();
+        Hashtable<String, String> props = new Hashtable<String, String>();
         props.put("a", "5");
         cf.update(props);
 
         Configuration cf2 = ca.createFactoryConfiguration("blueprint-sample-managed-service-factory3",
null);
-        Hashtable<String,String> props2 = new Hashtable<String,String>();
+        Hashtable<String, String> props2 = new Hashtable<String, String>();
         props2.put("a", "7");
         cf2.update(props2);
 
         ServiceReference sr = getServiceRef(Foo.class, "(&(key=foo3)(a=5))");
         ServiceReference sr2 = getServiceRef(Foo.class, "(&(key=foo3)(a=7))");
 
-        Foo foo = (Foo) context().getService(sr);
+        Foo foo = (Foo)context().getService(sr);
         assertNotNull(foo);
         assertEquals(5, foo.getA());
         assertEquals("default", foo.getB());
         assertEquals("5", sr.getProperty("a"));
         assertNull(sr.getProperty("b"));
 
-        Foo foo2 = (Foo) context().getService(sr2);
+        Foo foo2 = (Foo)context().getService(sr2);
         assertNotNull(foo2);
         assertEquals(7, foo2.getA());
         assertEquals("default", foo2.getB());
         assertEquals("7", sr2.getProperty("a"));
         assertNull(sr2.getProperty("b"));
 
-        props = new Hashtable<String,String>();
+        props = new Hashtable<String, String>();
         props.put("a", "5");
         props.put("b", "foo");
         cf.update(props);
 
-        props2 = new Hashtable<String,String>();
+        props2 = new Hashtable<String, String>();
         props2.put("a", "7");
         props2.put("b", "foo2");
         cf2.update(props2);
@@ -292,107 +288,108 @@ public class ManagedServiceFactoryUseSys
         cf2.delete();
     }
 
-  @Test
-  public void testCreateAndUpdateUsingUpdateMethod() throws Exception {
-    Configuration cf = ca.createFactoryConfiguration("blueprint-sample-managed-service-factory4",
null);
-    Hashtable<String, String> props = new Hashtable<String, String>();
-    props.put("a", "5");
-    cf.update(props);
-
-    Configuration cf2 = ca.createFactoryConfiguration("blueprint-sample-managed-service-factory4",
null);
-    Hashtable<String, String> props2 = new Hashtable<String, String>();
-    props2.put("a", "7");
-    cf2.update(props2);
-
-    ServiceReference sr = getServiceRef(Foo.class, "(&(key=foo4)(a=5))");
-    ServiceReference sr2 = getServiceRef(Foo.class, "(&(key=foo4)(a=7))");
-
-    Foo foo = (Foo) context().getService(sr);
-    assertNotNull(foo);
-    assertEquals(5, foo.getA());
-    assertEquals("default", foo.getB());
-    assertEquals("5", sr.getProperty("a"));
-    assertNull(sr.getProperty("b"));
-
-    Foo foo2 = (Foo) context().getService(sr2);
-    assertNotNull(foo2);
-    assertEquals(7, foo2.getA());
-    assertEquals("default", foo2.getB());
-    assertEquals("7", sr2.getProperty("a"));
-    assertNull(sr2.getProperty("b"));
-
-    props = new Hashtable<String, String>();
-    props.put("a", "5");
-    props.put("b", "foo");
-    cf.update(props);
-
-    props2 = new Hashtable<String, String>();
-    props2.put("a", "7");
-    props2.put("b", "foo2");
-    cf2.update(props2);
-
-    // Update after creation
-    Thread.sleep(500);
-    assertEquals(5, foo.getA());
-    assertEquals("foo", foo.getB());
-
-    // Update of service properties
-    assertEquals("5", sr.getProperty("a"));
-    assertEquals("foo", sr.getProperty("b"));
-
-    // 2a Update after creation
-    assertEquals(7, foo2.getA());
-    assertEquals("foo2", foo2.getB());
-
-    // 2b Update of service properties
-    assertEquals("7", sr2.getProperty("a"));
-    assertEquals("foo2", sr2.getProperty("b"));
-  }
-  
-  @Test
-  public void testFactoryCreation() throws Exception {
-    Configuration cf = ca.createFactoryConfiguration("blueprint-sample-managed-service-factory5",
null);
-    Hashtable<String, String> props = new Hashtable<String, String>();
-    props.put("a", "5");
-    cf.update(props);
-
-	ServiceReference sr = getServiceRef(Foo.class, "(key=foo5)");
-    Foo foo = (Foo) context().getService(sr);
-    assertNotNull(foo);
-    assertEquals(5, foo.getA());
-    assertEquals("default", foo.getB());
-    assertEquals("5", sr.getProperty("a"));
-    assertNull(sr.getProperty("b"));
-
-    props = new Hashtable<String, String>();
-    props.put("a", "5");
-    props.put("b", "foo");
-    cf.update(props);
-    Thread.sleep(500);
-
-    // No update of bean after creation
-    assertEquals(5, foo.getA());
-    assertEquals("default", foo.getB());
-
-    // Only initial update of service properties
-    assertEquals("5", sr.getProperty("a"));
-    assertNull(sr.getProperty("b"));
-  }
-  
-	private ServiceReference getServiceRef(Class serviceInterface, String filter) throws InvalidSyntaxException
{
-		int tries = 0;
-		do {
-			 ServiceReference[] srAr = bundleContext.getServiceReferences(serviceInterface.getName(),
filter);
-			 if (srAr != null && srAr.length > 0) {
-				 return (ServiceReference) srAr[0];
-			 }
-			 tries ++;
-			 try {
-				Thread.sleep(100);
-			} catch (InterruptedException e) {
-				// Ignore
-			}
-		}  while (tries < 100);
-      throw new RuntimeException("Could not find service " + serviceInterface.getName() +
", " + filter);
-	}
+    @Test
+    public void testCreateAndUpdateUsingUpdateMethod() throws Exception {
+        Configuration cf = ca.createFactoryConfiguration("blueprint-sample-managed-service-factory4",
null);
+        Hashtable<String, String> props = new Hashtable<String, String>();
+        props.put("a", "5");
+        cf.update(props);
+
+        Configuration cf2 = ca.createFactoryConfiguration("blueprint-sample-managed-service-factory4",
null);
+        Hashtable<String, String> props2 = new Hashtable<String, String>();
+        props2.put("a", "7");
+        cf2.update(props2);
+
+        ServiceReference sr = getServiceRef(Foo.class, "(&(key=foo4)(a=5))");
+        ServiceReference sr2 = getServiceRef(Foo.class, "(&(key=foo4)(a=7))");
+
+        Foo foo = (Foo)context().getService(sr);
+        assertNotNull(foo);
+        assertEquals(5, foo.getA());
+        assertEquals("default", foo.getB());
+        assertEquals("5", sr.getProperty("a"));
+        assertNull(sr.getProperty("b"));
+
+        Foo foo2 = (Foo)context().getService(sr2);
+        assertNotNull(foo2);
+        assertEquals(7, foo2.getA());
+        assertEquals("default", foo2.getB());
+        assertEquals("7", sr2.getProperty("a"));
+        assertNull(sr2.getProperty("b"));
+
+        props = new Hashtable<String, String>();
+        props.put("a", "5");
+        props.put("b", "foo");
+        cf.update(props);
+
+        props2 = new Hashtable<String, String>();
+        props2.put("a", "7");
+        props2.put("b", "foo2");
+        cf2.update(props2);
+
+        // Update after creation
+        Thread.sleep(500);
+        assertEquals(5, foo.getA());
+        assertEquals("foo", foo.getB());
+
+        // Update of service properties
+        assertEquals("5", sr.getProperty("a"));
+        assertEquals("foo", sr.getProperty("b"));
+
+        // 2a Update after creation
+        assertEquals(7, foo2.getA());
+        assertEquals("foo2", foo2.getB());
+
+        // 2b Update of service properties
+        assertEquals("7", sr2.getProperty("a"));
+        assertEquals("foo2", sr2.getProperty("b"));
+    }
+
+    @Test
+    public void testFactoryCreation() throws Exception {
+        Configuration cf = ca.createFactoryConfiguration("blueprint-sample-managed-service-factory5",
null);
+        Hashtable<String, String> props = new Hashtable<String, String>();
+        props.put("a", "5");
+        cf.update(props);
+
+        ServiceReference sr = getServiceRef(Foo.class, "(key=foo5)");
+        Foo foo = (Foo)context().getService(sr);
+        assertNotNull(foo);
+        assertEquals(5, foo.getA());
+        assertEquals("default", foo.getB());
+        assertEquals("5", sr.getProperty("a"));
+        assertNull(sr.getProperty("b"));
+
+        props = new Hashtable<String, String>();
+        props.put("a", "5");
+        props.put("b", "foo");
+        cf.update(props);
+        Thread.sleep(500);
+
+        // No update of bean after creation
+        assertEquals(5, foo.getA());
+        assertEquals("default", foo.getB());
+
+        // Only initial update of service properties
+        assertEquals("5", sr.getProperty("a"));
+        assertNull(sr.getProperty("b"));
+    }
+
+    private ServiceReference getServiceRef(Class serviceInterface, String filter)
+        throws InvalidSyntaxException {
+        int tries = 0;
+        do {
+            ServiceReference[] srAr = bundleContext.getServiceReferences(serviceInterface.getName(),
filter);
+            if (srAr != null && srAr.length > 0) {
+                return (ServiceReference)srAr[0];
+            }
+            tries++;
+            try {
+                Thread.sleep(100);
+            } catch (InterruptedException e) {
+                // Ignore
+            }
+        } while (tries < 100);
+        throw new RuntimeException("Could not find service " + serviceInterface.getName()
+ ", " + filter);
+    }
 }

Copied: aries/trunk/blueprint/blueprint-itests/src/test/resources/CmPropertiesTest.xml (from
r1675139, aries/trunk/blueprint/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/cm/service/CmPropertiesTest.xml)
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-itests/src/test/resources/CmPropertiesTest.xml?p2=aries/trunk/blueprint/blueprint-itests/src/test/resources/CmPropertiesTest.xml&p1=aries/trunk/blueprint/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/cm/service/CmPropertiesTest.xml&r1=1675139&r2=1675287&rev=1675287&view=diff
==============================================================================
    (empty)



Mime
View raw message