summaryrefslogtreecommitdiffstats
path: root/cps-ncmp-service
diff options
context:
space:
mode:
authormpriyank <priyank.maheshwari@est.tech>2022-07-11 12:15:55 +0100
committermpriyank <priyank.maheshwari@est.tech>2022-07-14 09:05:31 +0100
commita6fa6c368f04c85bf553fce2cf89d25ec366116e (patch)
treecc69b8995470a7c4af0eaf4ce2a830ffea98b5a2 /cps-ncmp-service
parent97c875cf3fea520563e1819209ab826f8c03fd5e (diff)
Code Refactoring Ncmp* to Lcm* as per new scope
- Refactored code to reflect the LcmEvents scope now. - Test cases updated and dependencies reviewed. - You can find few occurences of NcmpEvent for now but that will be cleaned up once we implement CPS-1104 which is for LcmEvent schema - UPCOMING: LcmEvent schema and then the code to publish the events on cmHandleStates - LATER : LcmEvents based on public properties update. Issue-ID: CPS-1137 Change-Id: I9f395ed733b4028e706205894c36a38412e3452e Signed-off-by: mpriyank <priyank.maheshwari@est.tech>
Diffstat (limited to 'cps-ncmp-service')
-rwxr-xr-xcps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImpl.java4
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/event/lcm/LcmEventsCmHandleStateHandler.java (renamed from cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/event/NcmpEventsCmHandleStateHandler.java)6
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/event/lcm/LcmEventsCmHandleStateHandlerImpl.java (renamed from cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/event/NcmpEventsCmHandleStateHandlerImpl.java)24
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/event/lcm/LcmEventsCreator.java (renamed from cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/event/NcmpEventsCreator.java)20
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/event/lcm/LcmEventsPublisher.java (renamed from cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/event/NcmpEventsPublisher.java)16
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/event/lcm/LcmEventsService.java (renamed from cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/event/NcmpEventsService.java)12
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/InventoryPersistence.java10
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplRegistrationSpec.groovy15
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplSpec.groovy10
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/event/lcm/LcmEventsCmHandleStateHandlerImplSpec.groovy (renamed from cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/event/NcmpEventsCmHandleStateHandlerImplSpec.groovy)28
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/event/lcm/LcmEventsCreatorSpec.groovy (renamed from cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/event/NcmpEventsCreatorSpec.groovy)11
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/event/lcm/LcmEventsPublisherSpec.groovy (renamed from cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/event/NcmpEventsPublisherSpec.groovy)9
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/event/lcm/LcmEventsServiceSpec.groovy (renamed from cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/event/NcmpEventsServiceSpec.groovy)17
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/InventoryPersistenceSpec.groovy14
14 files changed, 102 insertions, 94 deletions
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImpl.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImpl.java
index d827d465c0..16b9a66f4e 100755
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImpl.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImpl.java
@@ -290,9 +290,7 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService
private CmHandleRegistrationResponse registerNewCmHandle(final YangModelCmHandle yangModelCmHandle) {
try {
- final String cmHandleJsonData = String.format("{\"cm-handles\":[%s]}",
- jsonObjectMapper.asJsonString(yangModelCmHandle));
- inventoryPersistence.saveListElements(cmHandleJsonData);
+ inventoryPersistence.saveCmHandle(yangModelCmHandle);
return CmHandleRegistrationResponse.createSuccessResponse(yangModelCmHandle.getId());
} catch (final AlreadyDefinedException alreadyDefinedException) {
return CmHandleRegistrationResponse.createFailureResponse(
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/event/NcmpEventsCmHandleStateHandler.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/event/lcm/LcmEventsCmHandleStateHandler.java
index 7728b5f92d..8cab19405e 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/event/NcmpEventsCmHandleStateHandler.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/event/lcm/LcmEventsCmHandleStateHandler.java
@@ -18,16 +18,16 @@
* ============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.yangmodels.YangModelCmHandle;
import org.onap.cps.ncmp.api.inventory.CmHandleState;
/**
* The implementation of it should handle the persisting of composite state and delegate the request to publish the
- * corresponding ncmp event.
+ * corresponding lcm event.
*/
-public interface NcmpEventsCmHandleStateHandler {
+public interface LcmEventsCmHandleStateHandler {
/**
* Updates the composite state of cmHandle based on cmHandleState.
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/event/NcmpEventsCmHandleStateHandlerImpl.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/event/lcm/LcmEventsCmHandleStateHandlerImpl.java
index 26a1c5bab9..111d5dcd58 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/event/NcmpEventsCmHandleStateHandlerImpl.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/event/lcm/LcmEventsCmHandleStateHandlerImpl.java
@@ -18,7 +18,7 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.cps.ncmp.api.impl.event;
+package org.onap.cps.ncmp.api.impl.event.lcm;
import static org.onap.cps.ncmp.api.inventory.CmHandleState.ADVISED;
import static org.onap.cps.ncmp.api.inventory.CmHandleState.LOCKED;
@@ -32,7 +32,6 @@ import org.onap.cps.ncmp.api.inventory.CmHandleState;
import org.onap.cps.ncmp.api.inventory.CompositeStateUtils;
import org.onap.cps.ncmp.api.inventory.InventoryPersistence;
import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle;
-import org.onap.cps.utils.JsonObjectMapper;
import org.onap.ncmp.cmhandle.lcm.event.NcmpEvent;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
@@ -40,12 +39,11 @@ import org.springframework.stereotype.Service;
@Slf4j
@Service
@RequiredArgsConstructor
-public class NcmpEventsCmHandleStateHandlerImpl implements NcmpEventsCmHandleStateHandler {
+public class LcmEventsCmHandleStateHandlerImpl implements LcmEventsCmHandleStateHandler {
private final InventoryPersistence inventoryPersistence;
- private final NcmpEventsCreator ncmpEventsCreator;
- private final JsonObjectMapper jsonObjectMapper;
- private final NcmpEventsService ncmpEventsService;
+ private final LcmEventsCreator lcmEventsCreator;
+ private final LcmEventsService lcmEventsService;
@Value("${data-sync.cache.enabled:false}")
private boolean isGlobalDataSyncCacheEnabled;
@@ -59,7 +57,7 @@ public class NcmpEventsCmHandleStateHandlerImpl implements NcmpEventsCmHandleSta
log.debug("CmHandle with id : {} already in state : {}", yangModelCmHandle.getId(), targetCmHandleState);
} else {
updateToSpecifiedCmHandleState(yangModelCmHandle, targetCmHandleState);
- publishNcmpEvent(yangModelCmHandle);
+ publishLcmEvent(yangModelCmHandle);
}
}
@@ -85,22 +83,20 @@ public class NcmpEventsCmHandleStateHandlerImpl implements NcmpEventsCmHandleSta
}
private void retryCmHandle(final YangModelCmHandle yangModelCmHandle) {
- CompositeStateUtils.setCompositeStateForRetry()
- .accept(yangModelCmHandle.getCompositeState());
+ CompositeStateUtils.setCompositeStateForRetry().accept(yangModelCmHandle.getCompositeState());
inventoryPersistence.saveCmHandleState(yangModelCmHandle.getId(), yangModelCmHandle.getCompositeState());
}
private void registerNewCmHandle(final YangModelCmHandle yangModelCmHandle) {
CompositeStateUtils.setCompositeState(ADVISED).accept(yangModelCmHandle.getCompositeState());
- inventoryPersistence.saveListElements(
- String.format("{\"cm-handles\":[%s]}", jsonObjectMapper.asJsonString(yangModelCmHandle)));
+ inventoryPersistence.saveCmHandle(yangModelCmHandle);
}
- private void publishNcmpEvent(final YangModelCmHandle yangModelCmHandle) {
+ private void publishLcmEvent(final YangModelCmHandle yangModelCmHandle) {
final NcmpServiceCmHandle ncmpServiceCmHandle =
YangDataConverter.convertYangModelCmHandleToNcmpServiceCmHandle(yangModelCmHandle);
final String cmHandleId = ncmpServiceCmHandle.getCmHandleId();
- final NcmpEvent ncmpEvent = ncmpEventsCreator.populateNcmpEvent(cmHandleId, ncmpServiceCmHandle);
- ncmpEventsService.publishNcmpEvent(cmHandleId, ncmpEvent);
+ final NcmpEvent ncmpEvent = lcmEventsCreator.populateLcmEvent(cmHandleId, ncmpServiceCmHandle);
+ lcmEventsService.publishLcmEvent(cmHandleId, ncmpEvent);
}
}
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/event/NcmpEventsCreator.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/event/lcm/LcmEventsCreator.java
index df41eba8bd..783b299511 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/event/NcmpEventsCreator.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/event/lcm/LcmEventsCreator.java
@@ -18,7 +18,7 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.cps.ncmp.api.impl.event;
+package org.onap.cps.ncmp.api.impl.event.lcm;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
@@ -32,11 +32,11 @@ import org.springframework.stereotype.Component;
/**
- * NcmpEventsCreator to create NcmpEvent based on relevant operation.
+ * LcmEventsCreator to create LcmEvent based on relevant operation.
*/
@Slf4j
@Component
-public class NcmpEventsCreator {
+public class LcmEventsCreator {
/**
@@ -46,17 +46,17 @@ public class NcmpEventsCreator {
* @param ncmpServiceCmHandle Ncmp CmHandle Data
* @return Populated NcmpEvent
*/
- public NcmpEvent populateNcmpEvent(final String cmHandleId, final NcmpServiceCmHandle ncmpServiceCmHandle) {
- return createNcmpEvent(cmHandleId, ncmpServiceCmHandle);
+ public NcmpEvent populateLcmEvent(final String cmHandleId, final NcmpServiceCmHandle ncmpServiceCmHandle) {
+ return createLcmEvent(cmHandleId, ncmpServiceCmHandle);
}
- private NcmpEvent createNcmpEvent(final String cmHandleId, final NcmpServiceCmHandle ncmpServiceCmHandle) {
- final NcmpEvent ncmpEvent = ncmpEventHeader(cmHandleId);
- ncmpEvent.setEvent(ncmpEventPayload(cmHandleId, ncmpServiceCmHandle));
+ private NcmpEvent createLcmEvent(final String cmHandleId, final NcmpServiceCmHandle ncmpServiceCmHandle) {
+ final NcmpEvent ncmpEvent = lcmEventHeader(cmHandleId);
+ ncmpEvent.setEvent(lcmEventPayload(cmHandleId, ncmpServiceCmHandle));
return ncmpEvent;
}
- private Event ncmpEventPayload(final String eventCorrelationId, final NcmpServiceCmHandle ncmpServiceCmHandle) {
+ private Event lcmEventPayload(final String eventCorrelationId, final NcmpServiceCmHandle ncmpServiceCmHandle) {
final Event event = new Event();
event.setCmHandleId(eventCorrelationId);
event.setCmhandleState(
@@ -65,7 +65,7 @@ public class NcmpEventsCreator {
return event;
}
- private NcmpEvent ncmpEventHeader(final String eventCorrelationId) {
+ private NcmpEvent lcmEventHeader(final String eventCorrelationId) {
final NcmpEvent ncmpEvent = new NcmpEvent();
ncmpEvent.setEventId(UUID.randomUUID().toString());
ncmpEvent.setEventCorrelationId(eventCorrelationId);
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/event/NcmpEventsPublisher.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/event/lcm/LcmEventsPublisher.java
index 52ac4685e2..2a946b1008 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/event/NcmpEventsPublisher.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/event/lcm/LcmEventsPublisher.java
@@ -18,7 +18,7 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.cps.ncmp.api.impl.event;
+package org.onap.cps.ncmp.api.impl.event.lcm;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@@ -30,28 +30,28 @@ import org.springframework.util.concurrent.ListenableFuture;
import org.springframework.util.concurrent.ListenableFutureCallback;
/**
- * NcmpEventsPublisher to publish the NcmpEvents on event of CREATE, UPDATE and DELETE.
+ * LcmEventsPublisher to publish the LcmEvents on event of CREATE, UPDATE and DELETE.
*/
@Slf4j
@Service
@RequiredArgsConstructor
-public class NcmpEventsPublisher {
+public class LcmEventsPublisher {
- private final KafkaTemplate<String, NcmpEvent> ncmpEventKafkaTemplate;
+ private final KafkaTemplate<String, NcmpEvent> lcmEventKafkaTemplate;
/**
- * NCMP Event publisher.
+ * LCM Event publisher.
*
* @param topicName valid topic name
* @param eventKey message key
* @param ncmpEvent message payload
*/
public void publishEvent(final String topicName, final String eventKey, final NcmpEvent ncmpEvent) {
- final ListenableFuture<SendResult<String, NcmpEvent>> ncmpEventFuture =
- ncmpEventKafkaTemplate.send(topicName, eventKey, ncmpEvent);
+ final ListenableFuture<SendResult<String, NcmpEvent>> lcmEventFuture =
+ lcmEventKafkaTemplate.send(topicName, eventKey, ncmpEvent);
- ncmpEventFuture.addCallback(new ListenableFutureCallback<>() {
+ lcmEventFuture.addCallback(new ListenableFutureCallback<>() {
@Override
public void onFailure(final Throwable throwable) {
log.error("Unable to publish event to topic : {} due to {}", topicName, throwable.getMessage());
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/event/NcmpEventsService.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/event/lcm/LcmEventsService.java
index 5e02e0d94f..d9c9b9a1ce 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/event/NcmpEventsService.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/event/lcm/LcmEventsService.java
@@ -18,7 +18,7 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.cps.ncmp.api.impl.event;
+package org.onap.cps.ncmp.api.impl.event.lcm;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@@ -33,11 +33,11 @@ import org.springframework.stereotype.Service;
@Slf4j
@Service
@RequiredArgsConstructor
-public class NcmpEventsService {
+public class LcmEventsService {
- private final NcmpEventsPublisher ncmpEventsPublisher;
+ private final LcmEventsPublisher lcmEventsPublisher;
- @Value("${app.ncmp.events.topic:ncmp-events}")
+ @Value("${app.lcm.events.topic:ncmp-events}")
private String topicName;
@Value("${notification.enabled:true}")
@@ -49,9 +49,9 @@ public class NcmpEventsService {
* @param cmHandleId Cm Handle Id
* @param ncmpEvent Ncmp Event
*/
- public void publishNcmpEvent(final String cmHandleId, final NcmpEvent ncmpEvent) {
+ public void publishLcmEvent(final String cmHandleId, final NcmpEvent ncmpEvent) {
if (notificationsEnabled) {
- ncmpEventsPublisher.publishEvent(topicName, cmHandleId, ncmpEvent);
+ lcmEventsPublisher.publishEvent(topicName, cmHandleId, ncmpEvent);
} else {
log.debug("Notifications disabled.");
}
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/InventoryPersistence.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/InventoryPersistence.java
index af01fb4398..be26a58d58 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/InventoryPersistence.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/InventoryPersistence.java
@@ -182,13 +182,15 @@ public class InventoryPersistence {
}
/**
- * Method to save list elements.
+ * Method to save cmHandle.
*
- * @param cmHandleJsonData cmHandle JSON data
+ * @param yangModelCmHandle cmHandle represented as Yang Model
*/
- public void saveListElements(final String cmHandleJsonData) {
+ public void saveCmHandle(final YangModelCmHandle yangModelCmHandle) {
+ final String cmHandleJsonData =
+ String.format("{\"cm-handles\":[%s]}", jsonObjectMapper.asJsonString(yangModelCmHandle));
cpsDataService.saveListElements(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, NCMP_DMI_REGISTRY_PARENT,
- cmHandleJsonData, NO_TIMESTAMP);
+ cmHandleJsonData, NO_TIMESTAMP);
}
/**
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'() {