summaryrefslogtreecommitdiffstats
path: root/cps-ncmp-service/src/test/groovy/org
diff options
context:
space:
mode:
authormpriyank <priyank.maheshwari@est.tech>2022-05-16 17:14:25 +0100
committermpriyank <priyank.maheshwari@est.tech>2022-05-19 12:20:50 +0100
commit09156406ac7201a7329663e8fedb29dc28547048 (patch)
tree6f1d0bc41a36ea4762c79578bf7d9e04ddd0208e /cps-ncmp-service/src/test/groovy/org
parent806d31aed57c798cba0ecc33d92e5b43fa1d957b (diff)
Composite State to handle dmi-reg YANG updates
- Introduce CompositeState object which handles change in updated YANG for dmi-registry - Used Builder pattern as some of the fields are optional - Removed the abstract ready method from CmHandleState which was used as state machine - Fixed few test cases Issue-ID: CPS-1042 Change-Id: I8aaf6f819c66b3a9d30c5e8f0a0007f9528b247f Signed-off-by: mpriyank <priyank.maheshwari@est.tech>
Diffstat (limited to 'cps-ncmp-service/src/test/groovy/org')
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/CompositeStateSpec.groovy64
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/CmHandleStateSpec.groovy4
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncSpec.groovy7
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/SyncUtilsSpec.groovy7
4 files changed, 76 insertions, 6 deletions
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/CompositeStateSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/CompositeStateSpec.groovy
new file mode 100644
index 000000000..4f4cccfe7
--- /dev/null
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/CompositeStateSpec.groovy
@@ -0,0 +1,64 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2022 Nordix Foundation
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.cps.ncmp.api.inventory
+
+import com.fasterxml.jackson.databind.ObjectMapper
+import spock.lang.Specification
+
+import java.time.OffsetDateTime
+import java.time.ZoneOffset
+import java.time.format.DateTimeFormatter
+
+import static CompositeState.DataStores
+import static CompositeState.LockReason
+import static CompositeState.Operational
+import static CompositeState.Running
+import static org.onap.cps.ncmp.utils.TestUtils.getResourceFileContent
+import static org.springframework.util.StringUtils.trimAllWhitespace
+
+class CompositeStateSpec extends Specification {
+
+ def formattedDateAndTime = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSZ").format(OffsetDateTime.of(2022, 1, 1, 1, 1, 1, 1, ZoneOffset.MIN))
+ def objectMapper = new ObjectMapper()
+
+ def "Composite State Specification"() {
+ given: "a Composite State"
+ def compositeState = new CompositeState(cmhandleState: CmHandleState.ADVISED,
+ lockReason: LockReason.builder().reason('lock-reason').details("lock-misbehaving-details").build(),
+ lastUpdateTime: formattedDateAndTime.toString(),
+ dataSyncEnabled: false,
+ dataStores: dataStores())
+ when: 'it is represented as JSON'
+ def jsonStateModelAsString = objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(compositeState)
+ then: 'it matches expected state model as JSON'
+ def expectedStateModelAsjson = getResourceFileContent('expectedStateModel.json')
+ assert trimAllWhitespace(expectedStateModelAsjson) == trimAllWhitespace(jsonStateModelAsString)
+ }
+
+ def dataStores() {
+ DataStores.builder().operationalDataStore(Operational.builder()
+ .syncState('NONE_REQUESTED')
+ .lastSyncTime(formattedDateAndTime.toString()).build()).runningDataStore(Running.builder()
+ .syncState('NONE_REQUESTED')
+ .lastSyncTime(formattedDateAndTime.toString()).build())
+ .build()
+ }
+}
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/CmHandleStateSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/CmHandleStateSpec.groovy
index 923a9037d..bfc5c6fa3 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/CmHandleStateSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/CmHandleStateSpec.groovy
@@ -29,7 +29,7 @@ class CmHandleStateSpec extends Specification{
given: 'a cm handle with an ADVISED state'
def cmHandleState = CmHandleState.ADVISED
when: 'the state transitions to the READY state'
- cmHandleState = cmHandleState.ready()
+ cmHandleState = CmHandleState.READY
then: 'the cm handle state changes to READY'
assert CmHandleState.READY == cmHandleState
}
@@ -38,7 +38,7 @@ class CmHandleStateSpec extends Specification{
given: 'a cm handle with a READY state'
def cmHandleState = CmHandleState.READY
when: 'the state transitions to READY state'
- cmHandleState = cmHandleState.ready()
+ cmHandleState = CmHandleState.READY
then: 'the cm handle state remains as READY'
assert CmHandleState.READY == cmHandleState
}
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncSpec.groovy
index 0a06fbaa8..35de99fef 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncSpec.groovy
@@ -23,6 +23,7 @@ package org.onap.cps.ncmp.api.inventory.sync
import org.onap.cps.ncmp.api.impl.yangmodels.YangModelCmHandle
import org.onap.cps.ncmp.api.inventory.CmHandleState
+import org.onap.cps.ncmp.api.inventory.CompositeState
import spock.lang.Specification
class ModuleSyncSpec extends Specification {
@@ -37,8 +38,10 @@ class ModuleSyncSpec extends Specification {
def 'Schedule a Cm-Handle Sync for ADVISED Cm-Handles'() {
given: 'cm handles in an advised state'
- def yangModelCmHandle1 = new YangModelCmHandle(cmHandleState: cmHandleState)
- def yangModelCmHandle2 = new YangModelCmHandle(cmHandleState: cmHandleState)
+ def compositeState = new CompositeState()
+ compositeState.cmhandleState = cmHandleState
+ def yangModelCmHandle1 = new YangModelCmHandle(compositeState: compositeState)
+ def yangModelCmHandle2 = new YangModelCmHandle(compositeState: compositeState)
and: 'sync utilities return a cm handle twice'
mockSyncUtils.getAnAdvisedCmHandle() >>> [yangModelCmHandle1, yangModelCmHandle2, null]
when: 'module sync poll is executed'
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/SyncUtilsSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/SyncUtilsSpec.groovy
index e5d3652d2..c80263ef0 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/SyncUtilsSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/SyncUtilsSpec.groovy
@@ -25,6 +25,7 @@ import org.onap.cps.api.CpsDataService
import org.onap.cps.ncmp.api.impl.operations.YangModelCmHandleRetriever
import org.onap.cps.ncmp.api.impl.yangmodels.YangModelCmHandle
import org.onap.cps.ncmp.api.inventory.CmHandleState
+import org.onap.cps.ncmp.api.inventory.CompositeState
import org.onap.cps.spi.CpsDataPersistenceService
import org.onap.cps.spi.FetchDescendantsOption
import org.onap.cps.spi.model.DataNode
@@ -68,8 +69,10 @@ class SyncUtilsSpec extends Specification{
def 'Update cm handle state from Advised to Ready'() {
given: 'a yang model cm handle and the expected json data'
- def yangModelCmHandle = new YangModelCmHandle(id: 'Some-Cm-Handle', cmHandleState: CmHandleState.ADVISED)
- def expectedJsonData = '{"cm-handles":[{"id":"Some-Cm-Handle","state":"READY"}]}'
+ def compositeState = new CompositeState()
+ compositeState.cmhandleState = CmHandleState.ADVISED
+ def yangModelCmHandle = new YangModelCmHandle(id: 'Some-Cm-Handle', compositeState: compositeState )
+ def expectedJsonData = '{"cm-handles":[{"id":"Some-Cm-Handle","state":{"cm-handle-state":"READY"}}]}'
when: 'update cm handle state is called'
objectUnderTest.updateCmHandleState(yangModelCmHandle, CmHandleState.READY)
then: 'update data note leaves is invoked with the correct params'