Subscription Creation: Fixes for code review after demo

- Change missleading subscription details in testware
- Change datastore check to comply with CPS enum
- Remove redundant CloudConstructionException
- Change exception handling in cloud event mappers
  to avoid loss of information
- Remove exception handling from scheduler service
  as discussed in the meeting

Issue-ID: CPS-1732
Change-Id: I9fee2eafd4db97a0eed80e39219463c904f5a980
Signed-off-by: halil.cakal <halil.cakal@est.tech>
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/events/avcsubscription/ClientSubscriptionEventMapperSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/events/avcsubscription/ClientSubscriptionEventMapperSpec.groovy
index 85a58cd..b3d81e3 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/events/avcsubscription/ClientSubscriptionEventMapperSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/events/avcsubscription/ClientSubscriptionEventMapperSpec.groovy
@@ -54,7 +54,7 @@
         and: 'predicate targets is null'
             assert result.getData().getPredicates().getTargets() == []
         and: 'datastore is passthrough-running'
-            assert result.getData().getPredicates().getDatastore() == 'passthrough-running'
+            assert result.getData().getPredicates().getDatastore() == 'ncmp-datastore:passthrough-running'
     }
 
 }
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/events/avcsubscription/SubscriptionEventConsumerSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/events/avcsubscription/SubscriptionEventConsumerSpec.groovy
index 7fa8155..430d122 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/events/avcsubscription/SubscriptionEventConsumerSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/events/avcsubscription/SubscriptionEventConsumerSpec.groovy
@@ -25,6 +25,7 @@
 import io.cloudevents.core.builder.CloudEventBuilder
 import org.apache.kafka.clients.consumer.ConsumerRecord
 import org.onap.cps.ncmp.api.impl.subscriptions.SubscriptionPersistence
+import org.onap.cps.ncmp.api.impl.utils.SubscriptionEventCloudMapper
 import org.onap.cps.ncmp.api.impl.yangmodels.YangModelSubscriptionEvent
 import org.onap.cps.ncmp.api.kafka.MessagingBaseSpec
 import org.onap.cps.ncmp.events.avcsubscription1_0_0.client_to_ncmp.SubscriptionEvent;
@@ -39,7 +40,8 @@
     def mockSubscriptionEventForwarder = Mock(SubscriptionEventForwarder)
     def mockSubscriptionEventMapper = Mock(SubscriptionEventMapper)
     def mockSubscriptionPersistence = Mock(SubscriptionPersistence)
-    def objectUnderTest = new SubscriptionEventConsumer(mockSubscriptionEventForwarder, mockSubscriptionEventMapper, mockSubscriptionPersistence)
+    def subscriptionEventCloudMapper = new SubscriptionEventCloudMapper(new ObjectMapper())
+    def objectUnderTest = new SubscriptionEventConsumer(mockSubscriptionEventForwarder, mockSubscriptionEventMapper, mockSubscriptionPersistence, subscriptionEventCloudMapper)
 
     def yangModelSubscriptionEvent = new YangModelSubscriptionEvent()
 
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/events/avcsubscription/SubscriptionEventForwarderSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/events/avcsubscription/SubscriptionEventForwarderSpec.groovy
index 4193f75..dd93bf6 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/events/avcsubscription/SubscriptionEventForwarderSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/events/avcsubscription/SubscriptionEventForwarderSpec.groovy
@@ -30,6 +30,7 @@
 import org.onap.cps.ncmp.api.impl.events.EventsPublisher
 import org.onap.cps.ncmp.api.impl.subscriptions.SubscriptionPersistence
 import org.onap.cps.ncmp.api.impl.subscriptions.SubscriptionStatus
+import org.onap.cps.ncmp.api.impl.utils.SubscriptionEventCloudMapper
 import org.onap.cps.ncmp.api.impl.yangmodels.YangModelCmHandle
 import org.onap.cps.ncmp.api.impl.yangmodels.YangModelSubscriptionEvent.TargetCmHandle
 import org.onap.cps.ncmp.api.inventory.InventoryPersistence
