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
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);
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);
}
private void populateHeaderDetails(final LcmEventBase lcmEventBase,
+ final String eventSchemaVersion,
final String eventCorrelationId,
final LcmEventType lcmEventType) {
lcmEventBase.setEventId(UUID.randomUUID().toString());
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");
}
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
}
}
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)