Search in sources :

Example 11 with Requirement

use of org.osgi.resource.Requirement in project aries by apache.

the class OsgiRequirementAdapterTest method testGetNamePackage.

@Test
public void testGetNamePackage() {
    Requirement req = EasyMock.createNiceMock(Requirement.class);
    EasyMock.expect(req.getNamespace()).andReturn(PackageNamespace.PACKAGE_NAMESPACE);
    EasyMock.replay(req);
    OsgiRequirementAdapter adapter = new OsgiRequirementAdapter(req);
    assertEquals("Wrong name", Capability.PACKAGE, adapter.getName());
}
Also used : Requirement(org.osgi.resource.Requirement) OsgiRequirementAdapter(org.apache.aries.subsystem.util.felix.OsgiRequirementAdapter) Test(org.junit.Test)

Example 12 with Requirement

use of org.osgi.resource.Requirement in project aries by apache.

the class OsgiRequirementAdapterTest method testGetNameBundle.

@Test
public void testGetNameBundle() {
    Requirement req = EasyMock.createNiceMock(Requirement.class);
    EasyMock.expect(req.getNamespace()).andReturn(BundleNamespace.BUNDLE_NAMESPACE);
    EasyMock.replay(req);
    OsgiRequirementAdapter adapter = new OsgiRequirementAdapter(req);
    assertEquals("Wrong name", Capability.BUNDLE, adapter.getName());
}
Also used : Requirement(org.osgi.resource.Requirement) OsgiRequirementAdapter(org.apache.aries.subsystem.util.felix.OsgiRequirementAdapter) Test(org.junit.Test)

Example 13 with Requirement

use of org.osgi.resource.Requirement in project aries by apache.

the class TestRepository method findProviders.

@Override
public Map<Requirement, Collection<Capability>> findProviders(Collection<? extends Requirement> requirements) {
    Map<Requirement, Collection<Capability>> result = new HashMap<Requirement, Collection<Capability>>();
    for (Requirement requirement : requirements) {
        for (Resource resource : resources) {
            List<Capability> capabilities = resource.getCapabilities(requirement.getNamespace());
            for (Capability capability : capabilities) {
                if (ResourceHelper.matches(requirement, capability)) {
                    Collection<Capability> c = result.get(requirement);
                    if (c == null) {
                        c = new HashSet<Capability>();
                        result.put(requirement, c);
                    }
                    c.add(capability);
                }
            }
        }
    }
    return result;
}
Also used : Requirement(org.osgi.resource.Requirement) Capability(org.osgi.resource.Capability) HashMap(java.util.HashMap) Resource(org.osgi.resource.Resource) Collection(java.util.Collection)

Example 14 with Requirement

use of org.osgi.resource.Requirement in project aries by apache.

the class TestResource method getRequirements.

@Override
public List<Requirement> getRequirements(String namespace) {
    if (namespace == null)
        return Collections.unmodifiableList(requirements);
    ArrayList<Requirement> result = new ArrayList<Requirement>(requirements.size());
    for (Requirement requirement : requirements) if (namespace.equals(requirement.getNamespace()))
        result.add(requirement);
    result.trimToSize();
    return Collections.unmodifiableList(result);
}
Also used : Requirement(org.osgi.resource.Requirement) ArrayList(java.util.ArrayList)

Example 15 with Requirement

use of org.osgi.resource.Requirement in project aries by apache.

the class Aries1429Test method testMissingParentChildEdgeNotTolerated.

@Test
public void testMissingParentChildEdgeNotTolerated() throws Exception {
    Subsystem applicationA = installSubsystemFromFile(APPLICATION_A);
    try {
        removeConnectionWithParent(applicationA);
        try {
            ((AriesSubsystem) applicationA).addRequirements(Collections.singletonList((Requirement) new TestRequirement.Builder().namespace(PackageNamespace.PACKAGE_NAMESPACE).attribute(PackageNamespace.PACKAGE_NAMESPACE, "org.osgi.framework").build()));
            fail("No exception received");
        } catch (SubsystemException e) {
            Throwable cause = e.getCause();
            assertNotNull("Wrong cause", cause);
            assertEquals("Wrong cause", IllegalStateException.class, cause.getClass());
        }
    } finally {
        uninstallSubsystemSilently(applicationA);
    }
}
Also used : Requirement(org.osgi.resource.Requirement) TestRequirement(org.apache.aries.subsystem.itests.util.TestRequirement) AriesSubsystem(org.apache.aries.subsystem.AriesSubsystem) Subsystem(org.osgi.service.subsystem.Subsystem) SubsystemException(org.osgi.service.subsystem.SubsystemException) AriesSubsystem(org.apache.aries.subsystem.AriesSubsystem) SubsystemTest(org.apache.aries.subsystem.itests.SubsystemTest) Test(org.junit.Test)

Aggregations

Requirement (org.osgi.resource.Requirement)193 Capability (org.osgi.resource.Capability)102 Resource (org.osgi.resource.Resource)59 CapReqBuilder (aQute.bnd.osgi.resource.CapReqBuilder)53 ArrayList (java.util.ArrayList)46 Collection (java.util.Collection)44 BndEditModel (aQute.bnd.build.model.BndEditModel)35 IdentityCapability (aQute.bnd.osgi.resource.ResourceUtils.IdentityCapability)34 HashMap (java.util.HashMap)34 MockRegistry (test.lib.MockRegistry)32 List (java.util.List)19 Repository (org.osgi.service.repository.Repository)19 Test (org.junit.Test)18 File (java.io.File)14 Map (java.util.Map)12 Resolver (org.osgi.service.resolver.Resolver)11 LinkedHashSet (java.util.LinkedHashSet)10 LinkedList (java.util.LinkedList)10 Wire (org.osgi.resource.Wire)10 Parameters (aQute.bnd.header.Parameters)9