Java Code Examples for org.springframework.cloud.service.ServiceInfo

The following examples show how to use org.springframework.cloud.service.ServiceInfo. These examples are extracted from open source projects. 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
@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 2
@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 3
@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 4
@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 5
@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 6
@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 7
@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 8
@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 9
@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 10
Source Project: spring-cloud-connectors   Source File: CloudTest.java    License: 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 11
Source Project: spring-cloud-connectors   Source File: CloudScanHelper.java    License: 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 12
@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
/**
 * Gets the first detected {@link SolaceMessagingInfo}.
 *
 * @deprecated As of 1.1.0, usage of {@link SolaceMessagingInfo}
 * was replaced by its interface, {@link SolaceServiceCredentials}.
 * Use {@link #findFirstSolaceServiceCredentials()} instead.
 *
 * @return If in a Cloud Foundry environment, a Solace PubSub+ service is returned, otherwise null
 */
@Deprecated
@Bean @Primary
public SolaceMessagingInfo findFirstSolaceMessagingInfo() {
	SolaceMessagingInfo solacemessaging = null;
	Cloud cloud = cloudFactory.getCloud();
	List<ServiceInfo> serviceInfos = cloud.getServiceInfos();
	for (ServiceInfo serviceInfo : serviceInfos) {
		// Stop when we find the first one...
		// TODO: Consider annotation driven selection, or sorted plan based
		// selection
		if (serviceInfo instanceof SolaceMessagingInfo) {
			solacemessaging = (SolaceMessagingInfo) serviceInfo;
			logger.info("Found Cloud Solace PubSub+ Service Instance Id: " + solacemessaging.getId());
			break;
		}
	}

	if (solacemessaging == null) {
		// The CloudCondition should shield from this happening, should not
		// arrive to this state.
		logger.error("Cloud Solace PubSub+ Info was not found, cannot auto-configure");
		throw new IllegalStateException(
				"Unable to create SolConnectionFactory did not find SolaceMessagingInfo in the current cloud environment");
	}

	return solacemessaging;
}
 
Example 14
private DynatraceServiceInfo getDynatraceServiceInfo() {
    String serviceName = DynatraceServiceInfoCreator.DEFAULT_DYNATRACE_SERVICE_ID;
    try {
        CloudFactory cloudFactory = new CloudFactory();
        Cloud cloud = cloudFactory.getCloud();
        ServiceInfo serviceInfo = cloud.getServiceInfo(serviceName);
        if (serviceInfo instanceof DynatraceServiceInfo) {
            return (DynatraceServiceInfo) serviceInfo;
        }
        LOGGER.warn("Service instance did not match allowed name and type.");
    } catch (CloudException e) {
        LOGGER.warn(MessageFormat.format("Failed to detect service info for service \"{0}\"!", serviceName), e);
    }
    return null;
}
 
Example 15
protected static ServiceInfo getServiceInfo(List<ServiceInfo> serviceInfos, String serviceId) {
	for (ServiceInfo serviceInfo : serviceInfos) {
		if (serviceInfo.getId().equals(serviceId)) {
			return serviceInfo;
		}
	}
	return null;
}
 
Example 16
Source Project: spring-cloud-connectors   Source File: HerokuConnector.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void registerServiceInfoCreator(ServiceInfoCreator<? extends ServiceInfo, UriBasedServiceData> serviceInfoCreator) {
	super.registerServiceInfoCreator(serviceInfoCreator);
	HerokuServiceInfoCreator<?> herokuServiceInfoCreator = (HerokuServiceInfoCreator<?>) serviceInfoCreator;
	String[] envPrefixes = herokuServiceInfoCreator.getEnvPrefixes();

	// need to do this since this method gets called during construction and we cannot initialize serviceEnvPrefixes before this
	if (serviceEnvPrefixes == null) {
		serviceEnvPrefixes = new ArrayList<String>();
	}
	serviceEnvPrefixes.addAll(Arrays.asList(envPrefixes));
}
 
Example 17
private String[] getCloudProfiles(Cloud cloud) {
    if (cloud == null) {
        return null;
    }

    List<String> profiles = new ArrayList<>();

    List<ServiceInfo> serviceInfos = cloud.getServiceInfos();

    LOGGER.info("Found serviceInfos: " + StringUtils.collectionToCommaDelimitedString(serviceInfos));

    for (ServiceInfo serviceInfo : serviceInfos) {
        if (serviceTypeToProfileName.containsKey(serviceInfo.getClass())) {
            profiles.add(serviceTypeToProfileName.get(serviceInfo.getClass()));
        }
    }

    if (profiles.size() > 1) {
        throw new IllegalStateException(
                "Only one service of the following types may be bound to this application: " +
                        serviceTypeToProfileName.values().toString() + ". " +
                        "These services are bound to the application: [" +
                        StringUtils.collectionToCommaDelimitedString(profiles) + "]");
    }

    if (profiles.size() > 0) {
        return createProfileNames(profiles.get(0), "cloud");
    }

    return null;
}
 
