diff --git a/pom.xml b/pom.xml index 5249743..56726bc 100644 --- a/pom.xml +++ b/pom.xml @@ -1,3 +1,22 @@ + + 4.0.0 diff --git a/src/main/java/com/solace/labs/spring/cloud/cloudfoundry/SolaceMessagingInfoCreator.java b/src/main/java/com/solace/labs/spring/cloud/cloudfoundry/SolaceMessagingInfoCreator.java index 9a8aa46..6f6ad66 100644 --- a/src/main/java/com/solace/labs/spring/cloud/cloudfoundry/SolaceMessagingInfoCreator.java +++ b/src/main/java/com/solace/labs/spring/cloud/cloudfoundry/SolaceMessagingInfoCreator.java @@ -18,6 +18,7 @@ */ package com.solace.labs.spring.cloud.cloudfoundry; +import java.util.List; import java.util.Map; import org.springframework.cloud.cloudfoundry.CloudFoundryServiceInfoCreator; @@ -27,52 +28,118 @@ public class SolaceMessagingInfoCreator extends CloudFoundryServiceInfoCreator { - //private static final Log trace = LogFactory.getLog(SolaceMessagingInfoCreator.class); + // This creator will accept and parse any credentials that have the matching tag or label. + // Therefore the default accept method is sufficient and doesn't need further specification. + static private String solaceMessagingTag = "solace-messaging"; - String label = "solace-messaging"; - public SolaceMessagingInfoCreator() { - super(new Tags("solace-messaging", - "solace", - "rest", - "mqtt", - "mq", - "queue", - "event-streaming", - "amqp", - "jms", - "messaging")); + super(new Tags(solaceMessagingTag)); } - - - // As a starting point, will only accept if the labels match. - public boolean accept(Map serviceData) { - String serviceLabel = (String) serviceData.get("label"); - - if (!super.accept(serviceData)) - return false; - - if (!this.label.equals(serviceLabel)) - return false; - - return true; - } - + + @SuppressWarnings("unchecked") + @Override public SolaceMessagingInfo createServiceInfo(Map serviceData) { String id = getId(serviceData); + String clientUsername = null; + String clientPassword = null; + String msgVpnName = null; + String smfUri = null; + String smfTlsUri = null; + String smfZipUri = null; + String webMessagingUri = null; + String jmsUri = null; + String jmsTlsUri = null; + List restUris = null; + List restTlsUris = null; + List mqttUris = null; + List mqttTlsUris = null; + List mqttWsUris = null; + List mqttWssUris = null; + List managementHttpUris = null; + List managementHttpsUris = null; + String managementPassword = null; + String managementUsername = null; + Map credentials = getCredentials(serviceData); - SolaceMessagingInfo solMessagingInfo = new SolaceMessagingInfo(id, credentials); - - return solMessagingInfo; - } + if (credentials == null) { + throw new IllegalArgumentException("Received null credentials during object creation"); + } - // These will come later from future version of Spring Cloud. For now clone - // methods here. + // Populate this the quick and dirty way for now. Can improve later as + // we harden. As a start, we'll be tolerant of missing attributes and + // just leave fields set to null. + for (Map.Entry entry : credentials.entrySet()) { + String key = entry.getKey(); + Object value = entry.getValue(); - @SuppressWarnings("unchecked") - protected Map getCredentials(Map serviceData) { - return (Map) serviceData.get("credentials"); + switch (key) { + case "clientUsername": + clientUsername = (String) value; + break; + case "clientPassword": + clientPassword = (String) value; + break; + case "msgVpnName": + msgVpnName = (String) value; + break; + case "smfUri": + smfUri = (String) value; + break; + case "smfTlsUri": + smfTlsUri = (String) value; + break; + case "smfZipUri": + smfZipUri = (String) value; + break; + case "webMessagingUri": + webMessagingUri = (String) value; + break; + case "jmsUri": + jmsUri = (String) value; + break; + case "jmsTlsUri": + jmsTlsUri = (String) value; + break; + case "managementUsername": + managementUsername = (String) value; + break; + case "managementPassword": + managementPassword = (String) value; + break; + case "restUris": + restUris = (List) value; + break; + case "restTlsUris": + restTlsUris = (List) value; + break; + case "mqttUris": + mqttUris = (List) value; + break; + case "mqttTlsUris": + mqttTlsUris = (List) value; + break; + case "mqttWsUris": + mqttWsUris = (List) value; + break; + case "mqttWssUris": + mqttWssUris = (List) value; + break; + case "managementHttpUris": + managementHttpUris = (List) value; + break; + case "managementHttpsUris": + managementHttpsUris = (List) value; + break; + } + } + + SolaceMessagingInfo solMessagingInfo = new SolaceMessagingInfo(id, clientUsername, clientPassword, msgVpnName, + smfUri, smfTlsUri, smfZipUri, webMessagingUri, jmsUri, jmsTlsUri, restUris, restTlsUris, mqttUris, + mqttTlsUris, mqttWsUris, mqttWssUris, managementHttpUris, managementHttpsUris, managementPassword, + managementUsername); + + return solMessagingInfo; } } diff --git a/src/main/java/com/solace/labs/spring/cloud/core/SolaceMessagingInfo.java b/src/main/java/com/solace/labs/spring/cloud/core/SolaceMessagingInfo.java index 2031e7f..87910a0 100644 --- a/src/main/java/com/solace/labs/spring/cloud/core/SolaceMessagingInfo.java +++ b/src/main/java/com/solace/labs/spring/cloud/core/SolaceMessagingInfo.java @@ -19,7 +19,6 @@ package com.solace.labs.spring.cloud.core; import java.util.List; -import java.util.Map; import org.apache.commons.lang3.builder.ToStringBuilder; import org.springframework.cloud.service.BaseServiceInfo; @@ -57,94 +56,39 @@ public class SolaceMessagingInfo extends BaseServiceInfo { private String managementPassword; private String managementUsername; - // Some details about the binding - private String plan; - + // Default constructor to enable bean unit testing. public SolaceMessagingInfo() { super(null); } - - public SolaceMessagingInfo(String id) { + + public SolaceMessagingInfo(String id, String clientUsername, String clientPassword, String msgVpnName, + String smfUri, String smfTlsUri, String smfZipUri, String webMessagingUri, String jmsUri, String jmsTlsUri, + List restUris, List restTlsUris, List mqttUris, List mqttTlsUris, + List mqttWsUris, List mqttWssUris, List managementHttpUris, + List managementHttpsUris, String managementPassword, String managementUsername) { super(id); + this.clientUsername = clientUsername; + this.clientPassword = clientPassword; + this.msgVpnName = msgVpnName; + this.smfUri = smfUri; + this.smfTlsUri = smfTlsUri; + this.smfZipUri = smfZipUri; + this.webMessagingUri = webMessagingUri; + this.jmsUri = jmsUri; + this.jmsTlsUri = jmsTlsUri; + this.restUris = restUris; + this.restTlsUris = restTlsUris; + this.mqttUris = mqttUris; + this.mqttTlsUris = mqttTlsUris; + this.mqttWsUris = mqttWsUris; + this.mqttWssUris = mqttWssUris; + this.managementHttpUris = managementHttpUris; + this.managementHttpsUris = managementHttpsUris; + this.managementPassword = managementPassword; + this.managementUsername = managementUsername; } - @SuppressWarnings("unchecked") - public SolaceMessagingInfo(String id, Map credentials) { - super(id); - - if (credentials == null) { - throw new IllegalArgumentException("Received null credentials during object creation"); - } - - // Populate this the quick and dirty way for now. Can improve later as - // we harden. As a start, we'll be tolerant of missing attributes and - // just leave fields set to null. - for (Map.Entry entry : credentials.entrySet()) { - String key = entry.getKey(); - Object value = entry.getValue(); - - switch (key) { - case "clientUsername": - clientUsername = (String) value; - break; - case "clientPassword": - clientPassword = (String) value; - break; - case "msgVpnName": - msgVpnName = (String) value; - break; - case "smfUri": - smfUri = (String) value; - break; - case "smfTlsUri": - smfTlsUri = (String) value; - break; - case "smfZipUri": - smfZipUri = (String) value; - break; - case "webMessagingUri": - webMessagingUri = (String) value; - break; - case "jmsUri": - jmsUri = (String) value; - break; - case "jmsTlsUri": - jmsTlsUri = (String) value; - break; - case "managementUsername": - managementUsername = (String) value; - break; - case "managementPassword": - managementPassword = (String) value; - break; - case "restUris": - restUris = (List) value; - break; - case "restTlsUris": - restTlsUris = (List) value; - break; - case "mqttUris": - mqttUris = (List) value; - break; - case "mqttTlsUris": - mqttTlsUris = (List) value; - break; - case "mqttWsUris": - mqttWsUris = (List) value; - break; - case "mqttWssUris": - mqttWssUris = (List) value; - break; - case "managementHttpUris": - managementHttpUris = (List) value; - break; - case "managementHttpsUris": - managementHttpsUris = (List) value; - break; - } - } - - } + /** * @return the clientUsername @@ -337,7 +281,6 @@ public int hashCode() { result = prime * result + ((smfUri == null) ? 0 : smfUri.hashCode()); result = prime * result + ((smfZipUri == null) ? 0 : smfZipUri.hashCode()); result = prime * result + ((webMessagingUri == null) ? 0 : webMessagingUri.hashCode()); - result = prime * result + ((plan == null) ? 0 : plan.hashCode()); return result; } @@ -455,11 +398,6 @@ public boolean equals(Object obj) { return false; } else if (!webMessagingUri.equals(other.webMessagingUri)) return false; - if (plan == null) { - if (other.plan != null) - return false; - } else if (!plan.equals(other.plan)) - return false; return true; } diff --git a/src/test/java/com/solace/labs/spring/cloud/core/SolaceMessagingServiceInfoTest.java b/src/test/java/com/solace/labs/spring/cloud/core/SolaceMessagingServiceInfoTest.java index 7b53194..459f9bc 100644 --- a/src/test/java/com/solace/labs/spring/cloud/core/SolaceMessagingServiceInfoTest.java +++ b/src/test/java/com/solace/labs/spring/cloud/core/SolaceMessagingServiceInfoTest.java @@ -25,96 +25,87 @@ import java.lang.reflect.InvocationTargetException; import java.util.Arrays; -import java.util.HashMap; -import java.util.Map; +import java.util.List; -import org.junit.Assert; import org.junit.Test; import org.meanbean.test.BeanTester; import org.meanbean.test.EqualsMethodTester; -import com.solace.labs.spring.cloud.core.SolaceMessagingInfo; - - - - - public class SolaceMessagingServiceInfoTest { - @Test - public void basicConstructorTest() { - SolaceMessagingInfo smi = new SolaceMessagingInfo("test-instance"); - Assert.assertEquals("test-instance", smi.getId()); - - - } - @Test public void fullSetGetCredentialsTest() throws IllegalAccessException, InvocationTargetException { - - Map exCred = new HashMap(); - exCred.put("clientUsername", "sample-client-username"); - exCred.put("clientPassword", "sample-client-password"); - exCred.put("msgVpnName", "sample-msg-vpn"); - exCred.put("smfUri", "tcp://192.168.1.50:7000"); - exCred.put("smfTlsUri", "tcps://192.168.1.50:7003"); - exCred.put("smfZipUri", "tcp://192.168.1.50:7001"); - exCred.put("webMessagingUri", "http://192.168.1.50:80"); - exCred.put("jmsUri", "smf://192.168.1.50:7000"); - exCred.put("jmsTlsUri", "smfs://192.168.1.50:7003"); - exCred.put("mqttUris", Arrays.asList("tcp://192.168.1.50:7020")); - exCred.put("mqttTlsUris", Arrays.asList("ssl://192.168.1.50:7021")); - exCred.put("mqttWsUris", Arrays.asList("ws://192.168.1.50:7022")); - exCred.put("mqttWssUris", Arrays.asList("wss://192.168.1.50:7023")); - exCred.put("restUris", Arrays.asList("http://192.168.1.50:7018")); - exCred.put("restTlsUris", Arrays.asList("https://192.168.1.50:7019")); - exCred.put("managementHttpUris", Arrays.asList("http://192.168.1.50:8080/SEMP/v2")); - exCred.put("managementHttpsUris", Arrays.asList("https://192.168.1.50:443/SEMP/v2")); - exCred.put("managementUsername", "sample-mgmt-username"); - exCred.put("managementPassword", "sample-mgmt-password"); - - SolaceMessagingInfo smi = new SolaceMessagingInfo("full-credentials-instance", exCred); - + + String id = "full-credentials-instance"; + String clientUsername = "sample-client-username"; + String clientPassword = "sample-client-password"; + String msgVpnName = "sample-msg-vpn"; + String smfUri = "tcp://192.168.1.50:7000"; + String smfTlsUri = "tcps://192.168.1.50:7003"; + String smfZipUri = "tcp://192.168.1.50:7001"; + String webMessagingUri = "http://192.168.1.50:80"; + String jmsUri = "smf://192.168.1.50:7000"; + String jmsTlsUri = "smfs://192.168.1.50:7003"; + List mqttUris = Arrays.asList("tcp://192.168.1.50:7020"); + List mqttTlsUris = Arrays.asList("ssl://192.168.1.50:7021"); + List mqttWsUris = Arrays.asList("ws://192.168.1.50:7022"); + List mqttWssUris = Arrays.asList("wss://192.168.1.50:7023"); + List restUris = Arrays.asList("http://192.168.1.50:7018"); + List restTlsUris = Arrays.asList("https://192.168.1.50:7019"); + List managementHttpUris = Arrays.asList("http://192.168.1.50:8080/SEMP/v2"); + List managementHttpsUris = Arrays.asList("https://192.168.1.50:443/SEMP/v2"); + String managementUsername = "sample-mgmt-username"; + String managementPassword = "sample-mgmt-password"; + + SolaceMessagingInfo smi = new SolaceMessagingInfo(id, clientUsername, clientPassword, msgVpnName, smfUri, + smfTlsUri, smfZipUri, webMessagingUri, jmsUri, jmsTlsUri, restUris, restTlsUris, mqttUris, mqttTlsUris, + mqttWsUris, mqttWssUris, managementHttpUris, managementHttpsUris, managementPassword, + managementUsername); + // Check Top Level stuff - assertEquals("full-credentials-instance", smi.getId()); - assertEquals("sample-client-username", smi.getClientUsername()); - assertEquals("sample-client-password", smi.getClientPassword()); - assertEquals("sample-msg-vpn", smi.getMsgVpnName()); - + assertEquals(id, smi.getId()); + assertEquals(clientUsername, smi.getClientUsername()); + assertEquals(clientPassword, smi.getClientPassword()); + assertEquals(msgVpnName, smi.getMsgVpnName()); + // Check SMF - assertEquals("tcp://192.168.1.50:7000", smi.getSmfUri()); - assertEquals("tcps://192.168.1.50:7003", smi.getSmfTlsUri()); - assertEquals("tcp://192.168.1.50:7001", smi.getSmfZipUri()); - + assertEquals(smfUri, smi.getSmfUri()); + assertEquals(smfTlsUri, smi.getSmfTlsUri()); + assertEquals(smfZipUri, smi.getSmfZipUri()); + // Check Web Messsaging - assertEquals("http://192.168.1.50:80", smi.getWebMessagingUri()); - + assertEquals(webMessagingUri, smi.getWebMessagingUri()); + // Check JMS - assertThat(smi.getMqttUris(), is(Arrays.asList("tcp://192.168.1.50:7020"))); - assertThat(smi.getMqttTlsUris(), is(Arrays.asList("ssl://192.168.1.50:7021"))); - assertThat(smi.getMqttWsUris(), is(Arrays.asList("ws://192.168.1.50:7022"))); - assertThat(smi.getMqttWssUris(), is(Arrays.asList("wss://192.168.1.50:7023"))); - + assertEquals(jmsUri, smi.getJmsUri()); + assertEquals(jmsTlsUri, smi.getJmsTlsUri()); + + // Check MQTT + assertThat(smi.getMqttUris(), is(mqttUris)); + assertThat(smi.getMqttTlsUris(), is(mqttTlsUris)); + assertThat(smi.getMqttWsUris(), is(mqttWsUris)); + assertThat(smi.getMqttWssUris(), is(mqttWssUris)); + // Check REST - assertThat(smi.getRestUris(), is(Arrays.asList("http://192.168.1.50:7018"))); - assertThat(smi.getRestTlsUris(), is(Arrays.asList("https://192.168.1.50:7019"))); - + assertThat(smi.getRestUris(), is(restUris)); + assertThat(smi.getRestTlsUris(), is(restTlsUris)); + // Check Management Interfaces - assertThat(smi.getManagementHttpUris(), is(Arrays.asList("http://192.168.1.50:8080/SEMP/v2"))); - assertThat(smi.getManagementHttpsUris(), is(Arrays.asList("https://192.168.1.50:443/SEMP/v2"))); - assertEquals("sample-mgmt-username", smi.getManagementUsername()); - assertEquals("sample-mgmt-password", smi.getManagementPassword()); + assertThat(smi.getManagementHttpUris(), is(managementHttpUris)); + assertThat(smi.getManagementHttpsUris(), is(managementHttpsUris)); + assertEquals(managementUsername, smi.getManagementUsername()); + assertEquals(managementPassword, smi.getManagementPassword()); } - + @Test public void meanBeanGetterAndSetterCorrectness() throws Exception { - new BeanTester().testBean(SolaceMessagingInfo.class); + new BeanTester().testBean(SolaceMessagingInfo.class); } - @Test - public void meanBeanEqualsAndHashCodeContract() { - EqualsMethodTester tester = new EqualsMethodTester(); - tester.testEqualsMethod(SolaceMessagingInfo.class); - } + @Test + public void meanBeanEqualsAndHashCodeContract() { + EqualsMethodTester tester = new EqualsMethodTester(); + tester.testEqualsMethod(SolaceMessagingInfo.class); + } }