Skip to content

Commit ecbd61b

Browse files
SeanBeirneGerrit Code Review
authored andcommitted
Merge "LCM Event V2: Fix event schema in header (for both versions!)"
2 parents 2ea3648 + 84ad06b commit ecbd61b

4 files changed

Lines changed: 12 additions & 8 deletions

File tree

cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/sync/lcm/LcmEventObjectCreator.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
public class LcmEventObjectCreator {
4848

4949
/**
50-
* Create Lifecycle Management Event.
50+
* Create Lifecycle Management Event Version 1.
5151
*
5252
* @param currentNcmpServiceCmHandle current ncmp service cmhandle
5353
* @param targetNcmpServiceCmHandle target ncmp service cmhandle
@@ -59,7 +59,7 @@ public LcmEventV1 createLcmEventV1(final NcmpServiceCmHandle currentNcmpServiceC
5959
final LcmEventType lcmEventType =
6060
determineEventType(currentNcmpServiceCmHandle, targetNcmpServiceCmHandle);
6161
final LcmEventV1 lcmEventV1 = new LcmEventV1();
62-
populateHeaderDetails(lcmEventV1, cmHandleId, lcmEventType);
62+
populateHeaderDetails(lcmEventV1, "v1", cmHandleId, lcmEventType);
6363
final PayloadV1 payloadV1 = PayloadFactory.createPayloadV1(lcmEventType, currentNcmpServiceCmHandle,
6464
targetNcmpServiceCmHandle);
6565
lcmEventV1.setEvent(payloadV1);
@@ -79,7 +79,7 @@ public LcmEventV2 createLcmEventV2(final NcmpServiceCmHandle currentNcmpServiceC
7979
final String cmHandleId = targetNcmpServiceCmHandle.getCmHandleId();
8080
final LcmEventType lcmEventType =
8181
determineEventType(currentNcmpServiceCmHandle, targetNcmpServiceCmHandle);
82-
populateHeaderDetails(lcmEventV2, cmHandleId, lcmEventType);
82+
populateHeaderDetails(lcmEventV2, "v2", cmHandleId, lcmEventType);
8383
final PayloadV2 payloadV2 = PayloadFactory.createPayloadV2(lcmEventType, currentNcmpServiceCmHandle,
8484
targetNcmpServiceCmHandle);
8585
lcmEventV2.setEvent(payloadV2);
@@ -97,14 +97,15 @@ private static LcmEventType determineEventType(final NcmpServiceCmHandle current
9797
}
9898

9999
private void populateHeaderDetails(final LcmEventBase lcmEventBase,
100+
final String eventSchemaVersion,
100101
final String eventCorrelationId,
101102
final LcmEventType lcmEventType) {
102103
lcmEventBase.setEventId(UUID.randomUUID().toString());
103104
lcmEventBase.setEventCorrelationId(eventCorrelationId);
104105
lcmEventBase.setEventTime(EventDateTimeFormatter.getCurrentIsoFormattedDateTime());
105106
lcmEventBase.setEventSource("org.onap.ncmp");
106107
lcmEventBase.setEventType(lcmEventType.getEventType());
107-
lcmEventBase.setEventSchema("org.onap.ncmp:cmhandle-lcm-event");
108+
lcmEventBase.setEventSchema("org.onap.ncmp:cmhandle-lcm-event." + eventSchemaVersion);
108109
lcmEventBase.setEventSchemaVersion("1.0");
109110
}
110111

cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/sync/lcm/LcmEventProducerSpec.groovy

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,14 @@ class LcmEventProducerSpec extends Specification {
4949
objectUnderTest.eventSchemaVersion = eventVersion
5050
when: 'event send for (batch of) 1 cm handle transition pair (new cm handle going to READY)'
5151
objectUnderTest.sendLcmEventBatchAsynchronously([cmHandleTransitionPair])
52-
then: 'producer is called #expectedTimesMethodCalled times with correct identifiers'
52+
then: 'producer is called #expectedTimesMethodCalled times with correct identifiers and schema name'
5353
expectedTimesMethodCalled * mockEventProducer.sendLegacyEvent(_, 'ch-1', _, _) >> {
5454
args -> {
5555
def eventHeaders = args[2]
5656
def event = args[3]
5757
assert UUID.fromString(eventHeaders.get('eventId')) != null
5858
assert eventHeaders.get('eventCorrelationId') == 'ch-1'
59+
assert eventHeaders.get('eventSchema') == "org.onap.ncmp:cmhandle-lcm-event.${eventVersion}"
5960
assert event.class.simpleName == expectedEventClass
6061
}
6162
}

integration-test/src/test/groovy/org/onap/cps/integration/functional/ncmp/inventory/CmHandleCreateSpec.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ class CmHandleCreateSpec extends CpsIntegrationSpecBase {
319319
assert headerAsMap.get('eventSource') == eventSource
320320
assert eventType == 'org.onap.ncmp.cmhandle-lcm-event.'+expectedEventType
321321
assert headerAsMap.get('eventType') == eventType
322-
assert eventSchema == 'org.onap.ncmp:cmhandle-lcm-event'
322+
assert eventSchema == 'org.onap.ncmp:cmhandle-lcm-event.v1'
323323
assert headerAsMap.get('eventSchema') == eventSchema
324324
assert eventSchemaVersion == '1.0'
325325
assert headerAsMap.get('eventSchemaVersion') == eventSchemaVersion

integration-test/src/test/groovy/org/onap/cps/integration/functional/ncmp/inventory/CmHandleUpdateSpec.groovy

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,14 +154,16 @@ class CmHandleUpdateSpec extends CpsIntegrationSpecBase {
154154
def dmiPluginRegistrationResponseForUpdate = objectUnderTest.updateDmiRegistration(dmiPluginRegistrationForUpdate)
155155
then: 'registration gives successful response'
156156
assert dmiPluginRegistrationResponseForUpdate.updatedCmHandles == [CmHandleRegistrationResponse.createSuccessResponse(cmHandleId)]
157-
and: 'get the latest message'
157+
and: 'the latest message is for the correct cm handle'
158158
def consumerRecords = getLatestConsumerRecordsWithMaxPollOf1Second(kafkaConsumer, 1)
159-
and: 'the V2 message has the updated data producer identifier in newValues'
160159
def notificationMessages = []
161160
for (def consumerRecord : consumerRecords) {
162161
notificationMessages.add(jsonObjectMapper.convertJsonString(consumerRecord.value().toString(), LcmEventV2))
163162
}
164163
assert notificationMessages[0].event.cmHandleId.contains(cmHandleId)
164+
and: 'the message has the v2 schema'
165+
assert notificationMessages[0].eventSchema == 'org.onap.ncmp:cmhandle-lcm-event.v2'
166+
and: 'the V2 message has the updated data producer identifier in newValues'
165167
assert notificationMessages[0].event.newValues['dataProducerIdentifier'] == 'my-data-producer-id'
166168
cleanup: 'restore original event schema version and deregister CM handle'
167169
ReflectionTestUtils.setField(lcmEventProducer, 'eventSchemaVersion', originalEventSchemaVersion)

0 commit comments

Comments
 (0)