/** * Get the singleton {@link ServiceInfo} for the given service info type. * * @param <T> the class of service info to return * @param serviceInfoType * service info type * @return the single service info of the given type * @throws CloudException * if there are either 0 or more than 1 service info of the * given type. */ public <T extends ServiceInfo> T getSingletonServiceInfoByType(Class<T> serviceInfoType) { List<T> serviceInfos = getServiceInfosByType(serviceInfoType); if (serviceInfos.size() != 1) { throw new CloudException( "No unique service info " + serviceInfoType + " found. Expected 1, found " + serviceInfos.size()); } return serviceInfos.get(0); }
/** * Get the singleton {@link ServiceInfo} for the given service info type. * * @param <T> the class of service info to return * @param serviceInfoType * service info type * @return the single service info of the given type * @throws CloudException * if there are either 0 or more than 1 service info of the * given type. */ public <T extends ServiceInfo> T getSingletonServiceInfoByType(Class<T> serviceInfoType) { List<T> serviceInfos = getServiceInfosByType(serviceInfoType); if (serviceInfos.size() != 1) { throw new CloudException( "No unique service info " + serviceInfoType + " found. Expected 1, found " + serviceInfos.size()); } return serviceInfos.get(0); }
/** * Get the singleton {@link ServiceInfo} for the given service info type. * * @param <T> the class of service info to return * @param serviceInfoType * service info type * @return the single service info of the given type * @throws CloudException * if there are either 0 or more than 1 service info of the * given type. */ public <T extends ServiceInfo> T getSingletonServiceInfoByType(Class<T> serviceInfoType) { List<T> serviceInfos = getServiceInfosByType(serviceInfoType); if (serviceInfos.size() != 1) { throw new CloudException( "No unique service info " + serviceInfoType + " found. Expected 1, found " + serviceInfos.size()); } return serviceInfos.get(0); }
@Test public void getServiceInfosByType() { StubServiceInfo testServiceInfo = new StubServiceInfo("test-id", "test-host", 1000, "test-username", "test-password"); TestServiceInfoTypeA testServiceInfoTypeA1 = new TestServiceInfoTypeA("test-id-a1"); TestServiceInfoTypeA testServiceInfoTypeA2 = new TestServiceInfoTypeA("test-id-a2"); TestServiceInfoTypeB testServiceInfoTypeB = new TestServiceInfoTypeB("test-id-b"); StubCloudConnector stubCloudConnector = CloudTestUtil.getTestCloudConnector(testServiceInfo, testServiceInfoTypeA1, testServiceInfoTypeA2, testServiceInfoTypeB); Cloud testCloud = new Cloud(stubCloudConnector, serviceConnectorCreators); List<TestServiceInfoTypeA> actualServiceInfoTypeA = testCloud.getServiceInfosByType(TestServiceInfoTypeA.class); assertEquals(2, actualServiceInfoTypeA.size()); assertEquals(1, testCloud.getServiceInfosByType(TestServiceInfoTypeB.class).size()); }