+++ /dev/null
-/*
- * ============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 lombok.RequiredArgsConstructor;
-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 org.springframework.stereotype.Component;
-
-@Component
-@RequiredArgsConstructor
-public class EventsFacade {
- private final NcmpOutEventProducer ncmpOutEventProducer;
- private final DmiInEventProducer dmiInEventProducer;
-
- /**
- * Publish the event to the client who requested the subscription with key as subscription id and event is Cloud
- * Event compliant.
- *
- * @param subscriptionId Cm Subscription id
- * @param eventType Type of event
- * @param ncmpOutEvent Cm Notification Subscription Event for the
- * client
- * @param isScheduledEvent Determines if the event is to be scheduled
- * or published now
- */
- public void publishNcmpOutEvent(final String subscriptionId, final String eventType,
- final NcmpOutEvent ncmpOutEvent, final boolean isScheduledEvent) {
- ncmpOutEventProducer.publishNcmpOutEvent(subscriptionId, eventType, ncmpOutEvent, isScheduledEvent);
- }
-
- /**
- * Publish the event to the provided dmi plugin with key as subscription id and the event is in Cloud Event format.
- *
- * @param subscriptionId Cm Subscription id
- * @param dmiPluginName Dmi Plugin Name
- * @param eventType Type of event
- * @param dmiInEvent Cm Notification Subscription event for Dmi
- */
- public void publishDmiInEvent(final String subscriptionId, final String dmiPluginName,
- final String eventType, final DmiInEvent dmiInEvent) {
- dmiInEventProducer.publishDmiInEvent(subscriptionId,
- dmiPluginName, eventType, dmiInEvent);
- }
-}
+++ /dev/null
-/*
- * ============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 java.util.List;
-import java.util.Map;
-import lombok.RequiredArgsConstructor;
-import org.onap.cps.ncmp.impl.cmnotificationsubscription.dmi.DmiInEventMapper;
-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.ncmp.NcmpOutEventMapper;
-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 org.springframework.stereotype.Component;
-
-@Component
-@RequiredArgsConstructor
-public class MappersFacade {
-
- private final DmiInEventMapper dmiInEventMapper;
- private final NcmpOutEventMapper ncmpOutEventMapper;
-
- /**
- * Mapper to form a request for the DMI Plugin for the Cm Notification Subscription.
- *
- * @param dmiCmSubscriptionPredicates Collection of Cm Notification Subscription predicates
- * @return cm notification subscription dmi in event
- */
- public DmiInEvent toDmiInEvent(
- final List<DmiCmSubscriptionPredicate> dmiCmSubscriptionPredicates) {
- return dmiInEventMapper.toDmiInEvent(dmiCmSubscriptionPredicates);
- }
-
- /**
- * Mapper to form a response for the client for the Cm Notification Subscription.
- *
- * @param subscriptionId Cm Notification Subscription id
- * @param dmiSubscriptionsPerDmi contains CmNotificationSubscriptionDetails per dmi plugin
- * @return CmNotificationSubscriptionNcmpOutEvent to sent back to the client
- */
- public NcmpOutEvent toNcmpOutEvent(final String subscriptionId,
- final Map<String, DmiCmSubscriptionDetails> dmiSubscriptionsPerDmi) {
- return ncmpOutEventMapper.toNcmpOutEvent(subscriptionId,
- dmiSubscriptionsPerDmi);
- }
-
- /**
- * Mapper to form a rejected response for the client for the Cm Notification Subscription Request.
- *
- * @param subscriptionId subscription id
- * @param rejectedTargetFilters list of rejected target filters for the subscription request
- * @return to sent back to the client
- */
- public NcmpOutEvent toNcmpOutEventForRejectedRequest(
- final String subscriptionId, final List<String> rejectedTargetFilters) {
- return ncmpOutEventMapper.toNcmpOutEventForRejectedRequest(
- subscriptionId, rejectedTargetFilters);
- }
-}
import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.onap.cps.ncmp.api.NcmpResponseStatus;
-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.models.CmSubscriptionStatus;
import org.onap.cps.ncmp.impl.cmnotificationsubscription.models.DmiCmSubscriptionDetails;
+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.impl.cmnotificationsubscription_1_0_0.ncmp_to_client.NcmpOutEvent;
public class DmiOutEventConsumer {
private final DmiCacheHandler dmiCacheHandler;
- private final EventsFacade eventsFacade;
- private final MappersFacade mappersFacade;
+ private final NcmpOutEventProducer ncmpOutEventProducer;
+ private final NcmpOutEventMapper ncmpOutEventMapper;
private static final String CM_SUBSCRIPTION_CORRELATION_ID_SEPARATOR = "#";
}
private void handleEventsStatusPerDmi(final String subscriptionId, final String eventType) {
- final Map<String, DmiCmSubscriptionDetails> dmiSubscriptionsPerDmi =
- dmiCacheHandler.get(subscriptionId);
- final NcmpOutEvent ncmpOutEvent = mappersFacade.toNcmpOutEvent(subscriptionId,
- dmiSubscriptionsPerDmi);
- eventsFacade.publishNcmpOutEvent(subscriptionId, eventType,
- ncmpOutEvent, false);
+ final Map<String, DmiCmSubscriptionDetails> dmiSubscriptionsPerDmi = dmiCacheHandler.get(subscriptionId);
+ final NcmpOutEvent ncmpOutEvent = ncmpOutEventMapper.toNcmpOutEvent(subscriptionId, dmiSubscriptionsPerDmi);
+ ncmpOutEventProducer.publishNcmpOutEvent(subscriptionId, eventType, ncmpOutEvent, false);
}
private boolean checkStatusCodeAndMessage(final NcmpResponseStatus ncmpResponseStatus,
import java.util.Set;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
-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.CmSubscriptionStatus;
import org.onap.cps.ncmp.impl.cmnotificationsubscription.models.DmiCmSubscriptionDetails;
import org.onap.cps.ncmp.impl.cmnotificationsubscription.models.DmiCmSubscriptionPredicate;
private final CmSubscriptionPersistenceService cmSubscriptionPersistenceService;
private final CmSubscriptionComparator cmSubscriptionComparator;
- private final MappersFacade mappersFacade;
- private final EventsFacade eventsFacade;
+ private final NcmpOutEventMapper ncmpOutEventMapper;
+ private final DmiInEventMapper dmiInEventMapper;
+ private final NcmpOutEventProducer ncmpOutEventProducer;
+ private final DmiInEventProducer dmiInEventProducer;
private final DmiCacheHandler dmiCacheHandler;
@Override
}
private void scheduleNcmpOutEventResponse(final String subscriptionId, final String eventType) {
- eventsFacade.publishNcmpOutEvent(subscriptionId, eventType, null, true);
+ ncmpOutEventProducer.publishNcmpOutEvent(subscriptionId, eventType, null, true);
}
private void rejectAndPublishCreateRequest(final String subscriptionId, final List<Predicate> predicates) {
final Set<String> subscriptionTargetFilters =
predicates.stream().flatMap(predicate -> predicate.getTargetFilter().stream())
.collect(Collectors.toSet());
- final NcmpOutEvent ncmpOutEvent = mappersFacade.toNcmpOutEventForRejectedRequest(subscriptionId,
+ final NcmpOutEvent ncmpOutEvent = ncmpOutEventMapper.toNcmpOutEventForRejectedRequest(subscriptionId,
new ArrayList<>(subscriptionTargetFilters));
- eventsFacade.publishNcmpOutEvent(subscriptionId, "subscriptionCreateResponse", ncmpOutEvent, false);
+ ncmpOutEventProducer.publishNcmpOutEvent(subscriptionId, "subscriptionCreateResponse", ncmpOutEvent, false);
}
private void handleNewCmSubscription(final String subscriptionId) {
private void publishDmiInEventPerDmi(final String subscriptionId, final String dmiPluginName,
final List<DmiCmSubscriptionPredicate> dmiCmSubscriptionPredicates) {
- final DmiInEvent dmiInEvent = mappersFacade.toDmiInEvent(dmiCmSubscriptionPredicates);
- eventsFacade.publishDmiInEvent(subscriptionId, dmiPluginName,
+ final DmiInEvent dmiInEvent = dmiInEventMapper.toDmiInEvent(dmiCmSubscriptionPredicates);
+ dmiInEventProducer.publishDmiInEvent(subscriptionId, dmiPluginName,
"subscriptionCreateRequest", dmiInEvent);
}
final Map<String, DmiCmSubscriptionDetails> dmiSubscriptionsPerDmi =
dmiCacheHandler.get(subscriptionId);
dmiSubscriptionsPerDmi.forEach((dmiPluginName, dmiSubscriptionDetails) -> {
- final DmiInEvent dmiInEvent = mappersFacade.toDmiInEvent(
+ final DmiInEvent dmiInEvent = dmiInEventMapper.toDmiInEvent(
dmiSubscriptionDetails.getDmiCmSubscriptionPredicates());
- eventsFacade.publishDmiInEvent(subscriptionId, dmiPluginName,
+ dmiInEventProducer.publishDmiInEvent(subscriptionId, dmiPluginName,
"subscriptionDeleteRequest", dmiInEvent);
});
}
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
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.NcmpOutEvent;
import org.onap.cps.utils.JsonObjectMapper;
private final EventsPublisher<CloudEvent> eventsPublisher;
private final JsonObjectMapper jsonObjectMapper;
- private final MappersFacade mappersFacade;
+ private final NcmpOutEventMapper ncmpOutEventMapper;
private final DmiCacheHandler dmiCacheHandler;
private final ScheduledExecutorService scheduledExecutorService = Executors.newSingleThreadScheduledExecutor();
private static final Map<String, ScheduledFuture<?>> scheduledTasksPerSubscriptionId = new ConcurrentHashMap<>();
private ScheduledFuture<?> scheduleAndPublishNcmpOutEvent(final String subscriptionId, final String eventType) {
final NcmpOutEventPublishingTask ncmpOutEventPublishingTask =
new NcmpOutEventPublishingTask(ncmpOutEventTopic, subscriptionId, eventType, eventsPublisher,
- jsonObjectMapper, mappersFacade, dmiCacheHandler);
+ jsonObjectMapper, ncmpOutEventMapper, dmiCacheHandler);
return scheduledExecutorService.schedule(ncmpOutEventPublishingTask, dmiOutEventTimeoutInMs,
TimeUnit.MILLISECONDS);
}
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
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.models.DmiCmSubscriptionDetails;
import org.onap.cps.ncmp.impl.cmnotificationsubscription_1_0_0.ncmp_to_client.NcmpOutEvent;
private final String eventType;
private final EventsPublisher<CloudEvent> eventsPublisher;
private final JsonObjectMapper jsonObjectMapper;
- private final MappersFacade mappersFacade;
+ private final NcmpOutEventMapper ncmpOutEventMapper;
private final DmiCacheHandler dmiCacheHandler;
/**
public void run() {
final Map<String, DmiCmSubscriptionDetails> dmiSubscriptionsPerDmi =
dmiCacheHandler.get(subscriptionId);
- final NcmpOutEvent ncmpOutEvent = mappersFacade.toNcmpOutEvent(subscriptionId,
+ final NcmpOutEvent ncmpOutEvent = ncmpOutEventMapper.toNcmpOutEvent(subscriptionId,
dmiSubscriptionsPerDmi);
eventsPublisher.publishCloudEvent(topicName, subscriptionId,
buildAndGetNcmpOutEventAsCloudEvent(jsonObjectMapper, subscriptionId, eventType,
+++ /dev/null
-/*
- * ============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
+++ /dev/null
-/*
- * ============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)
- }
-}
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
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() {
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
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
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)]
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'() {
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'() {
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'() {
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)
}
}
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
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'
}
}
then: 'the cache handler is called once to remove accepted and rejected entries in cache'
- 1 * mockDmiCmNotificationSubscriptionCacheHandler.removeAcceptedAndRejectedDmiSubscriptionEntries(subscriptionId)
+ 1 * mockDmiCacheHandler.removeAcceptedAndRejectedDmiSubscriptionEntries(subscriptionId)
}