org.springframework.cloud.service.ServiceInfo Java Examples

The following examples show how to use org.springframework.cloud.service.ServiceInfo. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CloudFoundryConnectorPostgresqlServiceTest.java    From spring-cloud-connectors with Apache License 2.0 6 votes vote down vote up
@Test
public void postgresqlServiceCreationNoLabelNoTags() {
	String name1 = "database-1";
	String name2 = "database-2";
	when(mockEnvironment.getEnvValue("VCAP_SERVICES"))
			.thenReturn(getServicesPayload(
					getPostgresqlServicePayloadNoLabelNoTags("postgresql-1", hostname, port, username, password, name1),
					getPostgresqlServicePayloadNoLabelNoTags("postgresql-2", hostname, port, username, password, name2)));

	List<ServiceInfo> serviceInfos = testCloudConnector.getServiceInfos();
	ServiceInfo info1 = getServiceInfo(serviceInfos, "postgresql-1");
	ServiceInfo info2 = getServiceInfo(serviceInfos, "postgresql-2");

	assertServiceFoundOfType(info1, PostgresqlServiceInfo.class);
	assertServiceFoundOfType(info2, PostgresqlServiceInfo.class);

	assertJdbcUrlEqual(info1, POSTGRES_SCHEME, name1);
	assertJdbcUrlEqual(info2, POSTGRES_SCHEME, name2);

	assertUriBasedServiceInfoFields(info1, POSTGRES_SCHEME, hostname, port, username, password, name1);
	assertUriBasedServiceInfoFields(info2, POSTGRES_SCHEME, hostname, port, username, password, name2);
}
 
Example #2
Source File: CloudScanHelper.java    From spring-cloud-connectors with Apache License 2.0 6 votes vote down vote up
private void registerServiceBean(BeanDefinitionRegistry registry, ServiceInfo serviceInfo) {
	try {
		GenericCloudServiceConnectorFactory serviceFactory =
				new GenericCloudServiceConnectorFactory(serviceInfo.getId(), null);
		serviceFactory.setBeanFactory((BeanFactory) registry);
		serviceFactory.afterPropertiesSet();
		BeanDefinitionBuilder definitionBuilder =
				BeanDefinitionBuilder.genericBeanDefinition(ScannedServiceWrapper.class);
		definitionBuilder.addConstructorArgValue(serviceFactory);
		definitionBuilder.getRawBeanDefinition().setAttribute(
								  "factoryBeanObjectType", serviceFactory.getObjectType());
		registry.registerBeanDefinition(serviceInfo.getId(), definitionBuilder.getBeanDefinition());
	} catch (Exception ex) {
		logger.fine("Unable to create service for " + serviceInfo.getId() + " during service scanning. Skipping.");
	}
}
 
Example #3
Source File: CloudTest.java    From spring-cloud-connectors with Apache License 2.0 6 votes vote down vote up
@Test
public void compositeServiceInfoRecursive() {
    StubServiceInfo testServiceInfo1a = new StubServiceInfo("test-id-1a", "test-host", 1000, "test-username", "test-password");
    StubServiceInfo testServiceInfo1b = new StubServiceInfo("test-id-1b", "test-host", 1000, "test-username", "test-password");
    ServiceInfo testCompositeServiceInfo1 = new StubCompositeServiceInfo("test-composite-1",testServiceInfo1a, testServiceInfo1b);

    StubServiceInfo testServiceInfo2a = new StubServiceInfo("test-id-2a", "test-host", 1000, "test-username", "test-password");
    StubServiceInfo testServiceInfo2b = new StubServiceInfo("test-id-2b", "test-host", 1000, "test-username", "test-password");
    ServiceInfo testCompositeServiceInfo2 = new StubCompositeServiceInfo("test-composite-2",testServiceInfo2a, testServiceInfo2b);
    
    ServiceInfo testCompositeServiceInfo = new StubCompositeServiceInfo("test-composite",testCompositeServiceInfo1, testCompositeServiceInfo2);

    StubCloudConnector stubCloudConnector = CloudTestUtil.getTestCloudConnector(testCompositeServiceInfo);
    Cloud testCloud = new Cloud(stubCloudConnector, serviceConnectorCreators);
    
    assertNotNull(testCloud.getServiceInfo("test-id-1a"));
    assertNotNull(testCloud.getServiceInfo("test-id-1b"));
    assertNotNull(testCloud.getServiceInfo("test-id-2a"));
    assertNotNull(testCloud.getServiceInfo("test-id-2b"));
}
 
Example #4
Source File: CloudFoundryConnectorMysqlServiceTest.java    From spring-cloud-connectors with Apache License 2.0 6 votes vote down vote up
@Test
public void mysqlServiceCreationWithJdbcUrl() {
	String name1 = "database-1";
	String name2 = "database-2";
	when(mockEnvironment.getEnvValue("VCAP_SERVICES"))
			.thenReturn(getServicesPayload(
					getMysqlServicePayloadWithJdbcUrl("mysql-1", hostname, port, username, password, name1),
					getMysqlServicePayloadWithJdbcUrl("mysql-2", hostname, port, username, password, name2)));
	List<ServiceInfo> serviceInfos = testCloudConnector.getServiceInfos();

	ServiceInfo info1 = getServiceInfo(serviceInfos, "mysql-1");
	ServiceInfo info2 = getServiceInfo(serviceInfos, "mysql-2");

	assertServiceFoundOfType(info1, MysqlServiceInfo.class);
	assertServiceFoundOfType(info2, MysqlServiceInfo.class);

	assertJdbcUrlEqual(info1, MYSQL_SCHEME, name1);
	assertJdbcUrlEqual(info2, MYSQL_SCHEME, name2);

	assertUriBasedServiceInfoFields(info1, MYSQL_SCHEME, hostname, port, username, password, name1);
	assertUriBasedServiceInfoFields(info2, MYSQL_SCHEME, hostname, port, username, password, name2);
}
 
Example #5
Source File: CloudFoundryConnectorMysqlServiceTest.java    From spring-cloud-connectors with Apache License 2.0 6 votes vote down vote up
@Test
public void mysqlServiceCreationWithLabelNoUri() {
	String name1 = "database-1";
	String name2 = "database-2";
	when(mockEnvironment.getEnvValue("VCAP_SERVICES"))
		.thenReturn(getServicesPayload(
				getMysqlServicePayloadWithLabelNoUri("mysql-1", hostname, port, username, password, name1),
				getMysqlServicePayloadWithLabelNoUri("mysql-2", hostname, port, username, password, name2)));
	List<ServiceInfo> serviceInfos = testCloudConnector.getServiceInfos();

	ServiceInfo info1 = getServiceInfo(serviceInfos, "mysql-1");
	ServiceInfo info2 = getServiceInfo(serviceInfos, "mysql-2");

	assertServiceFoundOfType(info1, MysqlServiceInfo.class);
	assertServiceFoundOfType(info2, MysqlServiceInfo.class);

	assertJdbcUrlEqual(info1, MYSQL_SCHEME, name1);
	assertJdbcUrlEqual(info2, MYSQL_SCHEME, name2);

	assertUriBasedServiceInfoFields(info1, MYSQL_SCHEME, hostname, port, username, password, name1);
	assertUriBasedServiceInfoFields(info2, MYSQL_SCHEME, hostname, port, username, password, name2);
}
 
Example #6
Source File: CloudFoundryConnectorPostgresqlServiceTest.java    From spring-cloud-connectors with Apache License 2.0 6 votes vote down vote up
@Test
public void postgresqlWithSpecialCharsServiceCreation() {
	String userWithSpecialChars = "u%u:u+";
	String passwordWithSpecialChars = "p%p:p+";

	String name1 = "database-1";
	when(mockEnvironment.getEnvValue("VCAP_SERVICES")).thenReturn(
			getServicesPayload(getPostgresqlServicePayload("postgresql-1", hostname,
					port, userWithSpecialChars, passwordWithSpecialChars, name1)));

	List<ServiceInfo> serviceInfos = testCloudConnector.getServiceInfos();
	ServiceInfo info1 = getServiceInfo(serviceInfos, "postgresql-1");

	assertServiceFoundOfType(info1, PostgresqlServiceInfo.class);

	assertEquals(getJdbcUrl(hostname, port, userWithSpecialChars,
			passwordWithSpecialChars, name1),
			((RelationalServiceInfo) info1).getJdbcUrl());

	assertUriBasedServiceInfoFields(info1, POSTGRES_SCHEME, hostname, port,
			userWithSpecialChars, passwordWithSpecialChars, name1);
}
 
