Merge "Add CSIT test: Delete CM Handle"
[cps.git] / cps-ncmp-service / src / test / groovy / org / onap / cps / ncmp / api / impl / events / lcm / LcmEventsCreatorSpec.groovy
index f4adfc5..b7c3b87 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * ============LICENSE_START=======================================================
- * Copyright (C) 2022-2023 Nordix Foundation
+ * Copyright (C) 2022-2024 Nordix Foundation
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
 
 package org.onap.cps.ncmp.api.impl.events.lcm
 
-import org.onap.cps.ncmp.api.inventory.CmHandleState
-import org.onap.cps.ncmp.api.inventory.CompositeState
+import static org.onap.cps.ncmp.api.impl.inventory.CmHandleState.ADVISED
+import static org.onap.cps.ncmp.api.impl.inventory.CmHandleState.DELETING
+import static org.onap.cps.ncmp.api.impl.inventory.CmHandleState.READY
+
+import org.mapstruct.factory.Mappers
+import org.onap.cps.ncmp.api.impl.inventory.CmHandleState
+import org.onap.cps.ncmp.api.impl.inventory.CompositeState
 import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle
-import org.onap.ncmp.cmhandle.event.lcm.Values
+import org.onap.cps.ncmp.events.lcm.v1.Values
 import spock.lang.Specification
 
-import static org.onap.cps.ncmp.api.inventory.CmHandleState.ADVISED
-import static org.onap.cps.ncmp.api.inventory.CmHandleState.DELETING
-import static org.onap.cps.ncmp.api.inventory.CmHandleState.READY
-
 class LcmEventsCreatorSpec extends Specification {
 
-    def objectUnderTest = new LcmEventsCreator()
+    LcmEventHeaderMapper lcmEventsHeaderMapper = Mappers.getMapper(LcmEventHeaderMapper)
+
+    def objectUnderTest = new LcmEventsCreator(lcmEventsHeaderMapper)
     def cmHandleId = 'test-cm-handle'
 
     def 'Map the LcmEvent for #operation'() {
@@ -159,4 +162,30 @@ class LcmEventsCreatorSpec extends Specification {
             'null to null'   | null                       | null
 
     }
+
+    def 'Map the LcmEventHeader'() {
+        given: 'NCMP cm handle details with current and old details'
+            def existingNcmpServiceCmHandle = new NcmpServiceCmHandle(cmHandleId: cmHandleId, compositeState: new CompositeState(cmHandleState: ADVISED))
+            def targetNcmpServiceCmHandle = new NcmpServiceCmHandle(cmHandleId: cmHandleId, compositeState: new CompositeState(cmHandleState: READY))
+        when: 'the event header is populated'
+            def result = objectUnderTest.populateLcmEventHeader(cmHandleId, targetNcmpServiceCmHandle, existingNcmpServiceCmHandle)
+        then: 'the header has fields populated'
+            assert result.eventCorrelationId == cmHandleId
+            assert result.eventId != null
+    }
+
+    def 'Map the LcmEvent for alternate IDs when #scenario'() {
+        given: 'NCMP cm handle details with current and old alternate IDs'
+            def existingNcmpServiceCmHandle = new NcmpServiceCmHandle(cmHandleId: cmHandleId, alternateId: existingAlternateId, compositeState: new CompositeState(dataSyncEnabled: false))
+            def targetNcmpServiceCmHandle = new NcmpServiceCmHandle(cmHandleId: cmHandleId, alternateId: targetAlternateId, compositeState: new CompositeState(dataSyncEnabled: false))
+        when: 'the event is populated'
+            def result = objectUnderTest.populateLcmEvent(cmHandleId, targetNcmpServiceCmHandle, existingNcmpServiceCmHandle)
+        then: 'the alternate ID is present or is an empty string in the payload'
+            assert result.event.alternateId == expectedEventAlternateId
+        where: 'the following alternate IDs are provided'
+            scenario                                      | existingAlternateId | targetAlternateId || expectedEventAlternateId
+            'same new and old alternate ID'               | 'someAlternateId'   | 'someAlternateId' || 'someAlternateId'
+            'blank new and old alternate ID'              | ''                  | ''                || ''
+            'new alternate id and blank old alternate ID' | ''                  | 'someAlternateId' || 'someAlternateId'
+    }
 }
\ No newline at end of file