Package org.apache.felix.ipojo

Examples of org.apache.felix.ipojo.ServiceContext


    empty2.dispose();
  }

  public void testInvocation() {
    ServiceContext sc1 = Utils.getServiceContext(empty);
    Factory fact = Utils.getFactoryByName(sc1, "composite.empty");
    Properties p = new Properties();
    p.put("instance.name","empty2");
    ComponentInstance empty2 = null;
    try {
      empty2 = fact.createComponentInstance(p);
    } catch (Exception e) {
      fail("Cannot instantiate empty2 instance : " + e.getMessage());
    }

    ServiceContext sc2 = Utils.getServiceContext(empty2);

    Factory fact1 = Utils.getFactoryByName(sc2, "COMPO-SimpleCheckServiceProvider");
    Properties props = new Properties();
    props.put("instance.name","client");
    ComponentInstance client = null;
    try {
      client = fact1.createComponentInstance(props);
    } catch (Exception e) { e.printStackTrace(); fail("Cannot instantiate the client : " + e.getMessage()); }

    Factory fact2 = Utils.getFactoryByName(sc2, "COMPO-FooProviderType-1");
    Properties props2 = new Properties();
    props2.put("instance.name","provider");
    ComponentInstance provider = null;
    try {
      provider = fact2.createComponentInstance(props2);
    } catch (Exception e) {
      fail("Cannot instantiate the provider : " + e.getMessage());
    }

    ServiceReference ref = sc2.getServiceReference(CheckService.class.getName());
    assertNotNull("Check ref existency", ref);
    CheckService check = (CheckService) sc2.getService(ref);

    assertTrue("Check invocation", check.check());
    client.dispose();
    provider.dispose();
    empty2.dispose();
View Full Code Here


 
  public void testSimple() {
    import3.start();
    //Two providers
    assertTrue("Test component validity", import3.getState() == ComponentInstance.VALID);
    ServiceContext sc = Utils.getServiceContext(import3);
    ServiceReference[] refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
    assertNotNull("Test foo availability inside the composite - 1", refs);
    assertEquals("Test foo availability inside the composite - 1.2", refs.length, 1);
    FooService fs = (FooService) sc.getService(refs[0]);
    assertTrue("Test foo invocation", fs.foo());
    sc.ungetService(refs[0]);
   
    foo1.stop();
    assertTrue("Test component validity", import3.getState() == ComponentInstance.VALID);
    sc = Utils.getServiceContext(import3);
    refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
    assertNotNull("Test foo availability inside the composite - 1", refs);
    assertEquals("Test foo availability inside the composite - 1.2", refs.length, 1);
    fs = (FooService) sc.getService(refs[0]);
    assertTrue("Test foo invocation", fs.foo());
    sc.ungetService(refs[0]);
   
    // Stop the second provider
    foo2.stop();   
    assertTrue("Test component validity - 2", import3.getState() == ComponentInstance.VALID);
    sc = Utils.getServiceContext(import3);
    refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
    assertEquals("Test foo non-availability inside the composite - 3.1", refs.length, 0);
   
    foo2.start();
    assertTrue("Test component validity", import3.getState() == ComponentInstance.VALID);
    sc = Utils.getServiceContext(import3);
    refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
    assertNotNull("Test foo availability inside the composite - 3", refs);
    assertEquals("Test foo availability inside the composite - 3.1", refs.length, 1);
    fs = (FooService) sc.getService(refs[0]);
    assertTrue("Test foo invocation", fs.foo());
    sc.ungetService(refs[0]);
  }
View Full Code Here

 
  public void testSimple2() {
    import3.start();
    //Two providers
    assertTrue("Test component validity", import3.getState() == ComponentInstance.VALID);
    ServiceContext sc = Utils.getServiceContext(import3);
    ServiceReference[] refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
    assertNotNull("Test foo availability inside the composite - 1", refs);
    assertEquals("Test foo availability inside the composite - 1.2", refs.length, 1);
    FooService fs = (FooService) sc.getService(refs[0]);
    assertTrue("Test foo invocation", fs.foo());
    sc.ungetService(refs[0]);
   
    foo2.stop();
    assertTrue("Test component validity", import3.getState() == ComponentInstance.VALID);
    sc = Utils.getServiceContext(import3);
    refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
    assertNotNull("Test foo availability inside the composite - 1", refs);
    assertEquals("Test foo availability inside the composite - 1.2", refs.length, 1);
    fs = (FooService) sc.getService(refs[0]);
    assertTrue("Test foo invocation", fs.foo());
    sc.ungetService(refs[0]);
   
    // Stop the second provider
    foo1.stop();   
    assertTrue("Test component validity - 2", import3.getState() == ComponentInstance.VALID);
    sc = Utils.getServiceContext(import3);
    refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
    assertEquals("Test foo availability inside the composite - 3.1", refs.length, 0);
   
    foo1.start();
    assertTrue("Test component validity", import3.getState() == ComponentInstance.VALID);
    sc = Utils.getServiceContext(import3);
    refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
    assertNotNull("Test foo availability inside the composite - 3", refs);
    assertEquals("Test foo availability inside the composite - 3.1", refs.length, 1);
    fs = (FooService) sc.getService(refs[0]);
    assertTrue("Test foo invocation", fs.foo());
    sc.ungetService(refs[0]);
  }
View Full Code Here

 
  public void testSimple2() {
    import1.start();
    //Two providers
    assertTrue("Test component validity", import1.getState() == ComponentInstance.VALID);
    ServiceContext sc = Utils.getServiceContext(import1);
    ServiceReference[] refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
    assertNotNull("Test foo availability inside the composite - 1", refs);
    assertEquals("Test foo availability inside the composite - 1.2", refs.length, 1);
    FooService fs = (FooService) sc.getService(refs[0]);
    assertTrue("Test foo invocation", fs.foo());
    sc.ungetService(refs[0]);
   
    foo2.stop();
    assertTrue("Test component validity", import1.getState() == ComponentInstance.VALID);
    sc = Utils.getServiceContext(import1);
    refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
    assertNotNull("Test foo availability inside the composite - 1", refs);
    assertEquals("Test foo availability inside the composite - 1.2", refs.length, 1);
    fs = (FooService) sc.getService(refs[0]);
    assertTrue("Test foo invocation", fs.foo());
    sc.ungetService(refs[0]);
   
    // Stop the second provider
    foo1.stop();   
    assertTrue("Test component invalidity - 2", import1.getState() == ComponentInstance.INVALID);
   
    foo1.start();
    assertTrue("Test component validity", import1.getState() == ComponentInstance.VALID);
    sc = Utils.getServiceContext(import1);
    refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
    assertNotNull("Test foo availability inside the composite - 3", refs);
    assertEquals("Test foo availability inside the composite - 3.1", refs.length, 1);
    fs = (FooService) sc.getService(refs[0]);
    assertTrue("Test foo invocation", fs.foo());
    sc.ungetService(refs[0]);
  }
View Full Code Here

      under = bar2Factory.createComponentInstance(props);
    } catch(Exception e) {
      fail("Cannot instantiate under : " + e.getMessage());
   
    assertTrue("Check instance validity", under.getState() == ComponentInstance.VALID);
    ServiceContext sc = Utils.getServiceContext(under);
    assertNotNull("Check service availability", sc.getServiceReference(BarService.class.getName()));
    int count = Utils.getServiceReferences(sc, BarService.class.getName(), null).length;
    assertEquals("Check service provider number : " + count, count, 3);
   
    under.dispose();
  }
