@SuppressWarnings("rawtypes") @Test public void testGetApiMetadataFromMultipleClassLoaders() throws Exception { ClassLoader isolatedClassLoader = createIsolatedClassLoader(); MetadataBundleListener listener = new MetadataBundleListener(); Bundle bundle = createMock(Bundle.class); expect(bundle.getEntry("/META-INF/services/org.jclouds.apis.ApiMetadata")).andReturn( getClass().getResource("/META-INF/services/org.jclouds.apis.ApiMetadata")).anyTimes(); expect((Class) bundle.loadClass("org.jclouds.apis.JcloudsTestBlobStoreApiMetadata")).andReturn( isolatedClassLoader.loadClass(JcloudsTestBlobStoreApiMetadata.class.getName())).anyTimes(); expect((Class) bundle.loadClass("org.jclouds.apis.JcloudsTestComputeApiMetadata")).andReturn( JcloudsTestComputeApiMetadata.class).anyTimes(); expect((Class) bundle.loadClass("org.jclouds.apis.JcloudsTestYetAnotherComputeApiMetadata")).andReturn( JcloudsTestYetAnotherComputeApiMetadata.class).anyTimes(); replay(bundle); List<ApiMetadata> apiMetadataList = Lists.newArrayList(listener.listApiMetadata(bundle)); assertNotNull(apiMetadataList); assertEquals(2, apiMetadataList.size()); assertFalse(apiMetadataList.contains(new JcloudsTestBlobStoreApiMetadata())); assertTrue(apiMetadataList.contains(new JcloudsTestComputeApiMetadata())); assertTrue(apiMetadataList.contains(new JcloudsTestYetAnotherComputeApiMetadata())); verify(bundle); }
public Iterable<ApiMetadata> listApiMetadata(Bundle bundle) { Iterable<String> classNames = stringsForResourceInBundle("/META-INF/services/org.jclouds.apis.ApiMetadata", bundle); return instantiateAvailableClasses(bundle, classNames, ApiMetadata.class); }
MetadataBundleListener implements BundleListener { public Iterable<ApiMetadata> listApiMetadata(Bundle bundle) { Iterable<String> classNames = stringsForResourceInBundle("/META-INF/services/org.jclouds.apis.ApiMetadata", bundle); return instantiateAvailableClasses(bundle, classNames, ApiMetadata.class); } }
MetadataBundleListener implements BundleListener { public Iterable<ApiMetadata> listApiMetadata(Bundle bundle) { Iterable<String> classNames = stringsForResourceInBundle("/META-INF/services/org.jclouds.apis.ApiMetadata", bundle); return instantiateAvailableClasses(bundle, classNames, ApiMetadata.class); }  }
MetadataBundleListener implements BundleListener { public Iterable<ApiMetadata> listApiMetadata(Bundle bundle) { Iterable<String> classNames = stringsForResourceInBundle("/META-INF/services/org.jclouds.apis.ApiMetadata", bundle); return instantiateAvailableClasses(bundle, classNames, ApiMetadata.class); }  synchronized void start(BundleContext bundleContext); void stop(BundleContext bundleContext); @Override synchronized void bundleChanged(BundleEvent event); Iterable<ProviderMetadata> listProviderMetadata(Bundle bundle); Iterable<ApiMetadata> listApiMetadata(Bundle bundle); synchronized void addProviderListener(ProviderListener listener); synchronized void removeProviderListener(ProviderListener listener); synchronized void addApiListenerListener(ApiListener listener); synchronized void removeApiListenerListener(ApiListener listener); }
MetadataBundleListener implements BundleListener { public Iterable<ApiMetadata> listApiMetadata(Bundle bundle) { Iterable<String> classNames = stringsForResourceInBundle("/META-INF/services/org.jclouds.apis.ApiMetadata", bundle); return instantiateAvailableClasses(bundle, classNames, ApiMetadata.class); }  synchronized void start(BundleContext bundleContext); void stop(BundleContext bundleContext); @Override synchronized void bundleChanged(BundleEvent event); Iterable<ProviderMetadata> listProviderMetadata(Bundle bundle); Iterable<ApiMetadata> listApiMetadata(Bundle bundle); synchronized void addProviderListener(ProviderListener listener); synchronized void removeProviderListener(ProviderListener listener); synchronized void addApiListenerListener(ApiListener listener); synchronized void removeApiListenerListener(ApiListener listener);  }