Skip to content

Commit bbeaa8b

Browse files
leeanjellamacabuhayGerrit Code Review
authored andcommitted
Merge "Filling Code Coverage gaps in CPS-NCMP-Service"
2 parents a4ab475 + c41866f commit bbeaa8b

21 files changed

Lines changed: 432 additions & 355 deletions

‎cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NetworkCmProxyRestExceptionHandlerSpec.groovy‎

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -156,21 +156,20 @@ class NetworkCmProxyRestExceptionHandlerSpec extends Specification {
156156
then: 'an HTTP response is returned with correct message and details'
157157
assertTestResponse(response, expectedErrorCode, expectedErrorMessage, expectedErrorDetails)
158158
where:
159-
scenario | exception || expectedErrorCode | expectedErrorMessage | expectedErrorDetails
160-
'CPS' | new CpsException(sampleErrorMessage, sampleErrorDetails) || INTERNAL_SERVER_ERROR | sampleErrorMessage | sampleErrorDetails
161-
'NCMP-server' | new ServerNcmpException(sampleErrorMessage, sampleErrorDetails) || INTERNAL_SERVER_ERROR | sampleErrorMessage | null
162-
'DMI Request' | new DmiRequestException(sampleErrorMessage, sampleErrorDetails) || BAD_REQUEST | sampleErrorMessage | null
163-
'Invalid Operation' | new InvalidOperationException('some reason') || BAD_REQUEST | 'some reason' | null
164-
'Unsupported Operation' | new OperationNotSupportedException('not yet') || BAD_REQUEST | 'not yet' | null
165-
'DataNode Validation' | new DataNodeNotFoundException('myDataspaceName', 'myAnchorName') || NOT_FOUND | 'DataNode not found' | null
166-
'other' | new IllegalStateException(sampleErrorMessage) || INTERNAL_SERVER_ERROR | sampleErrorMessage | null
167-
'Data Node Not Found' | new DataNodeNotFoundException('myDataspaceName', 'myAnchorName') || NOT_FOUND | 'DataNode not found' | 'DataNode not found'
168-
'Existing entry' | new AlreadyDefinedException('name',null) || CONFLICT | 'Already defined exception' | 'name already exists'
169-
'Existing entries' | AlreadyDefinedException.forDataNodes(['A', 'B'], 'myAnchorName') || CONFLICT | 'Already defined exception' | '2 data node(s) already exist'
170-
'Operation too large' | new PayloadTooLargeException(sampleErrorMessage) || PAYLOAD_TOO_LARGE | sampleErrorMessage | 'Check logs'
171-
'Policy Executor' | new PolicyExecutorException(sampleErrorMessage, sampleErrorDetails, null) || CONFLICT | sampleErrorMessage | sampleErrorDetails
172-
'Invalid Path' | new ProvMnSException('not a valid path' ,'some invalid path not a valid path') || UNPROCESSABLE_ENTITY | 'not a valid path' | 'some invalid path not a valid path'
173-
'Invalid Path' | new ProvMnSException('some invalid path not a valid path') || UNPROCESSABLE_ENTITY | 'some invalid path not a valid path' | null
159+
scenario | exception || expectedErrorCode | expectedErrorMessage | expectedErrorDetails
160+
'CPS' | new CpsException(sampleErrorMessage, sampleErrorDetails) || INTERNAL_SERVER_ERROR | sampleErrorMessage | sampleErrorDetails
161+
'NCMP-server' | new ServerNcmpException(sampleErrorMessage, sampleErrorDetails) || INTERNAL_SERVER_ERROR | sampleErrorMessage | null
162+
'DMI Request' | new DmiRequestException(sampleErrorMessage, sampleErrorDetails) || BAD_REQUEST | sampleErrorMessage | null
163+
'Invalid Operation' | new InvalidOperationException('some reason') || BAD_REQUEST | 'some reason' | null
164+
'Unsupported Operation' | new OperationNotSupportedException('not yet') || BAD_REQUEST | 'not yet' | null
165+
'DataNode Validation' | new DataNodeNotFoundException('myDataspaceName', 'myAnchorName') || NOT_FOUND | 'DataNode not found' | null
166+
'other' | new IllegalStateException(sampleErrorMessage) || INTERNAL_SERVER_ERROR | sampleErrorMessage | null
167+
'Data Node Not Found' | new DataNodeNotFoundException('myDataspaceName', 'myAnchorName') || NOT_FOUND | 'DataNode not found' | 'DataNode not found'
168+
'Existing entry' | new AlreadyDefinedException('name',null) || CONFLICT | 'Already defined exception' | 'name already exists'
169+
'Existing entries' | AlreadyDefinedException.forDataNodes(['A', 'B'], 'myAnchorName') || CONFLICT | 'Already defined exception' | '2 data node(s) already exist'
170+
'Operation too large' | new PayloadTooLargeException(sampleErrorMessage) || PAYLOAD_TOO_LARGE | sampleErrorMessage | 'Check logs'
171+
'Policy Executor' | new PolicyExecutorException(sampleErrorMessage, sampleErrorDetails, null) || CONFLICT | sampleErrorMessage | sampleErrorDetails
172+
'Invalid Path' | new ProvMnSException('not a valid path' ,'some details') || UNPROCESSABLE_ENTITY | 'not a valid path' | 'some details'
174173
}
175174

