public static BundleWiringDTO[] newArrayBundleWiringDTO(BundleRevisions revisions) { if (revisions == null) { return null; } List<BundleRevision> revs = revisions.getRevisions(); final int size = revs.size(); List<BundleWiringDTO> dtos = new ArrayList<BundleWiringDTO>(size); for (int i = 0; i < size; i++) { BundleWiring wiring = revs.get(i).getWiring(); if (wiring != null) { dtos.add( new DTOBuilder().getBundleWiringDTO(wiring)); // use new DTOBuilder for each wiring dto } } return dtos.toArray(new BundleWiringDTO[dtos.size()]); }
@Test public void testResolveSingletonInSameRegions() { List<BundleCapability> collisionCandidates = new ArrayList<BundleCapability>(); collisionCandidates.add(bundleCapability(BUNDLE_B)); collisionCandidates.add(bundleCapability(BUNDLE_C)); collisionCandidates.add(bundleCapability(BUNDLE_D)); this.resolverHook.filterSingletonCollisions(bundleCapability(BUNDLE_A), collisionCandidates); assertEquals("Wrong number of collitions", 0, collisionCandidates.size()); }
private List<CapabilityDTO> getListCapabilityDTO(List<BundleCapability> caps) { if (caps == null) { return null; } List<CapabilityDTO> dtos = newList(caps.size()); for (BundleCapability cap : caps) { dtos.add(getCapabilityDTO(cap)); } return dtos; }
private List<WireDTO> getListBundleWireDTO(List<BundleWire> wires) { if (wires == null) { return null; } List<WireDTO> dtos = newList(wires.size()); for (BundleWire wire : wires) { dtos.add(getBundleWireDTO(wire)); } return dtos; }
private List<RequirementRefDTO> getListRequirementRefDTO(List<BundleRequirement> reqs) { if (reqs == null) { return null; } List<RequirementRefDTO> dtos = newList(reqs.size()); for (BundleRequirement req : reqs) { dtos.add(getRequirementRefDTO(req)); } return dtos; }
public static ServiceReferenceDTO[] newArrayServiceReferenceDTO( ServiceReference<?>[] references) { final int length = (references == null) ? 0 : references.length; List<ServiceReferenceDTO> refDTOs = new ArrayList<ServiceReferenceDTO>(length); for (int i = 0; i < length; i++) { ServiceReferenceDTO dto = getServiceReferenceDTO(references[i]); if (dto != null) { refDTOs.add(dto); } } return refDTOs.toArray(new ServiceReferenceDTO[refDTOs.size()]); }
public static BundleRevisionDTO[] newArrayBundleRevisionDTO(BundleRevisions revisions) { if (revisions == null) { return null; } List<BundleRevision> revs = revisions.getRevisions(); final int size = revs.size(); BundleRevisionDTO[] dtos = new BundleRevisionDTO[size]; for (int i = 0; i < size; i++) { dtos[i] = new DTOBuilder().getBundleRevisionDTO(revs.get(i)); } return dtos; }
@Test public void testResolveSingletonInDifferentRegions() throws BundleException { region(REGION_A).addBundle(bundle(BUNDLE_X)); BundleCapability collision = bundleCapability(BUNDLE_X); List<BundleCapability> collisionCandidates = new ArrayList<BundleCapability>(); collisionCandidates.add(collision); collisionCandidates.add(bundleCapability(BUNDLE_B)); collisionCandidates.add(bundleCapability(BUNDLE_C)); collisionCandidates.add(bundleCapability(BUNDLE_D)); this.resolverHook.filterSingletonCollisions(bundleCapability(BUNDLE_A), collisionCandidates); assertEquals("Wrong number of collitions", 1, collisionCandidates.size()); collisionCandidates.contains(collision); }
public void testBasic() throws BundleException, InvalidSyntaxException, InterruptedException { // get the system region Region systemRegion = digraph.getRegion(0); // create a disconnected test region Region testRegion = digraph.createRegion(getName()); List<Bundle> bundles = new ArrayList<Bundle>(); // Install all test bundles Bundle pp1, cp2, sc1; bundles.add(pp1 = bundleInstaller.installBundle(PP1, testRegion)); // should be able to start pp1 because it depends on nothing pp1.start(); // do a sanity check that we have no services available in the isolated region assertNull("Found some services.", pp1.getBundleContext().getAllServiceReferences(null, null)); assertEquals("Found extra bundles in region", 1, pp1.getBundleContext().getBundles().length); pp1.stop(); bundles.add(bundleInstaller.installBundle(SP1, testRegion)); bundles.add(bundleInstaller.installBundle(CP1, testRegion)); bundles.add(bundleInstaller.installBundle(PP2, testRegion)); bundles.add(bundleInstaller.installBundle(SP2, testRegion)); bundles.add(cp2 = bundleInstaller.installBundle(CP2, testRegion)); bundles.add(bundleInstaller.installBundle(PC1, testRegion)); bundles.add(bundleInstaller.installBundle(BC1, testRegion)); bundles.add(sc1 = bundleInstaller.installBundle(SC1, testRegion)); bundles.add(bundleInstaller.installBundle(CC1, testRegion)); // Import the system bundle from the systemRegion digraph.connect(testRegion, digraph.createRegionFilterBuilder().allow(RegionFilter.VISIBLE_BUNDLE_NAMESPACE, "(id=0)").build(), systemRegion); // must import Boolean services into systemRegion to test digraph.connect(systemRegion, digraph.createRegionFilterBuilder().allow(RegionFilter.VISIBLE_SERVICE_NAMESPACE, "(objectClass=java.lang.Boolean)").build(), testRegion); bundleInstaller.resolveBundles(bundles.toArray(new Bundle[bundles.size()])); for (Bundle bundle : bundles) { assertEquals("Bundle did not resolve: " + bundle.getSymbolicName(), Bundle.RESOLVED, bundle.getState()); bundle.start(); } BundleContext context = getContext(); ServiceTracker<Boolean, Boolean> cp2Tracker = new ServiceTracker<Boolean, Boolean>(context, context.createFilter("(&(objectClass=java.lang.Boolean)(bundle.id=" + cp2.getBundleId() + "))"), null); ServiceTracker<Boolean, Boolean> sc1Tracker = new ServiceTracker<Boolean, Boolean>(context, context.createFilter("(&(objectClass=java.lang.Boolean)(bundle.id=" + sc1.getBundleId() + "))"), null); cp2Tracker.open(); sc1Tracker.open(); assertNotNull("The cp2 bundle never found the service.", cp2Tracker.waitForService(2000)); assertNotNull("The sc1 bundle never found the service.", sc1Tracker.waitForService(2000)); cp2Tracker.close(); sc1Tracker.close(); }
@Test public void testResolveSingletonConnectedRegions() throws BundleException, InvalidSyntaxException { RegionFilter filter = createBundleFilter(BUNDLE_B, BUNDLE_VERSION); region(REGION_A).connectRegion(region(REGION_B), filter); region(REGION_A).addBundle(bundle(BUNDLE_X)); BundleCapability collisionX = bundleCapability(BUNDLE_X); BundleCapability collisionB = bundleCapability(BUNDLE_B); List<BundleCapability> collisionCandidates = new ArrayList<BundleCapability>(); collisionCandidates.add(collisionX); collisionCandidates.add(collisionB); collisionCandidates.add(bundleCapability(BUNDLE_C)); collisionCandidates.add(bundleCapability(BUNDLE_D)); this.resolverHook.filterSingletonCollisions(bundleCapability(BUNDLE_A), collisionCandidates); assertEquals("Wrong number of collitions", 2, collisionCandidates.size()); collisionCandidates.contains(collisionX); collisionCandidates.contains(collisionB); }
private static Object mapValue(Object v) { if ((v == null) || v instanceof Number || v instanceof Boolean || v instanceof Character || v instanceof String || v instanceof DTO) { return v; } if (v instanceof Map) { Map<?, ?> m = (Map<?, ?>) v; Map<Object, Object> map = newMap(m.size()); for (Map.Entry<?, ?> e : m.entrySet()) { map.put(mapValue(e.getKey()), mapValue(e.getValue())); } return map; } if (v instanceof List) { List<?> c = (List<?>) v; List<Object> list = newList(c.size()); for (Object o : c) { list.add(mapValue(o)); } return list; } if (v instanceof Set) { Set<?> c = (Set<?>) v; Set<Object> set = newSet(c.size()); for (Object o : c) { set.add(mapValue(o)); } return set; } if (v.getClass().isArray()) { final int length = Array.getLength(v); final Class<?> componentType = mapComponentType(v.getClass().getComponentType()); Object array = Array.newInstance(componentType, length); for (int i = 0; i < length; i++) { Array.set(array, i, mapValue(Array.get(v, i))); } return array; } return String.valueOf(v); }