Package org.apache.felix.ipojo.context

Examples of org.apache.felix.ipojo.context.ServiceRegistry


  }
 
  public void testGetService() {
    ComponentInstance im = new FakeComponent();
    ComponentInstance im2 = new FakeComponent();
    ServiceRegistry registry = new ServiceRegistry(getContext());
   
    try {
      assertNull("Check that there is no available service", registry.getServiceReferences(null, null));
    } catch (InvalidSyntaxException e) { fail("Cannot query the registry : " + e.getMessage()); }
   
    Properties props = new Properties();
    props.put("foo", "bar");
    ServiceRegistration reg1 = registry.registerService(im, BarService.class.getName(), new barProvider(), props);
   
    ServiceReference ref = registry.getServiceReference(BarService.class.getName());
    assertNotNull("Check ref not null", ref);
    assertEquals("Test property", ref.getProperty("foo"), "bar");
    BarService bar = (BarService) registry.getService(im2, ref);
    assertTrue("Test invocation", bar.bar());
   
    reg1.unregister();
    ref = registry.getServiceReference(BarService.class.getName());
    assertNull("Check ref null", ref);
  }
View Full Code Here


  }
 
  public void testGetFilteredService() {
    ComponentInstance im = new FakeComponent();
    ComponentInstance im2 = new FakeComponent();
    ServiceRegistry registry = new ServiceRegistry(getContext());
   
    try {
      assertNull("Check that there is no available service", registry.getServiceReferences(null, null));
    } catch (InvalidSyntaxException e) { fail("Cannot query the registry : " + e.getMessage()); }
   
    Properties props = new Properties();
    props.put("foo", "bar");
    ServiceRegistration reg1 = registry.registerService(im, BarService.class.getName(), new barProvider(), props);
    ServiceRegistration reg2 = registry.registerService(im2, BarService.class.getName(), new barProvider(), null);
   
    ServiceReference[] ref = null;
    try {
      ref = registry.getServiceReferences(BarService.class.getName(), "(foo=bar)");
    } catch (InvalidSyntaxException e) { fail("Registry query fail : " + e.getMessage()); }
    assertNotNull("Check ref not null", ref);
    assertEquals("Check ref count", ref.length, 1);
    assertEquals("Test property", ref[0].getProperty("foo"), "bar");
    BarService bar = (BarService) registry.getService(im2, ref[0]);
    assertTrue("Test invocation", bar.bar());
   
    ref = null;
    reg1.unregister();
    try {
      ref = registry.getServiceReferences(BarService.class.getName(), "(bar=foo)");
    } catch (InvalidSyntaxException e) { fail("Registry query fail : " + e.getMessage()); }
    assertNull("Check ref null", ref);
   
    reg2.unregister();
  }
View Full Code Here

  }
 
  public void testRegistrationAndListener() {
    ComponentInstance im = new FakeComponent();
    ComponentInstance im2 = new FakeComponent();
    ServiceRegistry registry = new ServiceRegistry(getContext());
    assertNotNull("Assert registry not null", registry);
    svcListener all = new svcListener();
    try {
      assertNull("Check that there is no available service", registry.getServiceReferences(null, null));
    } catch (InvalidSyntaxException e) { fail("Cannot query the registry : " + e.getMessage()); }
    registry.addServiceListener(all);
   
    ServiceRegistration reg1 = registry.registerService(im, BarService.class.getName(), new barProvider(), null);
   
    try {
      assertEquals("Check number of registred service", 1, registry.getServiceReferences(null, null).length);
    } catch (InvalidSyntaxException e) { fail("Cannot query the registry : " + e.getMessage());
     }
 
      ServiceRegistration reg2 = registry.registerService(im2, BarService.class.getName(), new barProvider(), null);
     
     try {
      assertEquals("Check number of registred service", 2, registry.getServiceReferences(null, null).length);
    } catch (InvalidSyntaxException e) { fail("Cannot query the registry : " + e.getMessage()); }
     
    assertEquals("Check the number of registration", 2, all.registration);
   
    Properties props = new Properties();
    props.put("foo", "bar");
    reg1.setProperties(props);
    assertEquals("Check the number of modification", 1, all.modification);
   
    reg1.unregister();
    assertEquals("Check the number of unregistration", 1, all.unregistration);
   
    reg2.setProperties(props);
    assertEquals("Check the number of modification", 2, all.modification);
   
    reg2.unregister();
    assertEquals("Check the number of unregistration", 2, all.unregistration);
   
    registry.removeServiceListener(all);
  }
