Fixing minor compilation
[cps.git] / cps-ncmp-service / src / test / groovy / org / onap / cps / ncmp / api / inventory / CompositeStateSpec.groovy
1 /*
2  * ============LICENSE_START=======================================================
3  * Copyright (C) 2022 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.inventory
22
23 import com.fasterxml.jackson.databind.ObjectMapper
24 import spock.lang.Specification
25
26 import java.time.OffsetDateTime
27 import java.time.ZoneOffset
28 import java.time.format.DateTimeFormatter
29
30 import static org.onap.cps.ncmp.api.inventory.CompositeState.DataStores
31 import static org.onap.cps.ncmp.api.inventory.CompositeState.Operational
32 import static org.onap.cps.ncmp.utils.TestUtils.getResourceFileContent
33 import static org.springframework.util.StringUtils.trimAllWhitespace
34
35 class CompositeStateSpec extends Specification {
36
37     def formattedDateAndTime = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSZ")
38         .format(OffsetDateTime.of(2022, 12, 31, 20, 30, 40, 1, ZoneOffset.UTC))
39     def objectMapper = new ObjectMapper()
40
41     def "Composite State Specification"() {
42         given: "a Composite State"
43             def compositeState = new CompositeState(cmHandleState: CmHandleState.ADVISED,
44                 lockReason: CompositeState.LockReason.builder().lockReasonCategory(LockReasonCategory.LOCKED_MODULE_SYNC_FAILED).details("lock details").build(),
45                 lastUpdateTime: formattedDateAndTime.toString(),
46                 dataSyncEnabled: false,
47                 dataStores: dataStores())
48         when: 'it is represented as JSON'
49             def resultJson = objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(compositeState)
50         then: 'it matches expected state model as JSON'
51             def expectedJson = getResourceFileContent('expectedStateModel.json')
52             assert trimAllWhitespace(expectedJson) == trimAllWhitespace(resultJson)
53     }
54
55     def dataStores() {
56         DataStores.builder().operationalDataStore(Operational.builder()
57             .dataStoreSyncState(DataStoreSyncState.NONE_REQUESTED)
58             .lastSyncTime(formattedDateAndTime.toString()).build())
59             .build()
60     }
61 }