BlueprintMetadata implements BlueprintMetadataMBean { public String[] getComponentIdsByType(long containerServiceId, String type) throws IOException { BlueprintContainer container = getBlueprintContainer(containerServiceId); Collection<? extends ComponentMetadata> components; if (type.equals(BlueprintMetadataMBean.SERVICE_METADATA)) { components = container.getMetadata(ServiceMetadata.class); } else if (type.equals(BlueprintMetadataMBean.BEAN_METADATA)) { components = container.getMetadata(BeanMetadata.class); } else if (type.equals(BlueprintMetadataMBean.SERVICE_REFERENCE_METADATA)) { components = container.getMetadata(ServiceReferenceMetadata.class); } else { throw new IllegalArgumentException("Unrecognized component type: " + type); } String ids[] = new String[components.size()]; int i = 0; for (ComponentMetadata component : components) { if(null == component) continue; ids[i++] = component.getId(); } return ids; } 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 normalGetComponentIdsByType() throws Exception { final long serviceId = 7117; final String [] cidarray = new String[]{".component-1"}; final Collection cMetadatas = new ArrayList(); cMetadatas.add(mockServiceMetadata); mockery.checking(new Expectations(){ { oneOf(mockContext).getServiceReferences(with(any(String.class)), with(any(String.class))); will(returnValue(mockServiceReferences)); oneOf(mockContext).getService(mockServiceReferences[0]); will(returnValue(mockContainer)); } }); mockery.checking(new Expectations(){ { oneOf(mockContainer).getMetadata(ServiceMetadata.class); will(returnValue(cMetadatas)); } }); mockery.checking(new Expectations(){ { oneOf(mockServiceMetadata).getId(); will(returnValue(cidarray[0])); } }); assertArrayEquals(cidarray, metadata.getComponentIdsByType(serviceId, BlueprintMetadataMBean.SERVICE_METADATA)); }