Example #7
Source File: CloudFoundryConnectorMysqlServiceTest.java    From spring-cloud-connectors with Apache License 2.0 6 votes vote down vote up
@Test
public void mysqlServiceCreationWithJdbcUrlOnly() {
	String name1 = "database-1";
	String name2 = "database-2";
	when(mockEnvironment.getEnvValue("VCAP_SERVICES"))
			.thenReturn(getServicesPayload(
					getMysqlServicePayloadWithJdbcUrlOnly("mysql-1", hostname, port, username, password, name1),
					getMysqlServicePayloadWithJdbcUrlOnly("mysql-2", hostname, port, username, password, name2)));
	List<ServiceInfo> serviceInfos = testCloudConnector.getServiceInfos();

	ServiceInfo info1 = getServiceInfo(serviceInfos, "mysql-1");
	ServiceInfo info2 = getServiceInfo(serviceInfos, "mysql-2");

	assertServiceFoundOfType(info1, MysqlServiceInfo.class);
	assertServiceFoundOfType(info2, MysqlServiceInfo.class);

	assertJdbcUrlEqual(info1, MYSQL_SCHEME, name1);
	assertJdbcUrlEqual(info2, MYSQL_SCHEME, name2);

	assertUriBasedServiceInfoFields(info1, "jdbc", null, -1, null, null, null);
	assertUriBasedServiceInfoFields(info2, "jdbc", null, -1, null, null, null);

	assertJdbcShemeSpecificPartEqual(info1, MYSQL_SCHEME, name1);
	assertJdbcShemeSpecificPartEqual(info2, MYSQL_SCHEME, name2);
}
 
Example #8
Source File: CloudFoundryConnectorAmqpServiceTest.java    From spring-cloud-connectors with Apache License 2.0 6 votes vote down vote up
@Test
public void qpidServiceCreationNoLabelNoTags() throws Exception {
	when(mockEnvironment.getEnvValue("VCAP_SERVICES"))
		.thenReturn(getServicesPayload(
				getQpidServicePayloadNoLabelNoTags("qpid-1", hostname, port, username, password, "q-1", "vhost1"),
				getQpidServicePayloadNoLabelNoTags("qpid-2", hostname, port, username, password, "q-2", "vhost2")));

	List<ServiceInfo> serviceInfos = testCloudConnector.getServiceInfos();
	assertServiceFoundOfType(serviceInfos, "qpid-1", AmqpServiceInfo.class);
	assertServiceFoundOfType(serviceInfos, "qpid-2", AmqpServiceInfo.class);
	AmqpServiceInfo serviceInfo = (AmqpServiceInfo) getServiceInfo(serviceInfos, "qpid-1");
	assertNotNull(serviceInfo);
	assertEquals(username, serviceInfo.getUserName());
	assertEquals(password, serviceInfo.getPassword());
	assertEquals("vhost1", serviceInfo.getVirtualHost());
	URI uri = new URI(serviceInfo.getUri());
	assertTrue(uri.getQuery().contains("tcp://" + hostname + ":" + port));
}
 
