Add tests for coverage in subscription files 59/142459/2
authoremaclee <lee.anjella.macabuhay@est.tech>
Thu, 20 Nov 2025 14:29:58 +0000 (14:29 +0000)
committeremaclee <lee.anjella.macabuhay@est.tech>
Thu, 20 Nov 2025 14:58:17 +0000 (14:58 +0000)
- added tests to cover lines in subscription related classes
- removed unused subscription cache (legacy)

Issue-ID: CPS-475
Change-Id: I9621e6f999399e70d20e1c289f8d991c649636ac
Signed-off-by: emaclee <lee.anjella.macabuhay@est.tech>
cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/datajobs/subscription/cache/CmSubscriptionConfig.java [deleted file]
cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/datajobs/subscription/ncmp/CmSubscriptionHandlerImplSpec.groovy
cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/datajobs/subscription/ncmp/NcmpInEventConsumerSpec.groovy

diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/datajobs/subscription/cache/CmSubscriptionConfig.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/datajobs/subscription/cache/CmSubscriptionConfig.java
deleted file mode 100644 (file)
index 6294c62..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- *  Copyright (C) 2024-2025 OpenInfra Foundation Europe. All rights reserved.
- *  ================================================================================
- *  Licensed 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.
- *
- *  SPDX-License-Identifier: Apache-2.0
- *  ============LICENSE_END=========================================================
- */
-
-package org.onap.cps.ncmp.impl.datajobs.subscription.cache;
-
-import com.hazelcast.config.MapConfig;
-import com.hazelcast.map.IMap;
-import java.util.Map;
-import org.onap.cps.impl.cache.HazelcastCacheConfig;
-import org.onap.cps.ncmp.impl.datajobs.subscription.models.DmiCmSubscriptionDetails;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-
-@Configuration
-public class CmSubscriptionConfig extends HazelcastCacheConfig {
-
-    private static final MapConfig cmNotificationSubscriptionCacheMapConfig =
-        createGenericMapConfig("cmNotificationSubscriptionCacheMapConfig");
-
-    /**
-     * Distributed instance of cm notification subscription information
-     * cache that contains subscription id as key
-     * and incoming event data processed per dmi plugin.
-     *
-     * @return configured map of subscription events.
-     */
-    @Bean
-    public IMap<String, Map<String, DmiCmSubscriptionDetails>> cmNotificationSubscriptionCache() {
-        return getOrCreateHazelcastInstance(cmNotificationSubscriptionCacheMapConfig).getMap(
-            "cmNotificationSubscriptionCache");
-    }
-}
index b806258..14dc906 100644 (file)
@@ -241,7 +241,17 @@ class CmSubscriptionHandlerImplSpec extends Specification {
             'data node selector for other dmi' | 'someOtherDmi' || 0
     }
 
-    def 'Log update when subscription status is REJECTED'() {
+    def 'Ignoring data node selector with no FDN prefix.'() {
+        given: 'the persistence service returns data node selector with no FDN prefix'
+            def myDataNodeSelectors = ['/noFdnPrefix'].asList()
+            mockCmSubscriptionPersistenceService.getInactiveDataNodeSelectors('someSubId') >> myDataNodeSelectors
+        when: 'method to update subscription status is called'
+            objectUnderTest.updateCmSubscriptionStatus('someSubId', 'someDmiServiceName', ACCEPTED)
+        then: 'update status is not delegated to persistence service'
+            0 * mockCmSubscriptionPersistenceService.updateCmSubscriptionStatus('/noFdnPrefix', ACCEPTED)
+    }
+
+    def 'Update subscription status to REJECTED'() {
         given: 'dmi service name and subscription id'
             def myDmi = 'myDmi'
             def mySubscriptionId = 'mySubscriptionId'
index 0d8ff4f..324b77e 100644 (file)
 
 package org.onap.cps.ncmp.impl.datajobs.subscription.ncmp
 
-import ch.qos.logback.classic.Level
-import ch.qos.logback.classic.Logger
-import ch.qos.logback.classic.spi.ILoggingEvent
-import ch.qos.logback.core.read.ListAppender
 import com.fasterxml.jackson.databind.ObjectMapper
+import org.onap.cps.ncmp.impl.datajobs.subscription.client_to_ncmp.DataJob
 import org.onap.cps.ncmp.impl.datajobs.subscription.client_to_ncmp.DataJobSubscriptionOperationInEvent
+import org.onap.cps.ncmp.impl.datajobs.subscription.client_to_ncmp.Event
 import org.onap.cps.ncmp.impl.utils.JexParser
 import org.onap.cps.ncmp.utils.TestUtils
-import org.slf4j.LoggerFactory
 import spock.lang.Specification
 
 class NcmpInEventConsumerSpec extends Specification {
@@ -70,6 +67,18 @@ class NcmpInEventConsumerSpec extends Specification {
             1 * mockCmSubscriptionHandler.deleteSubscription("myDataJobId")
     }
 
+    def 'Consuming subscription request with unknown event type.'() {
+        given: 'a subscription event with invalid event type'
+            def invalidEvent = new DataJobSubscriptionOperationInEvent(event:new Event(dataJob: new DataJob(id:'someId')), eventType: 'invalidEventType')
+        when: 'the event is consumed'
+            objectUnderTest.consumeSubscriptionEvent(invalidEvent)
+        then: 'no error thrown'
+            noExceptionThrown()
+        and: 'request was not delegated to be handled as CREATE or DELETE'
+            0 * mockCmSubscriptionHandler.deleteSubscription(_)
+            0 * mockCmSubscriptionHandler.createSubscription(_)
+    }
+
     def getDataNodeSelectorsAsXpaths(event) {
         return JexParser.toXpaths(event.event.dataJob.productionJobDefinition.targetSelector.dataNodeSelector)
     }