Exemplo n.º 1
0
  public void testResolveReq() throws Exception {
    RepositoryAdminImpl repoAdmin = createRepositoryAdmin();
    repoAdmin.addRepository(getClass().getResource("/repo_for_resolvertest.xml"));

    Resolver resolver = repoAdmin.resolver();
    resolver.add(
        repoAdmin.getHelper().requirement("package", "(package=org.apache.felix.test.osgi)"));
    assertTrue(resolver.resolve());
  }
Exemplo n.º 2
0
  public void testOptionalResolution() throws Exception {
    RepositoryAdminImpl repoAdmin = createRepositoryAdmin();
    repoAdmin.addRepository(getClass().getResource("/repo_for_optional_resources.xml"));

    Resolver resolver = repoAdmin.resolver();
    resolver.add(repoAdmin.getHelper().requirement("bundle", "(symbolicname=res1)"));

    assertTrue(resolver.resolve());
    assertEquals(1, resolver.getRequiredResources().length);
    assertEquals(2, resolver.getOptionalResources().length);
  }
Exemplo n.º 3
0
  public void testMatchingReq() throws Exception {
    RepositoryAdminImpl repoAdmin = createRepositoryAdmin();
    repoAdmin.addRepository(getClass().getResource("/repo_for_resolvertest.xml"));

    Resource[] res =
        repoAdmin.discoverResources(
            new Requirement[] {
              repoAdmin.getHelper().requirement("package", "(package=org.apache.felix.test.osgi)")
            });
    assertNotNull(res);
    assertEquals(1, res.length);
  }
Exemplo n.º 4
0
  public void testResolveInterrupt() throws Exception {
    RepositoryAdminImpl repoAdmin = createRepositoryAdmin();
    repoAdmin.addRepository(getClass().getResource("/repo_for_resolvertest.xml"));

    Resolver resolver = repoAdmin.resolver();
    resolver.add(
        repoAdmin.getHelper().requirement("package", "(package=org.apache.felix.test.osgi)"));

    Thread.currentThread().interrupt();
    try {
      resolver.resolve();
      fail("An excepiton should have been thrown");
    } catch (org.apache.felix.bundlerepository.InterruptedResolutionException e) {
      // ok
    }
  }
Exemplo n.º 5
0
  public void testReferral1() throws Exception {

    URL url = getClass().getResource("/repo_for_resolvertest.xml");
    RepositoryAdminImpl repoAdmin = createRepositoryAdmin();
    RepositoryImpl repo = (RepositoryImpl) repoAdmin.addRepository(url);

    Resolver resolver = repoAdmin.resolver();

    Resource[] discoverResources =
        repoAdmin.discoverResources("(symbolicname=org.apache.felix.test*)");
    assertNotNull(discoverResources);
    assertEquals(1, discoverResources.length);

    resolver.add(discoverResources[0]);
    assertTrue(resolver.resolve());
  }
Exemplo n.º 6
0
  private RepositoryAdminImpl createRepositoryAdmin() throws Exception {
    BundleContext bundleContext = (BundleContext) EasyMock.createMock(BundleContext.class);
    Bundle systemBundle = (Bundle) EasyMock.createMock(Bundle.class);

    Activator.setContext(bundleContext);
    EasyMock.expect(bundleContext.getProperty(RepositoryAdminImpl.REPOSITORY_URL_PROP))
        .andReturn(getClass().getResource("/referred.xml").toExternalForm());
    EasyMock.expect(bundleContext.getProperty((String) EasyMock.anyObject()))
        .andReturn(null)
        .anyTimes();
    EasyMock.expect(bundleContext.getBundle(0)).andReturn(systemBundle);
    EasyMock.expect(systemBundle.getHeaders()).andReturn(new Hashtable());
    EasyMock.expect(systemBundle.getRegisteredServices()).andReturn(null);
    EasyMock.expect(new Long(systemBundle.getBundleId())).andReturn(new Long(0)).anyTimes();
    EasyMock.expect(systemBundle.getBundleContext()).andReturn(bundleContext);
    bundleContext.addBundleListener((BundleListener) EasyMock.anyObject());
    bundleContext.addServiceListener((ServiceListener) EasyMock.anyObject());
    EasyMock.expect(bundleContext.getBundles()).andReturn(new Bundle[] {systemBundle});
    final Capture c = new Capture();
    EasyMock.expect(bundleContext.createFilter((String) capture(c)))
        .andAnswer(
            new IAnswer() {
              public Object answer() throws Throwable {
                return FilterImpl.newInstance((String) c.getValue());
              }
            })
        .anyTimes();
    EasyMock.replay(new Object[] {bundleContext, systemBundle});

    RepositoryAdminImpl repoAdmin =
        new RepositoryAdminImpl(bundleContext, new Logger(bundleContext));

    // force initialization && remove all initial repositories
    Repository[] repos = repoAdmin.listRepositories();
    for (int i = 0; repos != null && i < repos.length; i++) {
      repoAdmin.removeRepository(repos[i].getURI());
    }

    return repoAdmin;
  }
Exemplo n.º 7
0
  public void testMandatoryPackages() throws Exception {
    RepositoryAdminImpl repoAdmin = createRepositoryAdmin();
    repoAdmin.addRepository(getClass().getResource("/repo_for_mandatory.xml"));

    Resolver resolver = repoAdmin.resolver();
    resolver.add(repoAdmin.getHelper().requirement("bundle", "(symbolicname=res2)"));
    assertFalse(resolver.resolve());

    resolver = repoAdmin.resolver();
    resolver.add(repoAdmin.getHelper().requirement("bundle", "(symbolicname=res3)"));
    assertTrue(resolver.resolve());

    resolver = repoAdmin.resolver();
    resolver.add(repoAdmin.getHelper().requirement("bundle", "(symbolicname=res4)"));
    assertFalse(resolver.resolve());
  }