Example #9
Source File: CloudFoundryConnectorSqlServerServiceTest.java    From spring-cloud-connectors with Apache License 2.0 6 votes vote down vote up
@Test
public void sqlServerServiceCreationWithJdbcUrlAndSpecialChars() {
	String userWithSpecialChars = "u%u:u+";
	String passwordWithSpecialChars = "p%p:p+";

	when(mockEnvironment.getEnvValue("VCAP_SERVICES"))
			.thenReturn(getServicesPayload(
					getSqlServerServicePayloadWithJdbcurl(SERVICE_NAME, hostname, port, userWithSpecialChars, passwordWithSpecialChars, INSTANCE_NAME, SQLSERVER_SCHEME + ":")));
	List<ServiceInfo> serviceInfos = testCloudConnector.getServiceInfos();

	ServiceInfo info = getServiceInfo(serviceInfos, SERVICE_NAME);
	assertServiceFoundOfType(info, SqlServerServiceInfo.class);
	assertEquals(getJdbcUrl(hostname, port, SQLSERVER_SCHEME, INSTANCE_NAME,
			userWithSpecialChars, passwordWithSpecialChars), ((RelationalServiceInfo)info).getJdbcUrl());
	assertUriBasedServiceInfoFields(info, SQLSERVER_SCHEME, hostname, port, userWithSpecialChars, passwordWithSpecialChars, INSTANCE_NAME);
}
 
Example #10
Source File: CloudFoundryConnectorMysqlServiceTest.java    From spring-cloud-connectors with Apache License 2.0 6 votes vote down vote up
@Test
public void mysqlServiceCreation() {
	String name1 = "database-1";
	String name2 = "database-2";
	when(mockEnvironment.getEnvValue("VCAP_SERVICES"))
		.thenReturn(getServicesPayload(
						getMysqlServicePayload("mysql-1", hostname, port, username, password, name1),
						getMysqlServicePayload("mysql-2", hostname, port, username, password, name2)));
	List<ServiceInfo> serviceInfos = testCloudConnector.getServiceInfos();

	ServiceInfo info1 = getServiceInfo(serviceInfos, "mysql-1");
	ServiceInfo info2 = getServiceInfo(serviceInfos, "mysql-2");

	assertServiceFoundOfType(info1, MysqlServiceInfo.class);
	assertServiceFoundOfType(info2, MysqlServiceInfo.class);

	assertJdbcUrlEqual(info1, MYSQL_SCHEME, name1);
	assertJdbcUrlEqual(info2, MYSQL_SCHEME, name2);
}
 
Example #11
Source File: CloudFoundryConnectorMysqlServiceTest.java    From spring-cloud-connectors with Apache License 2.0 6 votes vote down vote up
@Test
public void mysqlServiceCreationNoLabelNoTags() {
	String name1 = "database-1";
	String name2 = "database-2";
	when(mockEnvironment.getEnvValue("VCAP_SERVICES"))
			.thenReturn(getServicesPayload(
					getMysqlServicePayloadNoLabelNoTags("mysql-1", hostname, port, username, password, name1),
					getMysqlServicePayloadNoLabelNoTags("mysql-2", hostname, port, username, password, name2)));
	List<ServiceInfo> serviceInfos = testCloudConnector.getServiceInfos();

	ServiceInfo info1 = getServiceInfo(serviceInfos, "mysql-1");
	ServiceInfo info2 = getServiceInfo(serviceInfos, "mysql-2");

	assertServiceFoundOfType(info1, MysqlServiceInfo.class);
	assertServiceFoundOfType(info2, MysqlServiceInfo.class);

	assertJdbcUrlEqual(info1, MYSQL_SCHEME, name1);
	assertJdbcUrlEqual(info2, MYSQL_SCHEME, name2);

	assertUriBasedServiceInfoFields(info1, MYSQL_SCHEME, hostname, port, username, password, name1);
	assertUriBasedServiceInfoFields(info2, MYSQL_SCHEME, hostname, port, username, password, name2);
}
 