Example 18
private String[] getCloudProfiles(Cloud cloud) {
    if (cloud == null) {
        return null;
    }

    List<String> profiles = new ArrayList<>();

    List<ServiceInfo> serviceInfos = cloud.getServiceInfos();

    LOGGER.info("Found serviceInfos: " + StringUtils.collectionToCommaDelimitedString(serviceInfos));

    for (ServiceInfo serviceInfo : serviceInfos) {
        if (serviceTypeToProfileName.containsKey(serviceInfo.getClass())) {
            profiles.add(serviceTypeToProfileName.get(serviceInfo.getClass()));
        }
    }

    if (profiles.size() > 1) {
        throw new IllegalStateException(
                "Only one service of the following types may be bound to this application: " +
                        serviceTypeToProfileName.values().toString() + ". " +
                        "These services are bound to the application: [" +
                        StringUtils.collectionToCommaDelimitedString(profiles) + "]");
    }

    if (profiles.size() > 0) {
        return createProfileNames(profiles.get(0), "cloud");
    }

    return null;
}
 
Example 19
@SuppressWarnings("unchecked")
protected <T extends ServiceInfo> T findServiceInfo(LatticeConnector connector, Class<T> type, String serviceInfoId) {
	List<ServiceInfo> serviceInfos = connector.getServiceInfos();
	assertNotNull("serviceInfos was null", serviceInfos);

	ServiceInfo serviceInfo = null;
	for (ServiceInfo si : serviceInfos) {
		if (si.getId().equals(serviceInfoId)) {
			serviceInfo = si;
		}
	}
	assertNotNull("serviceInfo is null", serviceInfo);
	assertThat(serviceInfo, is(instanceOf(type)));
	return (T) serviceInfo;
}
 
Example 20
@GetMapping("/infos")
public String getInfos() {
  Cloud cloud = getCloud();
  List<ServiceInfo> infos = cloud.getServiceInfos();
  String result = "Info:\n";
  for (ServiceInfo info : infos) {
    result += info.getClass().toString() + "\n";
  }
  return result;
}
 
Example 21
@Override
public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) {
    if (cloud != null) return;
    try {
        cloud = new CloudFactory().getCloud();
    } catch (CloudException e) {
        return; // not running on a known cloud environment, so nothing to do
    }

    for (ServiceInfo serviceInfo : cloud.getServiceInfos()) {
        if (serviceInfo instanceof SsoServiceInfo) {
            Map<String, Object> map = new HashMap<>();
            SsoServiceInfo ssoServiceInfo = (SsoServiceInfo) serviceInfo;
            map.put("security.oauth2.client.clientId", ssoServiceInfo.getClientId());
            map.put("security.oauth2.client.clientSecret", ssoServiceInfo.getClientSecret());
            map.put("security.oauth2.client.accessTokenUri", ssoServiceInfo.getAuthDomain() + "/oauth/token");
            map.put("security.oauth2.client.userAuthorizationUri", ssoServiceInfo.getAuthDomain() + "/oauth/authorize");
            map.put("ssoServiceUrl", ssoServiceInfo.getAuthDomain());
            map.put("security.oauth2.resource.userInfoUri", ssoServiceInfo.getAuthDomain() + "/userinfo");
            map.put("security.oauth2.resource.tokenInfoUri", ssoServiceInfo.getAuthDomain() + "/check_token");
            map.put("security.oauth2.resource.jwk.key-set-uri", ssoServiceInfo.getAuthDomain() + "/token_keys");
            MapPropertySource mapPropertySource = new MapPropertySource("vcapPivotalSso", map);

            event.getEnvironment().getPropertySources().addFirst(mapPropertySource);
        }
    }
}
 
Example 22
@Test
public void serviceCreation() {
	List<ServiceInfo> services = connector.getServiceInfos();
	ServiceInfo service = getServiceInfo(services, "oracle");
	assertNotNull(service);
	assertTrue(service instanceof OracleServiceInfo);
	assertUriParameters((OracleServiceInfo) service);
}
 