@@ -44,7 +45,6 @@
 import org.springframework.beans.factory.annotation.Autowired
 import org.springframework.boot.test.context.SpringBootTest
 import spock.util.concurrent.BlockingVariable
-
 import java.util.concurrent.TimeUnit
 
 @SpringBootTest(classes = [ObjectMapper, JsonObjectMapper, SubscriptionEventForwarder])
@@ -60,6 +60,8 @@
     @SpringBean
     IMap<String, Set<String>> mockForwardedSubscriptionEventCache = Mock(IMap<String, Set<String>>)
     @SpringBean
+    SubscriptionEventCloudMapper subscriptionEventCloudMapper = new SubscriptionEventCloudMapper(new ObjectMapper())
+    @SpringBean
     SubscriptionEventResponseOutcome mockSubscriptionEventResponseOutcome = Mock(SubscriptionEventResponseOutcome)
     @SpringBean
     SubscriptionPersistence mockSubscriptionPersistence = Mock(SubscriptionPersistence)
@@ -69,8 +71,8 @@
     ClientSubscriptionEventMapper clientSubscriptionEventMapper = Mappers.getMapper(ClientSubscriptionEventMapper)
     @Autowired
     JsonObjectMapper jsonObjectMapper
-
-    def objectMapper = new ObjectMapper()
+    @Autowired
+    ObjectMapper objectMapper
 
     def 'Forward valid CM create subscription and simulate timeout'() {
         given: 'an event'
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/events/avcsubscription/SubscriptionEventResponseConsumerSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/events/avcsubscription/SubscriptionEventResponseConsumerSpec.groovy
index 7cc40cc..3e6d7a8 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/events/avcsubscription/SubscriptionEventResponseConsumerSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/events/avcsubscription/SubscriptionEventResponseConsumerSpec.groovy
@@ -26,6 +26,7 @@
 import io.cloudevents.core.builder.CloudEventBuilder
 import org.apache.kafka.clients.consumer.ConsumerRecord
 import org.onap.cps.ncmp.api.impl.subscriptions.SubscriptionPersistenceImpl
+import org.onap.cps.ncmp.api.impl.utils.SubscriptionEventResponseCloudMapper
 import org.onap.cps.ncmp.api.kafka.MessagingBaseSpec
 import org.onap.cps.ncmp.events.avcsubscription1_0_0.dmi_to_ncmp.SubscriptionEventResponse
 import org.onap.cps.ncmp.utils.TestUtils
@@ -47,9 +48,10 @@
     def mockSubscriptionPersistence = Mock(SubscriptionPersistenceImpl)
     def mockSubscriptionEventResponseMapper  = Mock(SubscriptionEventResponseMapper)
     def mockSubscriptionEventResponseOutcome = Mock(SubscriptionEventResponseOutcome)
+    def mockSubscriptionEventResponseCloudMapper = new SubscriptionEventResponseCloudMapper(new ObjectMapper())
 
     def objectUnderTest = new SubscriptionEventResponseConsumer(mockForwardedSubscriptionEventCache,
-        mockSubscriptionPersistence, mockSubscriptionEventResponseMapper, mockSubscriptionEventResponseOutcome)
+        mockSubscriptionPersistence, mockSubscriptionEventResponseMapper, mockSubscriptionEventResponseOutcome, mockSubscriptionEventResponseCloudMapper)
 
     def 'Consume Subscription Event Response where all DMIs have responded'() {
         given: 'a consumer record including cloud event having subscription response'
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/events/avcsubscription/SubscriptionEventResponseMapperSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/events/avcsubscription/SubscriptionEventResponseMapperSpec.groovy
index 4c60281..d07d9bb 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/events/avcsubscription/SubscriptionEventResponseMapperSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/events/avcsubscription/SubscriptionEventResponseMapperSpec.groovy
@@ -50,11 +50,11 @@
         and: 'subscription name'
             assert result.subscriptionName == "cm-subscription-001"
         and: 'predicate targets cm handle size as expected'
-            assert result.predicates.targetCmHandles.size() == 7
+            assert result.predicates.targetCmHandles.size() == 4
         and: 'predicate targets cm handle ids as expected'
-            assert result.predicates.targetCmHandles.cmHandleId == ["CMHandle1", "CMHandle2", "CMHandle3", "CMHandle4", "CMHandle5", "CMHandle6", "CMHandle7"]
+            assert result.predicates.targetCmHandles.cmHandleId == ["CMHandle1", "CMHandle2", "CMHandle3", "CMHandle4"]
         and: 'the status for these targets is set to expected values'
-            assert result.predicates.targetCmHandles.status == [SubscriptionStatus.REJECTED, SubscriptionStatus.REJECTED, SubscriptionStatus.REJECTED, SubscriptionStatus.REJECTED, SubscriptionStatus.PENDING, SubscriptionStatus.PENDING, SubscriptionStatus.PENDING]
+            assert result.predicates.targetCmHandles.status == [SubscriptionStatus.REJECTED, SubscriptionStatus.REJECTED, SubscriptionStatus.PENDING, SubscriptionStatus.PENDING]
     }
 
 }
