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=b954b41ef2aee8853e0c1898c2c84081022d5f90;hb=05e7b8a207b1c641468e77d754fe1a5ae9e1a51e;hp=86c01b40736198144a89ef9c2cd375809f613c89;hpb=20b4f9cf0b662de4a7665b2a82593ef0205f5e06;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 86c01b407..b954b41ef 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,15 +22,22 @@ 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 +import static org.onap.cps.spi.CascadeDeleteAllowed.CASCADE_DELETE_ALLOWED + class NetworkCmProxyDataServiceImplRegistrationSpec extends Specification { @Shared @@ -40,7 +47,11 @@ class NetworkCmProxyDataServiceImplRegistrationSpec extends Specification { def cmHandlesArray = ['cmHandle001'] def mockCpsDataService = Mock(CpsDataService) - def spyObjectMapper = Spy(ObjectMapper) + def mockCpsModuleService = Mock(CpsModuleService) + def spiedJsonObjectMapper = Spy(new JsonObjectMapper(new ObjectMapper())) + def mockCpsAdminService = Mock(CpsAdminService) + def mockDmiModelOperations = Mock(DmiModelOperations) + def mockDmiDataOperations = Mock(DmiDataOperations) def noTimestamp = null @@ -62,16 +73,18 @@ class NetworkCmProxyDataServiceImplRegistrationSpec extends Specification { and: 'update node and child data nodes is invoked with correct parameters' expectedCallsToUpdateNode * mockCpsDataService.updateNodeLeavesAndExistingDescendantLeaves('NCMP-Admin', 'ncmp-dmi-registry', '/dmi-registry', expectedJsonData, noTimestamp) - and : 'delete list or list element is invoked with the correct parameters' - expectedCallsToDeleteListElement * mockCpsDataService.deleteListOrListElement('NCMP-Admin', + and: 'delete schema set is invoked with the correct parameters' + expectedCallsToDeleteSchemaSetAndListElement * mockCpsModuleService.deleteSchemaSet('NFP-Operational', 'cmHandle001', CASCADE_DELETE_ALLOWED) + and: 'delete list or list element is invoked with the correct parameters' + expectedCallsToDeleteSchemaSetAndListElement * mockCpsDataService.deleteListOrListElement('NCMP-Admin', 'ncmp-dmi-registry', "/dmi-registry/cm-handles[@id='cmHandle001']", noTimestamp) where: - scenario | createdCmHandles | updatedCmHandles | removedCmHandles || expectedCallsToSaveNode | expectedCallsToUpdateNode | expectedCallsToDeleteListElement - 'create' | [persistenceCmHandle] | [] | [] || 1 | 0 | 0 - 'update' | [] | [persistenceCmHandle] | [] || 0 | 1 | 0 - 'delete' | [] | [] | cmHandlesArray || 0 | 0 | 1 - 'create, update and delete' | [persistenceCmHandle] | [persistenceCmHandle] | cmHandlesArray || 1 | 1 | 1 - 'no valid data' | null | null | null || 0 | 0 | 0 + scenario | createdCmHandles | updatedCmHandles | removedCmHandles || expectedCallsToSaveNode | expectedCallsToUpdateNode | expectedCallsToDeleteSchemaSetAndListElement + 'create' | [persistenceCmHandle] | [] | [] || 1 | 0 | 0 + 'update' | [] | [persistenceCmHandle] | [] || 0 | 1 | 0 + 'delete' | [] | [] | cmHandlesArray || 0 | 0 | 1 + 'create, update and delete' | [persistenceCmHandle] | [persistenceCmHandle] | cmHandlesArray || 1 | 1 | 1 + 'no valid data' | null | null | null || 0 | 0 | 0 } def 'Register a DMI Plugin for the given cm-handle(s) without additional properties.'() { @@ -96,7 +109,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' @@ -120,6 +133,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() @@ -151,16 +177,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, null, - mockCpsDataService, null, null, spyObjectMapper)) + def objectUnderTest = Spy(new NetworkCmProxyDataServiceImpl(mockCpsDataService, spiedJsonObjectMapper, mockDmiDataOperations, mockDmiModelOperations, + mockCpsModuleService, mockCpsAdminService)) objectUnderTest.syncModulesAndCreateAnchor(*_) >> null return objectUnderTest }