Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -280,53 +280,51 @@ private void buildServices(ObjectMap map, Object builder, String clientId) {

private void populateFacilities(String clientId, ObjectMap map) {
ObjectMap node = map.getMap("facilities");
if (node == null) {
return;
}

state.withLevel("facilities", () -> {
node.keySet().forEach(key -> {
switch (key) {
case "cacheStore":
Facilities.setCacheStore(clientId, gatewayObjectConfigurator.buildFromNode(node.getMap(key), clientId, Store.class));
break;

case "encryptionService":
Facilities.setEncryptionService(clientId, gatewayObjectConfigurator.buildFromNode(node.getMap(key), clientId, EncryptionService.class));
break;

case "eventBus":
Facilities.addEventBus(clientId, gatewayObjectConfigurator.buildFromNode(node.getMap(key), clientId, EventBus.class));
break;

case "exceptionReporter":
Facilities.setExceptionReporter(clientId, gatewayObjectConfigurator.buildFromNode(node.getMap(key), clientId, ExceptionReporter.class));
break;

case "faultTolerantExecutor":
Facilities.setFaultTolerantExecutor(clientId, gatewayObjectConfigurator.buildFromNode(node.getMap(key), clientId, FaultTolerantExecutor.class));
break;

case "messageBroker":
Facilities.setMessageBroker(clientId, gatewayObjectConfigurator.buildFromNode(node.getMap(key), clientId, MessageBroker.class));
break;

case "sessionStore":
Facilities.setSessionStore(clientId, gatewayObjectConfigurator.buildFromNode(node.getMap(key), clientId, Store.class));
break;

case "secretStore":
Facilities.setSecretStore(clientId, gatewayObjectConfigurator.buildFromNode(node.getMap(key), clientId, Store.class));
break;

default:
throw new GatewayException("Invalid facility: " + key);
}
});
if (node != null) {
node.keySet().forEach(key -> {
switch (key) {
case "cacheStore":
Facilities.setCacheStore(clientId, gatewayObjectConfigurator.buildFromNode(node.getMap(key), clientId, Store.class));
break;

case "encryptionService":
Facilities.setEncryptionService(clientId, gatewayObjectConfigurator.buildFromNode(node.getMap(key), clientId, EncryptionService.class));
break;

case "eventBus":
Facilities.addEventBus(clientId, gatewayObjectConfigurator.buildFromNode(node.getMap(key), clientId, EventBus.class));
break;

case "exceptionReporter":
Facilities.setExceptionReporter(clientId, gatewayObjectConfigurator.buildFromNode(node.getMap(key), clientId, ExceptionReporter.class));
break;

case "faultTolerantExecutor":
Facilities.setFaultTolerantExecutor(clientId, gatewayObjectConfigurator.buildFromNode(node.getMap(key), clientId, FaultTolerantExecutor.class));
break;

case "messageBroker":
Facilities.setMessageBroker(clientId, gatewayObjectConfigurator.buildFromNode(node.getMap(key), clientId, MessageBroker.class));
break;

case "sessionStore":
Facilities.setSessionStore(clientId, gatewayObjectConfigurator.buildFromNode(node.getMap(key), clientId, Store.class));
break;

case "secretStore":
Facilities.setSecretStore(clientId, gatewayObjectConfigurator.buildFromNode(node.getMap(key), clientId, Store.class));
break;

default:
throw new GatewayException("Invalid facility: " + key);
}
});
}
});

ensureDefaultFacilities(clientId);

getObserver().notifyClientFacilitiesInitialized(clientId);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,24 @@ class ConfiguratorTest extends Specification {
gateways.get("client")
verify(observer, times(1)).notifyClientFacilitiesInitialized("client")
}

def "invokes facilities initialized listeners when facilities are empty"() {
given:
def yaml =
"client:\n" +
" accessor:\n" +
" class: com.mx.testing.accessors.BaseAccessor\n" +
" scope: singleton\n" +
" gateways:\n" +
" id: {}\n" +
" accounts: {}\n"

when:
Map<String, TestGateway> gateways = subject.buildFromYaml(yaml)

then:
gateways.get("client") != null
gateways.get("client")
verify(observer, times(1)).notifyClientFacilitiesInitialized("client")
}
}