summaryrefslogtreecommitdiffstats
path: root/cps-ncmp-service/src
diff options
context:
space:
mode:
authorPriyank Maheshwari <priyank.maheshwari@est.tech>2023-04-03 15:22:28 +0000
committerGerrit Code Review <gerrit@onap.org>2023-04-03 15:22:28 +0000
commit0497e296afb24523d94ce78e9202a4e28a41d7fc (patch)
treedc361526dab3febc17ac0089904528f859ffdebc /cps-ncmp-service/src
parent120686f7b5ff0ff873335905593b1e58be0133da (diff)
parent5201f5172ae24eee7d1b743efa18bf56e5319f71 (diff)
Merge "Persist SubscriptionEvent"
Diffstat (limited to 'cps-ncmp-service/src')
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/event/avc/SubscriptionEventConsumer.java12
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/event/avc/SubscriptionEventMapper.java52
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/notifications/avc/AvcEventMapper.java7
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/subscriptions/SubscriptionPersistence.java34
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/subscriptions/SubscriptionPersistenceImpl.java55
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/subscriptions/SubscriptionStatus.java27
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/yangmodels/YangModelSubscriptionEvent.java91
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/InventoryPersistenceImpl.java4
-rw-r--r--cps-ncmp-service/src/main/resources/model/subscription.yang4
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/event/avc/SubscriptionEventConsumerSpec.groovy36
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/notifications/avc/SubscriptionEventMapperSpec.groovy63
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/subscriptions/SubscriptionPersistenceSpec.groovy65
12 files changed, 430 insertions, 20 deletions
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/event/avc/SubscriptionEventConsumer.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/event/avc/SubscriptionEventConsumer.java
index d08baac5d4..1361d98ffc 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/event/avc/SubscriptionEventConsumer.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/event/avc/SubscriptionEventConsumer.java
@@ -22,6 +22,8 @@ package org.onap.cps.ncmp.api.impl.event.avc;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
+import org.onap.cps.ncmp.api.impl.subscriptions.SubscriptionPersistence;
+import org.onap.cps.ncmp.api.impl.yangmodels.YangModelSubscriptionEvent;
import org.onap.cps.ncmp.event.model.InnerSubscriptionEvent;
import org.onap.cps.ncmp.event.model.SubscriptionEvent;
import org.onap.cps.spi.exceptions.OperationNotYetSupportedException;
@@ -36,6 +38,8 @@ import org.springframework.stereotype.Component;
public class SubscriptionEventConsumer {
private final SubscriptionEventForwarder subscriptionEventForwarder;
+ private final SubscriptionEventMapper subscriptionEventMapper;
+ private final SubscriptionPersistence subscriptionPersistence;
@Value("${notification.enabled:true}")
private boolean notificationFeatureEnabled;
@@ -56,6 +60,7 @@ public class SubscriptionEventConsumer {
}
if ("CM".equals(event.getDataType().getDataCategory())) {
log.debug("Consuming event {} ...", subscriptionEvent);
+ persistSubscriptionEvent(subscriptionEvent);
if ("CREATE".equals(subscriptionEvent.getEventType().value())) {
log.info("Subscription for ClientID {} with name {} ...",
event.getSubscription().getClientID(),
@@ -68,4 +73,11 @@ public class SubscriptionEventConsumer {
log.trace("Non-CM subscription event ignored");
}
}
+
+ private void persistSubscriptionEvent(final SubscriptionEvent subscriptionEvent) {
+ final YangModelSubscriptionEvent yangModelSubscriptionEvent =
+ subscriptionEventMapper.toYangModelSubscriptionEvent(subscriptionEvent);
+ subscriptionPersistence.saveSubscriptionEvent(yangModelSubscriptionEvent);
+ }
+
}
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/event/avc/SubscriptionEventMapper.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/event/avc/SubscriptionEventMapper.java
new file mode 100644
index 0000000000..44f9abb08e
--- /dev/null
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/event/avc/SubscriptionEventMapper.java
@@ -0,0 +1,52 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2023 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.api.impl.event.avc;
+
+import java.util.List;
+import java.util.stream.Collectors;
+import org.mapstruct.Mapper;
+import org.mapstruct.Mapping;
+import org.mapstruct.Named;
+import org.onap.cps.ncmp.api.impl.yangmodels.YangModelSubscriptionEvent;
+import org.onap.cps.ncmp.event.model.SubscriptionEvent;
+
+@Mapper(componentModel = "spring")
+public interface SubscriptionEventMapper {
+
+ @Mapping(source = "event.subscription.clientID", target = "clientId")
+ @Mapping(source = "event.subscription.name", target = "subscriptionName")
+ @Mapping(source = "event.subscription.isTagged", target = "tagged", qualifiedByName = "mapIsTagged")
+ @Mapping(source = "event.predicates.targets",
+ target = "predicates.targetCmHandles", qualifiedByName = "mapTargetsToCmHandleTargets")
+ @Mapping(source = "event.predicates.datastore", target = "predicates.datastore")
+ YangModelSubscriptionEvent toYangModelSubscriptionEvent(SubscriptionEvent subscriptionEvent);
+
+ @Named("mapTargetsToCmHandleTargets")
+ default List<YangModelSubscriptionEvent.TargetCmHandle> mapTargetsToCmHandleTargets(List<Object> targets) {
+ return targets.stream().map(
+ target -> new YangModelSubscriptionEvent.TargetCmHandle(target.toString())).collect(Collectors.toList());
+ }
+
+ @Named("mapIsTagged")
+ default boolean mapIsTagged(Boolean isTagged) {
+ return (isTagged == null) ? false : isTagged;
+ }
+}
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/notifications/avc/AvcEventMapper.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/notifications/avc/AvcEventMapper.java
index aaa06c6659..adbf08fa27 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/notifications/avc/AvcEventMapper.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/notifications/avc/AvcEventMapper.java
@@ -33,14 +33,7 @@ import org.onap.cps.ncmp.event.model.AvcEvent;
@Mapper(componentModel = "spring")
public interface AvcEventMapper {
- @Mapping(source = "eventTime", target = "eventTime")
@Mapping(source = "eventId", target = "eventId", qualifiedByName = "avcEventId")
- @Mapping(source = "eventCorrelationId", target = "eventCorrelationId")
- @Mapping(source = "eventSchema", target = "eventSchema")
- @Mapping(source = "eventSchemaVersion", target = "eventSchemaVersion")
- @Mapping(source = "eventSource", target = "eventSource")
- @Mapping(source = "eventType", target = "eventType")
- @Mapping(source = "event", target = "event")
AvcEvent toOutgoingAvcEvent(AvcEvent incomingAvcEvent);
@Named("avcEventId")
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/subscriptions/SubscriptionPersistence.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/subscriptions/SubscriptionPersistence.java
new file mode 100644
index 0000000000..16d9b80f8b
--- /dev/null
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/subscriptions/SubscriptionPersistence.java
@@ -0,0 +1,34 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2023 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.api.impl.subscriptions;
+
+import org.onap.cps.ncmp.api.impl.yangmodels.YangModelSubscriptionEvent;
+
+public interface SubscriptionPersistence {
+
+ /**
+ * Save subscription Event.
+ *
+ * @param yangModelSubscriptionEvent subscription Event as Yang Model.
+ */
+ void saveSubscriptionEvent(YangModelSubscriptionEvent yangModelSubscriptionEvent);
+
+}
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/subscriptions/SubscriptionPersistenceImpl.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/subscriptions/SubscriptionPersistenceImpl.java
new file mode 100644
index 0000000000..4895735afe
--- /dev/null
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/subscriptions/SubscriptionPersistenceImpl.java
@@ -0,0 +1,55 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2023 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.api.impl.subscriptions;
+
+import static org.onap.cps.ncmp.api.impl.constants.DmiRegistryConstants.NO_TIMESTAMP;
+
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.onap.cps.api.CpsDataService;
+import org.onap.cps.ncmp.api.impl.yangmodels.YangModelSubscriptionEvent;
+import org.onap.cps.utils.JsonObjectMapper;
+import org.springframework.stereotype.Component;
+
+@Slf4j
+@RequiredArgsConstructor
+@Component
+public class SubscriptionPersistenceImpl implements SubscriptionPersistence {
+
+ private static final String SUBSCRIPTION_DATASPACE_NAME = "NCMP-Admin";
+ private static final String SUBSCRIPTION_ANCHOR_NAME = "AVC-Subscriptions";
+ private static final String SUBSCRIPTION_REGISTRY_PARENT = "/subscription-registry";
+
+ private final JsonObjectMapper jsonObjectMapper;
+ private final CpsDataService cpsDataService;
+
+ @Override
+ public void saveSubscriptionEvent(final YangModelSubscriptionEvent yangModelSubscriptionEvent) {
+ final String subscriptionEventJsonData =
+ createSubscriptionEventJsonData(jsonObjectMapper.asJsonString(yangModelSubscriptionEvent));
+ cpsDataService.saveListElements(SUBSCRIPTION_DATASPACE_NAME, SUBSCRIPTION_ANCHOR_NAME,
+ SUBSCRIPTION_REGISTRY_PARENT, subscriptionEventJsonData, NO_TIMESTAMP);
+ }
+
+ private static String createSubscriptionEventJsonData(final String yangModelSubscriptionAsJson) {
+ return "{\"subscription\":[" + yangModelSubscriptionAsJson + "]}";
+ }
+}
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/subscriptions/SubscriptionStatus.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/subscriptions/SubscriptionStatus.java
new file mode 100644
index 0000000000..0b4f91fac3
--- /dev/null
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/subscriptions/SubscriptionStatus.java
@@ -0,0 +1,27 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2023 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.api.impl.subscriptions;
+
+public enum SubscriptionStatus {
+ ACCEPTED,
+ REJECTED,
+ PENDING
+}
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/yangmodels/YangModelSubscriptionEvent.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/yangmodels/YangModelSubscriptionEvent.java
new file mode 100644
index 0000000000..4dcc5797ca
--- /dev/null
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/yangmodels/YangModelSubscriptionEvent.java
@@ -0,0 +1,91 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2023 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.api.impl.yangmodels;
+
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonInclude.Include;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import java.util.List;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+import org.onap.cps.ncmp.api.impl.subscriptions.SubscriptionStatus;
+
+/**
+ * Subscription event model to persist data into DB.
+ * Yang model subscription event
+ */
+@Getter
+@Setter
+@NoArgsConstructor
+@JsonInclude(Include.NON_NULL)
+@EqualsAndHashCode(onlyExplicitlyIncluded = true)
+public class YangModelSubscriptionEvent {
+
+ @EqualsAndHashCode.Include
+ @JsonProperty("clientID")
+ private String clientId;
+
+ @EqualsAndHashCode.Include
+ @JsonProperty("subscriptionName")
+ private String subscriptionName;
+
+ private String topic;
+
+ @JsonProperty("isTagged")
+ private boolean isTagged;
+
+ private Predicates predicates;
+
+
+ @Data
+ @JsonInclude(JsonInclude.Include.NON_NULL)
+ public static class Predicates {
+
+ private String datastore;
+
+ private List<TargetCmHandle> targetCmHandles;
+
+ }
+
+ @AllArgsConstructor
+ @Data
+ @JsonInclude(JsonInclude.Include.NON_NULL)
+ public static class TargetCmHandle {
+
+ @JsonProperty()
+ private final String cmHandleId;
+
+ @JsonProperty()
+ private final SubscriptionStatus status;
+
+ public TargetCmHandle(final String cmHandleId) {
+ this.cmHandleId = cmHandleId;
+ this.status = SubscriptionStatus.PENDING;
+ }
+ }
+}
+
+
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/InventoryPersistenceImpl.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/InventoryPersistenceImpl.java
index c8d6c05f96..7908e629cb 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/InventoryPersistenceImpl.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/InventoryPersistenceImpl.java
@@ -244,7 +244,7 @@ public class InventoryPersistenceImpl implements InventoryPersistence {
return "{\"state\":" + state + "}";
}
- private static String createCmHandleJsonData(final String cmHandleId) {
- return "{\"cm-handles\":[" + cmHandleId + "]}";
+ private static String createCmHandleJsonData(final String yangModelCmHandleAsJson) {
+ return "{\"cm-handles\":[" + yangModelCmHandleAsJson + "]}";
}
}
diff --git a/cps-ncmp-service/src/main/resources/model/subscription.yang b/cps-ncmp-service/src/main/resources/model/subscription.yang
index 2d4b207e17..8ae1be6646 100644
--- a/cps-ncmp-service/src/main/resources/model/subscription.yang
+++ b/cps-ncmp-service/src/main/resources/model/subscription.yang
@@ -11,13 +11,13 @@ module subscription {
container subscription-registry {
list subscription {
- key "clientID clientName";
+ key "clientID subscriptionName";
leaf clientID {
type string;
}
- leaf clientName {
+ leaf subscriptionName {
type string;
}
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/event/avc/SubscriptionEventConsumerSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/event/avc/SubscriptionEventConsumerSpec.groovy
index 7a9dadebc5..248eb8bbe2 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/event/avc/SubscriptionEventConsumerSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/event/avc/SubscriptionEventConsumerSpec.groovy
@@ -21,6 +21,8 @@
package org.onap.cps.ncmp.api.impl.event.avc
import com.fasterxml.jackson.databind.ObjectMapper
+import org.onap.cps.ncmp.api.impl.subscriptions.SubscriptionPersistence
+import org.onap.cps.ncmp.api.impl.yangmodels.YangModelSubscriptionEvent
import org.onap.cps.ncmp.api.kafka.MessagingBaseSpec
import org.onap.cps.ncmp.event.model.SubscriptionEvent
import org.onap.cps.ncmp.utils.TestUtils
@@ -32,13 +34,17 @@ import org.springframework.boot.test.context.SpringBootTest
@SpringBootTest(classes = [ObjectMapper, JsonObjectMapper])
class SubscriptionEventConsumerSpec extends MessagingBaseSpec {
- def subscriptionEventForwarder = Mock(SubscriptionEventForwarder)
- def objectUnderTest = new SubscriptionEventConsumer(subscriptionEventForwarder)
+ def mockSubscriptionEventForwarder = Mock(SubscriptionEventForwarder)
+ def mockSubscriptionEventMapper = Mock(SubscriptionEventMapper)
+ def mockSubscriptionPersistence = Mock(SubscriptionPersistence)
+ def objectUnderTest = new SubscriptionEventConsumer(mockSubscriptionEventForwarder, mockSubscriptionEventMapper, mockSubscriptionPersistence)
+
+ def yangModelSubscriptionEvent = new YangModelSubscriptionEvent()
@Autowired
JsonObjectMapper jsonObjectMapper
- def 'Consume and forward valid CM create message'() {
+ def 'Consume, persist and forward valid CM create message'() {
given: 'an event with data category CM'
def jsonData = TestUtils.getResourceFileContent('avcSubscriptionCreationEvent.json')
def testEventSent = jsonObjectMapper.convertJsonString(jsonData, SubscriptionEvent.class)
@@ -46,11 +52,15 @@ class SubscriptionEventConsumerSpec extends MessagingBaseSpec {
objectUnderTest.notificationFeatureEnabled = true
when: 'the valid event is consumed'
objectUnderTest.consumeSubscriptionEvent(testEventSent)
- then: 'the event is forwarded'
- 1 * subscriptionEventForwarder.forwardCreateSubscriptionEvent(testEventSent)
+ then: 'the event is mapped to a yangModelSubscription'
+ 1 * mockSubscriptionEventMapper.toYangModelSubscriptionEvent(testEventSent) >> yangModelSubscriptionEvent
+ and: 'the event is persisted'
+ 1 * mockSubscriptionPersistence.saveSubscriptionEvent(yangModelSubscriptionEvent)
+ and: 'the event is forwarded'
+ 1 * mockSubscriptionEventForwarder.forwardCreateSubscriptionEvent(testEventSent)
}
- def 'Consume valid CM create message where notifications are disabled'() {
+ def 'Consume and persist valid CM create message where notifications are disabled'() {
given: 'an event with data category CM'
def jsonData = TestUtils.getResourceFileContent('avcSubscriptionCreationEvent.json')
def testEventSent = jsonObjectMapper.convertJsonString(jsonData, SubscriptionEvent.class)
@@ -58,8 +68,12 @@ class SubscriptionEventConsumerSpec extends MessagingBaseSpec {
objectUnderTest.notificationFeatureEnabled = false
when: 'the valid event is consumed'
objectUnderTest.consumeSubscriptionEvent(testEventSent)
- then: 'the event is forwarded'
- 0 * subscriptionEventForwarder.forwardCreateSubscriptionEvent(testEventSent)
+ then: 'the event is mapped to a yangModelSubscription'
+ 1 * mockSubscriptionEventMapper.toYangModelSubscriptionEvent(testEventSent) >> yangModelSubscriptionEvent
+ and: 'the event is persisted'
+ 1 * mockSubscriptionPersistence.saveSubscriptionEvent(yangModelSubscriptionEvent)
+ and: 'the event is not forwarded'
+ 0 * mockSubscriptionEventForwarder.forwardCreateSubscriptionEvent(*_)
}
def 'Consume valid FM message'() {
@@ -72,8 +86,12 @@ class SubscriptionEventConsumerSpec extends MessagingBaseSpec {
objectUnderTest.consumeSubscriptionEvent(testEventSent)
then: 'no exception is thrown'
noExceptionThrown()
+ and: 'the event is not mapped to a yangModelSubscription'
+ 0 * mockSubscriptionEventMapper.toYangModelSubscriptionEvent(testEventSent) >> yangModelSubscriptionEvent
+ and: 'the event is not persisted'
+ 0 * mockSubscriptionPersistence.saveSubscriptionEvent(yangModelSubscriptionEvent)
and: 'No event is forwarded'
- 0 * subscriptionEventForwarder.forwardCreateSubscriptionEvent(*_)
+ 0 * mockSubscriptionEventForwarder.forwardCreateSubscriptionEvent(*_)
}
def 'Consume event with wrong datastore causes an exception'() {
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/notifications/avc/SubscriptionEventMapperSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/notifications/avc/SubscriptionEventMapperSpec.groovy
new file mode 100644
index 0000000000..93346303a8
--- /dev/null
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/notifications/avc/SubscriptionEventMapperSpec.groovy
@@ -0,0 +1,63 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (c) 2023 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.api.impl.notifications.avc
+
+import com.fasterxml.jackson.databind.ObjectMapper
+import org.mapstruct.factory.Mappers
+import org.onap.cps.ncmp.api.impl.event.avc.SubscriptionEventMapper
+import org.onap.cps.ncmp.api.impl.subscriptions.SubscriptionStatus
+import org.onap.cps.ncmp.event.model.SubscriptionEvent
+import org.onap.cps.ncmp.utils.TestUtils
+import org.onap.cps.utils.JsonObjectMapper
+import org.springframework.beans.factory.annotation.Autowired
+import org.springframework.boot.test.context.SpringBootTest
+import spock.lang.Specification
+
+
+@SpringBootTest(classes = [JsonObjectMapper, ObjectMapper])
+class SubscriptionEventMapperSpec extends Specification {
+
+ SubscriptionEventMapper objectUnderTest = Mappers.getMapper(SubscriptionEventMapper)
+
+ @Autowired
+ JsonObjectMapper jsonObjectMapper
+
+ def 'Map subscription event to yang model subscription event where #scenario'() {
+ given: 'a Subscription Event'
+ def jsonData = TestUtils.getResourceFileContent('avcSubscriptionCreationEvent.json')
+ def testEventToMap = jsonObjectMapper.convertJsonString(jsonData, SubscriptionEvent.class)
+ when: 'the event is mapped to a yang model subscription'
+ def result = objectUnderTest.toYangModelSubscriptionEvent(testEventToMap)
+ then: 'the resulting yang model subscription event contains the correct clientId'
+ assert result.clientId == "SCO-9989752"
+ and: 'client name'
+ assert result.subscriptionName == "cm-subscription-001"
+ and: 'is tagged value is false'
+ assert !result.isTagged
+ and: 'predicate targets '
+ assert result.predicates.targetCmHandles.cmHandleId == ["CMHandle1", "CMHandle2", "CMHandle3"]
+ and: 'the status for these targets is set to pending'
+ assert result.predicates.targetCmHandles.status == [SubscriptionStatus.PENDING, SubscriptionStatus.PENDING, SubscriptionStatus.PENDING]
+ and: 'the topic is null'
+ assert result.topic == null
+ }
+
+} \ No newline at end of file
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/subscriptions/SubscriptionPersistenceSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/subscriptions/SubscriptionPersistenceSpec.groovy
new file mode 100644
index 0000000000..dbc8104767
--- /dev/null
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/subscriptions/SubscriptionPersistenceSpec.groovy
@@ -0,0 +1,65 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2023 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.api.impl.subscriptions
+
+import com.fasterxml.jackson.databind.ObjectMapper
+import org.onap.cps.api.CpsDataService
+import org.onap.cps.ncmp.api.impl.yangmodels.YangModelSubscriptionEvent
+import org.onap.cps.utils.JsonObjectMapper
+import spock.lang.Specification
+
+import static org.onap.cps.ncmp.api.impl.constants.DmiRegistryConstants.NO_TIMESTAMP
+
+class SubscriptionPersistenceSpec extends Specification {
+
+ private static final String SUBSCRIPTION_DATASPACE_NAME = "NCMP-Admin";
+ private static final String SUBSCRIPTION_ANCHOR_NAME = "AVC-Subscriptions";
+ private static final String SUBSCRIPTION_REGISTRY_PARENT = "/subscription-registry";
+
+ def jsonObjectMapper = new JsonObjectMapper(new ObjectMapper())
+
+ def mockCpsDataService = Mock(CpsDataService)
+
+ def objectUnderTest = new SubscriptionPersistenceImpl(jsonObjectMapper, mockCpsDataService)
+
+ def 'save a subscription event' () {
+ given: 'a yang model subscription event'
+ def yangModelSubscriptionEvent = new YangModelSubscriptionEvent();
+ yangModelSubscriptionEvent.setClientId('some-client-id')
+ yangModelSubscriptionEvent.setSubscriptionName('some-subscription-name')
+ yangModelSubscriptionEvent.setTagged(true)
+ yangModelSubscriptionEvent.setTopic('some-topic')
+ def predicates = new YangModelSubscriptionEvent.Predicates(datastore: 'some-datastore',
+ targetCmHandles: [new YangModelSubscriptionEvent.TargetCmHandle('cmhandle1'), new YangModelSubscriptionEvent.TargetCmHandle('cmhandle2')])
+ yangModelSubscriptionEvent.setPredicates(predicates)
+ when: 'the yangModelSubscriptionEvent is saved'
+ objectUnderTest.saveSubscriptionEvent(yangModelSubscriptionEvent)
+ then: 'the cpsDataService is called with the correct data'
+ 1 * mockCpsDataService.saveListElements(SUBSCRIPTION_DATASPACE_NAME, SUBSCRIPTION_ANCHOR_NAME,
+ SUBSCRIPTION_REGISTRY_PARENT,
+ '{"subscription":[{' +
+ '"topic":"some-topic",' +
+ '"predicates":{"datastore":"some-datastore","targetCmHandles":[{"cmHandleId":"cmhandle1","status":"PENDING"},{"cmHandleId":"cmhandle2","status":"PENDING"}]},' +
+ '"clientID":"some-client-id","subscriptionName":"some-subscription-name","isTagged":true}]}',
+ NO_TIMESTAMP)
+ }
+
+}