/** * @see CloudConnector#getServiceInfos() * @return information about all services bound to the application */ public List<ServiceInfo> getServiceInfos() { return flatten(cloudConnector.getServiceInfos()); }
@Override public <T> T service(String serviceId, Class<T> serviceConnectorType, ServiceConnectorConfig serviceConnectorConfig){ return cloud.getServiceConnector(serviceId, serviceConnectorType, serviceConnectorConfig); } }
/** * Package-access constructor. * * @param cloudConnector the underlying connector * @param serviceConnectorCreators service connector creators */ Cloud(CloudConnector cloudConnector, List<ServiceConnectorCreator<?, ? extends ServiceInfo>> serviceConnectorCreators) { this.cloudConnector = cloudConnector; for (ServiceConnectorCreator<?, ? extends ServiceInfo> serviceCreator : serviceConnectorCreators) { registerServiceConnectorCreator(serviceCreator); } }
@Test public void serviceConnectorCreationSpecifiedTypeAndConfig() { StubServiceInfo testServiceInfo = new StubServiceInfo("test-id", "test-host", 1000, "test-username", "test-password"); StubCloudConnector stubCloudConnector = CloudTestUtil.getTestCloudConnector(testServiceInfo); serviceConnectorCreators.add(new StubServiceConnectorCreator()); Cloud testCloud = new Cloud(stubCloudConnector, serviceConnectorCreators); StubServiceConnectorConfig config = new StubServiceConnectorConfig("test-config"); StubServiceConnector connector = testCloud.getServiceConnector(testServiceInfo.getId(), StubServiceConnector.class, config); assertStubService(testServiceInfo, connector, config); }
@Test public void getSingletonServiceConnectorSingleService() { StubServiceInfo testServiceInfo = new StubServiceInfo("test-id", "test-host", 1000, "test-username", "test-password"); StubCloudConnector stubCloudConnector = CloudTestUtil.getTestCloudConnector(testServiceInfo); serviceConnectorCreators.add(new StubServiceConnectorCreator()); Cloud testCloud = new Cloud(stubCloudConnector, serviceConnectorCreators); StubServiceConnector connector = testCloud.getSingletonServiceConnector(null, null); assertStubService(testServiceInfo, connector, null); }
@Test public void servicePropsOneServiceOfTheSameLabel() { MysqlServiceInfo mysqlServiceInfo = createMysqlService("my-mysql"); MongoServiceInfo mongoServiceInfo = createMongoService("my-mongo"); CloudConnector stubCloudConnector = getTestCloudConnector(mysqlServiceInfo, mongoServiceInfo); Cloud testCloud = new Cloud(stubCloudConnector, serviceCreators); Properties cloudProperties = testCloud.getCloudProperties(); assertRelationalProps("cloud.services.my-mysql", mysqlServiceInfo, cloudProperties); assertMongoProps("cloud.services.my-mongo", mongoServiceInfo, cloudProperties); assertRelationalProps("cloud.services.mysql", mysqlServiceInfo, cloudProperties); assertMongoProps("cloud.services.mongo", mongoServiceInfo, cloudProperties); }
@Test public void servicePropsOneServiceOfTheSameLabel() { StubServiceInfo testServiceInfo = new StubServiceInfo("test-id", "test-host", 1000, "test-username", "test-password"); StubCloudConnector stubCloudConnector = CloudTestUtil.getTestCloudConnector(testServiceInfo); Cloud testCloud = new Cloud(stubCloudConnector, serviceConnectorCreators); Properties cloudProperties = testCloud.getCloudProperties(); assertStubServiceProp("cloud.services.test-id", testServiceInfo, cloudProperties); assertStubServiceProp("cloud.services.stub", testServiceInfo, cloudProperties); }
@Test public void servicePropsMongoMultipleHostsUriString() { String serviceId = "my-mongo-multiple-hosts-uri"; MongoServiceInfo mongoServiceInfo = createMongoServiceWithMultipleHostsByUri(serviceId); CloudConnector stubCloudConnector = getTestCloudConnector(mongoServiceInfo); Cloud testCloud = new Cloud(stubCloudConnector, serviceCreators); Properties cloudProperties = testCloud.getCloudProperties(); assertMongoPropsWithMultipleHostsByUri("cloud.services.my-mongo-multiple-hosts-uri", mongoServiceInfo, cloudProperties); assertMongoPropsWithMultipleHostsByUri("cloud.services.mongo", mongoServiceInfo, cloudProperties); }
@Test public void servicePropsRedis() { String serviceId = "my-redis"; RedisServiceInfo redisServiceInfo = createRedisService(serviceId); CloudConnector stubCloudConnector = getTestCloudConnector(redisServiceInfo); Cloud testCloud = new Cloud(stubCloudConnector, serviceCreators); Properties cloudProperties = testCloud.getCloudProperties(); assertBasicProps("cloud.services.my-redis", redisServiceInfo, cloudProperties); assertBasicProps("cloud.services.redis", redisServiceInfo, cloudProperties); }
@Test public void servicePropsRabbit() { String serviceId = "my-rabbit"; AmqpServiceInfo rabbitServiceInfo = createRabbitService(serviceId); CloudConnector stubCloudConnector = getTestCloudConnector(rabbitServiceInfo); Cloud testCloud = new Cloud(stubCloudConnector, serviceCreators); Properties cloudProperties = testCloud.getCloudProperties(); assertRabbitProps("cloud.services.my-rabbit", rabbitServiceInfo, cloudProperties); assertRabbitProps("cloud.services.rabbitmq", rabbitServiceInfo, cloudProperties); }
@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()); }
@Test(expected=CloudException.class) public void getSingletonServiceInfoByTypeMultipleServices() { StubServiceInfo testServiceInfo1 = new StubServiceInfo("test-id", "test-host", 1000, "test-username", "test-password"); StubServiceInfo testServiceInfo2 = new StubServiceInfo("test-id", "test-host", 1000, "test-username", "test-password"); StubCloudConnector stubCloudConnector = CloudTestUtil.getTestCloudConnector(testServiceInfo1, testServiceInfo2); Cloud testCloud = new Cloud(stubCloudConnector, serviceConnectorCreators); testCloud.getSingletonServiceInfoByType(StubServiceInfo.class); }
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel panel = new JPanel(); Cloud cloud = new Cloud(); Random random = new Random(); for (String s : WORDS) { for (int i = random.nextInt(50); i > 0; i--) { cloud.addTag(s); for (Tag tag : cloud.tags()) { final JLabel label = new JLabel(tag.getName()); label.setOpaque(false);
@Override public StubServiceConnector create(StubServiceInfo serviceInfo, ServiceConnectorConfig config) { return new StubServiceConnector(serviceInfo.getId(), serviceInfo.getHost(), serviceInfo.getPort(), serviceInfo.getUserName(), serviceInfo.getPassword(), config == null ? null : ((StubServiceConnectorConfig)config).config); }
public static StubCloudConnector getTestCloudConnector(ApplicationInstanceInfo applicationInstanceInfo, ServiceInfo... serviceInfos) { final StubCloudConnector stubCloudConnector = getTestCloudConnector(serviceInfos); stubCloudConnector.setApplicationInstance(applicationInstanceInfo); return stubCloudConnector; }
@Override public TestServiceInfo createServiceInfo(TestServiceData serviceData) { return new TestServiceInfo(serviceData.getId(), serviceData.getTag()); }
@Test public void serviceConnectorCreationDefaultTypeAndConfig() { StubServiceInfo testServiceInfo = new StubServiceInfo("test-id", "test-host", 1000, "test-username", "test-password"); StubCloudConnector stubCloudConnector = CloudTestUtil.getTestCloudConnector(testServiceInfo); serviceConnectorCreators.add(new StubServiceConnectorCreator()); Cloud testCloud = new Cloud(stubCloudConnector, serviceConnectorCreators); StubServiceConnector connector = testCloud.getServiceConnector(testServiceInfo.getId(), null, null); assertStubService(testServiceInfo, connector, null); }
@Test(expected=CloudException.class) public void getSingletonServiceConnectorMultipleServices() { StubServiceInfo testServiceInfo1 = new StubServiceInfo("test-id", "test-host", 1000, "test-username", "test-password"); StubServiceInfo testServiceInfo2 = new StubServiceInfo("test-id", "test-host", 1000, "test-username", "test-password"); StubCloudConnector stubCloudConnector = CloudTestUtil.getTestCloudConnector(testServiceInfo1, testServiceInfo2); serviceConnectorCreators.add(new StubServiceConnectorCreator()); Cloud testCloud = new Cloud(stubCloudConnector, serviceConnectorCreators); testCloud.getSingletonServiceConnector(null, null); }
/** * @see CloudConnector#getServiceInfos() * @return information about all services bound to the application */ public List<ServiceInfo> getServiceInfos() { return flatten(cloudConnector.getServiceInfos()); }
/** * @see CloudConnector#getServiceInfos() * @return information about all services bound to the application */ public List<ServiceInfo> getServiceInfos() { return flatten(cloudConnector.getServiceInfos()); }