From 8efdbd7eeb4a439fe26cdbf59d8e209fcb8aaa8f Mon Sep 17 00:00:00 2001 From: Matthew Nichols Date: Wed, 27 Nov 2024 10:41:28 -0700 Subject: [PATCH] fix: initialize facilities when facilities are empty --- .../gateway/configuration/Configurator.java | 82 +++++++++---------- .../configuration/ConfiguratorTest.groovy | 20 +++++ 2 files changed, 60 insertions(+), 42 deletions(-) diff --git a/gateway/src/main/java/com/mx/path/gateway/configuration/Configurator.java b/gateway/src/main/java/com/mx/path/gateway/configuration/Configurator.java index bc2e05ae..b337c6e8 100644 --- a/gateway/src/main/java/com/mx/path/gateway/configuration/Configurator.java +++ b/gateway/src/main/java/com/mx/path/gateway/configuration/Configurator.java @@ -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); } diff --git a/gateway/src/test/groovy/com/mx/path/gateway/configuration/ConfiguratorTest.groovy b/gateway/src/test/groovy/com/mx/path/gateway/configuration/ConfiguratorTest.groovy index 7ee7ccd3..eca38657 100644 --- a/gateway/src/test/groovy/com/mx/path/gateway/configuration/ConfiguratorTest.groovy +++ b/gateway/src/test/groovy/com/mx/path/gateway/configuration/ConfiguratorTest.groovy @@ -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 gateways = subject.buildFromYaml(yaml) + + then: + gateways.get("client") != null + gateways.get("client") + verify(observer, times(1)).notifyClientFacilitiesInitialized("client") + } }