Merge pull request #105 from xtreme-allan/master

Added support for pulling out "http_api_uri" for the CF AMQP connector
This commit is contained in:
Scott Frederick
2015-02-23 13:29:12 -06:00
4 changed files with 49 additions and 2 deletions

View File

@@ -21,8 +21,9 @@ public class AmqpServiceInfoCreator extends CloudFoundryServiceInfoCreator<AmqpS
String id = (String) serviceData.get("name");
String uri = getUriFromCredentials(credentials);
String managementUri = getStringFromCredentials(credentials, "http_api_uri");
return new AmqpServiceInfo(id, uri);
return new AmqpServiceInfo(id, uri, managementUri);
}
}

View File

@@ -1,10 +1,14 @@
package org.springframework.cloud.cloudfoundry;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.mockito.Matchers.isNull;
import static org.mockito.Mockito.when;
import java.util.List;
import org.junit.Test;
import org.mockito.internal.matchers.InstanceOf;
import org.springframework.cloud.service.ServiceInfo;
import org.springframework.cloud.service.common.AmqpServiceInfo;
@@ -26,6 +30,32 @@ public class CloudFoundryConnectorAmqpServiceTest extends AbstractCloudFoundryCo
assertServiceFoundOfType(serviceInfos, "rabbit-2", AmqpServiceInfo.class);
}
@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);
}
@Test
public void rabbitServiceCreationWithoutManagementUri() {
when(mockEnvironment.getEnvValue("VCAP_SERVICES"))
.thenReturn(getServicesPayload(
getRabbitServicePayloadNoLabelNoTags("rabbit-1", hostname, port, username, password, "q-1", "vhost1")));
List<ServiceInfo> 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"))

View File

@@ -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"
}
}

View File

@@ -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) {