diff options
author | mpriyank <priyank.maheshwari@est.tech> | 2024-07-05 12:33:06 +0100 |
---|---|---|
committer | mpriyank <priyank.maheshwari@est.tech> | 2024-07-05 12:33:11 +0100 |
commit | f3bfc359a12501b6f4a734d2566d115dc43136b0 (patch) | |
tree | 55b610550136cabba353abcfcb3431252bccfa6d /cps-ncmp-service/src/test | |
parent | c1c26ec8a97ce7de7d976665ae0c147fbf9ad80d (diff) |
Remove Mappers and Events Facade
- Removing Mappers and Events Facade and introducing the normal classes
that this facade was wrapping
- Corresponding changes in the testware
Issue-ID: CPS-2298
Change-Id: I380d73ff3a9b3bf79633cd91580d6a4dee00a662
Signed-off-by: mpriyank <priyank.maheshwari@est.tech>
Diffstat (limited to 'cps-ncmp-service/src/test')
5 files changed, 32 insertions, 156 deletions
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/cmnotificationsubscription/EventsFacadeSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/cmnotificationsubscription/EventsFacadeSpec.groovy deleted file mode 100644 index bc2df10ce3..0000000000 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/cmnotificationsubscription/EventsFacadeSpec.groovy +++ /dev/null @@ -1,58 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (c) 2024 Nordix Foundation. - * ================================================================================ - * 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.cmnotificationsubscription - -import org.onap.cps.ncmp.impl.cmnotificationsubscription.dmi.DmiInEventProducer -import org.onap.cps.ncmp.impl.cmnotificationsubscription.ncmp.NcmpOutEventProducer -import org.onap.cps.ncmp.impl.cmnotificationsubscription_1_0_0.ncmp_to_client.NcmpOutEvent -import org.onap.cps.ncmp.impl.cmnotificationsubscription_1_0_0.ncmp_to_dmi.DmiInEvent -import spock.lang.Specification - -class EventsFacadeSpec extends Specification { - - def mockCmNotificationSubscriptionNcmpOutEventProducer = Mock(NcmpOutEventProducer) - def mockCmNotificationSubscriptionDmiInEventProducer = Mock(DmiInEventProducer) - - def objectUnderTest = new EventsFacade(mockCmNotificationSubscriptionNcmpOutEventProducer, - mockCmNotificationSubscriptionDmiInEventProducer) - - def 'Publish cm notification subscription ncmp out event'() { - given: 'an ncmp out event' - def ncmpOutEvent = new NcmpOutEvent() - when: 'the method to publish cm notification subscription ncmp out event is called' - objectUnderTest.publishNcmpOutEvent("some-id", - "some-event", ncmpOutEvent, true) - then: 'the parameters is delegated to the correct method once' - 1 * mockCmNotificationSubscriptionNcmpOutEventProducer.publishNcmpOutEvent( - "some-id", "some-event", ncmpOutEvent, true) - } - - def 'Publish cm notification subscription dmi in event'() { - given: 'a dmi in event' - def dmiInEvent = new DmiInEvent() - when: 'the method to publish cm notification subscription ncmp out event is called' - objectUnderTest.publishDmiInEvent("some-id", - "some-dmi", "some-event", dmiInEvent) - then: 'the parameters is delegated to the correct method once' - 1 * mockCmNotificationSubscriptionDmiInEventProducer.publishDmiInEvent("some-id", - "some-dmi", "some-event", dmiInEvent) - } -}
\ No newline at end of file diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/cmnotificationsubscription/MappersFacadeSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/cmnotificationsubscription/MappersFacadeSpec.groovy deleted file mode 100644 index 79b9ad578f..0000000000 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/cmnotificationsubscription/MappersFacadeSpec.groovy +++ /dev/null @@ -1,65 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2024 Nordix Foundation - * ================================================================================ - * 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.cmnotificationsubscription - - -import org.onap.cps.ncmp.impl.cmnotificationsubscription.dmi.DmiInEventMapper -import org.onap.cps.ncmp.impl.cmnotificationsubscription.ncmp.NcmpOutEventMapper -import spock.lang.Specification - -class MappersFacadeSpec extends Specification{ - - def mockCmNotificationDmiInEventMapper = Mock(DmiInEventMapper) - def mockCmNotificationNcmpOutEventMapper = Mock(NcmpOutEventMapper) - - def objectUnderTest = new MappersFacade(mockCmNotificationDmiInEventMapper, - mockCmNotificationNcmpOutEventMapper) - - def 'Get cm notification subscription DMI in event'() { - given: 'a list of predicates' - def testListOfPredicates = [] - when: 'method to create a cm notification subscription dmi in event is called with predicates' - objectUnderTest.toDmiInEvent(testListOfPredicates) - then: 'the parameters is delegated to the correct dmi in event mapper method' - 1 * mockCmNotificationDmiInEventMapper.toDmiInEvent(testListOfPredicates) - } - - def 'Get cm notification subscription ncmp out event'() { - given: 'a subscription details map' - def testSubscriptionDetailsMap = [:] - when: 'method to create cm notification subscription ncmp out event is called with the following parameters' - objectUnderTest.toNcmpOutEvent("test-id", testSubscriptionDetailsMap) - then: 'the parameters is delegated to the correct ncmp out event mapper method' - 1 * mockCmNotificationNcmpOutEventMapper.toNcmpOutEvent("test-id", - testSubscriptionDetailsMap) - } - - def 'Get cm notification subscription ncmp out event for a rejected request'() { - given: 'a list of target filters' - def testRejectedTargetFilters = [] - when: 'method to create cm notification subscription ncmp out event is called with the following parameters' - objectUnderTest.toNcmpOutEventForRejectedRequest( - "test-id", testRejectedTargetFilters) - then: 'the parameters is delegated to the correct ncmp out event mapper method' - 1 * mockCmNotificationNcmpOutEventMapper.toNcmpOutEventForRejectedRequest( - "test-id", testRejectedTargetFilters) - } -} diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/cmnotificationsubscription/dmi/DmiOutEventConsumerSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/cmnotificationsubscription/dmi/DmiOutEventConsumerSpec.groovy index 44e24042a8..06003fdcb4 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/cmnotificationsubscription/dmi/DmiOutEventConsumerSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/cmnotificationsubscription/dmi/DmiOutEventConsumerSpec.groovy @@ -29,9 +29,9 @@ import io.cloudevents.CloudEvent import io.cloudevents.core.builder.CloudEventBuilder import org.apache.kafka.clients.consumer.ConsumerRecord import org.onap.cps.ncmp.api.kafka.MessagingBaseSpec -import org.onap.cps.ncmp.impl.cmnotificationsubscription.EventsFacade -import org.onap.cps.ncmp.impl.cmnotificationsubscription.MappersFacade import org.onap.cps.ncmp.impl.cmnotificationsubscription.cache.DmiCacheHandler +import org.onap.cps.ncmp.impl.cmnotificationsubscription.ncmp.NcmpOutEventMapper +import org.onap.cps.ncmp.impl.cmnotificationsubscription.ncmp.NcmpOutEventProducer import org.onap.cps.ncmp.impl.cmnotificationsubscription_1_0_0.dmi_to_ncmp.Data import org.onap.cps.ncmp.impl.cmnotificationsubscription_1_0_0.dmi_to_ncmp.DmiOutEvent import org.onap.cps.ncmp.utils.TestUtils @@ -53,10 +53,10 @@ class DmiOutEventConsumerSpec extends MessagingBaseSpec { ObjectMapper objectMapper def mockDmiCacheHandler = Mock(DmiCacheHandler) - def mockEventsHandler = Mock(EventsFacade) - def mockMappersHandler = Mock(MappersFacade) + def mockNcmpOutEventProducer = Mock(NcmpOutEventProducer) + def mockNcmpOutEventMapper = Mock(NcmpOutEventMapper) - def objectUnderTest = new DmiOutEventConsumer(mockDmiCacheHandler, mockEventsHandler, mockMappersHandler) + def objectUnderTest = new DmiOutEventConsumer(mockDmiCacheHandler, mockNcmpOutEventProducer, mockNcmpOutEventMapper) def logger = Spy(ListAppender<ILoggingEvent>) void setup() { @@ -107,9 +107,9 @@ class DmiOutEventConsumerSpec extends MessagingBaseSpec { and: 'correct number of calls to persist cache' expectedPersistenceCalls * mockDmiCacheHandler.persistIntoDatabasePerDmi('sub-1','test-dmi-plugin-name') and: 'correct number of calls to map the ncmp out event' - 1 * mockMappersHandler.toNcmpOutEvent('sub-1', _) + 1 * mockNcmpOutEventMapper.toNcmpOutEvent('sub-1', _) and: 'correct number of calls to publish the ncmp out event to client' - 1 * mockEventsHandler.publishNcmpOutEvent('sub-1', 'subscriptionCreateResponse', _, false) + 1 * mockNcmpOutEventProducer.publishNcmpOutEvent('sub-1', 'subscriptionCreateResponse', _, false) where: 'the following parameters are used' scenario | subscriptionStatus | statusCode || expectedCacheCalls | expectedPersistenceCalls 'Accepted Status' | ACCEPTED | '1' || 1 | 1 diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/cmnotificationsubscription/ncmp/CmSubscriptionHandlerImplSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/cmnotificationsubscription/ncmp/CmSubscriptionHandlerImplSpec.groovy index caefdeea1d..3f6556d47e 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/cmnotificationsubscription/ncmp/CmSubscriptionHandlerImplSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/cmnotificationsubscription/ncmp/CmSubscriptionHandlerImplSpec.groovy @@ -21,9 +21,9 @@ package org.onap.cps.ncmp.impl.cmnotificationsubscription.ncmp import com.fasterxml.jackson.databind.ObjectMapper -import org.onap.cps.ncmp.impl.cmnotificationsubscription.EventsFacade -import org.onap.cps.ncmp.impl.cmnotificationsubscription.MappersFacade import org.onap.cps.ncmp.impl.cmnotificationsubscription.cache.DmiCacheHandler +import org.onap.cps.ncmp.impl.cmnotificationsubscription.dmi.DmiInEventMapper +import org.onap.cps.ncmp.impl.cmnotificationsubscription.dmi.DmiInEventProducer import org.onap.cps.ncmp.impl.cmnotificationsubscription.models.DmiCmSubscriptionDetails import org.onap.cps.ncmp.impl.cmnotificationsubscription.models.DmiCmSubscriptionPredicate import org.onap.cps.ncmp.impl.cmnotificationsubscription.utils.CmSubscriptionPersistenceService @@ -41,15 +41,17 @@ import static org.onap.cps.ncmp.impl.cmnotificationsubscription.models.CmSubscri class CmSubscriptionHandlerImplSpec extends Specification { def jsonObjectMapper = new JsonObjectMapper(new ObjectMapper()) - def mockCmSubscriptionPersistenceService = Mock(CmSubscriptionPersistenceService); - def mockCmSubscriptionComparator = Mock(CmSubscriptionComparator); - def mockMappersFacade = Mock(MappersFacade); - def mockEventsFacade = Mock(EventsFacade); - def mockDmiCacheHandler = Mock(DmiCacheHandler); + def mockCmSubscriptionPersistenceService = Mock(CmSubscriptionPersistenceService) + def mockCmSubscriptionComparator = Mock(CmSubscriptionComparator) + def mockNcmpOutEventMapper = Mock(NcmpOutEventMapper) + def mockDmiInEventMapper = Mock(DmiInEventMapper) + def mockNcmpOutEventProducer = Mock(NcmpOutEventProducer) + def mockDmiInEventProducer = Mock(DmiInEventProducer) + def mockDmiCacheHandler = Mock(DmiCacheHandler) def objectUnderTest = new CmSubscriptionHandlerImpl(mockCmSubscriptionPersistenceService, - mockCmSubscriptionComparator, mockMappersFacade, - mockEventsFacade, mockDmiCacheHandler) + mockCmSubscriptionComparator, mockNcmpOutEventMapper, mockDmiInEventMapper, + mockNcmpOutEventProducer, mockDmiInEventProducer, mockDmiCacheHandler) def testDmiSubscriptionsPerDmi = ["dmi-1": new DmiCmSubscriptionDetails([], PENDING)] @@ -68,17 +70,16 @@ class CmSubscriptionHandlerImplSpec extends Specification { 1 * mockCmSubscriptionComparator.getNewDmiSubscriptionPredicates(_) >> testListOfDeltaPredicates and: 'the DMI in event mapper returns cm notification subscription event' def testDmiInEvent = new DmiInEvent() - 1 * mockMappersFacade - .toDmiInEvent(testListOfDeltaPredicates) >> testDmiInEvent + 1 * mockDmiInEventMapper.toDmiInEvent(testListOfDeltaPredicates) >> testDmiInEvent when: 'the valid and unique event is consumed' objectUnderTest.processSubscriptionCreateRequest(subscriptionId, predicates) then: 'the subscription cache handler is called once' 1 * mockDmiCacheHandler.add('test-id', _) and: 'the events handler method to publish DMI event is called correct number of times with the correct parameters' - testDmiSubscriptionsPerDmi.size() * mockEventsFacade.publishDmiInEvent( + testDmiSubscriptionsPerDmi.size() * mockDmiInEventProducer.publishDmiInEvent( "test-id", "dmi-1", "subscriptionCreateRequest", testDmiInEvent) and: 'we schedule to send the response after configured time from the cache' - 1 * mockEventsFacade.publishNcmpOutEvent('test-id', 'subscriptionCreateResponse', null, true) + 1 * mockNcmpOutEventProducer.publishNcmpOutEvent('test-id', 'subscriptionCreateResponse', null, true) } def 'Consume valid and Overlapping Cm Notification Subscription NcmpIn Event'() { @@ -98,7 +99,7 @@ class CmSubscriptionHandlerImplSpec extends Specification { and: 'the subscription details are updated in the cache' 1 * mockDmiCacheHandler.updateDmiSubscriptionStatusPerDmi('test-id', _, ACCEPTED) and: 'we schedule to send the response after configured time from the cache' - 1 * mockEventsFacade.publishNcmpOutEvent('test-id', 'subscriptionCreateResponse', null, true) + 1 * mockNcmpOutEventProducer.publishNcmpOutEvent('test-id', 'subscriptionCreateResponse', null, true) } def 'Consume valid and but non-unique CmNotificationSubscription create message'() { @@ -111,14 +112,14 @@ class CmSubscriptionHandlerImplSpec extends Specification { def predicates = testEventConsumed.getData().getPredicates() and: 'the NCMP out in event mapper returns an event for rejected request' def testNcmpOutEvent = new NcmpOutEvent() - 1 * mockMappersFacade.toNcmpOutEventForRejectedRequest( + 1 * mockNcmpOutEventMapper.toNcmpOutEventForRejectedRequest( "test-id", _) >> testNcmpOutEvent when: 'the valid but non-unique event is consumed' objectUnderTest.processSubscriptionCreateRequest(subscriptionId, predicates) then: 'the events handler method to publish DMI event is never called' - 0 * mockEventsFacade.publishDmiInEvent(_, _, _, _) + 0 * mockDmiInEventProducer.publishDmiInEvent(_, _, _, _) and: 'the events handler method to publish NCMP out event is called once' - 1 * mockEventsFacade.publishNcmpOutEvent('test-id', 'subscriptionCreateResponse', testNcmpOutEvent, false) + 1 * mockNcmpOutEventProducer.publishNcmpOutEvent('test-id', 'subscriptionCreateResponse', testNcmpOutEvent, false) } def 'Consume valid CmNotificationSubscriptionNcmpInEvent delete message'() { @@ -135,11 +136,11 @@ class CmSubscriptionHandlerImplSpec extends Specification { then: 'the subscription cache handler is called once' 1 * mockDmiCacheHandler.add('test-id', predicates) and: 'the mapper handler to get DMI in event is called once' - 1 * mockMappersFacade.toDmiInEvent(_) + 1 * mockDmiInEventMapper.toDmiInEvent(_) and: 'the events handler method to publish DMI event is called correct number of times with the correct parameters' - testDmiSubscriptionsPerDmi.size() * mockEventsFacade.publishDmiInEvent( + testDmiSubscriptionsPerDmi.size() * mockDmiInEventProducer.publishDmiInEvent( 'test-id', 'dmi-1', 'subscriptionDeleteRequest', _) and: 'we schedule to send the response after configured time from the cache' - 1 * mockEventsFacade.publishNcmpOutEvent('test-id', 'subscriptionDeleteResponse', null, true) + 1 * mockNcmpOutEventProducer.publishNcmpOutEvent('test-id', 'subscriptionDeleteResponse', null, true) } } diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/cmnotificationsubscription/ncmp/NcmpOutEventProducerSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/cmnotificationsubscription/ncmp/NcmpOutEventProducerSpec.groovy index f96f3df786..e03682d8c9 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/cmnotificationsubscription/ncmp/NcmpOutEventProducerSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/cmnotificationsubscription/ncmp/NcmpOutEventProducerSpec.groovy @@ -3,7 +3,6 @@ package org.onap.cps.ncmp.impl.cmnotificationsubscription.ncmp import com.fasterxml.jackson.databind.ObjectMapper import io.cloudevents.CloudEvent import org.onap.cps.events.EventsPublisher -import org.onap.cps.ncmp.impl.cmnotificationsubscription.MappersFacade import org.onap.cps.ncmp.impl.cmnotificationsubscription.cache.DmiCacheHandler import org.onap.cps.ncmp.impl.cmnotificationsubscription_1_0_0.ncmp_to_client.Data import org.onap.cps.ncmp.impl.cmnotificationsubscription_1_0_0.ncmp_to_client.NcmpOutEvent @@ -15,11 +14,10 @@ class NcmpOutEventProducerSpec extends Specification { def mockEventsPublisher = Mock(EventsPublisher) def jsonObjectMapper = new JsonObjectMapper(new ObjectMapper()) - def mockCmNotificationSubscriptionMappersHandler = Mock(MappersFacade) - def mockDmiCmNotificationSubscriptionCacheHandler = Mock(DmiCacheHandler) + def mockNcmpOutEventMapper = Mock(NcmpOutEventMapper) + def mockDmiCacheHandler = Mock(DmiCacheHandler) - def objectUnderTest = new NcmpOutEventProducer(mockEventsPublisher, jsonObjectMapper, - mockCmNotificationSubscriptionMappersHandler, mockDmiCmNotificationSubscriptionCacheHandler) + def objectUnderTest = new NcmpOutEventProducer(mockEventsPublisher, jsonObjectMapper, mockNcmpOutEventMapper, mockDmiCacheHandler) def 'Create and #scenario Cm Notification Subscription NCMP out event'() { given: 'a cm subscription response for the client' @@ -82,7 +80,7 @@ class NcmpOutEventProducerSpec extends Specification { } } then: 'the cache handler is called once to remove accepted and rejected entries in cache' - 1 * mockDmiCmNotificationSubscriptionCacheHandler.removeAcceptedAndRejectedDmiSubscriptionEntries(subscriptionId) + 1 * mockDmiCacheHandler.removeAcceptedAndRejectedDmiSubscriptionEntries(subscriptionId) } |