2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2021 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
24 import org.onap.cps.api.CpsAdminService
25 import org.onap.cps.api.CpsModuleService
26 import org.onap.cps.ncmp.api.impl.operations.DmiModelOperations
27 import org.onap.cps.ncmp.api.models.PersistenceCmHandle
28 import org.onap.cps.ncmp.utils.TestUtils
29 import org.onap.cps.spi.model.ModuleReference
30 import org.springframework.http.HttpStatus
31 import org.springframework.http.ResponseEntity
32 import spock.lang.Specification
34 class NetworkCmProxyDataServiceImplModelSyncSpec extends Specification {
36 def mockCpsModuleService = Mock(CpsModuleService)
37 def mockCpsAdminService = Mock(CpsAdminService)
38 def mockDmiModelOperations = Mock(DmiModelOperations)
40 def objectUnderTest = new NetworkCmProxyDataServiceImpl(null, mockDmiModelOperations,
41 mockCpsModuleService, null, null, mockCpsAdminService, null)
43 def expectedDataspaceName = 'NFP-Operational'
45 def 'Sync model for a (new) cm handle with #scenario'() {
46 given: 'persistence cm handle is given'
47 def cmHandleForModelSync = new PersistenceCmHandle(id:'some cm handle', dmiServiceName: 'some service name')
48 and: 'additional properties are set as required'
49 if (additionalProperties!=null) {
50 cmHandleForModelSync.asAdditionalProperties(additionalProperties)
52 and: 'dmi operations returns some module references'
53 def jsonData = TestUtils.getResourceFileContent('cmHandleModules.json')
54 def moduleReferencesFromCmHandleAsJson = new ResponseEntity<String>(jsonData, HttpStatus.OK)
55 mockDmiModelOperations.getModuleReferences(cmHandleForModelSync) >> moduleReferencesFromCmHandleAsJson
56 and: 'CPS-Core returns list of existing module resources'
57 mockCpsModuleService.getYangResourceModuleReferences(expectedDataspaceName) >> existingModuleResourcesInCps
58 and: 'DMI-Plugin returns resource(s) for "new" module(s)'
59 def moduleResources = new ResponseEntity<String>(sdncReponseBody, HttpStatus.OK)
60 mockDmiModelOperations.getNewYangResourcesFromDmi(cmHandleForModelSync, [new ModuleReference('module1', '1')]) >> moduleResources
61 when: 'module sync is triggered'
62 objectUnderTest.syncModulesAndCreateAnchor(cmHandleForModelSync)
63 then: 'the CPS module service is called once with the correct parameters'
64 1 * mockCpsModuleService.createSchemaSetFromModules(expectedDataspaceName, cmHandleForModelSync.getId(), expectedYangResourceToContentMap, expectedKnownModules)
65 and: 'admin service create anchor method has been called with correct parameters'
66 1 * mockCpsAdminService.createAnchor(expectedDataspaceName, cmHandleForModelSync.getId(), cmHandleForModelSync.getId())
67 where: 'the following parameters are used'
68 scenario | additionalProperties | existingModuleResourcesInCps | sdncReponseBody || expectedYangResourceToContentMap | expectedKnownModules | expectedJsonForAdditionalProperties
69 'one unknown module' | ['name1': 'value1'] | [new ModuleReference('module2', '2'), new ModuleReference('module3', '3')] | '[{"moduleName" : "module1", "revision" : "1","yangSource": "some yang source"}]' || [module1: 'some yang source'] | [new ModuleReference('module2', '2')] | '{"name1":"value1"}'
70 'no add. properties' | [:] | [new ModuleReference('module2', '2'), new ModuleReference('module3', '3')] | '[{"moduleName" : "module1", "revision" : "1","yangSource": "some yang source"}]' || [module1: 'some yang source'] | [new ModuleReference('module2', '2')] | '{}'
71 'additional properties is null' | null | [new ModuleReference('module2', '2'), new ModuleReference('module3', '3')] | '[{"moduleName" : "module1", "revision" : "1","yangSource": "some yang source"}]' || [module1: 'some yang source'] | [new ModuleReference('module2', '2')] | '{}'
72 'no unknown module' | [:] | [new ModuleReference('module1', '1'), new ModuleReference('module2', '2')] | '[]' || [:] | [new ModuleReference('module1', '1'), new ModuleReference('module2', '2')] | '{}'