View Full Code Here

  }
 
  public void testRegistrationAndFilter() {
    ComponentInstance im = new FakeComponent();
    ComponentInstance im2 = new FakeComponent();
    ServiceRegistry registry = new ServiceRegistry(getContext());
    svcListener filtered = new svcListener();
   
    try {
      assertNull("Check that there is no available service", registry.getServiceReferences(null, null));
    } catch (InvalidSyntaxException e) { fail("Cannot query the registry : " + e.getMessage()); }
     
    registry.addServiceListener(filtered, "(foo=bar)");
   
    Properties props = new Properties();
    props.put("foo", "bar");
    ServiceRegistration reg1 = registry.registerService(im, BarService.class.getName(), new barProvider(), props);
   
    try {
      assertEquals("Check number of registred service", 1, registry.getServiceReferences(null, null).length);
    } catch (InvalidSyntaxException e) { fail("Cannot query the registry : " + e.getMessage()); }
     
    ServiceRegistration reg2 = registry.registerService(im2, BarService.class.getName(), new barProvider(), null);
     
     try {
      assertEquals("Check number of registred service", 2, registry.getServiceReferences(null, null).length);
    } catch (InvalidSyntaxException e) { fail("Cannot query the registry : " + e.getMessage()); }
       
    assertEquals("Check the number of registration", 1, filtered.registration);
   
    reg2.setProperties(props);
    assertEquals("Check the number of modification", 1, filtered.modification);
    // Follow the OSGi semantics of filters
   
    reg1.unregister();
    reg2.unregister();
    assertEquals("Check the number of unregistration", 2, filtered.unregistration);
    registry.removeServiceListener(filtered);
  }
