From c66974bd346898c5cf5ac22a43a10fa47845db76 Mon Sep 17 00:00:00 2001 From: David Sloan <33483659+davidsloan@users.noreply.github.com> Date: Wed, 19 Jun 2024 09:36:53 +0100 Subject: [PATCH] GCP Storage - Fix for Invalid protocol (#44) --- .../common/config/source/ConfigWrapperSource.java | 2 +- .../common/config/source/MapConfigSource.java | 2 +- .../common/config/source/ConfigSourceTestBase.java | 9 +++++++++ .../common/config/source/ConfigWrapperSourceTest.java | 1 + 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/java-connectors/kafka-connect-common/src/main/java/io/lenses/streamreactor/common/config/source/ConfigWrapperSource.java b/java-connectors/kafka-connect-common/src/main/java/io/lenses/streamreactor/common/config/source/ConfigWrapperSource.java index c89b776f0a..0287b76b5f 100644 --- a/java-connectors/kafka-connect-common/src/main/java/io/lenses/streamreactor/common/config/source/ConfigWrapperSource.java +++ b/java-connectors/kafka-connect-common/src/main/java/io/lenses/streamreactor/common/config/source/ConfigWrapperSource.java @@ -44,7 +44,7 @@ public static Either fromConfigDef(ConfigD @Override public Optional getString(String key) { - return Optional.ofNullable(abstractConfig.getString(key)); + return Optional.ofNullable(abstractConfig.getString(key)).filter(s -> !s.isEmpty()); } @Override diff --git a/java-connectors/kafka-connect-common/src/main/java/io/lenses/streamreactor/common/config/source/MapConfigSource.java b/java-connectors/kafka-connect-common/src/main/java/io/lenses/streamreactor/common/config/source/MapConfigSource.java index f1ecbe603d..c11925b3ae 100644 --- a/java-connectors/kafka-connect-common/src/main/java/io/lenses/streamreactor/common/config/source/MapConfigSource.java +++ b/java-connectors/kafka-connect-common/src/main/java/io/lenses/streamreactor/common/config/source/MapConfigSource.java @@ -32,7 +32,7 @@ public class MapConfigSource implements ConfigSource { @Override public Optional getString(String key) { - return Optional.ofNullable((String) wrapped.get(key)); + return Optional.ofNullable((String) wrapped.get(key)).filter(s -> !s.isEmpty()); } @Override diff --git a/java-connectors/kafka-connect-common/src/test/java/io/lenses/streamreactor/common/config/source/ConfigSourceTestBase.java b/java-connectors/kafka-connect-common/src/test/java/io/lenses/streamreactor/common/config/source/ConfigSourceTestBase.java index 8f1811dd3a..042102e7e7 100644 --- a/java-connectors/kafka-connect-common/src/test/java/io/lenses/streamreactor/common/config/source/ConfigSourceTestBase.java +++ b/java-connectors/kafka-connect-common/src/test/java/io/lenses/streamreactor/common/config/source/ConfigSourceTestBase.java @@ -31,6 +31,8 @@ abstract class ConfigSourceTestBase { protected static final Password PASSWORD_VALUE = new Password("secret"); protected static final String USERNAME_KEY = "username"; protected static final String USERNAME_VALUE = "user123"; + protected static final String NULL_KEY = "valueNull"; + protected static final String NULL_VALUE = null; private ConfigSource configSource; @BeforeEach @@ -69,4 +71,11 @@ void testGetPassword_nonExistingKey_shouldReturnEmpty() { assertFalse(password.isPresent()); } + + @Test + void testGetString_nonExistingValue_shouldReturnEmpty() { + Optional password = configSource.getString(NULL_KEY); + + assertFalse(password.isPresent()); + } } diff --git a/java-connectors/kafka-connect-common/src/test/java/io/lenses/streamreactor/common/config/source/ConfigWrapperSourceTest.java b/java-connectors/kafka-connect-common/src/test/java/io/lenses/streamreactor/common/config/source/ConfigWrapperSourceTest.java index c06307d066..6bb8991f5b 100644 --- a/java-connectors/kafka-connect-common/src/test/java/io/lenses/streamreactor/common/config/source/ConfigWrapperSourceTest.java +++ b/java-connectors/kafka-connect-common/src/test/java/io/lenses/streamreactor/common/config/source/ConfigWrapperSourceTest.java @@ -27,6 +27,7 @@ ConfigSource createConfigSource() { AbstractConfig config = mock(AbstractConfig.class); when(config.getString(USERNAME_KEY)).thenReturn(USERNAME_VALUE); when(config.getPassword(PASSWORD_KEY)).thenReturn(PASSWORD_VALUE); + when(config.getString(NULL_KEY)).thenReturn(NULL_VALUE); return new ConfigWrapperSource(config); }