From de5dc151d0a02efd736dec7afa4a19151d7f8bd2 Mon Sep 17 00:00:00 2001 From: Vijay N Date: Thu, 9 Jan 2025 15:51:40 +0530 Subject: [PATCH 1/6] * Updated the PluginConfigurationEventHandler to handle eventConfigKeyName as both a raw string and JSON formatted metadata. * Added a unit test for this functionality. --- .../PluginConfigurationHandler.java | 17 +++- .../TestPluginConfigurationHandler.java | 85 +++++++++++++++++++ 2 files changed, 101 insertions(+), 1 deletion(-) create mode 100644 src/test/java/org/killbill/billing/plugin/api/notification/TestPluginConfigurationHandler.java diff --git a/src/main/java/org/killbill/billing/plugin/api/notification/PluginConfigurationHandler.java b/src/main/java/org/killbill/billing/plugin/api/notification/PluginConfigurationHandler.java index 54b0de5a..4b28e679 100644 --- a/src/main/java/org/killbill/billing/plugin/api/notification/PluginConfigurationHandler.java +++ b/src/main/java/org/killbill/billing/plugin/api/notification/PluginConfigurationHandler.java @@ -34,6 +34,10 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; + public abstract class PluginConfigurationHandler { private static final Logger logger = LoggerFactory.getLogger(PluginConfigurationHandler.class); @@ -49,7 +53,18 @@ public PluginConfigurationHandler(final String pluginName, final OSGIKillbillAPI protected abstract void configure(@Nullable UUID kbTenantId); protected void configure(final String eventConfigKeyName, @Nullable final UUID kbTenantId) { - if (eventConfigKeyName.equals(configKeyName)) { + String extractedKeyName = eventConfigKeyName; + + try { + final JsonNode jsonNode = new ObjectMapper().readTree(eventConfigKeyName); + if (jsonNode.has("key")) { + extractedKeyName = jsonNode.get("key").asText(); + } + } catch (final JsonProcessingException e) { + // No action required, eventConfigKeyName is a plain string. + } + + if (extractedKeyName.equals(configKeyName)) { configure(kbTenantId); } } diff --git a/src/test/java/org/killbill/billing/plugin/api/notification/TestPluginConfigurationHandler.java b/src/test/java/org/killbill/billing/plugin/api/notification/TestPluginConfigurationHandler.java new file mode 100644 index 00000000..7041fc25 --- /dev/null +++ b/src/test/java/org/killbill/billing/plugin/api/notification/TestPluginConfigurationHandler.java @@ -0,0 +1,85 @@ +/* + * Copyright 2020-2025 Equinix, Inc + * Copyright 2014-2025 The Billing Project, LLC + * + * The Billing Project licenses this file to you under the Apache License, version 2.0 + * (the "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + */ + +package org.killbill.billing.plugin.api.notification; + +import java.util.UUID; + +import org.killbill.billing.osgi.libs.killbill.OSGIKillbillAPI; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; + +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +public class TestPluginConfigurationHandler { + + private PluginConfigurationHandler pluginConfigurationHandler; + + @Mock + private OSGIKillbillAPI osgiKillbillAPI; + + @Mock + private ObjectMapper objectMapper; + + @BeforeMethod(groups = "fast") + void setUp() { + MockitoAnnotations.openMocks(this); + + pluginConfigurationHandler = spy(new PluginConfigurationHandler("email-notification-plugin", osgiKillbillAPI) { + @Override + protected void configure(final UUID kbTenantId) { + // Empty implementation for testing + } + }); + } + + @Test(groups = "fast") + void testConfigure_withValidJsonKey() throws Exception { + final String eventConfigKeyName = "{\"key\":\"PLUGIN_CONFIG_email-notification-plugin\"}"; + final UUID kbTenantId = UUID.randomUUID(); + + final JsonNode mockJsonNode = mock(JsonNode.class); + when(mockJsonNode.has("key")).thenReturn(true); + when(mockJsonNode.get("key")).thenReturn(mock(JsonNode.class)); + when(mockJsonNode.get("key").asText()).thenReturn("PLUGIN_CONFIG_email-notification-plugin"); + + when(objectMapper.readTree(eventConfigKeyName)).thenReturn(mockJsonNode); + + pluginConfigurationHandler.configure(eventConfigKeyName, kbTenantId); + + verify(pluginConfigurationHandler, times(1)).configure(kbTenantId); + } + + @Test(groups = "fast") + void testConfigure_withPlainString() { + final String eventConfigKeyName = "PLUGIN_CONFIG_email-notification-plugin"; + final UUID kbTenantId = UUID.randomUUID(); + + pluginConfigurationHandler.configure(eventConfigKeyName, kbTenantId); + + verify(pluginConfigurationHandler, times(1)).configure(kbTenantId); + } +} \ No newline at end of file From 534bc247714548db6551397fc8e69ddff4eb53e8 Mon Sep 17 00:00:00 2001 From: Vijay N Date: Sun, 12 Jan 2025 22:49:42 +0530 Subject: [PATCH 2/6] Updated the unit test method names to align with the existing naming convention. --- .../api/notification/TestPluginConfigurationHandler.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/org/killbill/billing/plugin/api/notification/TestPluginConfigurationHandler.java b/src/test/java/org/killbill/billing/plugin/api/notification/TestPluginConfigurationHandler.java index 7041fc25..2db01832 100644 --- a/src/test/java/org/killbill/billing/plugin/api/notification/TestPluginConfigurationHandler.java +++ b/src/test/java/org/killbill/billing/plugin/api/notification/TestPluginConfigurationHandler.java @@ -57,7 +57,7 @@ protected void configure(final UUID kbTenantId) { } @Test(groups = "fast") - void testConfigure_withValidJsonKey() throws Exception { + void testConfigureWithValidJsonKey() throws Exception { final String eventConfigKeyName = "{\"key\":\"PLUGIN_CONFIG_email-notification-plugin\"}"; final UUID kbTenantId = UUID.randomUUID(); @@ -74,7 +74,7 @@ void testConfigure_withValidJsonKey() throws Exception { } @Test(groups = "fast") - void testConfigure_withPlainString() { + void testConfigureWithPlainString() { final String eventConfigKeyName = "PLUGIN_CONFIG_email-notification-plugin"; final UUID kbTenantId = UUID.randomUUID(); From 10b402aaf0513c54e2481ec51e04d5ca4037716d Mon Sep 17 00:00:00 2001 From: Vijay N Date: Tue, 14 Jan 2025 19:17:36 +0530 Subject: [PATCH 3/6] Updated ci.yml to install libaio1, required Ubuntu dependency for embedded DB. --- .github/workflows/ci.yml | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 660cce09..95d56d93 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,4 +7,12 @@ on: jobs: ci: - uses: killbill/gh-actions-shared/.github/workflows/ci.yml@main + runs-on: ${{ inputs.ff-os }} + steps: + - name: Set up Ubuntu package dependencies + run: | + sudo apt-get update + sudo apt-get install -y libaio1 + + - name: Run shared CI workflow + uses: killbill/gh-actions-shared/.github/workflows/ci.yml@main From 459a88e43c0ef67fd984fc80ceff581fa1a1e3ee Mon Sep 17 00:00:00 2001 From: Vijay N Date: Tue, 14 Jan 2025 19:29:38 +0530 Subject: [PATCH 4/6] Updated ci.yml to install libaio1, required Ubuntu dependency for embedded DB. --- .github/workflows/ci.yml | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 95d56d93..521f4701 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,13 +6,11 @@ on: workflow_dispatch: jobs: - ci: + install-dependencies: runs-on: ${{ inputs.ff-os }} steps: - - name: Set up Ubuntu package dependencies - run: | + - run: | sudo apt-get update sudo apt-get install -y libaio1 - - - name: Run shared CI workflow - uses: killbill/gh-actions-shared/.github/workflows/ci.yml@main + ci: + uses: killbill/gh-actions-shared/.github/workflows/ci.yml@main From 564ee1a17e1456434fb84384285c1d4f57646201 Mon Sep 17 00:00:00 2001 From: Vijay N Date: Tue, 14 Jan 2025 19:45:04 +0530 Subject: [PATCH 5/6] Rolled back ci.yml changes. --- .github/workflows/ci.yml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 521f4701..660cce09 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,11 +6,5 @@ on: workflow_dispatch: jobs: - install-dependencies: - runs-on: ${{ inputs.ff-os }} - steps: - - run: | - sudo apt-get update - sudo apt-get install -y libaio1 ci: uses: killbill/gh-actions-shared/.github/workflows/ci.yml@main From 84e357179680f2efecc39d7aae4e9af0e048f44c Mon Sep 17 00:00:00 2001 From: Vijay N Date: Thu, 16 Jan 2025 07:49:01 +0530 Subject: [PATCH 6/6] Rerun build as shared CI/CD workflow is fixed. --- .../plugin/api/notification/TestPluginConfigurationHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/org/killbill/billing/plugin/api/notification/TestPluginConfigurationHandler.java b/src/test/java/org/killbill/billing/plugin/api/notification/TestPluginConfigurationHandler.java index 2db01832..5160bcc8 100644 --- a/src/test/java/org/killbill/billing/plugin/api/notification/TestPluginConfigurationHandler.java +++ b/src/test/java/org/killbill/billing/plugin/api/notification/TestPluginConfigurationHandler.java @@ -82,4 +82,4 @@ void testConfigureWithPlainString() { verify(pluginConfigurationHandler, times(1)).configure(kbTenantId); } -} \ No newline at end of file +}