diff options
Diffstat (limited to 'cps-ncmp-service')
2 files changed, 40 insertions, 10 deletions
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/lcm/LcmEventsCmHandleStateHandlerImpl.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/lcm/LcmEventsCmHandleStateHandlerImpl.java index 2f77ec3204..ce19712c08 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/lcm/LcmEventsCmHandleStateHandlerImpl.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/lcm/LcmEventsCmHandleStateHandlerImpl.java @@ -100,14 +100,13 @@ public class LcmEventsCmHandleStateHandlerImpl implements LcmEventsCmHandleState cmHandleTransitionPairs.add(cmHandleTransitionPair); } }); - return cmHandleTransitionPairs; } private void persistCmHandle(final YangModelCmHandle targetYangModelCmHandle, final YangModelCmHandle currentYangModelCmHandle) { - if (isNew(currentYangModelCmHandle.getCompositeState(), targetYangModelCmHandle.getCompositeState())) { + if (isNew(currentYangModelCmHandle.getCompositeState())) { log.debug("Registering a new cm handle {}", targetYangModelCmHandle.getId()); inventoryPersistence.saveCmHandle(targetYangModelCmHandle); } else if (isDeleted(targetYangModelCmHandle.getCompositeState())) { @@ -124,8 +123,8 @@ public class LcmEventsCmHandleStateHandlerImpl implements LcmEventsCmHandleState final Map<String, CompositeState> compositeStatePerCmHandleId = new LinkedHashMap<>(); cmHandleTransitionPairs.forEach(cmHandleTransitionPair -> { - if (isNew(cmHandleTransitionPair.getCurrentYangModelCmHandle().getCompositeState(), - cmHandleTransitionPair.getTargetYangModelCmHandle().getCompositeState())) { + if (isNew(cmHandleTransitionPair.getCurrentYangModelCmHandle().getCompositeState() + )) { newCmHandles.add(cmHandleTransitionPair.getTargetYangModelCmHandle()); } else if (!isDeleted(cmHandleTransitionPair.getTargetYangModelCmHandle().getCompositeState())) { compositeStatePerCmHandleId.put(cmHandleTransitionPair.getTargetYangModelCmHandle().getId(), @@ -172,8 +171,8 @@ public class LcmEventsCmHandleStateHandlerImpl implements LcmEventsCmHandleState CompositeStateUtils.setCompositeState(targetCmHandleState).accept(yangModelCmHandle.getCompositeState()); } - private boolean isNew(final CompositeState existingCompositeState, final CompositeState targetCompositeState) { - return (existingCompositeState == null && targetCompositeState.getCmHandleState() == ADVISED); + private boolean isNew(final CompositeState existingCompositeState) { + return (existingCompositeState == null); } private boolean isDeleted(final CompositeState targetCompositeState) { diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/events/lcm/LcmEventsCmHandleStateHandlerImplSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/events/lcm/LcmEventsCmHandleStateHandlerImplSpec.groovy index bfebc44bae..261b6e069d 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/events/lcm/LcmEventsCmHandleStateHandlerImplSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/events/lcm/LcmEventsCmHandleStateHandlerImplSpec.groovy @@ -63,7 +63,7 @@ class LcmEventsCmHandleStateHandlerImplSpec extends Specification { 'ADVISED to ADVISED' | ADVISED | ADVISED || 0 | 0 'READY to READY' | READY | READY || 0 | 0 'LOCKED to LOCKED' | LOCKED | LOCKED || 0 | 0 - + 'DELETED to ADVISED' | DELETED | ADVISED || 0 | 1 } def 'Update and Publish Events on State Change from NO_EXISTING state to ADVISED'() { @@ -94,6 +94,17 @@ class LcmEventsCmHandleStateHandlerImplSpec extends Specification { 1 * mockLcmEventsService.publishLcmEvent(cmHandleId, _, _) } + def 'Update and Publish Events on State Change from DELETING to ADVISED'() { + given: 'Cm Handle represented as YangModelCmHandle in DELETING state' + yangModelCmHandle = new YangModelCmHandle(id: cmHandleId, dmiProperties: [], publicProperties: [], compositeState: compositeState) + when: 'update state is invoked' + objectUnderTest.updateCmHandleState(yangModelCmHandle, ADVISED) + then: 'the cm handle is saved using inventory persistence' + 1 * mockInventoryPersistence.saveCmHandle(yangModelCmHandle) + and: 'event service is called to publish event' + 1 * mockLcmEventsService.publishLcmEvent(cmHandleId, _, _) + } + def 'Update and Publish Events on State Change to READY'() { given: 'Cm Handle represented as YangModelCmHandle' compositeState = new CompositeState(cmHandleState: ADVISED) @@ -167,7 +178,7 @@ class LcmEventsCmHandleStateHandlerImplSpec extends Specification { assert (args[0] as Collection<YangModelCmHandle>).id.containsAll('cmhandle1', 'cmhandle2') } } - and: 'event service is called to publish event' + and: 'event service is called to publish events' 2 * mockLcmEventsService.publishLcmEvent(_, _, _) } @@ -183,9 +194,23 @@ class LcmEventsCmHandleStateHandlerImplSpec extends Specification { assert (args[0] as Map<String, CompositeState>).keySet().containsAll(['cmhandle1','cmhandle2']) } } - and: 'event service is called to publish event' + and: 'event service is called to publish events' 2 * mockLcmEventsService.publishLcmEvent(_, _, _) + } + def 'Batch of existing cm handles is deleted'() { + given: 'A batch of deleted cm handles' + def cmHandleStateMap = setupBatch('DELETED') + when: 'updating a batch of changes' + objectUnderTest.updateCmHandleStateBatch(cmHandleStateMap) + then : 'existing cm handles composite state is persisted' + 1 * mockInventoryPersistence.saveCmHandleStateBatch(_) >> { + args -> { + assert (args[0] as Map<String, CompositeState>).isEmpty() + } + } + and: 'event service is called to publish events' + 2 * mockLcmEventsService.publishLcmEvent(_, _, _) } def setupBatch(type) { @@ -197,6 +222,12 @@ class LcmEventsCmHandleStateHandlerImplSpec extends Specification { return [(yangModelCmHandle1): ADVISED, (yangModelCmHandle2): ADVISED] } + if ('DELETED' == type) { + yangModelCmHandle1.compositeState = new CompositeState(cmHandleState: READY) + yangModelCmHandle2.compositeState = new CompositeState(cmHandleState: READY) + return [(yangModelCmHandle1): DELETED, (yangModelCmHandle2): DELETED] + } + if ('UPDATE' == type) { yangModelCmHandle1.compositeState = new CompositeState(cmHandleState: ADVISED) yangModelCmHandle2.compositeState = new CompositeState(cmHandleState: READY) @@ -209,4 +240,4 @@ class LcmEventsCmHandleStateHandlerImplSpec extends Specification { return [(yangModelCmHandle1): ADVISED, (yangModelCmHandle2): READY] } } -}
\ No newline at end of file +} |