\ No newline at end of file
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/events/avcsubscription/SubscriptionEventResponseOutcomeSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/events/avcsubscription/SubscriptionEventResponseOutcomeSpec.groovy
index c1c428b..a6c8712 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/events/avcsubscription/SubscriptionEventResponseOutcomeSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/events/avcsubscription/SubscriptionEventResponseOutcomeSpec.groovy
@@ -49,6 +49,8 @@
     EventsPublisher<CloudEvent> mockSubscriptionEventOutcomePublisher = Mock(EventsPublisher<CloudEvent>)
     @SpringBean
     SubscriptionOutcomeMapper subscriptionOutcomeMapper = Mappers.getMapper(SubscriptionOutcomeMapper)
+    @SpringBean
+    SubscriptionOutcomeCloudMapper subscriptionOutcomeCloudMapper = new SubscriptionOutcomeCloudMapper(new ObjectMapper())
 
     @Autowired
     JsonObjectMapper jsonObjectMapper
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/events/avcsubscription/SubscriptionOutcomeMapperSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/events/avcsubscription/SubscriptionOutcomeMapperSpec.groovy
index f5fbdfc..ea1b9e7 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/events/avcsubscription/SubscriptionOutcomeMapperSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/events/avcsubscription/SubscriptionOutcomeMapperSpec.groovy
@@ -48,14 +48,14 @@
             def result = objectUnderTest.toSubscriptionEventOutcome(subscriptionResponseEvent)
         then: 'the resulting subscription event outcome contains expected pending targets per details grouping'
             def pendingCmHandleTargetsPerDetails = result.getData().getAdditionalInfo().getPending()
-            assert pendingCmHandleTargetsPerDetails.get(0).getDetails() == 'EMS or node connectivity issues, retrying'
-            assert pendingCmHandleTargetsPerDetails.get(0).getTargets() == ['CMHandle5', 'CMHandle6','CMHandle7']
+            assert pendingCmHandleTargetsPerDetails.get(0).getDetails() == 'No reply from DMI yet'
+            assert pendingCmHandleTargetsPerDetails.get(0).getTargets() == ['CMHandle3', 'CMHandle4']
         and: 'the resulting subscription event outcome contains expected rejected targets per details grouping'
             def rejectedCmHandleTargetsPerDetails = result.getData().getAdditionalInfo().getRejected()
