X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=cps-ncmp-service%2Fsrc%2Ftest%2Fgroovy%2Forg%2Fonap%2Fcps%2Fncmp%2Fapi%2Fimpl%2FNetworkCmProxyDataServiceImplRegistrationSpec.groovy;h=3ec6f3a00d0d367e3ae243b373af94cc95016c3c;hb=63132cec2c18363a8224646039cc23b6144d8e6c;hp=41084541c2a1a7d5cf5d14feff53daa1b6942e4d;hpb=5af63eb8c5a32180f1c1d52048fe3390305dc4ac;p=cps.git diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplRegistrationSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplRegistrationSpec.groovy index 41084541c..3ec6f3a00 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplRegistrationSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplRegistrationSpec.groovy @@ -1,6 +1,6 @@ /* * ============LICENSE_START======================================================= - * Copyright (C) 2021 Nordix Foundation + * Copyright (C) 2021-2022 Nordix Foundation * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,13 +22,17 @@ package org.onap.cps.ncmp.api.impl import com.fasterxml.jackson.core.JsonProcessingException import com.fasterxml.jackson.databind.ObjectMapper +import org.onap.cps.api.CpsAdminService import org.onap.cps.api.CpsDataService import org.onap.cps.api.CpsModuleService import org.onap.cps.ncmp.api.impl.exception.NcmpException +import org.onap.cps.ncmp.api.impl.operations.DmiDataOperations +import org.onap.cps.ncmp.api.impl.operations.DmiModelOperations import org.onap.cps.ncmp.api.models.CmHandle import org.onap.cps.ncmp.api.models.DmiPluginRegistration import org.onap.cps.spi.exceptions.DataNodeNotFoundException import org.onap.cps.spi.exceptions.DataValidationException +import org.onap.cps.utils.JsonObjectMapper import spock.lang.Shared import spock.lang.Specification @@ -44,7 +48,10 @@ class NetworkCmProxyDataServiceImplRegistrationSpec extends Specification { def mockCpsDataService = Mock(CpsDataService) def mockCpsModuleService = Mock(CpsModuleService) - def spyObjectMapper = Spy(ObjectMapper) + def spiedJsonObjectMapper = Spy(new JsonObjectMapper(new ObjectMapper())) + def mockCpsAdminService = Mock(CpsAdminService) + def mockDmiModelOperations = Mock(DmiModelOperations) + def mockDmiDataOperations = Mock(DmiDataOperations) def noTimestamp = null @@ -53,11 +60,15 @@ class NetworkCmProxyDataServiceImplRegistrationSpec extends Specification { def objectUnderTest = getObjectUnderTestWithModelSyncDisabled() def dmiPluginRegistration = new DmiPluginRegistration(dmiPlugin:'my-server') persistenceCmHandle.cmHandleID = '123' - persistenceCmHandle.cmHandleProperties = [name1: 'value1', name2: 'value2'] + persistenceCmHandle.dmiProperties = [dmiProp1: 'dmiValue1', dmiProp2: 'dmiValue2'] + persistenceCmHandle.publicProperties = [publicProp1: 'publicValue1', publicProp2: 'publicValue2' ] dmiPluginRegistration.createdCmHandles = createdCmHandles dmiPluginRegistration.updatedCmHandles = updatedCmHandles dmiPluginRegistration.removedCmHandles = removedCmHandles - def expectedJsonData = '{"cm-handles":[{"id":"123","dmi-service-name":"my-server","dmi-data-service-name":null,"dmi-model-service-name":null,"additional-properties":[{"name":"name1","value":"value1"},{"name":"name2","value":"value2"}]}]}' + def expectedJsonData = '{"cm-handles":[{"id":"123","dmi-service-name":"my-server","dmi-data-service-name":null,"dmi-model-service-name":null,' + + '"additional-properties":[{"name":"dmiProp1","value":"dmiValue1"},{"name":"dmiProp2","value":"dmiValue2"}],' + + '"public-properties":[{"name":"publicProp1","value":"publicValue1"},{"name":"publicProp2","value":"publicValue2"}]' + + '}]}' when: 'registration is updated and modules are synced' objectUnderTest.updateDmiRegistrationAndSyncModule(dmiPluginRegistration) then: 'save list elements is invoked with the expected parameters' @@ -80,14 +91,15 @@ class NetworkCmProxyDataServiceImplRegistrationSpec extends Specification { 'no valid data' | null | null | null || 0 | 0 | 0 } - def 'Register a DMI Plugin for the given cm-handle(s) without additional properties.'() { + def 'Register a DMI Plugin for the given cm-handle(s) without DMI properties.'() { given: 'a registration without cm-handle properties' NetworkCmProxyDataServiceImpl objectUnderTest = getObjectUnderTestWithModelSyncDisabled() def dmiPluginRegistration = new DmiPluginRegistration(dmiPlugin:'my-server') persistenceCmHandle.cmHandleID = '123' - persistenceCmHandle.cmHandleProperties = null + persistenceCmHandle.dmiProperties = Collections.emptyMap() + persistenceCmHandle.publicProperties = Collections.emptyMap() dmiPluginRegistration.createdCmHandles = [persistenceCmHandle] - def expectedJsonData = '{"cm-handles":[{"id":"123","dmi-service-name":"my-server","dmi-data-service-name":null,"dmi-model-service-name":null,"additional-properties":[]}]}' + def expectedJsonData = '{"cm-handles":[{"id":"123","dmi-service-name":"my-server","dmi-data-service-name":null,"dmi-model-service-name":null,"additional-properties":[],"public-properties":[]}]}' when: 'registration is updated' objectUnderTest.updateDmiRegistrationAndSyncModule(dmiPluginRegistration) then: 'save list elements is invoked with the expected parameters' @@ -102,7 +114,7 @@ class NetworkCmProxyDataServiceImplRegistrationSpec extends Specification { dmiPluginRegistration.createdCmHandles = createdCmHandles dmiPluginRegistration.updatedCmHandles = updatedCmHandles and: 'an json processing exception occurs' - spyObjectMapper.writeValueAsString(_) >> { throw (new JsonProcessingException('')) } + spiedJsonObjectMapper.asJsonString(_) >> { throw (new JsonProcessingException('')) } when: 'registration is updated and modules are synced' objectUnderTest.updateDmiRegistrationAndSyncModule(dmiPluginRegistration) then: 'a data validation exception is thrown' @@ -126,6 +138,19 @@ class NetworkCmProxyDataServiceImplRegistrationSpec extends Specification { noExceptionThrown() } + def 'Register a DMI Plugin for the given cm-handle(s) with no schema set found during delete process.'() { + given: 'a registration' + def objectUnderTest = getObjectUnderTestWithModelSyncDisabled() + def dmiPluginRegistration = new DmiPluginRegistration(dmiPlugin:'my-server') + dmiPluginRegistration.removedCmHandles = cmHandlesArray + and: 'an exception occurs during delete schema set process' + mockCpsModuleService.deleteSchemaSet(_,_,_) >> { throw (new Exception('')) } + when: 'registration is updated and modules are synced' + objectUnderTest.updateDmiRegistrationAndSyncModule(dmiPluginRegistration) + then: 'delete list or list element is still called' + 1 * mockCpsDataService.deleteListOrListElement(_,_,_,_) + } + def 'Dmi plugin registration with #scenario'() { given: 'a registration ' def objectUnderTest = getObjectUnderTestWithModelSyncDisabled() @@ -143,7 +168,7 @@ class NetworkCmProxyDataServiceImplRegistrationSpec extends Specification { 'data & model using same service' | '' | 'service1' | 'service1' } - def 'Invalid dmi plugin registration with #scenario'() { + def 'Invalid DMI plugin registration with #scenario'() { given: 'a registration ' def objectUnderTest = getObjectUnderTestWithModelSyncDisabled() def dmiPluginRegistration = new DmiPluginRegistration(dmiPlugin:dmiPlugin, dmiModelPlugin:dmiModelPlugin, @@ -157,16 +182,20 @@ class NetworkCmProxyDataServiceImplRegistrationSpec extends Specification { and: 'registration is not called' 0 * objectUnderTest.parseAndCreateCmHandlesInDmiRegistrationAndSyncModules(dmiPluginRegistration) where: - scenario | dmiPlugin | dmiModelPlugin | dmiDataPlugin || expectedMessageDetails - 'no DMI plugin' | '' | '' | '' || 'No DMI plugin service names' - 'all DMI plugins' | 'service1' | 'service2' | 'service3' || 'Invalid combination of plugin service names' - 'no model DMI plugin' | 'service1' | '' | 'service2' || 'Invalid combination of plugin service names' - 'no data DMI plugin' | 'service1' | 'service2' | '' || 'Invalid combination of plugin service names' + scenario | dmiPlugin | dmiModelPlugin | dmiDataPlugin || expectedMessageDetails + 'empty DMI plugins' | '' | '' | '' || 'No DMI plugin service names' + 'blank DMI plugins' | ' ' | ' ' | ' ' || 'No DMI plugin service names' + 'null DMI plugins' | null | null | null || 'No DMI plugin service names' + 'all DMI plugins' | 'service1' | 'service2' | 'service3' || 'Cannot register combined plugin service name and other service names' + '(combined)DMI and Data Plugin' | 'service1' | '' | 'service2' || 'Cannot register combined plugin service name and other service names' + '(combined)DMI and model Plugin'| 'service1' | 'service2' | '' || 'Cannot register combined plugin service name and other service names' + 'only model DMI plugin' | '' | 'service1' | '' || 'Cannot register just a Data or Model plugin service name' + 'only data DMI plugin' | '' | '' | 'service1' || 'Cannot register just a Data or Model plugin service name' } def getObjectUnderTestWithModelSyncDisabled() { - def objectUnderTest = Spy(new NetworkCmProxyDataServiceImpl(null, null, mockCpsModuleService, - mockCpsDataService, null, null, spyObjectMapper)) + def objectUnderTest = Spy(new NetworkCmProxyDataServiceImpl(mockCpsDataService, spiedJsonObjectMapper, mockDmiDataOperations, mockDmiModelOperations, + mockCpsModuleService, mockCpsAdminService)) objectUnderTest.syncModulesAndCreateAnchor(*_) >> null return objectUnderTest }