2 * ============LICENSE_START=======================================================
3 * Copyright (C) 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
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.init
23 import org.onap.cps.api.CpsAnchorService
25 import static org.onap.cps.ncmp.api.impl.ncmppersistence.NcmpPersistence.NCMP_DATASPACE_NAME
26 import static org.onap.cps.ncmp.api.impl.ncmppersistence.NcmpPersistence.NCMP_DMI_REGISTRY_ANCHOR
28 import ch.qos.logback.classic.Level
29 import ch.qos.logback.classic.Logger
30 import ch.qos.logback.core.read.ListAppender
31 import org.onap.cps.api.CpsDataspaceService
32 import org.onap.cps.api.CpsDataService
33 import org.onap.cps.api.CpsModuleService
34 import org.onap.cps.spi.model.Dataspace
35 import org.slf4j.LoggerFactory
36 import org.springframework.boot.context.event.ApplicationReadyEvent
37 import org.springframework.context.annotation.AnnotationConfigApplicationContext
38 import spock.lang.Specification
40 class InventoryModelLoaderSpec extends Specification {
42 def mockCpsAdminService = Mock(CpsDataspaceService)
43 def mockCpsModuleService = Mock(CpsModuleService)
44 def mockCpsDataService = Mock(CpsDataService)
45 def mockCpsAnchorService = Mock(CpsAnchorService)
46 def objectUnderTest = new InventoryModelLoader(mockCpsAdminService, mockCpsModuleService, mockCpsDataService, mockCpsAnchorService)
48 def applicationContext = new AnnotationConfigApplicationContext()
50 def expectedYangResourceToContentMap
51 def logger = (Logger) LoggerFactory.getLogger(objectUnderTest.class)
52 def loggingListAppender
55 expectedYangResourceToContentMap = objectUnderTest.createYangResourcesToContentMap('dmi-registry@2023-11-27.yang')
56 logger.setLevel(Level.DEBUG)
57 loggingListAppender = new ListAppender()
58 logger.addAppender(loggingListAppender)
59 loggingListAppender.start()
60 applicationContext.refresh()
64 ((Logger) LoggerFactory.getLogger(CmDataSubscriptionModelLoader.class)).detachAndStopAllAppenders()
65 applicationContext.close()
68 def 'Onboard subscription model via application ready event.'() {
69 given: 'dataspace is ready for use'
70 mockCpsAdminService.getDataspace(NCMP_DATASPACE_NAME) >> new Dataspace('')
71 when: 'the application is ready'
72 objectUnderTest.onApplicationEvent(Mock(ApplicationReadyEvent))
73 then: 'the module service is used to create the new schema set from the correct resource'
74 1 * mockCpsModuleService.createSchemaSet(NCMP_DATASPACE_NAME, 'dmi-registry-2023-11-27', expectedYangResourceToContentMap)
75 and: 'the admin service is used to update the anchor'
76 1 * mockCpsAnchorService.updateAnchorSchemaSet(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, 'dmi-registry-2023-11-27')
77 and: 'No schema sets are being removed by the module service (yet)'
78 0 * mockCpsModuleService.deleteSchemaSet(NCMP_DATASPACE_NAME, _, _)