-            assert rejectedCmHandleTargetsPerDetails.get(0).getDetails() == 'Target(s) do not exist'
-            assert rejectedCmHandleTargetsPerDetails.get(0).getTargets() == ['CMHandle4']
-            assert rejectedCmHandleTargetsPerDetails.get(1).getDetails() == 'Faulty subscription format for target(s)'
-            assert rejectedCmHandleTargetsPerDetails.get(1).getTargets() == ['CMHandle1', 'CMHandle2','CMHandle3']
+            assert rejectedCmHandleTargetsPerDetails.get(0).getDetails() == 'Some other error message from the DMI'
+            assert rejectedCmHandleTargetsPerDetails.get(0).getTargets() == ['CMHandle2']
+            assert rejectedCmHandleTargetsPerDetails.get(1).getDetails() == 'Some error message from the DMI'
+            assert rejectedCmHandleTargetsPerDetails.get(1).getTargets() == ['CMHandle1']
     }
 
     def 'Map subscription event response with null of subscription status list to subscription event outcome causes an exception'() {
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/utils/SubscriptionEventCloudMapperSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/utils/SubscriptionEventCloudMapperSpec.groovy
index 4023441..ae61749 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/utils/SubscriptionEventCloudMapperSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/utils/SubscriptionEventCloudMapperSpec.groovy
@@ -20,6 +20,7 @@
 
 package org.onap.cps.ncmp.api.impl.utils
 
+import com.fasterxml.jackson.core.JsonProcessingException
 import com.fasterxml.jackson.databind.ObjectMapper
 import io.cloudevents.core.builder.CloudEventBuilder
 import org.onap.cps.ncmp.events.avcsubscription1_0_0.client_to_ncmp.SubscriptionEvent
@@ -38,6 +39,10 @@
     @Autowired
     ObjectMapper objectMapper
 
+    def spyObjectMapper = Spy(ObjectMapper)
+
+    def objectUnderTest = new SubscriptionEventCloudMapper(spyObjectMapper)
+
     def 'Map the data of the cloud event to subscription event'() {
         given: 'a cloud event having a subscription event in the data part'
             def jsonData = TestUtils.getResourceFileContent('avcSubscriptionCreationEvent.json')
@@ -49,7 +54,7 @@
                 .withSource(URI.create('some-resource'))
                 .withExtension('correlationid', 'test-cmhandle1').build()
         when: 'the cloud event map to subscription event'
-            def resultSubscriptionEvent = SubscriptionEventCloudMapper.toSubscriptionEvent(testCloudEvent)
+            def resultSubscriptionEvent = objectUnderTest.toSubscriptionEvent(testCloudEvent)
         then: 'the subscription event resulted having expected values'
             resultSubscriptionEvent.getData() == testEventData.getData()
     }
@@ -63,7 +68,7 @@
                 .withSource(URI.create('some-resource'))
                 .withExtension('correlationid', 'test-cmhandle1').build()
         when: 'the cloud event map to subscription event'
-            def resultSubscriptionEvent = SubscriptionEventCloudMapper.toSubscriptionEvent(testCloudEvent)
+            def resultSubscriptionEvent = objectUnderTest.toSubscriptionEvent(testCloudEvent)
         then: 'the subscription event resulted having a null value'
             resultSubscriptionEvent == null
     }
@@ -81,7 +86,7 @@
                 .withExtension('correlationid', 'test-cmhandle1').build()
         when: 'the subscription event map to data of cloud event'
             SubscriptionEventCloudMapper.randomId = 'some-id'
-            def resultCloudEvent = SubscriptionEventCloudMapper.toCloudEvent(testEventData, 'some-event-key', 'subscriptionCreated')
+            def resultCloudEvent = objectUnderTest.toCloudEvent(testEventData, 'some-event-key', 'subscriptionCreated')
         then: 'the subscription event resulted having expected values'
             resultCloudEvent.getData() == testCloudEvent.getData()
             resultCloudEvent.getId() == testCloudEvent.getId()
@@ -90,14 +95,20 @@
             resultCloudEvent.getDataSchema() == URI.create('urn:cps:org.onap.cps.ncmp.events.avcsubscription1_0_0.ncmp_to_dmi.SubscriptionEvent:1.0.0')
     }
 