View Full Code Here

     * given bundle context.
     *
     * @param context : the bundle context
     */
    public CompositeServiceContext(BundleContext context) {
        m_registry = new ServiceRegistry(context);
        if (context instanceof IPojoContext) {
            m_global = ((IPojoContext) context).getGlobalContext();
        } else {
            m_global = context; // the parent context is the global context
        }
View Full Code Here

    @Test
    public void testRegistrationAndListener() {
        ComponentInstance im = new FakeComponent();
        ComponentInstance im2 = new FakeComponent();
        ServiceRegistry registry = new ServiceRegistry(getContext());
        assertNotNull("Assert registry not null", registry);
        svcListener all = new svcListener();
        try {
            assertNull("Check that there is no available service", registry.getServiceReferences(null, null));
        } catch (InvalidSyntaxException e) {
            fail("Cannot query the registry : " + e.getMessage());
        }
        registry.addServiceListener(all);

        ServiceRegistration reg1 = registry.registerService(im, BarService.class.getName(), new barProvider(), null);

        try {
            assertEquals("Check number of registred service", 1, registry.getServiceReferences(null, null).length);
        } catch (InvalidSyntaxException e) {
            fail("Cannot query the registry : " + e.getMessage());
        }

        ServiceRegistration reg2 = registry.registerService(im2, BarService.class.getName(), new barProvider(), null);

        try {
            assertEquals("Check number of registred service", 2, registry.getServiceReferences(null, null).length);
        } catch (InvalidSyntaxException e) {
            fail("Cannot query the registry : " + e.getMessage());
        }

        assertEquals("Check the number of registration", 2, all.registration);

        Dictionary<String, String> props = new Hashtable<String, String>();
        props.put("foo", "bar");
        reg1.setProperties(props);
        assertEquals("Check the number of modification", 1, all.modification);

        reg1.unregister();
        assertEquals("Check the number of unregistration", 1, all.unregistration);

        reg2.setProperties(props);
        assertEquals("Check the number of modification", 2, all.modification);

        reg2.unregister();
        assertEquals("Check the number of unregistration", 2, all.unregistration);

        registry.removeServiceListener(all);
    }
View Full Code Here

    @Test
    public void testRegistrationAndFilter() {
        ComponentInstance im = new FakeComponent();
        ComponentInstance im2 = new FakeComponent();
        ServiceRegistry registry = new ServiceRegistry(getContext());
        svcListener filtered = new svcListener();

        try {
            assertNull("Check that there is no available service", registry.getServiceReferences(null, null));
        } catch (InvalidSyntaxException e) {
            fail("Cannot query the registry : " + e.getMessage());
        }

        registry.addServiceListener(filtered, "(foo=bar)");

        Dictionary<String, String> props = new Hashtable<String, String>();
        props.put("foo", "bar");
        ServiceRegistration reg1 = registry.registerService(im, BarService.class.getName(), new barProvider(), props);

        try {
            assertEquals("Check number of registred service", 1, registry.getServiceReferences(null, null).length);
        } catch (InvalidSyntaxException e) {
            fail("Cannot query the registry : " + e.getMessage());
        }

        ServiceRegistration reg2 = registry.registerService(im2, BarService.class.getName(), new barProvider(), null);

        try {
            assertEquals("Check number of registred service", 2, registry.getServiceReferences(null, null).length);
        } catch (InvalidSyntaxException e) {
            fail("Cannot query the registry : " + e.getMessage());
        }

        assertEquals("Check the number of registration", 1, filtered.registration);

        reg2.setProperties(props);
        assertEquals("Check the number of modification", 1, filtered.modification);
        // Follow the OSGi semantics of filters

        reg1.unregister();
        reg2.unregister();
        assertEquals("Check the number of unregistration", 2, filtered.unregistration);
        registry.removeServiceListener(filtered);
    }
View Full Code Here

    @Test
    public void testGetService() {
        ComponentInstance im = new FakeComponent();
        ComponentInstance im2 = new FakeComponent();
        ServiceRegistry registry = new ServiceRegistry(getContext());

        try {
            assertNull("Check that there is no available service", registry.getServiceReferences(null, null));
        } catch (InvalidSyntaxException e) {
            fail("Cannot query the registry : " + e.getMessage());
        }

        Properties props = new Properties();
        props.put("foo", "bar");
        ServiceRegistration reg1 = registry.registerService(im, BarService.class.getName(), new barProvider(), props);

        ServiceReference ref = registry.getServiceReference(BarService.class.getName());
        assertNotNull("Check ref not null", ref);
        assertEquals("Test property", ref.getProperty("foo"), "bar");
        BarService bar = (BarService) registry.getService(im2, ref);
        assertTrue("Test invocation", bar.bar());

        reg1.unregister();
        ref = registry.getServiceReference(BarService.class.getName());
        assertNull("Check ref null", ref);
    }
View Full Code Here

    @Test
    public void testGetFilteredService() {
        ComponentInstance im = new FakeComponent();
        ComponentInstance im2 = new FakeComponent();
        ServiceRegistry registry = new ServiceRegistry(getContext());

        try {
            assertNull("Check that there is no available service", registry.getServiceReferences(null, null));
        } catch (InvalidSyntaxException e) {
            fail("Cannot query the registry : " + e.getMessage());
        }

        Properties props = new Properties();
        props.put("foo", "bar");
        ServiceRegistration reg1 = registry.registerService(im, BarService.class.getName(), new barProvider(), props);
        ServiceRegistration reg2 = registry.registerService(im2, BarService.class.getName(), new barProvider(), null);

        ServiceReference[] ref = null;
        try {
            ref = registry.getServiceReferences(BarService.class.getName(), "(foo=bar)");
        } catch (InvalidSyntaxException e) {
            fail("Registry query fail : " + e.getMessage());
        }
        assertNotNull("Check ref not null", ref);
        assertEquals("Check ref count", ref.length, 1);
        assertEquals("Test property", ref[0].getProperty("foo"), "bar");
        BarService bar = (BarService) registry.getService(im2, ref[0]);
        assertTrue("Test invocation", bar.bar());

        ref = null;
        reg1.unregister();
        try {
            ref = registry.getServiceReferences(BarService.class.getName(), "(bar=foo)");
        } catch (InvalidSyntaxException e) {
            fail("Registry query fail : " + e.getMessage());
        }
        assertNull("Check ref null", ref);
View Full Code Here

     * given bundle context.
     *
     * @param context : the bundle context
     */
    public CompositeServiceContext(BundleContext context) {
        m_registry = new ServiceRegistry(context);
        if (context instanceof IPojoContext) {
            m_global = ((IPojoContext) context).getGlobalContext();
        } else {
            m_global = context; // the parent context is the global context
        }
View Full Code Here

TOP

Related Classes of org.apache.felix.ipojo.context.ServiceRegistry

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.