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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.cps.ncmp.api.inventory
23 import com.fasterxml.jackson.databind.ObjectMapper
24 import spock.lang.Specification
25 import java.time.OffsetDateTime
26 import java.time.ZoneOffset
27 import java.time.format.DateTimeFormatter
29 import static org.onap.cps.ncmp.api.inventory.CompositeState.DataStores
30 import static org.onap.cps.ncmp.api.inventory.CompositeState.Operational
31 import static org.onap.cps.ncmp.utils.TestUtils.getResourceFileContent
32 import static org.springframework.util.StringUtils.trimAllWhitespace
34 class CompositeStateSpec extends Specification {
36 def formattedDateAndTime = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSZ")
37 .format(OffsetDateTime.of(2022, 12, 31, 20, 30, 40, 1, ZoneOffset.UTC))
38 def objectMapper = new ObjectMapper()
40 def "Composite State Specification"() {
41 given: "a Composite State"
42 def compositeState = new CompositeState(cmHandleState: CmHandleState.ADVISED,
43 lockReason: CompositeState.LockReason.builder().lockReasonCategory(LockReasonCategory.LOCKED_MODULE_SYNC_FAILED).details("lock details").build(),
44 lastUpdateTime: formattedDateAndTime.toString(),
45 dataSyncEnabled: false,
46 dataStores: dataStores())
47 when: 'it is represented as JSON'
48 def resultJson = objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(compositeState)
49 then: 'it matches expected state model as JSON'
50 def expectedJson = getResourceFileContent('expectedStateModel.json')
51 assert trimAllWhitespace(expectedJson) == trimAllWhitespace(resultJson)
55 DataStores.builder().operationalDataStore(Operational.builder()
56 .dataStoreSyncState(DataStoreSyncState.NONE_REQUESTED)
57 .lastSyncTime(formattedDateAndTime.toString()).build())