Example 23
@Test
public void hystrixAmqpServiceCreation() {
	when(mockEnvironment.getEnvValue(VCAP_SERVICES_ENV_KEY))
			.thenReturn(getServicesPayload(getServicePayload(SERVICE_TAG_NAME, hostname, port, username, password, "vhost1")));

	List<ServiceInfo> serviceInfos = testCloudConnector.getServiceInfos();
	assertServiceFoundOfType(serviceInfos, SERVICE_TAG_NAME, HystrixAmqpServiceInfo.class);

	// ensure this type will not match on AmqpServiceInfos
	assertServiceNotFoundOfType(serviceInfos, AmqpServiceInfo.class);
}
 
Example 24
private void assertServiceNotFoundOfType(List<ServiceInfo> serviceInfos, Class<? extends ServiceInfo> expected) {
	for (ServiceInfo serviceInfo : serviceInfos) {
		if (expected.isAssignableFrom(serviceInfo.getClass())) {
			fail("ServiceInfo of type " + expected.getName() + " should not have been found");
		}
	}
}
 
Example 25
@Test
public void sqlServerServiceCreationWithNoUri() {
	when(mockEnvironment.getEnvValue("VCAP_SERVICES"))
			.thenReturn(getServicesPayload(
					getUserProvidedServicePayloadWithNoUri(SERVICE_NAME, hostname, port, username, password, INSTANCE_NAME)));
	List<ServiceInfo> serviceInfos = testCloudConnector.getServiceInfos();

	ServiceInfo info = getServiceInfo(serviceInfos, SERVICE_NAME);
	assertNotNull(info);
	assertFalse(SqlServerServiceInfo.class.isAssignableFrom(info.getClass()));  // service was not detected as SQL-Server
}
 
Example 26
@BeforeClass
public static void beforeClass() {
	List<ServiceInfo> serviceInfosWithAddedRabbitCloudBinding = new ArrayList<>(MockCloudConnector.instance.getServiceInfos());
	serviceInfosWithAddedRabbitCloudBinding.add(
			new AmqpServiceInfo("rabbitmq", "example.com", 5672, "username", "password", "virtualHost")
	);
	when(MockCloudConnector.instance.getServiceInfos()).thenReturn(serviceInfosWithAddedRabbitCloudBinding);
}
 
Example 27
@BeforeClass
@SuppressWarnings("unchecked")
public static void beforeClass() throws IOException {
	when(MockCloudConnector.instance.isInMatchingCloud()).thenReturn(true);
	when(MockCloudConnector.instance.getServiceInfos()).thenReturn(
			Arrays.asList(
					(ServiceInfo) new HystrixAmqpServiceInfo("circuit-breaker", URI, URIS, true),
					(ServiceInfo) new EurekaServiceInfo("service-registry", "https://example.com", "clientId", "clientSecret", "https://example.com/token")
			)
	);
}
 
Example 28
@Test
public void smtpServiceCreationWithUri() {
	when(mockEnvironment.getEnvValue("VCAP_SERVICES"))
		.thenReturn(getServicesPayload(getSmtpServicePayloadWithUri("smtp-1", hostname, port, username, password)));

	List<ServiceInfo> serviceInfos = testCloudConnector.getServiceInfos();
	SmtpServiceInfo smtpServiceInfo = (SmtpServiceInfo) getServiceInfo(serviceInfos, "smtp-1");
	assertNotNull(smtpServiceInfo);
	assertEquals(hostname, smtpServiceInfo.getHost());
	assertEquals(port, smtpServiceInfo.getPort());
	assertEquals(username, smtpServiceInfo.getUserName());
	assertEquals(password, smtpServiceInfo.getPassword());
}
 
Example 29
@Test
public void servicesInfosWithNullServices() {
	when(mockEnvironment.getEnvValue("VCAP_SERVICES")).thenReturn(null);
	List<ServiceInfo> serviceInfos = testCloudConnector.getServiceInfos();
	assertNotNull(serviceInfos);
	assertEquals(0, serviceInfos.size());
}
 
Example 30
@Test
public void amqpServiceCreation() {
	Map<String, String> env = new HashMap<String, String>();
	String amqpUrl = getAmqpServiceUrl("db");
	env.put("CLOUDAMQP_URL", amqpUrl);
	when(mockEnvironment.getEnv()).thenReturn(env);

	List<ServiceInfo> serviceInfos = testCloudConnector.getServiceInfos();
	ServiceInfo serviceInfo = getServiceInfo(serviceInfos, "CLOUDAMQP");
	assertNotNull(serviceInfo);
	assertTrue(serviceInfo instanceof AmqpServiceInfo);
	assertAmqpServiceInfo((AmqpServiceInfo) serviceInfo, "db");
}