View Full Code Here

   
    under.dispose();
  }
 
  public void testCreationLevel2() {
    ServiceContext sc = Utils.getServiceContext(empty);
    Properties props = new Properties();
    props.put("instance.name","under");
    ComponentInstance under = null;
    try {
      under = bar2Factory.createComponentInstance(props, sc);
View Full Code Here

    assertTrue("Check instance validity", under.getState() == ComponentInstance.VALID);
    under.dispose();
  }
 
  public void testServiceAvailabilityLevel2() {
    ServiceContext sc = Utils.getServiceContext(empty);
    Properties props = new Properties();
    props.put("instance.name","under");
    ComponentInstance under = null;
    try {
      under = bar2Factory.createComponentInstance(props, sc);
    } catch(Exception e) {
      fail("Cannot instantiate under : " + e.getMessage());
   
    assertTrue("Check instance validity", under.getState() == ComponentInstance.VALID);
    ServiceContext sc2 = Utils.getServiceContext(under);
    assertNotNull("Check service availability", sc2.getServiceReference(BarService.class.getName()));
    assertEquals("Check service provider number", Utils.getServiceReferences(sc2, BarService.class.getName(), null).length, 3);
   
    under.dispose();
  }
View Full Code Here

    try {
      under = bar2Factory.createComponentInstance(props);
    } catch(Exception e) {
      fail("Cannot instantiate under : " + e.getMessage());
    }
    ServiceContext sc = Utils.getServiceContext(under);
    assertTrue("Check instance validity - 1", under.getState() == ComponentInstance.VALID);
   
    ComponentFactory fact1 = (ComponentFactory) Utils.getFactoryByName(getContext(), "COMPO-FooBarProviderType-1");
    ComponentFactory fact2 = (ComponentFactory) Utils.getFactoryByName(getContext(), "COMPO-FooBarProviderType-2");
    ComponentFactory fact3 = (ComponentFactory) Utils.getFactoryByName(getContext(), "COMPO-FooBarProviderType-3");
View Full Code Here

    fact2.start();
    fact3.start();
  }
 
  public void testFactoryManagementLevel2() {
    ServiceContext sc = Utils.getServiceContext(empty);
    Properties props = new Properties();
    props.put("instance.name","under");
    ComponentInstance under = null;
    try {
      under = bar2Factory.createComponentInstance(props, sc);
    } catch(Exception e) {
      fail("Cannot instantiate under : " + e.getMessage());
    }
    assertTrue("Check instance validity - 1", under.getState() == ComponentInstance.VALID);
    ServiceContext sc2 = Utils.getServiceContext(under);
   
    ComponentFactory fact1 = (ComponentFactory) Utils.getFactoryByName(getContext(), "COMPO-FooBarProviderType-1");
    ComponentFactory fact2 = (ComponentFactory) Utils.getFactoryByName(getContext(), "COMPO-FooBarProviderType-2");
    ComponentFactory fact3 = (ComponentFactory) Utils.getFactoryByName(getContext(), "COMPO-FooBarProviderType-3");
   
View Full Code Here

      under = compoFactory.createComponentInstance(props);
    } catch(Exception e) {
      fail("Cannot instantiate under : " + e.getMessage());
   
    assertTrue("Check instance validity", under.getState() == ComponentInstance.VALID);
    ServiceContext sc = Utils.getServiceContext(under);
      
    assertNotNull("Check service availability", sc.getServiceReference(FooService.class.getName()));
        assertEquals("Check service provider", Utils.getServiceReferences(sc, FooService.class.getName(), null).length, 2);
   
    under.dispose();
  }
View Full Code Here

TOP

Related Classes of org.apache.felix.ipojo.ServiceContext

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.