diff options
Diffstat (limited to 'cps-ncmp-service/src/test')
7 files changed, 58 insertions, 46 deletions
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 31cf31d777..dccba0be48 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 @@ -26,6 +26,8 @@ import org.onap.cps.api.CpsModuleService import org.onap.cps.ncmp.api.NetworkCmProxyCmHandlerQueryService import org.onap.cps.ncmp.api.impl.exception.DmiRequestException import org.onap.cps.ncmp.api.impl.operations.DmiDataOperations +import org.onap.cps.ncmp.api.impl.yangmodels.YangModelCmHandle +import org.onap.cps.ncmp.api.inventory.CmHandleState import org.onap.cps.ncmp.api.inventory.InventoryPersistence import org.onap.cps.ncmp.api.models.CmHandleRegistrationResponse import org.onap.cps.ncmp.api.models.DmiPluginRegistration @@ -150,10 +152,13 @@ class NetworkCmProxyDataServiceImplRegistrationSpec extends Specification { assert it.status == Status.SUCCESS assert it.cmHandle == 'cmhandle' } - and: 'save list elements is invoked once with the expected parameters' - 1 * mockInventoryPersistence.saveListElements(_) >> { + and: 'save cmhandle is invoked once with the expected parameters' + 1 * mockInventoryPersistence.saveCmHandle(_) >> { args -> { - assert args[0].startsWith('{"cm-handles":[{"id":"cmhandle","dmi-service-name":"my-server","state":{"cm-handle-state":"ADVISED","last-update-time":"20') + def result = (args[0] as YangModelCmHandle) + assert result.id == 'cmhandle' + assert result.dmiServiceName == 'my-server' + assert result.compositeState.cmHandleState == CmHandleState.ADVISED } } where: @@ -172,7 +177,7 @@ class NetworkCmProxyDataServiceImplRegistrationSpec extends Specification { new NcmpServiceCmHandle(cmHandleId: 'cmhandle2'), new NcmpServiceCmHandle(cmHandleId: 'cmhandle3')]) and: 'cm-handle creation is successful for 1st and 3rd; failed for 2nd' - mockInventoryPersistence.saveListElements(_) >> {} >> { throw new RuntimeException("Failed") } >> {} + mockInventoryPersistence.saveCmHandle(_) >> {} >> { throw new RuntimeException("Failed") } >> {} when: 'registration is updated to create cm-handles' def response = objectUnderTest.updateDmiRegistrationAndSyncModule(dmiPluginRegistration) then: 'a response is received for all cm-handles' @@ -200,7 +205,7 @@ class NetworkCmProxyDataServiceImplRegistrationSpec extends Specification { def dmiPluginRegistration = new DmiPluginRegistration(dmiPlugin: 'my-server') dmiPluginRegistration.createdCmHandles = [new NcmpServiceCmHandle(cmHandleId: cmHandleId)] and: 'cm-handler registration fails: #scenario' - mockInventoryPersistence.saveListElements(_) >> { throw exception } + mockInventoryPersistence.saveCmHandle(_) >> { throw exception } when: 'registration is updated' def response = objectUnderTest.updateDmiRegistrationAndSyncModule(dmiPluginRegistration) then: 'a failure response is received' diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplSpec.groovy index 1c8b561141..3febaa51bd 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplSpec.groovy @@ -69,7 +69,7 @@ class NetworkCmProxyDataServiceImplSpec extends Specification { @Shared def OPTIONS_PARAM = '(a=1,b=2)' @Shared - def ncmpServiceCmHandle = new NcmpServiceCmHandle(cmHandleId: 'some-cm-handle-id') + def ncmpServiceCmHandle = new NcmpServiceCmHandle(cmHandleId: 'test-cm-handle-id') def objectUnderTest = new NetworkCmProxyDataServiceImpl(spiedJsonObjectMapper, mockDmiDataOperations, nullNetworkCmProxyDataServicePropertyHandler, mockInventoryPersistence, mockCpsCmHandlerQueryService) @@ -270,10 +270,12 @@ class NetworkCmProxyDataServiceImplSpec extends Specification { mockDmiPluginRegistration.getCreatedCmHandles() >> [ncmpServiceCmHandle] when: 'parse and create cm handle in dmi registration then sync module' objectUnderTest.parseAndCreateCmHandlesInDmiRegistrationAndSyncModules(mockDmiPluginRegistration) - then: 'validate params for creating anchor and list elements' - 1 * mockInventoryPersistence.saveListElements(_) >> { + then: 'system persists the cm handle state' + 1 * mockInventoryPersistence.saveCmHandle(_) >> { args -> { - assert args[0].startsWith('{"cm-handles":[{"id":"some-cm-handle-id","state":{"cm-handle-state":"ADVISED","last-update-time":"20') + def result = (args[0] as YangModelCmHandle) + assert result.id == 'test-cm-handle-id' + assert result.compositeState.cmHandleState == CmHandleState.ADVISED } } } diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/event/NcmpEventsCmHandleStateHandlerImplSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/event/lcm/LcmEventsCmHandleStateHandlerImplSpec.groovy index f2e730d3a3..7a4bde07ac 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/event/NcmpEventsCmHandleStateHandlerImplSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/event/lcm/LcmEventsCmHandleStateHandlerImplSpec.groovy @@ -18,14 +18,12 @@ * ============LICENSE_END========================================================= */ -package org.onap.cps.ncmp.api.impl.event +package org.onap.cps.ncmp.api.impl.event.lcm -import com.fasterxml.jackson.databind.ObjectMapper import org.onap.cps.ncmp.api.impl.yangmodels.YangModelCmHandle import org.onap.cps.ncmp.api.inventory.CompositeState import org.onap.cps.ncmp.api.inventory.DataStoreSyncState import org.onap.cps.ncmp.api.inventory.InventoryPersistence -import org.onap.cps.utils.JsonObjectMapper import spock.lang.Specification import static org.onap.cps.ncmp.api.inventory.CmHandleState.ADVISED @@ -33,14 +31,13 @@ import static org.onap.cps.ncmp.api.inventory.CmHandleState.LOCKED import static org.onap.cps.ncmp.api.inventory.CmHandleState.READY import static org.onap.cps.ncmp.api.inventory.LockReasonCategory.LOCKED_MODULE_SYNC_FAILED -class NcmpEventsCmHandleStateHandlerImplSpec extends Specification { +class LcmEventsCmHandleStateHandlerImplSpec extends Specification { def mockInventoryPersistence = Mock(InventoryPersistence) - def mockNcmpEventsCreator = Mock(NcmpEventsCreator) - def spiedJsonObjectMapper = Spy(new JsonObjectMapper(new ObjectMapper())) - def mockNcmpEventsService = Mock(NcmpEventsService) + def mockLcmEventsCreator = Mock(LcmEventsCreator) + def mockLcmEventsService = Mock(LcmEventsService) - def objectUnderTest = new NcmpEventsCmHandleStateHandlerImpl(mockInventoryPersistence, mockNcmpEventsCreator, spiedJsonObjectMapper, mockNcmpEventsService) + def objectUnderTest = new LcmEventsCmHandleStateHandlerImpl(mockInventoryPersistence, mockLcmEventsCreator, mockLcmEventsService) def 'Update and Publish Events on State Change #stateChange'() { given: 'Cm Handle represented as YangModelCmHandle' @@ -52,7 +49,7 @@ class NcmpEventsCmHandleStateHandlerImplSpec extends Specification { then: 'state is saved using inventory persistence' expectedCallsToInventoryPersistence * mockInventoryPersistence.saveCmHandleState(cmHandleId, _) and: 'event service is called to publish event' - expectedCallsToEventService * mockNcmpEventsService.publishNcmpEvent(cmHandleId, _) + expectedCallsToEventService * mockLcmEventsService.publishLcmEvent(cmHandleId, _) where: 'state change parameters are provided' stateChange | fromCmHandleState | toCmHandleState || expectedCallsToInventoryPersistence | expectedCallsToEventService 'ADVISED to READY' | ADVISED | READY || 1 | 1 @@ -71,9 +68,9 @@ class NcmpEventsCmHandleStateHandlerImplSpec extends Specification { when: 'update state is invoked' objectUnderTest.updateCmHandleState(yangModelCmHandle, ADVISED) then: 'state is saved using inventory persistence' - 1 * mockInventoryPersistence.saveListElements(_) + 1 * mockInventoryPersistence.saveCmHandle(yangModelCmHandle) and: 'event service is called to publish event' - 1 * mockNcmpEventsService.publishNcmpEvent(cmHandleId, _) + 1 * mockLcmEventsService.publishLcmEvent(cmHandleId, _) } def 'Update and Publish Events on State Change from LOCKED to ADVISED'() { @@ -91,7 +88,7 @@ class NcmpEventsCmHandleStateHandlerImplSpec extends Specification { } } and: 'event service is called to publish event' - 1 * mockNcmpEventsService.publishNcmpEvent(cmHandleId, _) + 1 * mockLcmEventsService.publishLcmEvent(cmHandleId, _) } def 'Update and Publish Events on State Change to READY with #scenario'() { @@ -106,13 +103,14 @@ class NcmpEventsCmHandleStateHandlerImplSpec extends Specification { then: 'state is saved using inventory persistence with expected dataSyncState' 1 * mockInventoryPersistence.saveCmHandleState(cmHandleId, _) >> { args-> { - assert (args[1] as CompositeState).dataSyncEnabled == dataSyncCacheEnabled - assert (args[1] as CompositeState).dataStores.operationalDataStore.dataStoreSyncState == expectedDataStoreSyncState + def result = (args[1] as CompositeState) + assert result.dataSyncEnabled == dataSyncCacheEnabled + assert result.dataStores.operationalDataStore.dataStoreSyncState == expectedDataStoreSyncState } } and: 'event service is called to publish event' - 1 * mockNcmpEventsService.publishNcmpEvent(cmHandleId, _) + 1 * mockLcmEventsService.publishLcmEvent(cmHandleId, _) where: scenario | dataSyncCacheEnabled || expectedDataStoreSyncState 'data sync cache enabled' | true || DataStoreSyncState.UNSYNCHRONIZED diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/event/NcmpEventsCreatorSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/event/lcm/LcmEventsCreatorSpec.groovy index 24362ee47c..b578700a21 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/event/NcmpEventsCreatorSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/event/lcm/LcmEventsCreatorSpec.groovy @@ -18,24 +18,25 @@ * ============LICENSE_END========================================================= */ -package org.onap.cps.ncmp.api.impl.event +package org.onap.cps.ncmp.api.impl.event.lcm +import org.onap.cps.ncmp.api.impl.event.lcm.LcmEventsCreator import org.onap.cps.ncmp.api.inventory.CmHandleState import org.onap.cps.ncmp.api.inventory.CompositeStateBuilder import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle import spock.lang.Specification -class NcmpEventsCreatorSpec extends Specification { +class LcmEventsCreatorSpec extends Specification { - def objectUnderTest = new NcmpEventsCreator() + def objectUnderTest = new LcmEventsCreator() def cmHandleId = 'test-cm-handle' - def 'Map the NcmpEvent for operation #operation'() { + def 'Map the LcmEvent for operation #operation'() { given: 'NCMP cm handle details' def ncmpServiceCmHandle = new NcmpServiceCmHandle(cmHandleId: cmHandleId, compositeState: new CompositeStateBuilder().withCmHandleState(CmHandleState.READY).build(), publicProperties: ['publicProperty1': 'value1', 'publicProperty2': 'value2']) when: 'the event is populated' - def result = objectUnderTest.populateNcmpEvent(cmHandleId, ncmpServiceCmHandle) + def result = objectUnderTest.populateLcmEvent(cmHandleId, ncmpServiceCmHandle) then: 'event header is mapped correctly' assert result.eventSource == 'org.onap.ncmp' assert result.eventCorrelationId == cmHandleId diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/event/NcmpEventsPublisherSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/event/lcm/LcmEventsPublisherSpec.groovy index fa486d04e0..8b9addc119 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/event/NcmpEventsPublisherSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/event/lcm/LcmEventsPublisherSpec.groovy @@ -18,10 +18,11 @@ * ============LICENSE_END========================================================= */ -package org.onap.cps.ncmp.api.impl.event +package org.onap.cps.ncmp.api.impl.event.lcm import com.fasterxml.jackson.databind.ObjectMapper import org.apache.kafka.clients.consumer.KafkaConsumer +import org.onap.cps.ncmp.api.impl.event.lcm.LcmEventsPublisher import org.onap.cps.ncmp.api.utils.MessagingSpec import org.onap.cps.ncmp.utils.TestUtils import org.onap.cps.utils.JsonObjectMapper @@ -35,17 +36,17 @@ import org.testcontainers.spock.Testcontainers import java.time.Duration -@SpringBootTest(classes = [NcmpEventsPublisher, ObjectMapper, JsonObjectMapper]) +@SpringBootTest(classes = [LcmEventsPublisher, ObjectMapper, JsonObjectMapper]) @Testcontainers @DirtiesContext -class NcmpEventsPublisherSpec extends MessagingSpec { +class LcmEventsPublisherSpec extends MessagingSpec { def kafkaConsumer = new KafkaConsumer<>(consumerConfigProperties('ncmp-group')) def testTopic = 'ncmp-events-test' @SpringBean - NcmpEventsPublisher ncmpEventsPublisher = new NcmpEventsPublisher(kafkaTemplate) + LcmEventsPublisher ncmpEventsPublisher = new LcmEventsPublisher(kafkaTemplate) @Autowired JsonObjectMapper jsonObjectMapper diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/event/NcmpEventsServiceSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/event/lcm/LcmEventsServiceSpec.groovy index 8bf02c11c2..3dab5aff17 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/event/NcmpEventsServiceSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/event/lcm/LcmEventsServiceSpec.groovy @@ -18,28 +18,27 @@ * ============LICENSE_END========================================================= */ -package org.onap.cps.ncmp.api.impl.event - +package org.onap.cps.ncmp.api.impl.event.lcm import org.onap.ncmp.cmhandle.lcm.event.NcmpEvent import spock.lang.Specification -class NcmpEventsServiceSpec extends Specification { +class LcmEventsServiceSpec extends Specification { - def mockNcmpEventsPublisher = Mock(NcmpEventsPublisher) + def mockLcmEventsPublisher = Mock(LcmEventsPublisher) - def objectUnderTest = new NcmpEventsService(mockNcmpEventsPublisher) + def objectUnderTest = new LcmEventsService(mockLcmEventsPublisher) - def 'Create and Publish ncmp event where events are #scenario'() { + def 'Create and Publish lcm event where events are #scenario'() { given: 'a cm handle id and Ncmp Event' def cmHandleId = 'test-cm-handle-id' def ncmpEvent = new NcmpEvent(eventId: UUID.randomUUID().toString(), eventCorrelationId: cmHandleId) and: 'notifications enabled is #notificationsEnabled' objectUnderTest.notificationsEnabled = notificationsEnabled - when: 'service is called to publish ncmp event' - objectUnderTest.publishNcmpEvent('test-cm-handle-id', ncmpEvent) + when: 'service is called to publish lcm event' + objectUnderTest.publishLcmEvent('test-cm-handle-id', ncmpEvent) then: 'publisher is called #expectedTimesMethodCalled times' - expectedTimesMethodCalled * mockNcmpEventsPublisher.publishEvent(_, cmHandleId, ncmpEvent) + expectedTimesMethodCalled * mockLcmEventsPublisher.publishEvent(_, cmHandleId, ncmpEvent) where: 'the following values are used' scenario | notificationsEnabled || expectedTimesMethodCalled 'enabled' | true || 1 diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/InventoryPersistenceSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/InventoryPersistenceSpec.groovy index 50494c0c37..7ac231c169 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/InventoryPersistenceSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/InventoryPersistenceSpec.groovy @@ -227,11 +227,17 @@ class InventoryPersistenceSpec extends Specification { assert result == moduleReferences } - def 'Save list elements'() { - when: 'the method to save list elements is called' - objectUnderTest.saveListElements('sample Json data') + def 'Save Cmhandle'() { + given: 'cmHandle represented as Yang Model' + def yangModelCmHandle = new YangModelCmHandle(id: 'cmhandle', dmiProperties: [], publicProperties: []) + when: 'the method to save cmhandle is called' + objectUnderTest.saveCmHandle(yangModelCmHandle) then: 'the data service method to save list elements is called once' - 1 * mockCpsDataService.saveListElements('NCMP-Admin','ncmp-dmi-registry','/dmi-registry','sample Json data',null) + 1 * mockCpsDataService.saveListElements('NCMP-Admin','ncmp-dmi-registry','/dmi-registry',_,null) >> { + args -> { + assert args[3].startsWith('{"cm-handles":[{"id":"cmhandle","additional-properties":[],"public-properties":[]}]}') + } + } } def 'Delete list or list elements'() { |