Example #12
Source File: CloudFoundryConnectorSqlServerServiceTest.java    From spring-cloud-connectors with Apache License 2.0 6 votes vote down vote up
@Test
public void sqlServerServiceCreationWithSpecialChars() {
	String userWithSpecialChars = "u%u:u+";
	String passwordWithSpecialChars = "p%p:p+";

	when(mockEnvironment.getEnvValue("VCAP_SERVICES"))
			.thenReturn(getServicesPayload(
					getUserProvidedServicePayload(SERVICE_NAME, hostname, port, userWithSpecialChars, passwordWithSpecialChars, INSTANCE_NAME, SQLSERVER_SCHEME + ":")));
	List<ServiceInfo> serviceInfos = testCloudConnector.getServiceInfos();

	ServiceInfo info = getServiceInfo(serviceInfos, SERVICE_NAME);
	assertServiceFoundOfType(info, SqlServerServiceInfo.class);
	assertEquals(getJdbcUrl(hostname, port, SQLSERVER_SCHEME, INSTANCE_NAME, 
			userWithSpecialChars, passwordWithSpecialChars), ((RelationalServiceInfo)info).getJdbcUrl());
	assertUriBasedServiceInfoFields(info, SQLSERVER_SCHEME, hostname, port, userWithSpecialChars, passwordWithSpecialChars, INSTANCE_NAME);
}
 
Example #13
Source File: CloudFoundryConnectorOracleServiceTest.java    From spring-cloud-connectors with Apache License 2.0 5 votes vote down vote up
@Test
public void oracleServiceCreation() {
	when(mockEnvironment.getEnvValue("VCAP_SERVICES"))
			.thenReturn(getServicesPayload(
					getUserProvidedServicePayload(SERVICE_NAME, hostname, port, username, password, INSTANCE_NAME, ORACLE_SCHEME + ":")));
	List<ServiceInfo> serviceInfos = testCloudConnector.getServiceInfos();

	ServiceInfo info = getServiceInfo(serviceInfos, SERVICE_NAME);
	assertServiceFoundOfType(info, OracleServiceInfo.class);
	assertJdbcUrlEqual(info, ORACLE_SCHEME, INSTANCE_NAME);
	assertUriBasedServiceInfoFields(info, ORACLE_SCHEME, hostname, port, username, password, INSTANCE_NAME);
}
 
Example #14
Source File: CloudTest.java    From spring-cloud-connectors with Apache License 2.0 5 votes vote down vote up
@Test
public void serviceInfosForConnectorType() {
	String serviceId = "mysql-db";
	CloudConnector stubCloudConnector = getTestCloudConnector(createMysqlService(serviceId));
	Cloud testCloud = new Cloud(stubCloudConnector, serviceCreators);

	List<ServiceInfo> serviceInfos = testCloud.getServiceInfos(DataSource.class);
	assertEquals(1, serviceInfos.size());
}
 
Example #15
Source File: CloudFactoryTest.java    From spring-cloud-connectors with Apache License 2.0 5 votes vote down vote up
@Test
public void cloudServiceConnectorCreatorRegistration() {
	CloudFactory cloudFactory = new CloudFactory();
	List<ServiceConnectorCreator<?, ? extends ServiceInfo>> registeredServiceConnectorCreators = cloudFactory.getServiceCreators();
	
	assertEquals("One serviceCreators registered", 2, registeredServiceConnectorCreators.size());
	assertEquals("First registered connector is a stub", StubServiceConnectorCreator.class, 
			registeredServiceConnectorCreators.get(0).getClass());
	assertEquals("Second egistered connector is a non-parameterized stub", NonParameterizedStubServiceConnectorCreator.class, 
			registeredServiceConnectorCreators.get(1).getClass());
}
 
Example #16
Source File: CloudFoundryConnectorApplicationTest.java    From spring-cloud-connectors with Apache License 2.0 5 votes vote down vote up
@Test
public void serviceInfosWithPostProcessedCredentials() {
	when(mockEnvironment.getEnvValue("VCAP_SERVICES")).
			thenReturn(getServicesPayload(readTestDataFile("test-credentials-post-processed.json")));
	List<ServiceInfo> serviceInfos = testCloudConnector.getServiceInfos();
	assertNotNull(serviceInfos);
	assertEquals(1, serviceInfos.size());
	assertThat(serviceInfos.get(0), instanceOf(MysqlServiceInfo.class));
	assertEquals(((MysqlServiceInfo) serviceInfos.get(0)).getUri(), "MYSQL://USERNAME:[email protected]/DB");
}
 
