コード例 #1
0
  @Test
  public void testRequireBundleWithFilter() throws Exception {

    XRequirementBuilder builder = XRequirementBuilder.create(BundleNamespace.BUNDLE_NAMESPACE);
    builder
        .getDirectives()
        .put(BundleNamespace.REQUIREMENT_FILTER_DIRECTIVE, "(osgi.wiring.bundle=org.acme.pool)");
    XRequirement req = builder.getRequirement();

    Collection<Capability> providers = storage.findProviders(req);
    Assert.assertNotNull("Providers not null", providers);
    Assert.assertEquals("One provider", 1, providers.size());
  }
コード例 #2
0
  @Test
  public void testRepositoryService() throws Exception {

    Repository repo = getRepository();
    MavenCoordinates coordinates =
        MavenCoordinates.parse("org.apache.felix:org.apache.felix.eventadmin:1.2.6");
    Requirement req = XRequirementBuilder.createArtifactRequirement(coordinates);
    assertNotNull("Requirement not null", req);

    Collection<Capability> caps = repo.findProviders(Collections.singleton(req)).get(req);
    assertEquals("Capability not null", 1, caps.size());

    XIdentityCapability xcap = (XIdentityCapability) caps.iterator().next();
    assertEquals("org.apache.felix.eventadmin", xcap.getSymbolicName());
    InputStream content = ((XResource) xcap.getResource()).getContent();
    try {
      Bundle bundle = context.installBundle(xcap.getSymbolicName(), content);
      try {
        bundle.start();
        Assert.assertEquals(Bundle.ACTIVE, bundle.getState());
        ServiceReference sref = context.getServiceReference("org.osgi.service.event.EventAdmin");
        assertNotNull("EventAdmin service not null", sref);
      } finally {
        bundle.uninstall();
      }
    } finally {
      content.close();
    }
  }
コード例 #3
0
  @Test
  public void testRequireBundle() throws Exception {

    RepositoryReader reader = storage.getRepositoryReader();
    XResource resource = reader.nextResource();
    Assert.assertNotNull("Resource not null", resource);
    Assert.assertNull("One resource only", reader.nextResource());

    XRequirementBuilder builder =
        XRequirementBuilder.create(BundleNamespace.BUNDLE_NAMESPACE, "org.acme.pool");
    XRequirement req = builder.getRequirement();

    Collection<Capability> providers = storage.findProviders(req);
    Assert.assertNotNull("Providers not null", providers);
    Assert.assertEquals("One provider", 1, providers.size());

    XCapability cap = (XCapability) providers.iterator().next();
    Assert.assertNotNull("Capability not null", cap);
    Assert.assertSame(resource, cap.getResource());
  }