diff --git a/spring-cloud-cloudfoundry-connector/src/main/java/org/springframework/cloud/cloudfoundry/AmqpServiceInfoCreator.java b/spring-cloud-cloudfoundry-connector/src/main/java/org/springframework/cloud/cloudfoundry/AmqpServiceInfoCreator.java index e1b868e..b1d36a5 100644 --- a/spring-cloud-cloudfoundry-connector/src/main/java/org/springframework/cloud/cloudfoundry/AmqpServiceInfoCreator.java +++ b/spring-cloud-cloudfoundry-connector/src/main/java/org/springframework/cloud/cloudfoundry/AmqpServiceInfoCreator.java @@ -21,8 +21,9 @@ public class AmqpServiceInfoCreator extends CloudFoundryServiceInfoCreator serviceInfos = testCloudConnector.getServiceInfos(); + assertServiceFoundOfType(serviceInfos, "rabbit-1", AmqpServiceInfo.class); + AmqpServiceInfo amqpServiceInfo = (AmqpServiceInfo) serviceInfos.get(0); + assertEquals(amqpServiceInfo.getManagementUri(), expectedManagementUri); + } + + @Test + public void rabbitServiceCreationWithoutManagementUri() { + when(mockEnvironment.getEnvValue("VCAP_SERVICES")) + .thenReturn(getServicesPayload( + getRabbitServicePayloadNoLabelNoTags("rabbit-1", hostname, port, username, password, "q-1", "vhost1"))); + + List serviceInfos = testCloudConnector.getServiceInfos(); + assertServiceFoundOfType(serviceInfos, "rabbit-1", AmqpServiceInfo.class); + AmqpServiceInfo amqpServiceInfo = (AmqpServiceInfo) serviceInfos.get(0); + assertNull(amqpServiceInfo.getManagementUri()); + } + @Test public void rabbitServiceCreationWithoutTags() { when(mockEnvironment.getEnvValue("VCAP_SERVICES")) diff --git a/spring-cloud-cloudfoundry-connector/src/test/resources/org/springframework/cloud/cloudfoundry/test-rabbit-info.json b/spring-cloud-cloudfoundry-connector/src/test/resources/org/springframework/cloud/cloudfoundry/test-rabbit-info.json index 16e3428..6e4f299 100644 --- a/spring-cloud-cloudfoundry-connector/src/test/resources/org/springframework/cloud/cloudfoundry/test-rabbit-info.json +++ b/spring-cloud-cloudfoundry-connector/src/test/resources/org/springframework/cloud/cloudfoundry/test-rabbit-info.json @@ -4,6 +4,7 @@ "plan":"free", "tags":["amqp","rabbitmq"], "credentials":{ - "uri": "amqp://$username:$password@$hostname/$virtualHost" + "uri": "amqp://$username:$password@$hostname/$virtualHost", + "http_api_uri": "http://$user:$pass@$hostname/api" } } diff --git a/spring-cloud-core/src/main/java/org/springframework/cloud/service/common/AmqpServiceInfo.java b/spring-cloud-core/src/main/java/org/springframework/cloud/service/common/AmqpServiceInfo.java index 75acd5e..81feb83 100644 --- a/spring-cloud-core/src/main/java/org/springframework/cloud/service/common/AmqpServiceInfo.java +++ b/spring-cloud-core/src/main/java/org/springframework/cloud/service/common/AmqpServiceInfo.java @@ -18,12 +18,24 @@ public class AmqpServiceInfo extends UriBasedServiceInfo { public static final String AMQP_SCHEME = "amqp"; public static final String AMQPS_SCHEME = "amqps"; + private String managementUri; + public AmqpServiceInfo(String id, String host, int port, String username, String password, String virtualHost) { + this(id, host, port, username, password, virtualHost, null); + } + + public AmqpServiceInfo(String id, String host, int port, String username, String password, String virtualHost, String managementUri) { super(id, AMQP_SCHEME, host, port, username, password, virtualHost); + this.managementUri = managementUri; } public AmqpServiceInfo(String id, String uri) throws CloudException { + this(id, uri, null); + } + + public AmqpServiceInfo(String id, String uri, String managementUri) throws CloudException { super(id, uri); + this.managementUri = managementUri; } @ServiceProperty(category="connection") @@ -31,6 +43,9 @@ public class AmqpServiceInfo extends UriBasedServiceInfo { return getUriInfo().getPath(); } + @ServiceProperty(category="connection") + public String getManagementUri() { return managementUri; } + @Override protected UriInfo validateAndCleanUriInfo(UriInfo uriInfo) { if (uriInfo.getScheme() == null) {