-    def 'Map the subscription event to data of the cloud event with wrong content causes an exception'() {
-        given: 'an empty ncmp subscription event'
-            def testNcmpSubscriptionEvent = new org.onap.cps.ncmp.events.avcsubscription1_0_0.ncmp_to_dmi.SubscriptionEvent()
-        when: 'the subscription event map to data of cloud event'
-            SubscriptionEventCloudMapper.toCloudEvent(testNcmpSubscriptionEvent, 'some-key', 'some-event-type')
-        then: 'a run time exception is thrown'
-            def exception = thrown(CloudEventConstructionException)
-            exception.details == 'Invalid object to serialize or required headers is missing'
+    def 'Map the subscription event to cloud event with JSON processing exception'() {
+        given: 'a json processing exception during process'
+            def jsonProcessingException = new JsonProcessingException('The Cloud Event could not be constructed')
+            spyObjectMapper.writeValueAsBytes(_) >> { throw jsonProcessingException }
+        and: 'a subscription event of ncmp version'
+            def jsonData = TestUtils.getResourceFileContent('avcSubscriptionCreationEventNcmpVersion.json')
+            def testEventData = jsonObjectMapper.convertJsonString(jsonData,
+                org.onap.cps.ncmp.events.avcsubscription1_0_0.ncmp_to_dmi.SubscriptionEvent.class)
+        when: 'the subscription event map to cloud event'
+            def expectedResult = objectUnderTest.toCloudEvent(testEventData, 'some-key', 'some-event-type')
+        then: 'no exception is thrown since it has been handled already'
+            noExceptionThrown()
+        and: 'expected result should be null'
+            expectedResult == null
     }
 
 }
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/utils/SubscriptionEventResponseCloudMapperSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/utils/SubscriptionEventResponseCloudMapperSpec.groovy
new file mode 100644
index 0000000..9dcd0a6
--- /dev/null
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/utils/SubscriptionEventResponseCloudMapperSpec.groovy
@@ -0,0 +1,74 @@
+/*
+ * ============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.utils
+
+import com.fasterxml.jackson.databind.ObjectMapper
+import io.cloudevents.core.builder.CloudEventBuilder
+import org.onap.cps.ncmp.events.avcsubscription1_0_0.dmi_to_ncmp.SubscriptionEventResponse
+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 = [ObjectMapper, JsonObjectMapper])
+class SubscriptionEventResponseCloudMapperSpec extends Specification {
+
+    @Autowired
+    JsonObjectMapper jsonObjectMapper
+
+    @Autowired
+    ObjectMapper objectMapper
+
+    def spyObjectMapper = Spy(ObjectMapper)
+
+    def objectUnderTest = new SubscriptionEventResponseCloudMapper(spyObjectMapper)
+
+    def 'Map the cloud event to subscription event response'() {
+        given: 'a cloud event having a subscription event response in the data part'
+            def jsonData = TestUtils.getResourceFileContent('avcSubscriptionEventResponse.json')
+            def testEventData = jsonObjectMapper.convertJsonString(jsonData, SubscriptionEventResponse.class)
+            def testCloudEvent = CloudEventBuilder.v1()
+                .withData(objectMapper.writeValueAsBytes(testEventData))
+                .withId('some-event-id')
+                .withType('subscriptionCreatedStatus')
+                .withSource(URI.create('some-resource'))
+                .withExtension('correlationid', 'test-cmhandle1').build()
+        when: 'the cloud event map to subscription event response'
+            def resultSubscriptionEvent = objectUnderTest.toSubscriptionEventResponse(testCloudEvent)
+        then: 'the subscription event resulted having expected values'
+            resultSubscriptionEvent.getData() == testEventData.getData()
+    }
+
+    def 'Map null of the data of the cloud event to subscription event response'() {
+        given: 'a cloud event having a null subscription event response in the data part'
+            def testCloudEvent = CloudEventBuilder.v1()
+                .withData(null)
+                .withId('some-event-id')
+                .withType('subscriptionCreatedStatus')
+                .withSource(URI.create('some-resource'))
+                .withExtension('correlationid', 'test-cmhandle1').build()
+        when: 'the cloud event map to subscription event response'
+            def resultSubscriptionEvent = objectUnderTest.toSubscriptionEventResponse(testCloudEvent)
+        then: 'the subscription event response resulted having a null value'
+            resultSubscriptionEvent == null
+    }
+}
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/utils/SubscriptionOutcomeCloudMapperSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/utils/SubscriptionOutcomeCloudMapperSpec.groovy
new file mode 100644
index 0000000..ac055b5
--- /dev/null
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/utils/SubscriptionOutcomeCloudMapperSpec.groovy
@@ -0,0 +1,82 @@
+/*
+ * ============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.utils
+
+import com.fasterxml.jackson.core.JsonProcessingException
+import com.fasterxml.jackson.databind.ObjectMapper
+import io.cloudevents.core.builder.CloudEventBuilder
+import org.onap.cps.ncmp.events.avcsubscription1_0_0.ncmp_to_client.SubscriptionEventOutcome
+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 = [ObjectMapper, JsonObjectMapper])
+class SubscriptionOutcomeCloudMapperSpec extends Specification {
+
+    @Autowired
+    JsonObjectMapper jsonObjectMapper
+
+    @Autowired
+    ObjectMapper objectMapper
+
+    def spyObjectMapper = Spy(ObjectMapper)
+
+    def objectUnderTest = new SubscriptionOutcomeCloudMapper(spyObjectMapper)
+
+    def 'Map the subscription outcome to cloud event'() {
+        given: 'a subscription event'
+            def jsonData = TestUtils.getResourceFileContent('avcSubscriptionOutcomeEvent.json')
+            def testEventData = jsonObjectMapper.convertJsonString(jsonData, SubscriptionEventOutcome.class)
+            def testCloudEvent = CloudEventBuilder.v1()
+                .withData(objectMapper.writeValueAsBytes(testEventData))
+                .withId('some-id')
+                .withType('subscriptionCreatedStatus')
+                .withSource(URI.create('NCMP'))
+                .withExtension('correlationid', 'test-cmhandle1').build()
+        when: 'the subscription event map to data of cloud event'
+            SubscriptionOutcomeCloudMapper.randomId = 'some-id'
+            def resultCloudEvent = objectUnderTest.toCloudEvent(testEventData, 'some-event-key', 'subscriptionCreatedStatus')
+        then: 'the subscription event resulted having expected values'
+            resultCloudEvent.getData() == testCloudEvent.getData()
+            resultCloudEvent.getId() == testCloudEvent.getId()
+            resultCloudEvent.getType() == testCloudEvent.getType()
+            resultCloudEvent.getSource() == testCloudEvent.getSource()
+            resultCloudEvent.getDataSchema() == URI.create('urn:cps:org.onap.cps.ncmp.events.avcsubscription1_0_0.ncmp_to_client.SubscriptionEventOutcome:1.0.0')
+    }
+
+    def 'Map the subscription outcome to cloud event with JSON processing exception'() {
+        given: 'a json processing exception during process'
+            def jsonProcessingException = new JsonProcessingException('The Cloud Event could not be constructed')
+            spyObjectMapper.writeValueAsBytes(_) >> { throw jsonProcessingException }
+        and: 'a cloud event having a subscription outcome in the data part'
+            def jsonData = TestUtils.getResourceFileContent('avcSubscriptionOutcomeEvent.json')
+            def testEventData = jsonObjectMapper.convertJsonString(jsonData, SubscriptionEventOutcome.class)
+        when: 'the subscription outcome map to cloud event'
+            def expectedResult = objectUnderTest.toCloudEvent(testEventData, 'some-key', 'some-event-type')
+        then: 'no exception is thrown since it has been handled already'
+            noExceptionThrown()
+        and: 'expected result should be null'
+            expectedResult == null
+    }
+
+}
diff --git a/cps-ncmp-service/src/test/resources/avcSubscriptionCreationEvent.json b/cps-ncmp-service/src/test/resources/avcSubscriptionCreationEvent.json
index e4539fb..803fa48 100644
--- a/cps-ncmp-service/src/test/resources/avcSubscriptionCreationEvent.json
+++ b/cps-ncmp-service/src/test/resources/avcSubscriptionCreationEvent.json
@@ -15,7 +15,7 @@
         "CMHandle2",
         "CMHandle3"
       ],
-      "datastore": "passthrough-running",
+      "datastore": "ncmp-datastore:passthrough-running",
       "datastore-xpath-filter": "//_3gpp-nr-nrm-gnbdufunction:GNBDUFunction/_3gpp-nr-nrm-nrcelldu:NRCellDU/ | //_3gpp-nr-nrm-gnbcuupfunction:GNBCUUPFunction// | //_3gpp-nr-nrm-gnbcucpfunction:GNBCUCPFunction/_3gpp-nr-nrm-nrcelldu:NRCellCU// | //_3gpp-nr-nrm-nrsectorcarrier:NRSectorCarrier//"
     }
   }
diff --git a/cps-ncmp-service/src/test/resources/avcSubscriptionEventResponse.json b/cps-ncmp-service/src/test/resources/avcSubscriptionEventResponse.json
index 52ca1df..dfe8f50 100644
--- a/cps-ncmp-service/src/test/resources/avcSubscriptionEventResponse.json
+++ b/cps-ncmp-service/src/test/resources/avcSubscriptionEventResponse.json
@@ -7,37 +7,22 @@
       {
         "id": "CMHandle1",
         "status": "REJECTED",
-        "details": "Faulty subscription format for target(s)"
+        "details": "Some error message from the DMI"
       },
       {
         "id": "CMHandle2",
         "status": "REJECTED",
-        "details": "Faulty subscription format for target(s)"
+        "details": "Some other error message from the DMI"
       },
       {
         "id": "CMHandle3",
-        "status": "REJECTED",
-        "details": "Faulty subscription format for target(s)"
+        "status": "PENDING",
+        "details": "No reply from DMI yet"
       },
       {
         "id": "CMHandle4",
-        "status": "REJECTED",
-        "details": "Target(s) do not exist"
-      },
-      {
-        "id": "CMHandle5",
         "status": "PENDING",
-        "details": "EMS or node connectivity issues, retrying"
-      },
-      {
-        "id": "CMHandle6",
-        "status": "PENDING",
-        "details": "EMS or node connectivity issues, retrying"
-      },
-      {
-        "id": "CMHandle7",
-        "status": "PENDING",
-        "details": "EMS or node connectivity issues, retrying"
+        "details": "No reply from DMI yet"
       }
     ]
   }
diff --git a/cps-ncmp-service/src/test/resources/avcSubscriptionOutcomeEvent.json b/cps-ncmp-service/src/test/resources/avcSubscriptionOutcomeEvent.json
index 2d83bdd..14e8cbb 100644
--- a/cps-ncmp-service/src/test/resources/avcSubscriptionOutcomeEvent.json
+++ b/cps-ncmp-service/src/test/resources/avcSubscriptionOutcomeEvent.json
@@ -5,18 +5,18 @@
     "additionalInfo": {
       "rejected": [
         {
-          "details": "Target(s) do not exist",
-          "targets": ["CMHandle4"]
+          "details": "Some other error message from the DMI",
+          "targets": ["CMHandle2"]
         },
         {
-          "details": "Faulty subscription format for target(s)",
-          "targets": ["CMHandle1", "CMHandle2", "CMHandle3"]
+          "details": "Some error message from the DMI",
+          "targets": ["CMHandle1"]
         }
       ],
       "pending": [
         {
-          "details": "EMS or node connectivity issues, retrying",
-          "targets": ["CMHandle5", "CMHandle6", "CMHandle7"]
+          "details": "No reply from DMI yet",
+          "targets": ["CMHandle3", "CMHandle4"]
         }
       ]
     }