diff options
Diffstat (limited to 'cps-ncmp-rest/src')
6 files changed, 36 insertions, 29 deletions
diff --git a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NcmpRestInputMapper.java b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NcmpRestInputMapper.java index b3f36f9c8b..af785d5658 100644 --- a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NcmpRestInputMapper.java +++ b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NcmpRestInputMapper.java @@ -48,6 +48,9 @@ public interface NcmpRestInputMapper { @Mapping(source = "removedCmHandles", target = "removedCmHandles", nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS, nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.SET_TO_DEFAULT) + @Mapping(source = "upgradedCmHandles", target = "upgradedCmHandles", + nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS, + nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.SET_TO_DEFAULT) DmiPluginRegistration toDmiPluginRegistration(final RestDmiPluginRegistration restDmiPluginRegistration); @Mapping(source = "cmHandle", target = "cmHandleId") diff --git a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NetworkCmProxyInventoryController.java b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NetworkCmProxyInventoryController.java index 87f9d835a1..453abcabb1 100755 --- a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NetworkCmProxyInventoryController.java +++ b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NetworkCmProxyInventoryController.java @@ -110,23 +110,23 @@ public class NetworkCmProxyInventoryController implements NetworkCmProxyInventor getFailedResponses(dmiPluginRegistrationResponse.getUpdatedCmHandles())); dmiPluginRegistrationErrorResponse.setFailedRemovedCmHandles( getFailedResponses(dmiPluginRegistrationResponse.getRemovedCmHandles())); - + dmiPluginRegistrationErrorResponse.setFailedUpgradeCmHandles( + getFailedResponses(dmiPluginRegistrationResponse.getUpgradedCmHandles())); return dmiPluginRegistrationErrorResponse; } private List<CmHandlerRegistrationErrorResponse> getFailedResponses( - final List<CmHandleRegistrationResponse> cmHandleRegistrationResponseList) { + final List<CmHandleRegistrationResponse> cmHandleRegistrationResponseList) { return cmHandleRegistrationResponseList.stream() - .filter(cmHandleRegistrationResponse -> cmHandleRegistrationResponse.getStatus() == Status.FAILURE) - .map(this::toCmHandleRegistrationErrorResponse) - .collect(Collectors.toList()); + .filter(cmHandleRegistrationResponse -> cmHandleRegistrationResponse.getStatus() == Status.FAILURE) + .map(this::toCmHandleRegistrationErrorResponse).collect(Collectors.toList()); } private CmHandlerRegistrationErrorResponse toCmHandleRegistrationErrorResponse( final CmHandleRegistrationResponse registrationResponse) { return new CmHandlerRegistrationErrorResponse() .cmHandle(registrationResponse.getCmHandle()) - .errorCode(registrationResponse.getRegistrationError().errorCode) + .errorCode(registrationResponse.getNcmpResponseStatus().getCode()) .errorText(registrationResponse.getErrorText()); } diff --git a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/mapper/CmHandleStateMapper.java b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/mapper/CmHandleStateMapper.java index 82dc4837f8..b436540fc2 100644 --- a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/mapper/CmHandleStateMapper.java +++ b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/mapper/CmHandleStateMapper.java @@ -20,6 +20,8 @@ package org.onap.cps.ncmp.rest.mapper; +import static org.onap.cps.ncmp.api.impl.inventory.LockReasonCategory.LOCKED_MISBEHAVING; + import org.mapstruct.Mapper; import org.mapstruct.Mapping; import org.mapstruct.Named; @@ -75,8 +77,10 @@ public interface CmHandleStateMapper { @Named("toExternalLockReason") static LockReason toExternalLockReason(CompositeState.LockReason internalLockReason) { final LockReason externalLockReason = new LockReason(); - if (internalLockReason.getLockReasonCategory() != null) { - externalLockReason.setReason("LOCKED_MISBEHAVING"); + if (internalLockReason.getLockReasonCategory() == null) { + externalLockReason.setReason(LOCKED_MISBEHAVING.name()); + } else { + externalLockReason.setReason(internalLockReason.getLockReasonCategory().name()); } externalLockReason.setDetails(internalLockReason.getDetails()); return externalLockReason; diff --git a/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NetworkCmProxyControllerSpec.groovy b/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NetworkCmProxyControllerSpec.groovy index 6bfa5936ed..de044d0aac 100644 --- a/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NetworkCmProxyControllerSpec.groovy +++ b/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NetworkCmProxyControllerSpec.groovy @@ -615,8 +615,7 @@ class NetworkCmProxyControllerSpec extends Specification { def expectedContent = [ '"state":', '"cmHandleState":"ADVISED"', - '"reason":"LOCKED_MISBEHAVING"', - '"details":"lock details"', + '"lockReason":{"reason":"MODULE_SYNC_FAILED","details":"lock details"}', '"lastUpdateTime":"2022-12-31T20:30:40.000+0000"', '"dataSyncEnabled":false', '"dataSyncState":', diff --git a/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NetworkCmProxyInventoryControllerSpec.groovy b/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NetworkCmProxyInventoryControllerSpec.groovy index e755094dd2..1d03be107d 100644 --- a/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NetworkCmProxyInventoryControllerSpec.groovy +++ b/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NetworkCmProxyInventoryControllerSpec.groovy @@ -219,14 +219,14 @@ class NetworkCmProxyInventoryControllerSpec extends Specification { responseBody.getFailedUpdatedCmHandles() == expectedFailedUpdateCmHandle responseBody.getFailedRemovedCmHandles() == expectedFailedRemovedCmHandle where: - scenario | createCmHandleResponse | updateCmHandleResponse | removeCmHandleResponse || expectedFailedCreatedCmHandle | expectedFailedUpdateCmHandle | expectedFailedRemovedCmHandle - 'only create failed' | failedResponse('cm-handle-1') | successResponse('cm-handle-2') | successResponse('cm-handle-3') || [failedRestResponse('cm-handle-1')] | [] | [] - 'only update failed' | successResponse('cm-handle-1') | failedResponse('cm-handle-2') | successResponse('cm-handle-3') || [] | [failedRestResponse('cm-handle-2')] | [] - 'only delete failed' | successResponse('cm-handle-1') | successResponse('cm-handle-2') | failedResponse('cm-handle-3') || [] | [] | [failedRestResponse('cm-handle-3')] - 'all three failed' | failedResponse('cm-handle-1') | failedResponse('cm-handle-2') | failedResponse('cm-handle-3') || [failedRestResponse('cm-handle-1')] | [failedRestResponse('cm-handle-2')] | [failedRestResponse('cm-handle-3')] - 'create update failed' | failedResponse('cm-handle-1') | failedResponse('cm-handle-2') | successResponse('cm-handle-3') || [failedRestResponse('cm-handle-1')] | [failedRestResponse('cm-handle-2')] | [] - 'create delete failed' | failedResponse('cm-handle-1') | successResponse('cm-handle-2') | failedResponse('cm-handle-3') || [failedRestResponse('cm-handle-1')] | [] | [failedRestResponse('cm-handle-3')] - 'update delete failed' | successResponse('cm-handle-1') | failedResponse('cm-handle-2') | failedResponse('cm-handle-3') || [] | [failedRestResponse('cm-handle-2')] | [failedRestResponse('cm-handle-3')] + scenario | createCmHandleResponse | updateCmHandleResponse | removeCmHandleResponse || expectedFailedCreatedCmHandle | expectedFailedUpdateCmHandle | expectedFailedRemovedCmHandle + 'only create failed' | expectedFailedResponse('cm-handle-1') | expectedSuccessResponse('cm-handle-2') | expectedSuccessResponse('cm-handle-3') || [expectedUnknownErrorResponse('cm-handle-1')] | [] | [] + 'only update failed' | expectedSuccessResponse('cm-handle-1') | expectedFailedResponse('cm-handle-2') | expectedSuccessResponse('cm-handle-3') || [] | [expectedUnknownErrorResponse('cm-handle-2')] | [] + 'only delete failed' | expectedSuccessResponse('cm-handle-1') | expectedSuccessResponse('cm-handle-2') | expectedFailedResponse('cm-handle-3') || [] | [] | [expectedUnknownErrorResponse('cm-handle-3')] + 'all three failed' | expectedFailedResponse('cm-handle-1') | expectedFailedResponse('cm-handle-2') | expectedFailedResponse('cm-handle-3') || [expectedUnknownErrorResponse('cm-handle-1')] | [expectedUnknownErrorResponse('cm-handle-2')] | [expectedUnknownErrorResponse('cm-handle-3')] + 'create update failed' | expectedFailedResponse('cm-handle-1') | expectedFailedResponse('cm-handle-2') | expectedSuccessResponse('cm-handle-3') || [expectedUnknownErrorResponse('cm-handle-1')] | [expectedUnknownErrorResponse('cm-handle-2')] | [] + 'create delete failed' | expectedFailedResponse('cm-handle-1') | expectedSuccessResponse('cm-handle-2') | expectedFailedResponse('cm-handle-3') || [expectedUnknownErrorResponse('cm-handle-1')] | [] | [expectedUnknownErrorResponse('cm-handle-3')] + 'update delete failed' | expectedSuccessResponse('cm-handle-1') | expectedFailedResponse('cm-handle-2') | expectedFailedResponse('cm-handle-3') || [] | [expectedUnknownErrorResponse('cm-handle-2')] | [expectedUnknownErrorResponse('cm-handle-3')] } def 'Get all cm handle IDs by DMI plugin identifier.'() { @@ -246,15 +246,15 @@ class NetworkCmProxyInventoryControllerSpec extends Specification { assert response.contentAsString.contains('cm-handle-id-2') } - def failedRestResponse(cmHandle) { - return new CmHandlerRegistrationErrorResponse('cmHandle': cmHandle, 'errorCode': '00', 'errorText': 'Failed') + def expectedUnknownErrorResponse(cmHandle) { + return new CmHandlerRegistrationErrorResponse('cmHandle': cmHandle, 'errorCode': '108', 'errorText': 'Failed') } - def failedResponse(cmHandle) { + def expectedFailedResponse(cmHandle) { return CmHandleRegistrationResponse.createFailureResponse(cmHandle, new RuntimeException('Failed')) } - def successResponse(cmHandle) { + def expectedSuccessResponse(cmHandle) { return CmHandleRegistrationResponse.createSuccessResponse(cmHandle) } diff --git a/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/mapper/CmHandleStateMapperSpec.groovy b/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/mapper/CmHandleStateMapperSpec.groovy index 1fa83a539c..f394f91938 100644 --- a/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/mapper/CmHandleStateMapperSpec.groovy +++ b/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/mapper/CmHandleStateMapperSpec.groovy @@ -1,6 +1,6 @@ /* * ============LICENSE_START======================================================= - * Copyright (C) 2022 Nordix Foundation + * Copyright (C) 2022-2023 Nordix Foundation * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,6 +20,7 @@ package org.onap.cps.ncmp.rest.mapper +import static org.onap.cps.ncmp.api.impl.inventory.LockReasonCategory.LOCKED_MISBEHAVING import static org.onap.cps.ncmp.api.impl.inventory.LockReasonCategory.MODULE_SYNC_FAILED import org.mapstruct.factory.Mappers @@ -55,7 +56,7 @@ class CmHandleStateMapperSpec extends Specification { and: 'mapped result should have correct values' assert !result.dataSyncEnabled assert result.lastUpdateTime == formattedDateAndTime - assert result.lockReason.reason == 'LOCKED_MISBEHAVING' + assert result.lockReason.reason == MODULE_SYNC_FAILED.name() assert result.lockReason.details == 'locked details' assert result.cmHandleState == 'ADVISED' assert result.dataSyncState.operational.getSyncState() != null @@ -69,17 +70,17 @@ class CmHandleStateMapperSpec extends Specification { def 'Internal to External Lock Reason Mapping of #scenario'() { given: 'a LOCKED composite state with locked reason of #scenario' - def compositeState = new CompositeStateBuilder() + def compositeState = new CompositeStateBuilder() .withCmHandleState(CmHandleState.LOCKED) .withLockReason(lockReason, '').build() when: 'the composite state is mapped to a CMHandle composite state' - def result = objectUnderTest.toCmHandleCompositeStateExternalLockReason(compositeState) + def result = objectUnderTest.toCmHandleCompositeStateExternalLockReason(compositeState) then: 'the composite state contains the expected lock Reason and details' - result.getLockReason().getReason() == expectedExternalLockReason + result.getLockReason().getReason() == (expectedExternalLockReason as String) where: scenario | lockReason || expectedExternalLockReason - 'MODULE_SYNC_FAILED' | MODULE_SYNC_FAILED || 'LOCKED_MISBEHAVING' - 'null value' | null || null + 'MODULE_SYNC_FAILED' | MODULE_SYNC_FAILED || MODULE_SYNC_FAILED + 'null value' | null || LOCKED_MISBEHAVING } } |