176175
def 'Post request with exception returns correct HTTP Status.'() {

‎cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/exceptions/ProvMnSException.java‎

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,4 @@ public ProvMnSException(final String message, final String details) {
3232
super(message, details);
3333
}
3434

35-
/**
36-
* Constructor.
37-
*
38-
* @param message exception message
39-
*/
40-
public ProvMnSException(final String message) {
41-
super(message, null);
42-
}
43-
4435
}

‎cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/models/CompositeStateBuilder.java‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* ============LICENSE_START=======================================================
33
* Copyright (C) 2022 Bell Canada
4-
* Modifications Copyright (C) 2022-2023 Nordix Foundation.
4+
* Modifications Copyright (C) 2022-2025 OpenInfra Foundation Europe.
55
* ================================================================================
66
* Licensed under the Apache License, Version 2.0 (the "License");
77
* you may not use this file except in compliance with the License.
@@ -123,13 +123,13 @@ public CompositeStateBuilder fromDataNode(final DataNode dataNode) {
123123
}
124124
for (final DataNode stateChildNode : dataNode.getChildDataNodes()) {
125125
if (stateChildNode.getXpath().endsWith("/lock-reason")) {
126-
this.lockReason = getLockReason(stateChildNode);
126+
this.lockReason = toLockReason(stateChildNode);
127127
}
128128
if (stateChildNode.getXpath().endsWith("/datastores")) {
129129
for (final DataNode dataStoreNodes : stateChildNode.getChildDataNodes()) {
130130
Operational operationalDataStore = null;
131131
if (dataStoreNodes.getXpath().contains("/operational")) {
132-
operationalDataStore = getOperationalDataStore(dataStoreNodes);
132+
operationalDataStore = toOperationalDataStore(dataStoreNodes);
133133
}
134134
this.datastores = DataStores.builder().operationalDataStore(operationalDataStore).build();
135135
}
@@ -138,14 +138,14 @@ public CompositeStateBuilder fromDataNode(final DataNode dataNode) {
138138
return this;
139139
}
140140

141-
private Operational getOperationalDataStore(final DataNode dataStoreNodes) {
141+
private Operational toOperationalDataStore(final DataNode dataStoreNodes) {
142142
return Operational.builder()
143143
.dataStoreSyncState(DataStoreSyncState.valueOf((String) dataStoreNodes.getLeaves().get("sync-state")))
144144
.lastSyncTime((String) dataStoreNodes.getLeaves().get("last-sync-time"))
145145
.build();
146146
}
147147

148-
private LockReason getLockReason(final DataNode stateChildNode) {
148+
private LockReason toLockReason(final DataNode stateChildNode) {
149149
final boolean isLockReasonExists = stateChildNode.getLeaves().containsKey("reason");
150150
return new LockReason(isLockReasonExists
151151
? LockReasonCategory.valueOf((String) stateChildNode.getLeaves().get("reason"))

‎cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/NetworkCmProxyInventoryFacadeImpl.java‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ public Collection<ModuleDefinition> getModuleDefinitionsByCmHandleReference(fina
9898
}
9999
}
100100

101+
102+
101103
@Override
102104
public Collection<ModuleDefinition> getModuleDefinitionsByCmHandleAndModule(final String cmHandleReference,
103105
final String moduleName,

‎cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/CmHandleRegistrationServicePropertyHandler.java‎

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
import org.onap.cps.ncmp.api.inventory.models.CmHandleRegistrationResponse;
5656
import org.onap.cps.ncmp.api.inventory.models.NcmpServiceCmHandle;
5757
import org.onap.cps.ncmp.impl.inventory.models.YangModelCmHandle;
58+
import org.onap.cps.ncmp.impl.inventory.sync.lcm.CmHandleTransitionPair;
5859
import org.onap.cps.ncmp.impl.inventory.sync.lcm.LcmEventsHelper;
5960
import org.onap.cps.ncmp.impl.utils.YangDataConverter;
6061
import org.onap.cps.utils.ContentType;
@@ -142,7 +143,7 @@ private void updateAlternateId(final NcmpServiceCmHandle ncmpServiceCmHandle) {
142143
}
143144

144145
private void updateDataProducerIdentifier(final DataNode cmHandleDataNode,
145-
final NcmpServiceCmHandle ncmpServiceCmHandle) {
146+
final NcmpServiceCmHandle ncmpServiceCmHandle) {
146147
final String targetDataProducerIdentifier = ncmpServiceCmHandle.getDataProducerIdentifier();
147148
final String cmHandleId = ncmpServiceCmHandle.getCmHandleId();
148149

@@ -151,31 +152,26 @@ private void updateDataProducerIdentifier(final DataNode cmHandleDataNode,
151152
return;
152153
}
153154

154-
final YangModelCmHandle existingYangModelCmHandle = YangDataConverter.toYangModelCmHandle(cmHandleDataNode);
155-
final String existingDataProducerIdentifier = existingYangModelCmHandle.getDataProducerIdentifier();
155+
final YangModelCmHandle currentYangModelCmHandle = YangDataConverter.toYangModelCmHandle(cmHandleDataNode);
156+
final String currentDataProducerIdentifier = currentYangModelCmHandle.getDataProducerIdentifier();
156157

157-
if (existingDataProducerIdentifier.equals(targetDataProducerIdentifier)) {
158+
if (currentDataProducerIdentifier.equals(targetDataProducerIdentifier)) {
158159
log.debug("Ignoring update as dataProducerIdentifier for cmHandle {} is already set to {}.", cmHandleId,
159160
targetDataProducerIdentifier);
160161
return;
161162
}
162-
163163
setAndUpdateCmHandleField(cmHandleId, "data-producer-identifier", targetDataProducerIdentifier);
164164
log.debug("dataProducerIdentifier for cmHandle {} updated from {} to {}", cmHandleId,
165-
existingDataProducerIdentifier, targetDataProducerIdentifier);
166-
sendLcmEventForDataProducerIdentifier(cmHandleId, existingYangModelCmHandle);
165+
currentDataProducerIdentifier, targetDataProducerIdentifier);
166+
sendLcmEventForDataProducerIdentifier(cmHandleId, currentYangModelCmHandle);
167167
}
168168

169169
private void sendLcmEventForDataProducerIdentifier(final String cmHandleId,
170-
final YangModelCmHandle existingYangModelCmHandle) {
170+
final YangModelCmHandle currentYangModelCmHandle) {
171171
final YangModelCmHandle updatedYangModelCmHandle = inventoryPersistence.getYangModelCmHandle(cmHandleId);
172-
final NcmpServiceCmHandle existingNcmpServiceCmHandle =
173-
YangDataConverter.toNcmpServiceCmHandle(existingYangModelCmHandle);
174-
final NcmpServiceCmHandle updatedNcmpServiceCmHandle =
175-
YangDataConverter.toNcmpServiceCmHandle(updatedYangModelCmHandle);
176-
177-
lcmEventsHelper.sendLcmEventAsynchronously(updatedNcmpServiceCmHandle,
178-
existingNcmpServiceCmHandle);
172+
final CmHandleTransitionPair cmHandleTransitionPair =
173+
new CmHandleTransitionPair(currentYangModelCmHandle, updatedYangModelCmHandle);
174+
lcmEventsHelper.sendLcmEventBatchAsynchronously(List.of(cmHandleTransitionPair));
179175
}
180176

181177
private void updateProperties(final DataNode existingCmHandleDataNode, final PropertyType propertyType,

‎cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/sync/lcm/CmHandleStateMonitor.java‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import org.onap.cps.ncmp.api.inventory.models.CmHandleState;
3030
import org.onap.cps.ncmp.api.inventory.models.CompositeState;
3131
import org.onap.cps.ncmp.impl.inventory.CmHandleQueryService;
32-
import org.onap.cps.ncmp.impl.inventory.sync.lcm.LcmEventsCmHandleStateHandlerImpl.CmHandleTransitionPair;
3332
import org.onap.cps.ncmp.utils.events.NcmpInventoryModelOnboardingFinishedEvent;
3433
import org.springframework.context.annotation.DependsOn;
3534
import org.springframework.context.event.EventListener;
@@ -76,12 +75,12 @@ public void updateCmHandleStateMetrics(final Collection<CmHandleTransitionPair>
7675
}
7776

7877
private void updateMetricWithStateChange(final CmHandleTransitionPair cmHandleTransitionPair) {
79-
final CmHandleState targetCmHandleState = cmHandleTransitionPair.getTargetYangModelCmHandle()
78+
final CmHandleState targetCmHandleState = cmHandleTransitionPair.targetYangModelCmHandle()
8079
.getCompositeState().getCmHandleState();
81-
if (isNew(cmHandleTransitionPair.getCurrentYangModelCmHandle().getCompositeState())) {
80+
if (isNew(cmHandleTransitionPair.currentYangModelCmHandle().getCompositeState())) {
8281
updateTargetStateCount(targetCmHandleState);
8382
} else {
84-
final CmHandleState previousCmHandleState = cmHandleTransitionPair.getCurrentYangModelCmHandle()
83+
final CmHandleState previousCmHandleState = cmHandleTransitionPair.currentYangModelCmHandle()
8584
.getCompositeState().getCmHandleState();
8685
updatePreviousStateCount(previousCmHandleState);
8786
updateTargetStateCount(targetCmHandleState);
@@ -98,8 +97,8 @@ private void updateTargetStateCount(final CmHandleState targetCmHandleState) {
9897
cmHandlesByState.executeOnKey(keyName, new IncreasingEntryProcessor());
9998
}
10099

101-
private boolean isNew(final CompositeState existingCompositeState) {
102-
return (existingCompositeState == null);
100+
private boolean isNew(final CompositeState currentCompositeState) {
101+
return (currentCompositeState == null);
103102
}
104103

105104
static class DecreasingEntryProcessor implements EntryProcessor<String, Integer, Void> {
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* ============LICENSE_START=======================================================
3+
* Copyright (C) 2025 OpenInfra Foundation Europe. All rights reserved.
4+
* ================================================================================
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*
17+
* SPDX-License-Identifier: Apache-2.0
18+
* ============LICENSE_END=========================================================
19+
*/
20+
21+
package org.onap.cps.ncmp.impl.inventory.sync.lcm;
22+
23+
import org.onap.cps.ncmp.impl.inventory.models.YangModelCmHandle;
24+
25+
public record CmHandleTransitionPair(YangModelCmHandle currentYangModelCmHandle,
26+
YangModelCmHandle targetYangModelCmHandle
27+
) {}

0 commit comments

Comments
 (0)