Update Model to allow Persisting of alternateId
[cps.git] / cps-ncmp-service / src / test / groovy / org / onap / cps / ncmp / api / models / NcmpServiceCmHandleSpec.groovy
1 /*
2  *  ============LICENSE_START=======================================================
3  *  Copyright (C) 2022-2023 Nordix Foundation
4  *  ================================================================================
5  *  Licensed under the Apache License, Version 2.0 (the "License");
6  *  you may not use this file except in compliance with the License.
7  *  You may obtain a copy of the License at
8  *
9  *        http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *  Unless required by applicable law or agreed to in writing, software
12  *  distributed under the License is distributed on an "AS IS" BASIS,
13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *  See the License for the specific language governing permissions and
15  *  limitations under the License.
16  *
17  *  SPDX-License-Identifier: Apache-2.0
18  *  ============LICENSE_END=========================================================
19  */
20
21 package org.onap.cps.ncmp.api.models
22
23 import org.onap.cps.ncmp.api.impl.inventory.CmHandleState
24 import org.onap.cps.ncmp.api.impl.inventory.CompositeState
25 import spock.lang.Specification
26
27 class NcmpServiceCmHandleSpec extends Specification {
28
29
30     def 'NCMP Service CmHandle check for deep copy operation'() {
31         given: 'ncmp service cm handle'
32             def originalNcmpServiceCmHandle = new NcmpServiceCmHandle(cmHandleId: 'cmhandleid',
33                 dmiProperties: ['property1': 'value1', 'property2': 'value2'],
34                 publicProperties: ['pubproperty1': 'value1', 'pubproperty2': 'value2'],
35                 compositeState: new CompositeState(cmHandleState: CmHandleState.ADVISED, dataSyncEnabled: Boolean.FALSE))
36         when: 'we create a deep copy'
37             def deepCopiedNcmpServiceCmHandle = new NcmpServiceCmHandle(originalNcmpServiceCmHandle)
38         and: 'we change the original ncmp service cmhandle'
39             originalNcmpServiceCmHandle.dmiProperties = ['newProperty1': 'newValue1']
40             originalNcmpServiceCmHandle.publicProperties = ['newPublicProperty1': 'newPubValue1']
41             originalNcmpServiceCmHandle.compositeState = new CompositeState(cmHandleState: CmHandleState.DELETED, dataSyncEnabled: Boolean.TRUE)
42         then: 'no change in the copied dmi and public properties of ncmp service cmhandle'
43             deepCopiedNcmpServiceCmHandle.dmiProperties == ['property1': 'value1', 'property2': 'value2']
44             deepCopiedNcmpServiceCmHandle.publicProperties == ['pubproperty1': 'value1', 'pubproperty2': 'value2']
45         and: 'no change in the composite state'
46             deepCopiedNcmpServiceCmHandle.compositeState.cmHandleState == CmHandleState.ADVISED
47             deepCopiedNcmpServiceCmHandle.compositeState.dataSyncEnabled == Boolean.FALSE
48     }
49
50 }