JcloudsProviderAndApiLoader { public static boolean isProvider(String id) { if (Strings.isBlank(id)) return false; return getProvider(id).isPresent(); }  static boolean isProvider(String id); static boolean isApi(String id); static Optional<ProviderMetadata> getProvider(String id); static Optional<ApiMetadata> getApi(String id); static final Logger log; }
@Test public void testRegisteredProvider() throws Exception { String id = "my-example-provider"; assertFalse(JcloudsProviderAndApiLoader.isProvider(id)); ProviderMetadata provider = new BaseProviderMetadata.Builder() .id(id) .name("My Example Provider") .apiMetadata(new AWSEC2ApiMetadata()) .build(); ProviderRegistry.registerProvider(provider); try { assertIsProvider(id); ProviderRegistry.unregisterProvider(provider); assertFalse(JcloudsProviderAndApiLoader.isProvider(id)); } finally { ProviderRegistry.unregisterProvider(provider); } }
@Test public void testRenamedRegisteredProvider() throws Exception { String newId = "my-example-provider2"; String oldId = "my-example-provider-renamed"; assertFalse(JcloudsProviderAndApiLoader.isProvider(newId)); ProviderMetadata provider = new BaseProviderMetadata.Builder() .id(newId) .name("My Example Provider 2") .apiMetadata(new AWSEC2ApiMetadata()) .build(); ProviderRegistry.registerProvider(provider); try { assertIsProvider(newId); assertFalse(JcloudsProviderAndApiLoader.isProvider(oldId)); DeserializingJcloudsRenamesProvider.INSTANCE.loadDeserializingMapping().put(oldId,newId); assertIsProvider(oldId, newId); ProviderRegistry.unregisterProvider(provider); assertFalse(JcloudsProviderAndApiLoader.isProvider(newId)); assertFalse(JcloudsProviderAndApiLoader.isProvider(oldId)); } finally { ProviderRegistry.unregisterProvider(provider); } }