Example #17
Source File: CloudFoundryConnectorSmtpServiceTest.java    From spring-cloud-connectors with Apache License 2.0 5 votes vote down vote up
@Test
public void smtpServiceCreation() {
	when(mockEnvironment.getEnvValue("VCAP_SERVICES"))
		.thenReturn(getServicesPayload(getSmtpServicePayload("smtp-1", hostname, username, password)));

	List<ServiceInfo> serviceInfos = testCloudConnector.getServiceInfos();
	SmtpServiceInfo smtpServiceInfo = (SmtpServiceInfo) getServiceInfo(serviceInfos, "smtp-1");
	assertNotNull(smtpServiceInfo);
	assertEquals(hostname, smtpServiceInfo.getHost());
	assertEquals(587, smtpServiceInfo.getPort());
	assertEquals(username, smtpServiceInfo.getUserName());
	assertEquals(password, smtpServiceInfo.getPassword());
}
 
Example #18
Source File: LocalConfigConnectorDB2ServiceTest.java    From spring-cloud-connectors with Apache License 2.0 5 votes vote down vote up
@Test
public void serviceCreation() {
	List<ServiceInfo> services = connector.getServiceInfos();
	ServiceInfo service = getServiceInfo(services, "db2");
	assertNotNull(service);
	assertTrue(service instanceof DB2ServiceInfo);
	assertUriParameters((DB2ServiceInfo) service);
}
 
Example #19
Source File: HerokuConnectorMysqlServiceTest.java    From spring-cloud-connectors with Apache License 2.0 5 votes vote down vote up
@Test
public void mysqlServiceCreation() {
	Map<String, String> env = new HashMap<String, String>();
	String mysqlUrl = getRelationalServiceUrl("db");
	env.put("CLEARDB_DATABASE_URL", mysqlUrl);
	when(mockEnvironment.getEnv()).thenReturn(env);

	List<ServiceInfo> serviceInfos = testCloudConnector.getServiceInfos();
	ServiceInfo serviceInfo = getServiceInfo(serviceInfos, "CLEARDB_DATABASE");
	assertNotNull(serviceInfo);
	assertTrue(serviceInfo instanceof MysqlServiceInfo);
	assertReleationServiceInfo((MysqlServiceInfo) serviceInfo, "db");
}
 
Example #20
Source File: CloudTest.java    From spring-cloud-connectors with Apache License 2.0 5 votes vote down vote up
@Test
public void compositeServiceInfo() {
       StubServiceInfo testServiceInfo1 = new StubServiceInfo("test-id-1", "test-host", 1000, "test-username", "test-password");
       StubServiceInfo testServiceInfo2 = new StubServiceInfo("test-id-2", "test-host", 1000, "test-username", "test-password");
       ServiceInfo testCompositeServiceInfo = new StubCompositeServiceInfo("test-composite",testServiceInfo1, testServiceInfo2);

       StubCloudConnector stubCloudConnector = CloudTestUtil.getTestCloudConnector(testCompositeServiceInfo);
       Cloud testCloud = new Cloud(stubCloudConnector, serviceConnectorCreators);
       
       assertNotNull(testCloud.getServiceInfo("test-id-1"));
       assertNotNull(testCloud.getServiceInfo("test-id-2"));
}
 
Example #21
Source File: AbstractCloudConnectorTest.java    From spring-cloud-connectors with Apache License 2.0 5 votes vote down vote up
@Test 
public void fallbacksCorrectly() {
	TestServiceData acceptableServiceData = new TestServiceData("my-service1", "test-tag");
	TestServiceData unAcceptableServiceData = new TestServiceData("my-service2", "unknown-tag");
	
	CloudConnector testCloudConnector = new TestCloudConnector(acceptableServiceData, unAcceptableServiceData);
	List<ServiceInfo> serviceInfos = testCloudConnector.getServiceInfos();
	assertNotNull(serviceInfos);
	assertEquals(2, serviceInfos.size());
	assertThat(serviceInfos.get(0), is(instanceOf(TestServiceInfo.class)));
	assertThat(serviceInfos.get(0), is(instanceOf(BaseServiceInfo.class)));
}
 
