BlueprintMetadata implements BlueprintMetadataMBean { public long[] getBlueprintContainerServiceIds() throws IOException { ServiceReference[] serviceReferences = null; try { serviceReferences = bundleContext.getServiceReferences(BlueprintContainer.class.getName(), null); } catch (InvalidSyntaxException e) { throw new RuntimeException(e); } if (serviceReferences == null || serviceReferences.length < 1) return null; long[] serviceIds = new long[serviceReferences.length]; for (int i = 0; i < serviceReferences.length; i++) { serviceIds[i] = (Long) serviceReferences[i].getProperty(Constants.SERVICE_ID); } return serviceIds; } BlueprintMetadata(BundleContext bundleContext); long getBlueprintContainerServiceId(long bundleId); long[] getBlueprintContainerServiceIds(); String[] getComponentIds(long containerServiceId); String[] getComponentIdsByType(long containerServiceId, String type); CompositeData getComponentMetadata(long containerServiceId, String componentId);  }
@Test public void normalBlueprintContainerServiceIds() throws Exception { final long serviceId = 7117; final long [] serviceIds = new long[]{serviceId}; mockery.checking(new Expectations() { { oneOf(mockContext).getServiceReferences(with(any(String.class)), with(any(String.class))); will(returnValue(mockServiceReferences)); } }); mockery.checking(new Expectations() { { allowing(mockServiceReferences[0]).getProperty(Constants.SERVICE_ID); will(returnValue(serviceId)); } }); assertArrayEquals(serviceIds, metadata.getBlueprintContainerServiceIds()); }
@Test public void noBlueprintContainerServiceIds() throws Exception { mockery.checking(new Expectations() { { oneOf(mockContext).getServiceReferences(with(any(String.class)), with(any(String.class))); will(returnValue(null)); } }); assertNull(metadata.getBlueprintContainerServiceIds()); }