From 2fc70f2e5fb7aa36fa8091a1829e0984e766cd56 Mon Sep 17 00:00:00 2001 From: emaclee Date: Thu, 20 Nov 2025 14:29:58 +0000 Subject: [PATCH] Add tests for coverage in subscription files - 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 --- .../subscription/cache/CmSubscriptionConfig.java | 49 ---------------------- .../ncmp/CmSubscriptionHandlerImplSpec.groovy | 12 +++++- .../ncmp/NcmpInEventConsumerSpec.groovy | 19 ++++++--- 3 files changed, 25 insertions(+), 55 deletions(-) delete mode 100644 cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/datajobs/subscription/cache/CmSubscriptionConfig.java 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 index 6294c62b62..0000000000 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/datajobs/subscription/cache/CmSubscriptionConfig.java +++ /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> cmNotificationSubscriptionCache() { - return getOrCreateHazelcastInstance(cmNotificationSubscriptionCacheMapConfig).getMap( - "cmNotificationSubscriptionCache"); - } -} diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/datajobs/subscription/ncmp/CmSubscriptionHandlerImplSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/datajobs/subscription/ncmp/CmSubscriptionHandlerImplSpec.groovy index b806258008..14dc9067e3 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/datajobs/subscription/ncmp/CmSubscriptionHandlerImplSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/datajobs/subscription/ncmp/CmSubscriptionHandlerImplSpec.groovy @@ -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' diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/datajobs/subscription/ncmp/NcmpInEventConsumerSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/datajobs/subscription/ncmp/NcmpInEventConsumerSpec.groovy index 0d8ff4fba4..324b77ef31 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/datajobs/subscription/ncmp/NcmpInEventConsumerSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/datajobs/subscription/ncmp/NcmpInEventConsumerSpec.groovy @@ -20,15 +20,12 @@ 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) } -- 2.16.6