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 ch.qos.logback.classic.Level
24 import ch.qos.logback.classic.Logger
25 import ch.qos.logback.core.read.ListAppender
26 import org.onap.cps.api.CpsAdminService
27 import org.onap.cps.api.CpsDataService
28 import org.onap.cps.api.CpsModuleService
29 import org.onap.cps.spi.model.Dataspace
30 import org.slf4j.LoggerFactory
31 import org.springframework.boot.context.event.ApplicationReadyEvent
32 import org.springframework.context.annotation.AnnotationConfigApplicationContext
33 import spock.lang.Specification
35 class InventoryModelLoaderSpec extends Specification {
37 def mockCpsAdminService = Mock(CpsAdminService)
38 def mockCpsModuleService = Mock(CpsModuleService)
39 def mockCpsDataService = Mock(CpsDataService)
40 def objectUnderTest = new InventoryModelLoader(mockCpsAdminService, mockCpsModuleService, mockCpsDataService)
42 def applicationContext = new AnnotationConfigApplicationContext()
44 def expectedYangResourceToContentMap
45 def logger = (Logger) LoggerFactory.getLogger(objectUnderTest.class)
46 def loggingListAppender
49 expectedYangResourceToContentMap = objectUnderTest.createYangResourceToContentMap('dmi-registry@2023-08-23.yang')
50 logger.setLevel(Level.DEBUG)
51 loggingListAppender = new ListAppender()
52 logger.addAppender(loggingListAppender)
53 loggingListAppender.start()
54 applicationContext.refresh()
58 ((Logger) LoggerFactory.getLogger(SubscriptionModelLoader.class)).detachAndStopAllAppenders()
59 applicationContext.close()
62 def 'Onboard subscription model via application ready event.'() {
63 given: 'dataspace is ready for use'
64 mockCpsAdminService.getDataspace('NCMP-Admin') >> new Dataspace('')
65 when: 'the application is ready'
66 objectUnderTest.onApplicationEvent(Mock(ApplicationReadyEvent))
67 then: 'the module service is used to create the new schema set from the correct resource'
68 1 * mockCpsModuleService.createSchemaSet('NCMP-Admin', 'dmi-registry-2023-08-23', expectedYangResourceToContentMap)
69 and: 'the admin service is used to update the anchor'
70 1 * mockCpsAdminService.updateAnchorSchemaSet('NCMP-Admin', 'ncmp-dmi-registry', 'dmi-registry-2023-08-23')
71 and: 'No schema sets are being removed by the module service (yet)'
72 0 * mockCpsModuleService.deleteSchemaSet('NCMP-Admin', _, _)