Example #22
Source File: CloudFoundryConnectorMongodbServiceTest.java    From spring-cloud-connectors with Apache License 2.0 5 votes vote down vote up
@Test
public void mongoServiceCreation() {
	when(mockEnvironment.getEnvValue("VCAP_SERVICES"))
			.thenReturn(getServicesPayload(
					getMongoServicePayload("mongo-1", hostname, port, username, password, "inventory-1", "db"),
					getMongoServicePayload("mongo-2", hostname, port, username, password, "inventory-2", "db")));

	List<ServiceInfo> serviceInfos = testCloudConnector.getServiceInfos();
	assertServiceFoundOfType(serviceInfos, "mongo-1", MongoServiceInfo.class);
	assertServiceFoundOfType(serviceInfos, "mongo-2", MongoServiceInfo.class);
}
 
Example #23
Source File: CloudFoundryConnectorDB2ServiceTest.java    From spring-cloud-connectors with Apache License 2.0 5 votes vote down vote up
@Test
public void db2ServiceCreation() {
	when(mockEnvironment.getEnvValue("VCAP_SERVICES"))
			.thenReturn(getServicesPayload(
					getUserProvidedServicePayload(SERVICE_NAME, hostname, port, username, password, INSTANCE_NAME, DB2_SCHEME + ":")));
	List<ServiceInfo> serviceInfos = testCloudConnector.getServiceInfos();

	ServiceInfo info = getServiceInfo(serviceInfos, SERVICE_NAME);
	assertServiceFoundOfType(info, DB2ServiceInfo.class);
	assertJdbcUrlEqual(info, DB2_SCHEME, INSTANCE_NAME);
	assertUriBasedServiceInfoFields(info, DB2_SCHEME, hostname, port, username, password, INSTANCE_NAME);
}
 
Example #24
Source File: CloudFoundryConnectorAmqpServiceTest.java    From spring-cloud-connectors with Apache License 2.0 5 votes vote down vote up
@Test
public void rabbitServiceCreationWithManagementUri() {
	when(mockEnvironment.getEnvValue("VCAP_SERVICES"))
			.thenReturn(getServicesPayload(
					getRabbitServicePayloadWithTags("rabbit-1", hostname, port, username, password, "q-1", "vhost1")));

	String expectedManagementUri = "http://" + username + ":" + password + "@" + hostname + "/api";

	List<ServiceInfo> serviceInfos = testCloudConnector.getServiceInfos();
	assertServiceFoundOfType(serviceInfos, "rabbit-1", AmqpServiceInfo.class);
	AmqpServiceInfo amqpServiceInfo = (AmqpServiceInfo) serviceInfos.get(0);
	assertEquals(amqpServiceInfo.getManagementUri(), expectedManagementUri);
}
 
Example #25
Source File: CloudFoundryConnectorSqlServerServiceTest.java    From spring-cloud-connectors with Apache License 2.0 5 votes vote down vote up
@Test
public void sqlServerServiceCreation() {
	when(mockEnvironment.getEnvValue("VCAP_SERVICES"))
			.thenReturn(getServicesPayload(
					getUserProvidedServicePayload(SERVICE_NAME, hostname, port, username, password, INSTANCE_NAME, SQLSERVER_SCHEME + ":")));
	List<ServiceInfo> serviceInfos = testCloudConnector.getServiceInfos();

	ServiceInfo info = getServiceInfo(serviceInfos, SERVICE_NAME);
	assertServiceFoundOfType(info, SqlServerServiceInfo.class);
	assertJdbcUrlEqual(info, SQLSERVER_SCHEME, INSTANCE_NAME);
	assertUriBasedServiceInfoFields(info, SQLSERVER_SCHEME, hostname, port, username, password, INSTANCE_NAME);
}
 
