LCM Event V2: Fix event schema in header (for both versions!) 68/143668/2
authorToineSiebelink <toine.siebelink@est.tech>
Tue, 24 Mar 2026 09:23:45 +0000 (09:23 +0000)
committerToineSiebelink <toine.siebelink@est.tech>
Tue, 24 Mar 2026 10:17:51 +0000 (10:17 +0000)
Issue-ID: CPS-2975
Change-Id: I6a2065d4428428b7e208fe003340a26e80b73ce8
Signed-off-by: ToineSiebelink <toine.siebelink@est.tech>
cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/sync/lcm/LcmEventObjectCreator.java
cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/sync/lcm/LcmEventProducerSpec.groovy
integration-test/src/test/groovy/org/onap/cps/integration/functional/ncmp/inventory/CmHandleCreateSpec.groovy
integration-test/src/test/groovy/org/onap/cps/integration/functional/ncmp/inventory/CmHandleUpdateSpec.groovy

index 28c5dd3..e1d78e1 100644 (file)
@@ -47,7 +47,7 @@ import org.springframework.stereotype.Service;
 public class LcmEventObjectCreator {
 
     /**
-     * Create Lifecycle Management Event.
+     * Create Lifecycle Management Event Version 1.
      *
      * @param currentNcmpServiceCmHandle  current ncmp service cmhandle
      * @param targetNcmpServiceCmHandle   target ncmp service cmhandle
@@ -59,7 +59,7 @@ public class LcmEventObjectCreator {
         final LcmEventType lcmEventType =
             determineEventType(currentNcmpServiceCmHandle, targetNcmpServiceCmHandle);
         final LcmEventV1 lcmEventV1 = new LcmEventV1();
-        populateHeaderDetails(lcmEventV1, cmHandleId, lcmEventType);
+        populateHeaderDetails(lcmEventV1, "v1", cmHandleId, lcmEventType);
         final PayloadV1 payloadV1 = PayloadFactory.createPayloadV1(lcmEventType, currentNcmpServiceCmHandle,
                                                                                  targetNcmpServiceCmHandle);
         lcmEventV1.setEvent(payloadV1);
@@ -79,7 +79,7 @@ public class LcmEventObjectCreator {
         final String cmHandleId = targetNcmpServiceCmHandle.getCmHandleId();
         final LcmEventType lcmEventType =
             determineEventType(currentNcmpServiceCmHandle, targetNcmpServiceCmHandle);
-        populateHeaderDetails(lcmEventV2, cmHandleId, lcmEventType);
+        populateHeaderDetails(lcmEventV2, "v2", cmHandleId, lcmEventType);
         final PayloadV2 payloadV2 = PayloadFactory.createPayloadV2(lcmEventType, currentNcmpServiceCmHandle,
             targetNcmpServiceCmHandle);
         lcmEventV2.setEvent(payloadV2);
@@ -97,6 +97,7 @@ public class LcmEventObjectCreator {
     }
 
     private void populateHeaderDetails(final LcmEventBase lcmEventBase,
+                                       final String eventSchemaVersion,
                                        final String eventCorrelationId,
                                        final LcmEventType lcmEventType) {
         lcmEventBase.setEventId(UUID.randomUUID().toString());
@@ -104,7 +105,7 @@ public class LcmEventObjectCreator {
         lcmEventBase.setEventTime(EventDateTimeFormatter.getCurrentIsoFormattedDateTime());
         lcmEventBase.setEventSource("org.onap.ncmp");
         lcmEventBase.setEventType(lcmEventType.getEventType());
-        lcmEventBase.setEventSchema("org.onap.ncmp:cmhandle-lcm-event");
+        lcmEventBase.setEventSchema("org.onap.ncmp:cmhandle-lcm-event." + eventSchemaVersion);
         lcmEventBase.setEventSchemaVersion("1.0");
     }
 
index 42bb9d7..3870839 100644 (file)
@@ -49,13 +49,14 @@ class LcmEventProducerSpec extends Specification {
             objectUnderTest.eventSchemaVersion = eventVersion
         when: 'event send for (batch of) 1 cm handle transition pair (new cm handle going to READY)'
             objectUnderTest.sendLcmEventBatchAsynchronously([cmHandleTransitionPair])
-        then: 'producer is called #expectedTimesMethodCalled times with correct identifiers'
+        then: 'producer is called #expectedTimesMethodCalled times with correct identifiers and schema name'
             expectedTimesMethodCalled * mockEventProducer.sendLegacyEvent(_, 'ch-1', _, _) >> {
                 args -> {
                     def eventHeaders = args[2]
                     def event = args[3]
                     assert UUID.fromString(eventHeaders.get('eventId')) != null
                     assert eventHeaders.get('eventCorrelationId') == 'ch-1'
+                    assert eventHeaders.get('eventSchema') == "org.onap.ncmp:cmhandle-lcm-event.${eventVersion}"
                     assert event.class.simpleName == expectedEventClass
                 }
             }
index 8f84c5f..259166b 100644 (file)
@@ -319,7 +319,7 @@ class CmHandleCreateSpec extends CpsIntegrationSpecBase {
             assert headerAsMap.get('eventSource') == eventSource
             assert eventType == 'org.onap.ncmp.cmhandle-lcm-event.'+expectedEventType
             assert headerAsMap.get('eventType') == eventType
-            assert eventSchema == 'org.onap.ncmp:cmhandle-lcm-event'
+            assert eventSchema == 'org.onap.ncmp:cmhandle-lcm-event.v1'
             assert headerAsMap.get('eventSchema') == eventSchema
             assert eventSchemaVersion == '1.0'
             assert headerAsMap.get('eventSchemaVersion') == eventSchemaVersion
index a86bfa3..34fe7b0 100644 (file)
@@ -154,14 +154,16 @@ class CmHandleUpdateSpec extends CpsIntegrationSpecBase {
             def dmiPluginRegistrationResponseForUpdate = objectUnderTest.updateDmiRegistration(dmiPluginRegistrationForUpdate)
         then: 'registration gives successful response'
             assert dmiPluginRegistrationResponseForUpdate.updatedCmHandles == [CmHandleRegistrationResponse.createSuccessResponse(cmHandleId)]
-        and: 'get the latest message'
+        and: 'the latest message is for the correct cm handle'
             def consumerRecords = getLatestConsumerRecordsWithMaxPollOf1Second(kafkaConsumer, 1)
-        and: 'the V2 message has the updated data producer identifier in newValues'
             def notificationMessages = []
             for (def consumerRecord : consumerRecords) {
                 notificationMessages.add(jsonObjectMapper.convertJsonString(consumerRecord.value().toString(), LcmEventV2))
             }
             assert notificationMessages[0].event.cmHandleId.contains(cmHandleId)
+        and: 'the message has the v2 schema'
+            assert notificationMessages[0].eventSchema == 'org.onap.ncmp:cmhandle-lcm-event.v2'
+        and: 'the V2 message has the updated data producer identifier in newValues'
             assert notificationMessages[0].event.newValues['dataProducerIdentifier'] == 'my-data-producer-id'
         cleanup: 'restore original event schema version and deregister CM handle'
             ReflectionTestUtils.setField(lcmEventProducer, 'eventSchemaVersion', originalEventSchemaVersion)