1+ /*
2+ * Copyright 2020-2025 Equinix, Inc
3+ * Copyright 2014-2025 The Billing Project, LLC
4+ *
5+ * The Billing Project licenses this file to you under the Apache License, version 2.0
6+ * (the "License"); you may not use this file except in compliance with the
7+ * License. You may obtain a copy of the License at:
8+ *
9+ * http://www.apache.org/licenses/LICENSE-2.0
10+ *
11+ * Unless required by applicable law or agreed to in writing, software
12+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14+ * License for the specific language governing permissions and limitations
15+ * under the License.
16+ */
17+
18+ package org .killbill .billing .plugin .api .notification ;
19+
20+ import java .util .UUID ;
21+
22+ import org .killbill .billing .osgi .libs .killbill .OSGIKillbillAPI ;
23+ import org .mockito .Mock ;
24+ import org .mockito .MockitoAnnotations ;
25+ import org .testng .annotations .BeforeMethod ;
26+ import org .testng .annotations .Test ;
27+
28+ import com .fasterxml .jackson .databind .JsonNode ;
29+ import com .fasterxml .jackson .databind .ObjectMapper ;
30+
31+ import static org .mockito .Mockito .mock ;
32+ import static org .mockito .Mockito .spy ;
33+ import static org .mockito .Mockito .times ;
34+ import static org .mockito .Mockito .verify ;
35+ import static org .mockito .Mockito .when ;
36+
37+ public class TestPluginConfigurationHandler {
38+
39+ private PluginConfigurationHandler pluginConfigurationHandler ;
40+
41+ @ Mock
42+ private OSGIKillbillAPI osgiKillbillAPI ;
43+
44+ @ Mock
45+ private ObjectMapper objectMapper ;
46+
47+ @ BeforeMethod (groups = "fast" )
48+ void setUp () {
49+ MockitoAnnotations .openMocks (this );
50+
51+ pluginConfigurationHandler = spy (new PluginConfigurationHandler ("email-notification-plugin" , osgiKillbillAPI ) {
52+ @ Override
53+ protected void configure (final UUID kbTenantId ) {
54+ // Empty implementation for testing
55+ }
56+ });
57+ }
58+
59+ @ Test (groups = "fast" )
60+ void testConfigure_withValidJsonKey () throws Exception {
61+ final String eventConfigKeyName = "{\" key\" :\" PLUGIN_CONFIG_email-notification-plugin\" }" ;
62+ final UUID kbTenantId = UUID .randomUUID ();
63+
64+ final JsonNode mockJsonNode = mock (JsonNode .class );
65+ when (mockJsonNode .has ("key" )).thenReturn (true );
66+ when (mockJsonNode .get ("key" )).thenReturn (mock (JsonNode .class ));
67+ when (mockJsonNode .get ("key" ).asText ()).thenReturn ("PLUGIN_CONFIG_email-notification-plugin" );
68+
69+ when (objectMapper .readTree (eventConfigKeyName )).thenReturn (mockJsonNode );
70+
71+ pluginConfigurationHandler .configure (eventConfigKeyName , kbTenantId );
72+
73+ verify (pluginConfigurationHandler , times (1 )).configure (kbTenantId );
74+ }
75+
76+ @ Test (groups = "fast" )
77+ void testConfigure_withPlainString () {
78+ final String eventConfigKeyName = "PLUGIN_CONFIG_email-notification-plugin" ;
79+ final UUID kbTenantId = UUID .randomUUID ();
80+
81+ pluginConfigurationHandler .configure (eventConfigKeyName , kbTenantId );
82+
83+ verify (pluginConfigurationHandler , times (1 )).configure (kbTenantId );
84+ }
85+ }
0 commit comments