Example #26
Source File: CloudFoundryConnectorApplicationTest.java    From spring-cloud-connectors with Apache License 2.0 5 votes vote down vote up
@Test
public void serviceInfosWithMissingCredentials() {
	when(mockEnvironment.getEnvValue("VCAP_SERVICES")).
			thenReturn(getServicesPayload(readTestDataFile("test-credentials-missing.json")));
	List<ServiceInfo> serviceInfos = testCloudConnector.getServiceInfos();
	assertNotNull(serviceInfos);
	assertEquals(1, serviceInfos.size());
}
 
Example #27
Source File: StubCloudConnectorTest.java    From spring-cloud-connectors with Apache License 2.0 5 votes vote down vote up
protected ApplicationContext getTestApplicationContext(Class<?> configClass, ServiceInfo... serviceInfos) {
	final CloudConnector stubCloudConnector = CloudTestUtil.getTestCloudConnector(serviceInfos);
	
	return new AnnotationConfigApplicationContext(configClass) {
		@Override
		protected void prepareBeanFactory(ConfigurableListableBeanFactory beanFactory) {
			CloudFactory cloudFactory = new CloudFactory();
			cloudFactory.getCloudConnectors().clear();
			cloudFactory.registerCloudConnector(stubCloudConnector);
			getBeanFactory().registerSingleton(MOCK_CLOUD_BEAN_NAME, cloudFactory);
			super.prepareBeanFactory(beanFactory);
		}
	};
}
 
Example #28
Source File: Cloud.java    From spring-cloud-connectors with Apache License 2.0 5 votes vote down vote up
/**
 * Get the singleton service connector for the given connector type, configured with the given config
 *
 * @param <SC> The class of the service connector to return.
 * @param serviceConnectorType The expected class of service connector such as, DataSource.class.
 * @param serviceConnectorConfig service connector configuration (such as pooling parameters).
 * @return the single service connector of the specified type with the given configuration applied
 *
 */
public <SC> SC getSingletonServiceConnector(Class<SC> serviceConnectorType, ServiceConnectorConfig serviceConnectorConfig) {
	List<ServiceInfo> matchingServiceInfos = getServiceInfos(serviceConnectorType);

	if (matchingServiceInfos.size() != 1) {
		throw new CloudException("No unique service matching " + serviceConnectorType + " found. Expected 1, found "
			+ matchingServiceInfos.size());
	}

	ServiceInfo matchingServiceInfo = matchingServiceInfos.get(0);

	return getServiceConnector(matchingServiceInfo, serviceConnectorType, serviceConnectorConfig);
}
 
Example #29
Source File: CloudFoundryConnectorAmqpServiceTest.java    From spring-cloud-connectors with Apache License 2.0 5 votes vote down vote up
@Test
public void rabbitServiceCreationWithoutTags() {
	when(mockEnvironment.getEnvValue("VCAP_SERVICES"))
			.thenReturn(getServicesPayload(
					getRabbitServicePayloadWithoutTags("rabbit-1", hostname, port, username, password, "q-1", "vhost1"),
					getRabbitServicePayloadWithoutTags("rabbit-2", hostname, port, username, password, "q-2", "vhost2")));

	List<ServiceInfo> serviceInfos = testCloudConnector.getServiceInfos();
	assertServiceFoundOfType(serviceInfos, "rabbit-1", AmqpServiceInfo.class);
	assertServiceFoundOfType(serviceInfos, "rabbit-2", AmqpServiceInfo.class);
}
 
Example #30
Source File: Cloud.java    From spring-cloud-connectors with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private <SC, SI extends ServiceInfo> ServiceConnectorCreator<SC, SI> getServiceCreatorOrNull(Class<SC> serviceConnectorType,
	SI serviceInfo) {
	for (ServiceConnectorCreator<?, ? extends ServiceInfo> serviceConnectorCreator : serviceConnectorCreators) {
		logger.fine("Trying connector creator type " + serviceConnectorCreator);
		if (accept(serviceConnectorCreator, serviceConnectorType, serviceInfo)) {
			return (ServiceConnectorCreator<SC, SI>) serviceConnectorCreator;
		}
	}
	return null;
}