2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2021-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.impl
23 import org.onap.cps.api.CpsAdminService
24 import org.onap.cps.api.CpsModuleService
25 import org.onap.cps.ncmp.api.impl.operations.DmiDataOperations
26 import org.onap.cps.ncmp.api.impl.operations.DmiModelOperations
27 import org.onap.cps.ncmp.api.models.CmHandle
28 import org.onap.cps.ncmp.api.models.PersistenceCmHandle
29 import org.onap.cps.spi.model.ModuleReference
30 import org.onap.cps.utils.JsonObjectMapper
31 import spock.lang.Specification
33 class NetworkCmProxyDataServiceImplModelSyncSpec extends Specification {
35 def mockJsonObjectMapper = Mock(JsonObjectMapper)
36 def mockCpsModuleService = Mock(CpsModuleService)
37 def mockCpsAdminService = Mock(CpsAdminService)
38 def mockDmiModelOperations = Mock(DmiModelOperations)
39 def mockDmiDataOperations = Mock(DmiDataOperations)
41 def objectUnderTest = new NetworkCmProxyDataServiceImpl(null, mockJsonObjectMapper, mockDmiDataOperations, mockDmiModelOperations,
42 mockCpsModuleService, mockCpsAdminService)
44 def expectedDataspaceName = 'NFP-Operational'
46 def 'Sync model for a (new) cm handle with #scenario'() {
47 given: 'persistence cm handle is given'
48 def cmHandle = new CmHandle()
49 def dmiServiceName = 'some service name'
50 cmHandle.cmHandleID = 'cm handle id 1'
51 cmHandle.dmiProperties = dmiProperties
52 def persistenceCmHandle = PersistenceCmHandle.toPersistenceCmHandle(dmiServiceName, '' , '', cmHandle)
53 and: 'DMI operations returns some module references'
54 def moduleReferences = [ new ModuleReference(moduleName:'module1',revision:'1'),
55 new ModuleReference(moduleName:'module2',revision:'2') ]
56 mockDmiModelOperations.getModuleReferences(persistenceCmHandle) >> moduleReferences
57 and: 'CPS-Core returns list of existing module resources'
58 mockCpsModuleService.getYangResourceModuleReferences(expectedDataspaceName) >> existingModuleResourcesInCps
59 and: 'DMI-Plugin returns resource(s) for "new" module(s)'
60 mockDmiModelOperations.getNewYangResourcesFromDmi(persistenceCmHandle, [new ModuleReference('module1', '1')]) >> yangResourceToContentMap
61 when: 'module sync is triggered'
62 objectUnderTest.syncModulesAndCreateAnchor(persistenceCmHandle)
63 then: 'the CPS module service is called once with the correct parameters'
64 1 * mockCpsModuleService.createSchemaSetFromModules(expectedDataspaceName, persistenceCmHandle.getId(), yangResourceToContentMap, expectedKnownModules)
65 and: 'admin service create anchor method has been called with correct parameters'
66 1 * mockCpsAdminService.createAnchor(expectedDataspaceName, persistenceCmHandle.getId(), persistenceCmHandle.getId())
67 where: 'the following parameters are used'
68 scenario | dmiProperties | existingModuleResourcesInCps | yangResourceToContentMap || expectedKnownModules
69 'one unknown module' | ['name1': 'value1'] | [new ModuleReference('module2', '2'), new ModuleReference('module3', '3')] | [module1: 'some yang source'] || [new ModuleReference('module2', '2')]
70 'no add. properties' | [:] | [new ModuleReference('module2', '2'), new ModuleReference('module3', '3')] | [module1: 'some yang source'] || [new ModuleReference('module2', '2')]
71 'no unknown module' | [:] | [new ModuleReference('module1', '1'), new ModuleReference('module2', '2')] | [:] || [new ModuleReference('module1', '1'), new ModuleReference('module2', '2')]