Package org.apache.felix.ipojo

Examples of org.apache.felix.ipojo.ServiceContext


    empty.dispose();
    empty = null;
  }
 
  public void testLevelOne1() {
    ServiceContext sc2 = Utils.getServiceContext(empty);
   
    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) { 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());
    CheckService check = (CheckService) sc2.getService(ref);
   
    assertTrue("Check invocation", check.check());
   
    sc2.ungetService(ref);
   
    // Check visibility
    assertNotNull("Check foo service visible inside the composite", sc2.getServiceReference(FooService.class.getName()));
    assertNotNull("Check check service visible inside the composite", sc2.getServiceReference(CheckService.class.getName()));
    // Check invisibilty
    assertNull("Check foo service invisible inside the context", getContext().getServiceReference(FooService.class.getName()));
    try {
      assertNull("Check check service invisible inside the context", getContext().getServiceReferences(CheckService.class.getName(), "(instance.name=client)"));
    } catch (InvalidSyntaxException e) {
      fail("Invalid filter : " + e);
    }
   
    provider.dispose();
    client.dispose();
    
    assertNull("Check foo service invisible inside the composite", sc2.getServiceReference(FooService.class.getName()));
    assertNull("Check check service invisible inside the composite", sc2.getServiceReference(CheckService.class.getName()));
    assertNull("Check foo service invisible from the context", getContext().getServiceReference(FooService.class.getName()));
    try {
      assertNull("Check check service invisible inside the context", getContext().getServiceReferences(CheckService.class.getName(), "(instance.name=client)"));
    } catch (InvalidSyntaxException e) {
      fail("Invalid filter : " + e);
View Full Code Here


      fail("Invalid filter : " + e);
    }
  }
 
  public void testLevelOne2() {
    ServiceContext sc2 = Utils.getServiceContext(empty);
   
    Factory fact1 = Utils.getFactoryByName(sc2, "COMPO-SimpleCheckServiceProvider");
    Properties props = new Properties();
    props.put("instance.name","client");
    ComponentInstance client = null;
    try {
      client = fact1.createComponentInstance(props, sc2);
    } catch(Exception e) { 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, sc2);
    } catch(Exception e) {
      fail("Cannot instantiate the provider : " + e.getMessage());
    }
   
    ServiceReference ref = sc2.getServiceReference(CheckService.class.getName());
    CheckService check = (CheckService) sc2.getService(ref);
   
    assertTrue("Check invocation", check.check());
   
    sc2.ungetService(ref);
   
    // Check visibility
    assertNotNull("Check foo service visible inside the composite", sc2.getServiceReference(FooService.class.getName()));
    assertNotNull("Check check service visible inside the composite", sc2.getServiceReference(CheckService.class.getName()));
    // Check invisibilty
    assertNull("Check foo service invisible inside the context", getContext().getServiceReference(FooService.class.getName()));
    try {
      assertNull("Check check service invisible inside the context", getContext().getServiceReferences(CheckService.class.getName(), "(instance.name=client)"));
    } catch (InvalidSyntaxException e) {
      fail("Invalid filter : " + e);
    }
   
    client.dispose();
    provider.dispose();
    
    assertNull("Check foo service visible inside the composite 2", sc2.getServiceReference(FooService.class.getName()));
    assertNull("Check check service visible inside the composite 2", sc2.getServiceReference(CheckService.class.getName()));
    assertNull("Check foo service invisible inside the global", getContext().getServiceReference(FooService.class.getName()));
    try {
      assertNull("Check check service invisible inside the context", getContext().getServiceReferences(CheckService.class.getName(), "(instance.name=client)"));
    } catch (InvalidSyntaxException e) {
      fail("Invalid filter : " + e);
View Full Code Here

      fail("Invalid filter : " + e);
    }
  }
 
  public void testLevelOne3() {
    ServiceContext sc2 = Utils.getServiceContext(empty);
   
    Factory fact1 = Utils.getFactoryByName(getContext(), "COMPO-SimpleCheckServiceProvider");
    Properties props = new Properties();
    props.put("instance.name","client");
    ComponentInstance client = null;
    try {
      client = fact1.createComponentInstance(props, sc2);
    } catch(Exception e) { fail("Cannot instantiate the client : " + e.getMessage()); }
   
    Factory fact2 = Utils.getFactoryByName(getContext(), "COMPO-FooProviderType-1");
    Properties props2 = new Properties();
    props2.put("instance.name","provider");
    ComponentInstance provider = null;
    try {
      provider = fact2.createComponentInstance(props2, sc2);
    } catch(Exception e) {
      fail("Cannot instantiate the provider : " + e.getMessage());
    }
   
    ServiceReference ref = sc2.getServiceReference(CheckService.class.getName());
    CheckService check = (CheckService) sc2.getService(ref);
   
    assertTrue("Check invocation", check.check());
   
    sc2.ungetService(ref);
   
    // Check visibility
    assertNotNull("Check foo service visible inside the composite", sc2.getServiceReference(FooService.class.getName()));
    assertNotNull("Check check service visible inside the composite", sc2.getServiceReference(CheckService.class.getName()));
    // Check invisibilty
    assertNull("Check foo service invisible inside the context", getContext().getServiceReference(FooService.class.getName()));
    try {
      assertNull("Check check service invisible inside the context", getContext().getServiceReferences(CheckService.class.getName(), "(instance.name=client)"));
    } catch (InvalidSyntaxException e) {
      fail("Invalid filter : " + e);
    }
   
    client.dispose();
    provider.dispose();
    
    assertNull("Check foo service visible inside the composite 2", sc2.getServiceReference(FooService.class.getName()));
    assertNull("Check check service visible inside the composite 2", sc2.getServiceReference(CheckService.class.getName()));
    assertNull("Check foo service invisible inside the global", getContext().getServiceReference(FooService.class.getName()));
    try {
      assertNull("Check check service invisible inside the context", getContext().getServiceReferences(CheckService.class.getName(), "(instance.name=client)"));
    } catch (InvalidSyntaxException e) {
      fail("Invalid filter : " + e);
View Full Code Here

      fail("Invalid filter : " + e);
    }
  }
 
  public void testLevelTwo1() {
    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) { 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());
    CheckService check = (CheckService) sc2.getService(ref);
   
    assertTrue("Check invocation", check.check());
   
    sc2.ungetService(ref);
   
    //  Check visibility
    assertNotNull("Check foo service visible inside the composite 2", sc2.getServiceReference(FooService.class.getName()));
    assertNotNull("Check check service visible inside the composite 2", sc2.getServiceReference(CheckService.class.getName()));
    // Check invisibilty
    assertNull("Check foo service invisible inside the composite 1", sc1.getServiceReference(FooService.class.getName()));
    assertNull("Check check service invisible inside the composite 1", sc1.getServiceReference(CheckService.class.getName()));
    assertNull("Check foo service invisible inside the global", getContext().getServiceReference(FooService.class.getName()));
    try {
      assertNull("Check check service invisible inside the context", getContext().getServiceReferences(CheckService.class.getName(), "(instance.name=client)"));
    } catch (InvalidSyntaxException e) {
      fail("Invalid filter : " + e);
    }
   
    client.dispose();
    provider.dispose();
    
    assertNull("Check foo service visible inside the composite 2", sc2.getServiceReference(FooService.class.getName()));
    assertNull("Check check service visible inside the composite 2", sc2.getServiceReference(CheckService.class.getName()));
    assertNull("Check foo service invisible inside the composite 1", sc1.getServiceReference(FooService.class.getName()));
    assertNull("Check check service invisible inside the composite 1", sc1.getServiceReference(CheckService.class.getName()));
    assertNull("Check foo service invisible inside the global", getContext().getServiceReference(FooService.class.getName()));
    try {
      assertNull("Check check service invisible inside the context", getContext().getServiceReferences(CheckService.class.getName(), "(instance.name=client)"));
View Full Code Here

    }
    empty2.dispose();
  }
 
  public void testLevelTwo2() {
    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(sc1, "COMPO-SimpleCheckServiceProvider");
    Properties props = new Properties();
    props.put("instance.name","client");
    ComponentInstance client = null;
    try {
      client = fact1.createComponentInstance(props, sc2);
    } catch(Exception e) { fail("Cannot instantiate the client : " + e.getMessage()); }
   
    Factory fact2 = Utils.getFactoryByName(sc1, "COMPO-FooProviderType-1");
    Properties props2 = new Properties();
    props2.put("instance.name","provider");
    ComponentInstance provider = null;
    try {
      provider = fact2.createComponentInstance(props2, sc2);
    } catch(Exception e) {
      fail("Cannot instantiate the provider : " + e.getMessage());
    }
   
    ServiceReference ref = sc2.getServiceReference(CheckService.class.getName());
    CheckService check = (CheckService) sc2.getService(ref);
   
    assertTrue("Check invocation", check.check());
   
    sc2.ungetService(ref);
   
    //  Check visibility
    assertNotNull("Check foo service visible inside the composite 2", sc2.getServiceReference(FooService.class.getName()));
    assertNotNull("Check check service visible inside the composite 2", sc2.getServiceReference(CheckService.class.getName()));
    // Check invisibilty
    assertNull("Check foo service invisible inside the composite 1", sc1.getServiceReference(FooService.class.getName()));
    assertNull("Check check service invisible inside the composite 1", sc1.getServiceReference(CheckService.class.getName()));
    assertNull("Check foo service invisible inside the global", getContext().getServiceReference(FooService.class.getName()));
    try {
      assertNull("Check check service invisible inside the context", getContext().getServiceReferences(CheckService.class.getName(), "(instance.name=client)"));
    } catch (InvalidSyntaxException e) {
      fail("Invalid filter : " + e);
    }
   
    client.dispose();
    provider.dispose();
    
    assertNull("Check foo service visible inside the composite 2", sc2.getServiceReference(FooService.class.getName()));
    assertNull("Check check service visible inside the composite 2", sc2.getServiceReference(CheckService.class.getName()));
    assertNull("Check foo service invisible inside the composite 1", sc1.getServiceReference(FooService.class.getName()));
    assertNull("Check check service invisible inside the composite 1", sc1.getServiceReference(CheckService.class.getName()));
    assertNull("Check foo service invisible inside the global", getContext().getServiceReference(FooService.class.getName()));
    try {
      assertNull("Check check service invisible inside the context", getContext().getServiceReferences(CheckService.class.getName(), "(instance.name=client)"));
View Full Code Here

    }
    empty2.dispose();
  }
 
  public void testLevelTwo3() {
    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(getContext(), "COMPO-SimpleCheckServiceProvider");
    Properties props = new Properties();
    props.put("instance.name","client");
    ComponentInstance client = null;
    try {
      client = fact1.createComponentInstance(props, sc2);
    } catch(Exception e) { fail("Cannot instantiate the client : " + e.getMessage()); }
   
    Factory fact2 = Utils.getFactoryByName(getContext(), "COMPO-FooProviderType-1");
    Properties props2 = new Properties();
    props2.put("instance.name","provider");
    ComponentInstance provider = null;
    try {
      provider = fact2.createComponentInstance(props2, sc2);
    } catch(Exception e) {
      fail("Cannot instantiate the provider : " + e.getMessage());
    }
   
    ServiceReference ref = sc2.getServiceReference(CheckService.class.getName());
    CheckService check = (CheckService) sc2.getService(ref);
   
    assertTrue("Check invocation", check.check());
   
    sc2.ungetService(ref);
   
    //  Check visibility
    assertNotNull("Check foo service visible inside the composite 2", sc2.getServiceReference(FooService.class.getName()));
    assertNotNull("Check check service visible inside the composite 2", sc2.getServiceReference(CheckService.class.getName()));
    // Check invisibilty
    assertNull("Check foo service invisible inside the composite 1", sc1.getServiceReference(FooService.class.getName()));
    assertNull("Check check service invisible inside the composite 1", sc1.getServiceReference(CheckService.class.getName()));
    assertNull("Check foo service invisible inside the global", getContext().getServiceReference(FooService.class.getName()));
    try {
      assertNull("Check check service invisible inside the context", getContext().getServiceReferences(CheckService.class.getName(), "(instance.name=client)"));
    } catch (InvalidSyntaxException e) {
      fail("Invalid filter : " + e);
    }
   
    client.dispose();
    provider.dispose();
    
    assertNull("Check foo service visible inside the composite 2", sc2.getServiceReference(FooService.class.getName()));
    assertNull("Check check service visible inside the composite 2", sc2.getServiceReference(CheckService.class.getName()));
    assertNull("Check foo service invisible inside the composite 1", sc1.getServiceReference(FooService.class.getName()));
    assertNull("Check check service invisible inside the composite 1", sc1.getServiceReference(CheckService.class.getName()));
    assertNull("Check foo service invisible inside the global", getContext().getServiceReference(FooService.class.getName()));
    try {
      assertNull("Check check service invisible inside the context", getContext().getServiceReferences(CheckService.class.getName(), "(instance.name=client)"));
View Full Code Here

    }
    empty2.dispose();
  }
 
  public void testLevelTwo4() {
    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, sc2);
    } catch(Exception e) { 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, sc2);
    } catch(Exception e) {
      fail("Cannot instantiate the provider : " + e.getMessage());
    }
   
    ServiceReference ref = sc2.getServiceReference(CheckService.class.getName());
    CheckService check = (CheckService) sc2.getService(ref);
   
    assertTrue("Check invocation", check.check());
   
    sc2.ungetService(ref);
   
    //  Check visibility
    assertNotNull("Check foo service visible inside the composite 2", sc2.getServiceReference(FooService.class.getName()));
    assertNotNull("Check check service visible inside the composite 2", sc2.getServiceReference(CheckService.class.getName()));
    // Check invisibilty
    assertNull("Check foo service invisible inside the composite 1", sc1.getServiceReference(FooService.class.getName()));
    assertNull("Check check service invisible inside the composite 1", sc1.getServiceReference(CheckService.class.getName()));
    assertNull("Check foo service invisible inside the global", getContext().getServiceReference(FooService.class.getName()));
    try {
      assertNull("Check check service invisible inside the context", getContext().getServiceReferences(CheckService.class.getName(), "(instance.name=client)"));
    } catch (InvalidSyntaxException e) {
      fail("Invalid filter : " + e);
    }
   
    client.dispose();
    provider.dispose();
    
    assertNull("Check foo service visible inside the composite 2", sc2.getServiceReference(FooService.class.getName()));
    assertNull("Check check service visible inside the composite 2", sc2.getServiceReference(CheckService.class.getName()));
    assertNull("Check foo service invisible inside the composite 1", sc1.getServiceReference(FooService.class.getName()));
    assertNull("Check check service invisible inside the composite 1", sc1.getServiceReference(CheckService.class.getName()));
    assertNull("Check foo service invisible inside the global", getContext().getServiceReference(FooService.class.getName()));
    try {
      assertNull("Check check service invisible inside the context", getContext().getServiceReferences(CheckService.class.getName(), "(instance.name=client)"));
View Full Code Here

    empty = null;
  }

  public void testOneLevelExposition() {
    ServiceReference[] parentsFactoryReferences = Utils.getServiceReferences(getContext(), Factory.class.getName(), null);
    ServiceContext sc = Utils.getServiceContext(empty);
    ServiceReference[] internalFactoryReferences = Utils.getServiceReferences(sc, Factory.class.getName(), null);

    assertEquals("Check the number of available factories", parentsFactoryReferences.length, internalFactoryReferences.length);

    for(int i = 0; i < parentsFactoryReferences.length; i++) {
View Full Code Here

    }
  }

  public void testTwoLevelExposition() {
    ServiceReference[] parentsFactoryReferences = Utils.getServiceReferences(getContext(), Factory.class.getName(), null);
    ServiceContext sc1 = Utils.getServiceContext(empty);
    ServiceReference[] Level1FactoryReferences = Utils.getServiceReferences(sc1, Factory.class.getName(), null);

    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);
    ServiceReference[] Level2FactoryReferences = Utils.getServiceReferences(sc2, Factory.class.getName(), null);

    assertEquals("Check the number of available factories - 1", parentsFactoryReferences.length, Level1FactoryReferences.length);
    assertEquals("Check the number of available factories - 2", parentsFactoryReferences.length, Level2FactoryReferences.length);
    assertEquals("Check the number of available factories - 3", Level1FactoryReferences.length, Level2FactoryReferences.length);
View Full Code Here

    empty2.dispose();
  }

  public void testDynamism() {
    ServiceReference[] parentsFactoryReferences = Utils.getServiceReferences(getContext(), Factory.class.getName(), null);
    ServiceContext sc1 = Utils.getServiceContext(empty);
    ServiceReference[] Level1FactoryReferences = Utils.getServiceReferences(sc1, Factory.class.getName(), null);

    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);
    ServiceReference[] Level2FactoryReferences = Utils.getServiceReferences(sc2, Factory.class.getName(), null);

    assertEquals("Check the number of available factories - 1", parentsFactoryReferences.length, Level1FactoryReferences.length);
    assertEquals("Check the number of available factories - 2", parentsFactoryReferences.length, Level2FactoryReferences.length);
    assertEquals("Check the number of available factories - 3", Level1FactoryReferences.length, Level2FactoryReferences.length);
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.