Merge "Simplified 'External' lock reason Mapping"
[cps.git] / cps-ncmp-service / src / test / groovy / org / onap / cps / ncmp / api / models / YangModelCmHandleSpec.groovy
index cdfcf59..09f42e4 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * ============LICENSE_START=======================================================
+ *  ============LICENSE_START=======================================================
  *  Copyright (C) 2021-2022 Nordix Foundation
  *  ================================================================================
  *  Licensed under the Apache License, Version 2.0 (the "License");
@@ -22,7 +22,9 @@ package org.onap.cps.ncmp.api.models
 
 import org.onap.cps.ncmp.api.impl.yangmodels.YangModelCmHandle
 import org.onap.cps.ncmp.api.inventory.CmHandleState
-import org.onap.ncmp.cmhandle.lcm.event.Event
+import org.onap.cps.ncmp.api.inventory.CompositeStateBuilder
+import org.onap.cps.ncmp.api.inventory.LockReasonCategory
+import org.onap.cps.ncmp.api.inventory.DataStoreSyncState
 import spock.lang.Specification
 
 import static org.onap.cps.ncmp.api.impl.operations.RequiredDmiService.DATA
@@ -36,8 +38,15 @@ class YangModelCmHandleSpec extends Specification {
             ncmpServiceCmHandle.cmHandleId = 'cm-handle-id01'
             ncmpServiceCmHandle.dmiProperties = [myDmiProperty:'value1']
             ncmpServiceCmHandle.publicProperties = [myPublicProperty:'value2']
+        and: 'with a composite state'
+            def compositeState = new CompositeStateBuilder()
+                .withCmHandleState(CmHandleState.LOCKED)
+                .withLastUpdatedTime('some-update-time')
+                .withLockReason(LockReasonCategory.LOCKED_MODULE_SYNC_FAILED, 'locked details')
+                .withOperationalDataStores(DataStoreSyncState.SYNCHRONIZED, 'some-sync-time').build()
+            ncmpServiceCmHandle.setCompositeState(compositeState)
         when: 'it is converted to a yang model cm handle'
-            def objectUnderTest = YangModelCmHandle.toYangModelCmHandle('','','', CmHandleState.ADVISED, ncmpServiceCmHandle)
+            def objectUnderTest = YangModelCmHandle.toYangModelCmHandle('', '', '', ncmpServiceCmHandle)
         then: 'the result has the right size'
             assert objectUnderTest.dmiProperties.size() == 1
         and: 'the DMI property in the result has the correct name and value'
@@ -46,11 +55,14 @@ class YangModelCmHandleSpec extends Specification {
         and: 'the public property in the result has the correct name and value'
             assert objectUnderTest.publicProperties[0].name == 'myPublicProperty'
             assert objectUnderTest.publicProperties[0].value == 'value2'
+        and: 'the composite state matches the composite state of the ncmpServiceCmHandle'
+            objectUnderTest.getCompositeState().cmHandleState == CmHandleState.LOCKED
+            objectUnderTest.getCompositeState() == ncmpServiceCmHandle.getCompositeState()
     }
 
     def 'Resolve DMI service name: #scenario and #requiredService service require.'() {
         given: 'a yang model cm handle'
-            def objectUnderTest = YangModelCmHandle.toYangModelCmHandle(dmiServiceName, dmiDataServiceName, dmiModelServiceName, CmHandleState.ADVISED, new NcmpServiceCmHandle(cmHandleId: 'cm-handle-id-1'))
+            def objectUnderTest = YangModelCmHandle.toYangModelCmHandle(dmiServiceName, dmiDataServiceName, dmiModelServiceName, new NcmpServiceCmHandle(cmHandleId: 'cm-handle-id-1'))
         expect:
             assert objectUnderTest.resolveDmiServiceName(requiredService) == expectedService
         where: