Skip to content

Commit

Permalink
Merge pull request #14 from SolaceDev/UserProvided
Browse files Browse the repository at this point in the history
User provided
  • Loading branch information
PhilippeKhalife authored Nov 24, 2017
2 parents b119d60 + b6782a2 commit 309fbcd
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ public SolaceMessagingInfo createServiceInfo(Map<String, Object> serviceData) {
case "amqpTlsUris":
amqpTlsUris = (List<String>) value;
break;

case "managementHostnames":
managementHostnames = (List<String>) value;
break;
Expand Down Expand Up @@ -167,4 +166,40 @@ public SolaceMessagingInfo createServiceInfo(Map<String, Object> serviceData) {

return solMessagingInfo;
}
}


public boolean accept(Map<String, Object> serviceData) {
return super.accept(serviceData) || (isUserProvided(serviceData) && isSolaceMessagingInfo(serviceData));
}

public boolean isUserProvided(Map<String, Object> serviceData) {
if( serviceData == null )
return false;

String label = (String) serviceData.get("label");
if( "user-provided".startsWith(label)) {
return true;
}
return false;
}

public boolean isSolaceMessagingInfo(Map<String, Object> serviceData) {
if( serviceData == null )
return false;

try {
SolaceMessagingInfo solMessagingInfo = createServiceInfo(serviceData);
// Good enough test
// Don't check for client or management username/password as they can be missing when using LDAP
// Not checking other Uri(s) especially that this can be a user-provided service.
if( solMessagingInfo != null && solMessagingInfo.getId() != null && solMessagingInfo.getMsgVpnName() != null )
return true;

} catch(Throwable t) {
return false;
}

return false;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
*/
package com.solace.labs.spring.cloud.core;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.apache.commons.lang3.builder.ToStringBuilder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
Expand Down Expand Up @@ -55,6 +56,23 @@ public void basicSolaceMessagingServiceInfoCreationTest() {
validateExampleSmi(smi);

}


@Test
public void cupsSolaceMessagingServiceInfoCreationTest() {

Map<String, Object> exVcapServices = createCUPSVcapMap();

SolaceMessagingInfoCreator smic = new SolaceMessagingInfoCreator();

assertTrue(smic.accept(exVcapServices));

SolaceMessagingInfo smi = smic.createServiceInfo(exVcapServices);

validateExampleSmi(smi);

}


@Test
public void mismatchLabelTest() {
Expand Down Expand Up @@ -134,17 +152,16 @@ public void loadCreatorFromMeta() {
}
try {
Class<?> z = Class.forName(solaceMessagingInfoCreatorClassName);
assertTrue(z != null);
assertTrue(z.equals(SolaceMessagingInfoCreator.class));
assertNotNull(z);
assertEquals(z,SolaceMessagingInfoCreator.class);
} catch (ClassNotFoundException e) {
fail("Should not throw.");
}

}

private Map<String, Object> createVcapMap() {
Map<String, Object> exVcapServices = new HashMap<String, Object>();

private Map<String,Object> createCredentialsMap() {

Map<String, Object> exCred = new HashMap<String, Object>();

exCred.put("clientUsername", "sample-client-username");
Expand All @@ -169,7 +186,15 @@ private Map<String, Object> createVcapMap() {
exCred.put("managementUsername", "sample-mgmt-username");
exCred.put("managementPassword", "sample-mgmt-password");
exCred.put("activeManagementHostname", "vmr-medium-web");

return exCred;
}

private Map<String, Object> createVcapMap() {
Map<String, Object> exVcapServices = new HashMap<String, Object>();

Map<String, Object> exCred = createCredentialsMap();

exVcapServices.put("credentials", exCred);
exVcapServices.put("label", "solace-messaging");
exVcapServices.put("name", "test-service-instance-name");
Expand All @@ -179,6 +204,17 @@ private Map<String, Object> createVcapMap() {
exVcapServices.put("tags", Arrays.asList("solace", "rest", "mqtt", "mq", "queue", "jms", "messaging", "amqp"));
return exVcapServices;
}

private Map<String, Object> createCUPSVcapMap() {
Map<String, Object> exVcapServices = new HashMap<String, Object>();
Map<String, Object> exCred = createCredentialsMap();
exVcapServices.put("credentials", exCred);

exVcapServices.put("label", "user-provided");
exVcapServices.put("name", "test-service-instance-name");
exVcapServices.put("tags", Arrays.asList());
return exVcapServices;
}

private void validateExampleSmi(SolaceMessagingInfo smi) {
// Validate it all got set correctly.
Expand Down

0 comments on commit 309fbcd

Please sign in to comment.