Search in sources :

Example 1 with ServiceInfo

use of org.springframework.cloud.service.ServiceInfo in project spring-cloud-connectors by spring-cloud.

the class CloudFoundryConnectorPostgresqlServiceTest method postgresqlServiceCreationWithJdbcUrl.

@Test
public void postgresqlServiceCreationWithJdbcUrl() {
    String name1 = "database-1";
    String name2 = "database-2";
    when(mockEnvironment.getEnvValue("VCAP_SERVICES")).thenReturn(getServicesPayload(getPostgresqlServicePayloadWithJdbcUrl("postgresql-1", hostname, port, username, password, name1), getPostgresqlServicePayloadWithJdbcUrl("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);
}
Also used : ServiceInfo(org.springframework.cloud.service.ServiceInfo) PostgresqlServiceInfo(org.springframework.cloud.service.common.PostgresqlServiceInfo) Test(org.junit.Test)

Example 2 with ServiceInfo

use of org.springframework.cloud.service.ServiceInfo in project spring-cloud-connectors by spring-cloud.

the class CloudFoundryConnectorSmtpServiceTest method smtpServiceCreation.

@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());
}
Also used : ServiceInfo(org.springframework.cloud.service.ServiceInfo) SmtpServiceInfo(org.springframework.cloud.service.common.SmtpServiceInfo) SmtpServiceInfo(org.springframework.cloud.service.common.SmtpServiceInfo) Test(org.junit.Test)

Example 3 with ServiceInfo

use of org.springframework.cloud.service.ServiceInfo in project spring-cloud-connectors by spring-cloud.

the class CloudFoundryConnectorSqlServerServiceTest method sqlServerServiceCreationWithJdbcUrl.

@Test
public void sqlServerServiceCreationWithJdbcUrl() {
    when(mockEnvironment.getEnvValue("VCAP_SERVICES")).thenReturn(getServicesPayload(getSqlServerServicePayloadWithJdbcurl(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);
}
Also used : ServiceInfo(org.springframework.cloud.service.ServiceInfo) SqlServerServiceInfo(org.springframework.cloud.service.common.SqlServerServiceInfo) Test(org.junit.Test)

Example 4 with ServiceInfo

use of org.springframework.cloud.service.ServiceInfo in project spring-cloud-connectors by spring-cloud.

the class AbstractCloudConnector method getServiceInfo.

private ServiceInfo getServiceInfo(SD serviceData) {
    for (ServiceInfoCreator<? extends ServiceInfo, SD> serviceInfoCreator : serviceInfoCreators) {
        if (serviceInfoCreator.accept(serviceData)) {
            return serviceInfoCreator.createServiceInfo(serviceData);
        }
    }
    // Fallback with a warning
    ServiceInfo fallackServiceInfo = getFallbackServiceInfoCreator().createServiceInfo(serviceData);
    logger.warning("No suitable service info creator found for service " + fallackServiceInfo.getId() + " Did you forget to add a ServiceInfoCreator?");
    return fallackServiceInfo;
}
Also used : ServiceInfo(org.springframework.cloud.service.ServiceInfo)

Example 5 with ServiceInfo

use of org.springframework.cloud.service.ServiceInfo in project spring-cloud-connectors by spring-cloud.

the class ServiceConnectorCreatorRegistry method getServiceLabel.

private static String getServiceLabel(ServiceInfo serviceInfo) {
    Class<? extends ServiceInfo> serviceInfoClass = serviceInfo.getClass();
    ServiceLabel labelAnnotation = serviceInfoClass.getAnnotation(ServiceInfo.ServiceLabel.class);
    if (labelAnnotation == null) {
        return null;
    } else {
        return labelAnnotation.value();
    }
}
Also used : ServiceInfo(org.springframework.cloud.service.ServiceInfo) CompositeServiceInfo(org.springframework.cloud.service.CompositeServiceInfo) ServiceLabel(org.springframework.cloud.service.ServiceInfo.ServiceLabel)

Aggregations

ServiceInfo (org.springframework.cloud.service.ServiceInfo)47 Test (org.junit.Test)37 MysqlServiceInfo (org.springframework.cloud.service.common.MysqlServiceInfo)16 AmqpServiceInfo (org.springframework.cloud.service.common.AmqpServiceInfo)8 HashMap (java.util.HashMap)6 CompositeServiceInfo (org.springframework.cloud.service.CompositeServiceInfo)5 MongoServiceInfo (org.springframework.cloud.service.common.MongoServiceInfo)5 PostgresqlServiceInfo (org.springframework.cloud.service.common.PostgresqlServiceInfo)5 RedisServiceInfo (org.springframework.cloud.service.common.RedisServiceInfo)4 ArrayList (java.util.ArrayList)3 UriBasedServiceInfo (org.springframework.cloud.service.UriBasedServiceInfo)3 DB2ServiceInfo (org.springframework.cloud.service.common.DB2ServiceInfo)3 OracleServiceInfo (org.springframework.cloud.service.common.OracleServiceInfo)3 SqlServerServiceInfo (org.springframework.cloud.service.common.SqlServerServiceInfo)3 StubCloudConnector (org.springframework.cloud.CloudTestUtil.StubCloudConnector)2 StubCompositeServiceInfo (org.springframework.cloud.CloudTestUtil.StubCompositeServiceInfo)2 StubServiceInfo (org.springframework.cloud.CloudTestUtil.StubServiceInfo)2 BaseServiceInfo (org.springframework.cloud.service.BaseServiceInfo)2 RelationalServiceInfo (org.springframework.cloud.service.common.RelationalServiceInfo)2 SmtpServiceInfo (org.springframework.cloud.service.common.SmtpServiceInfo)2