@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()); }
@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()); }
@Before public void setUp() throws Exception { storage = new MemoryRepositoryStorage(Mockito.mock(XRepository.class)); RepositoryReader reader = getRepositoryReader("xml/sample-repository.xml"); storage.addResource(reader.nextResource()); }