From e24f5e8934c6be58e56949223727f6bde114c8d3 Mon Sep 17 00:00:00 2001 From: emaclee Date: Sat, 23 Sep 2023 13:46:15 +0100 Subject: [PATCH] Update return body of RestOutputCMHandle Issue-ID: CPS-1869 Signed-off-by: emaclee Change-Id: I946db9e6785fc50775d1c5ff18e7462e8bad9af6 --- cps-ncmp-rest/docs/openapi/components.yaml | 6 + .../rest/controller/NetworkCmProxyController.java | 7 + .../controller/NetworkCmProxyControllerSpec.groovy | 202 +++++++++++---------- 3 files changed, 120 insertions(+), 95 deletions(-) diff --git a/cps-ncmp-rest/docs/openapi/components.yaml b/cps-ncmp-rest/docs/openapi/components.yaml index 022e2bab7..62c9eb050 100644 --- a/cps-ncmp-rest/docs/openapi/components.yaml +++ b/cps-ncmp-rest/docs/openapi/components.yaml @@ -242,6 +242,8 @@ components: $ref: '#/components/schemas/CmHandlePublicProperties' state: $ref: '#/components/schemas/CmHandleCompositeState' + trustLevel: + $ref: '#/components/schemas/CmHandleTrustLevel' CmHandlePublicProperties: type: object items: @@ -265,6 +267,10 @@ components: example: false dataSyncState: $ref: '#/components/schemas/dataStores' + CmHandleTrustLevel: + type: string + description: Current trust level of the relevant CM handle ID. + example: COMPLETE lock-reason: type: object diff --git a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NetworkCmProxyController.java b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NetworkCmProxyController.java index 6c730cb1f..ef70a3763 100755 --- a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NetworkCmProxyController.java +++ b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NetworkCmProxyController.java @@ -32,6 +32,7 @@ import static org.onap.cps.ncmp.api.impl.operations.OperationType.UPDATE; import java.util.Collection; import java.util.List; +import java.util.Map; import java.util.stream.Collectors; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -39,6 +40,7 @@ import org.onap.cps.ncmp.api.NetworkCmProxyDataService; import org.onap.cps.ncmp.api.impl.exception.InvalidDatastoreException; import org.onap.cps.ncmp.api.impl.inventory.CompositeState; import org.onap.cps.ncmp.api.impl.operations.DatastoreType; +import org.onap.cps.ncmp.api.impl.trustlevel.TrustLevel; import org.onap.cps.ncmp.api.models.CmHandleQueryApiParameters; import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle; import org.onap.cps.ncmp.rest.api.NetworkCmProxyApi; @@ -77,6 +79,7 @@ public class NetworkCmProxyController implements NetworkCmProxyApi { private final NcmpCachedResourceRequestHandler ncmpCachedResourceRequestHandler; private final NcmpPassthroughResourceRequestHandler ncmpPassthroughResourceRequestHandler; private final DataOperationRequestMapper dataOperationRequestMapper; + private final Map trustLevelPerCmHandle; /** * Get resource data from datastore. @@ -361,11 +364,15 @@ public class NetworkCmProxyController implements NetworkCmProxyApi { private RestOutputCmHandle toRestOutputCmHandle(final NcmpServiceCmHandle ncmpServiceCmHandle) { final RestOutputCmHandle restOutputCmHandle = new RestOutputCmHandle(); final CmHandlePublicProperties cmHandlePublicProperties = new CmHandlePublicProperties(); + final TrustLevel cmHandleCurrentTrustLevel = trustLevelPerCmHandle.get(ncmpServiceCmHandle.getCmHandleId()); restOutputCmHandle.setCmHandle(ncmpServiceCmHandle.getCmHandleId()); cmHandlePublicProperties.add(ncmpServiceCmHandle.getPublicProperties()); restOutputCmHandle.setPublicCmHandleProperties(cmHandlePublicProperties); restOutputCmHandle.setState(cmHandleStateMapper.toCmHandleCompositeStateExternalLockReason( ncmpServiceCmHandle.getCompositeState())); + if (cmHandleCurrentTrustLevel != null) { + restOutputCmHandle.setTrustLevel(cmHandleCurrentTrustLevel.toString()); + } return restOutputCmHandle; } 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 de044d0aa..314a0b221 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 @@ -49,6 +49,7 @@ import org.onap.cps.ncmp.api.impl.inventory.CmHandleState import org.onap.cps.ncmp.api.impl.inventory.CompositeState import org.onap.cps.ncmp.api.impl.inventory.DataStoreSyncState import org.onap.cps.ncmp.api.impl.inventory.LockReasonCategory +import org.onap.cps.ncmp.api.impl.trustlevel.TrustLevel import org.onap.cps.ncmp.rest.model.DataOperationRequest import org.onap.cps.ncmp.rest.model.DataOperationDefinition import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle @@ -102,6 +103,9 @@ class NetworkCmProxyControllerSpec extends Specification { @SpringBean DataOperationRequestMapper dataOperationRequestMapper = Mappers.getMapper(DataOperationRequestMapper) + @SpringBean + Map trustLevelPerCmHandle = [:] + @SpringBean CpsNcmpTaskExecutor mockCpsTaskExecutor = Mock() @@ -136,15 +140,15 @@ class NetworkCmProxyControllerSpec extends Specification { def 'Get Resource Data from pass-through operational.'() { given: 'resource data url' def getUrl = "$ncmpBasePathV1/ch/testCmHandle/data/ds/ncmp-datastore:passthrough-operational" + - "?resourceIdentifier=parent/child&options=(a=1,b=2)" + "?resourceIdentifier=parent/child&options=(a=1,b=2)" when: 'get data resource request is performed' def response = mvc.perform( - get(getUrl) - .contentType(MediaType.APPLICATION_JSON) + get(getUrl) + .contentType(MediaType.APPLICATION_JSON) ).andReturn().response then: 'the NCMP data service is called with getResourceDataOperationalForCmHandle' 1 * mockNetworkCmProxyDataService.getResourceDataForCmHandle(PASSTHROUGH_OPERATIONAL.datastoreName, 'testCmHandle', - 'parent/child','(a=1,b=2)', NO_TOPIC, NO_REQUEST_ID) + 'parent/child','(a=1,b=2)', NO_TOPIC, NO_REQUEST_ID) and: 'response status is Ok' response.status == HttpStatus.OK.value() } @@ -152,10 +156,10 @@ class NetworkCmProxyControllerSpec extends Specification { def 'Get Resource Data from ncmp-datastore:operational (cached) parameters handling with #scenario.'() { given: 'resource data url' def getUrl = "$ncmpBasePathV1/ch/h123/data/ds/ncmp-datastore:operational" + - "?resourceIdentifier=parent/child${additionalUrlParam}" + "?resourceIdentifier=parent/child${additionalUrlParam}" when: 'get data resource request is performed' def response = mvc.perform( - get(getUrl).contentType(MediaType.APPLICATION_JSON)).andReturn().response + get(getUrl).contentType(MediaType.APPLICATION_JSON)).andReturn().response then: 'task executor is called appropriate number of times' 1 * mockNetworkCmProxyDataService.getResourceDataForCmHandle('ncmp-datastore:operational', 'h123', 'parent/child', expectedIncludeDescendants) and: 'response status is OK' @@ -226,16 +230,16 @@ class NetworkCmProxyControllerSpec extends Specification { def 'Query Resource Data from operational.'() { given: 'the query resource data url' def getUrl = "$ncmpBasePathV1/ch/testCmHandle/data/ds/ncmp-datastore:operational/query" + - "?cps-path=/cps/path" + "?cps-path=/cps/path" when: 'the query data resource request is performed' def response = mvc.perform( - get(getUrl) - .contentType(MediaType.APPLICATION_JSON) + get(getUrl) + .contentType(MediaType.APPLICATION_JSON) ).andReturn().response then: 'the NCMP query service is called with queryResourceDataOperationalForCmHandle' 1 * mockNetworkCmProxyQueryService.queryResourceDataOperational('testCmHandle', - '/cps/path', - FetchDescendantsOption.OMIT_DESCENDANTS) + '/cps/path', + FetchDescendantsOption.OMIT_DESCENDANTS) and: 'response status is Ok' response.status == HttpStatus.OK.value() } @@ -243,11 +247,11 @@ class NetworkCmProxyControllerSpec extends Specification { def 'Query Resource Data with unsupported datastore'() { given: 'the query resource data url' def getUrl = "$ncmpBasePathV1/ch/testCmHandle/data/ds/ncmp-datastore:passthrough-running/query" + - "?cps-path=/cps/path" + "?cps-path=/cps/path" when: 'the query data resource request is performed' def response = mvc.perform( - get(getUrl) - .contentType(MediaType.APPLICATION_JSON) + get(getUrl) + .contentType(MediaType.APPLICATION_JSON) ).andReturn().response then: 'a 400 BAD_REQUEST is returned for the unsupported datastore' response.status == 400 @@ -258,14 +262,14 @@ class NetworkCmProxyControllerSpec extends Specification { def 'Get Resource Data from pass-through running with #scenario value in resource identifier param.'() { given: 'resource data url' def getUrl = "$ncmpBasePathV1/ch/testCmHandle/data/ds/ncmp-datastore:passthrough-running" + - "?resourceIdentifier=" + resourceIdentifier + "&options=(a=1,b=2)" + "?resourceIdentifier=" + resourceIdentifier + "&options=(a=1,b=2)" and: 'ncmp service returns json object' mockNetworkCmProxyDataService.getResourceDataForCmHandle(PASSTHROUGH_RUNNING.datastoreName, 'testCmHandle', - resourceIdentifier,'(a=1,b=2)', NO_TOPIC, NO_REQUEST_ID) >> '{valid-json}' + resourceIdentifier,'(a=1,b=2)', NO_TOPIC, NO_REQUEST_ID) >> '{valid-json}' when: 'get data resource request is performed' def response = mvc.perform( - get(getUrl) - .contentType(MediaType.APPLICATION_JSON) + get(getUrl) + .contentType(MediaType.APPLICATION_JSON) ).andReturn().response then: 'response status is Ok' response.status == HttpStatus.OK.value() @@ -284,15 +288,15 @@ class NetworkCmProxyControllerSpec extends Specification { def 'Update resource data from pass-through running.'() { given: 'update resource data url' def updateUrl = "$ncmpBasePathV1/ch/testCmHandle/data/ds/ncmp-datastore:passthrough-running" + - "?resourceIdentifier=parent/child" + "?resourceIdentifier=parent/child" when: 'update data resource request is performed' def response = mvc.perform( - put(updateUrl) - .contentType(MediaType.APPLICATION_JSON_VALUE).content(requestBody) + put(updateUrl) + .contentType(MediaType.APPLICATION_JSON_VALUE).content(requestBody) ).andReturn().response then: 'ncmp service method to update resource is called' 1 * mockNetworkCmProxyDataService.writeResourceDataPassThroughRunningForCmHandle('testCmHandle', - 'parent/child', UPDATE, requestBody, 'application/json;charset=UTF-8') + 'parent/child', UPDATE, requestBody, 'application/json;charset=UTF-8') and: 'the response status is OK' response.status == HttpStatus.OK.value() } @@ -300,15 +304,15 @@ class NetworkCmProxyControllerSpec extends Specification { def 'Create Resource Data from pass-through running with #scenario.'() { given: 'resource data url' def url = "$ncmpBasePathV1/ch/testCmHandle/data/ds/ncmp-datastore:passthrough-running" + - "?resourceIdentifier=parent/child" + "?resourceIdentifier=parent/child" when: 'create resource request is performed' def response = mvc.perform( - post(url) - .contentType(MediaType.APPLICATION_JSON_VALUE).content(requestBody) + post(url) + .contentType(MediaType.APPLICATION_JSON_VALUE).content(requestBody) ).andReturn().response then: 'ncmp service method to create resource called' 1 * mockNetworkCmProxyDataService.writeResourceDataPassThroughRunningForCmHandle('testCmHandle', - 'parent/child', CREATE, requestBody, 'application/json;charset=UTF-8') + 'parent/child', CREATE, requestBody, 'application/json;charset=UTF-8') and: 'resource is created' response.status == HttpStatus.CREATED.value() } @@ -320,7 +324,7 @@ class NetworkCmProxyControllerSpec extends Specification { def response = mvc.perform(get(getUrl)).andReturn().response then: 'ncmp service method to get yang resource module references is called' mockNetworkCmProxyDataService.getYangResourcesModuleReferences('some-cmhandle') - >> [new ModuleReference(moduleName: 'some-name1', revision: '2021-10-03')] + >> [new ModuleReference(moduleName: 'some-name1', revision: '2021-10-03')] and: 'response contains an array with the module name and revision' response.getContentAsString() == '[{"moduleName":"some-name1","revision":"2021-10-03"}]' and: 'response returns an OK http code' @@ -333,20 +337,23 @@ class NetworkCmProxyControllerSpec extends Specification { String jsonString = TestUtils.getResourceFileContent('cmhandle-search.json') and: 'the service method is invoked with module names and returns two cm handles' def cmHandle1 = new NcmpServiceCmHandle() - cmHandle1.cmHandleId = 'some-cmhandle-id1' + cmHandle1.cmHandleId = 'ch-1' cmHandle1.publicProperties = [color: 'yellow'] def cmHandle2 = new NcmpServiceCmHandle() - cmHandle2.cmHandleId = 'some-cmhandle-id2' + cmHandle2.cmHandleId = 'ch-2' cmHandle2.publicProperties = [color: 'green'] mockNetworkCmProxyDataService.executeCmHandleSearch(_) >> [cmHandle1, cmHandle2] + and: 'map for trust level per cmHandle has value for only one cm handle' +// trustLevelPerCmHandle.get('') >> { TrustLevel.NONE } + trustLevelPerCmHandle.put('ch-1', TrustLevel.NONE) when: 'the searches api is invoked' def response = mvc.perform(post(searchesEndpoint) - .contentType(MediaType.APPLICATION_JSON) - .content(jsonString)).andReturn().response + .contentType(MediaType.APPLICATION_JSON) + .content(jsonString)).andReturn().response then: 'response status returns OK' response.status == HttpStatus.OK.value() and: 'the expected response content is returned' - response.contentAsString == '[{"cmHandle":"some-cmhandle-id1","publicCmHandleProperties":[{"color":"yellow"}],"state":null},{"cmHandle":"some-cmhandle-id2","publicCmHandleProperties":[{"color":"green"}],"state":null}]' + response.contentAsString == '[{"cmHandle":"ch-1","publicCmHandleProperties":[{"color":"yellow"}],"state":null,"trustLevel":"NONE"},{"cmHandle":"ch-2","publicCmHandleProperties":[{"color":"green"}],"state":null,"trustLevel":null}]' } def 'Get complete Cm Handle details by Cm Handle id.'() { @@ -360,9 +367,11 @@ class NetworkCmProxyControllerSpec extends Specification { def ncmpServiceCmHandle = new NcmpServiceCmHandle(cmHandleId: cmHandleId, dmiProperties: dmiProperties, publicProperties: publicProperties, compositeState: compositeState) and: 'the service method is invoked with the cm handle id' 1 * mockNetworkCmProxyDataService.getNcmpServiceCmHandle('some-cm-handle') >> ncmpServiceCmHandle + and: 'map for trust level per cmHandle has values' + trustLevelPerCmHandle.get('some-cm-handle') >> { TrustLevel.COMPLETE } when: 'the cm handle details api is invoked' def response = mvc.perform( - get(cmHandleDetailsEndpoint)).andReturn().response + get(cmHandleDetailsEndpoint)).andReturn().response then: 'the correct response is returned' response.status == HttpStatus.OK.value() and: 'the response contains the public properties' @@ -380,10 +389,10 @@ class NetworkCmProxyControllerSpec extends Specification { def publicProperties = ['public prop': 'some public property'] and: 'the service method is invoked with the cm handle id returning the cm handle public properties' 1 * mockNetworkCmProxyDataService - .getCmHandlePublicProperties('some-cm-handle') >> publicProperties + .getCmHandlePublicProperties('some-cm-handle') >> publicProperties when: 'the cm handle properties api is invoked' def response = mvc.perform( - get(cmHandlePropertiesEndpoint)).andReturn().response + get(cmHandlePropertiesEndpoint)).andReturn().response then: 'the correct response is returned' response.status == HttpStatus.OK.value() and: 'the response contains the public properties' @@ -397,10 +406,10 @@ class NetworkCmProxyControllerSpec extends Specification { def compositeState = compositeStateTestObject() and: 'the service method is invoked with the cm handle id returning the cm handle composite state' 1 * mockNetworkCmProxyDataService - .getCmHandleCompositeState('some-cm-handle') >> compositeState + .getCmHandleCompositeState('some-cm-handle') >> compositeState when: 'the cm handle state api is invoked' def response = mvc.perform( - get(cmHandlePropertiesEndpoint)).andReturn().response + get(cmHandlePropertiesEndpoint)).andReturn().response then: 'the correct response is returned' response.status == HttpStatus.OK.value() and: 'the response contains the cm handle state' @@ -413,33 +422,36 @@ class NetworkCmProxyControllerSpec extends Specification { String jsonString = TestUtils.getResourceFileContent('invalid-cmhandle-search.json') and: 'the service method is invoked with module names and returns two cm handles' def cmHandel1 = new NcmpServiceCmHandle() - cmHandel1.cmHandleId = 'some-cmhandle-id1' + cmHandel1.cmHandleId = 'ch-1' cmHandel1.publicProperties = [color: 'yellow'] def cmHandel2 = new NcmpServiceCmHandle() - cmHandel2.cmHandleId = 'some-cmhandle-id2' + cmHandel2.cmHandleId = 'ch-2' cmHandel2.publicProperties = [color: 'green'] mockNetworkCmProxyDataService.executeCmHandleSearch(_) >> [cmHandel1, cmHandel2] + and: 'map for trust level per cmHandle has values' + trustLevelPerCmHandle.put('ch-1', TrustLevel.COMPLETE) + trustLevelPerCmHandle.put('ch-2', TrustLevel.NONE) when: 'the searches api is invoked' def response = mvc.perform( - post(searchesEndpoint) - .contentType(MediaType.APPLICATION_JSON) - .content(jsonString)).andReturn().response + post(searchesEndpoint) + .contentType(MediaType.APPLICATION_JSON) + .content(jsonString)).andReturn().response then: 'an empty cm handle identifier is returned' - response.contentAsString == '[{"cmHandle":"some-cmhandle-id1","publicCmHandleProperties":[{"color":"yellow"}],"state":null},{"cmHandle":"some-cmhandle-id2","publicCmHandleProperties":[{"color":"green"}],"state":null}]' + response.contentAsString == '[{"cmHandle":"ch-1","publicCmHandleProperties":[{"color":"yellow"}],"state":null,"trustLevel":"COMPLETE"},{"cmHandle":"ch-2","publicCmHandleProperties":[{"color":"green"}],"state":null,"trustLevel":"NONE"}]' } def 'Query for cm handles matching query parameters'() { given: 'an endpoint and json data' def searchesEndpoint = "$ncmpBasePathV1/ch/id-searches" and: 'the service method is invoked with module names and returns cm handle ids' - 1 * mockNetworkCmProxyDataService.executeCmHandleIdSearch(_) >> ['some-cmhandle-id1', 'some-cmhandle-id2'] + 1 * mockNetworkCmProxyDataService.executeCmHandleIdSearch(_) >> ['ch-1', 'ch-2'] when: 'the searches api is invoked' def response = mvc.perform( - post(searchesEndpoint) - .contentType(MediaType.APPLICATION_JSON) - .content('{}')).andReturn().response + post(searchesEndpoint) + .contentType(MediaType.APPLICATION_JSON) + .content('{}')).andReturn().response then: 'cm handle ids are returned' - response.contentAsString == '["some-cmhandle-id1","some-cmhandle-id2"]' + response.contentAsString == '["ch-1","ch-2"]' } def 'Query for cm handles with invalid request payload'() { @@ -447,9 +459,9 @@ class NetworkCmProxyControllerSpec extends Specification { def searchesEndpoint = "$ncmpBasePathV1/ch/id-searches" def invalidInputData = '{invalidJson}' def response = mvc.perform( - post(searchesEndpoint) - .contentType(MediaType.APPLICATION_JSON) - .content(invalidInputData)).andReturn().response + post(searchesEndpoint) + .contentType(MediaType.APPLICATION_JSON) + .content(invalidInputData)).andReturn().response then: 'BAD_REQUEST is returned' response.getStatus() == 400 } @@ -457,16 +469,16 @@ class NetworkCmProxyControllerSpec extends Specification { def 'Patch resource data in pass-through running datastore.'() { given: 'patch resource data url' def url = "$ncmpBasePathV1/ch/testCmHandle/data/ds/ncmp-datastore:passthrough-running" + - "?resourceIdentifier=parent/child" + "?resourceIdentifier=parent/child" when: 'patch data resource request is performed' def response = mvc.perform( - patch(url) - .contentType(MediaType.APPLICATION_JSON) - .accept(MediaType.APPLICATION_JSON).content(requestBody) + patch(url) + .contentType(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON).content(requestBody) ).andReturn().response then: 'ncmp service method to update resource is called' 1 * mockNetworkCmProxyDataService.writeResourceDataPassThroughRunningForCmHandle('testCmHandle', - 'parent/child', PATCH, requestBody, 'application/json;charset=UTF-8') + 'parent/child', PATCH, requestBody, 'application/json;charset=UTF-8') and: 'the response status is OK' response.status == HttpStatus.OK.value() } @@ -474,14 +486,14 @@ class NetworkCmProxyControllerSpec extends Specification { def 'Delete resource data in pass-through running datastore.'() { given: 'delete resource data url' def url = "$ncmpBasePathV1/ch/testCmHandle/data/ds/ncmp-datastore:passthrough-running" + - "?resourceIdentifier=parent/child" + "?resourceIdentifier=parent/child" when: 'delete data resource request is performed' def response = mvc.perform( - delete(url) - .contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON)).andReturn().response + delete(url) + .contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON)).andReturn().response then: 'the ncmp service method to delete resource is called (with null as body)' 1 * mockNetworkCmProxyDataService.writeResourceDataPassThroughRunningForCmHandle('testCmHandle', - 'parent/child', DELETE, null, 'application/json;charset=UTF-8') + 'parent/child', DELETE, null, 'application/json;charset=UTF-8') and: 'the response is No Content' response.status == HttpStatus.NO_CONTENT.value() } @@ -489,12 +501,12 @@ class NetworkCmProxyControllerSpec extends Specification { def 'Get resource data from DMI with valid topic i.e. async request for #scenario'() { given: 'resource data url' def getUrl = "$ncmpBasePathV1/ch/testCmHandle/data/ds/ncmp-datastore:${datastoreInUrl}" + - "?resourceIdentifier=parent/child&options=(a=1,b=2)&topic=my-topic-name" + "?resourceIdentifier=parent/child&options=(a=1,b=2)&topic=my-topic-name" when: 'get data resource request is performed' def response = mvc.perform( - get(getUrl) - .contentType(MediaType.APPLICATION_JSON) - .accept(MediaType.APPLICATION_JSON_VALUE) + get(getUrl) + .contentType(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON_VALUE) ).andReturn().response then: 'async request id is generated' assert response.contentAsString.contains("requestId") @@ -507,12 +519,12 @@ class NetworkCmProxyControllerSpec extends Specification { def 'Get module definitions based on cmHandleId.'() { when: 'get module definition request is performed' def response = mvc.perform( - get("$ncmpBasePathV1/ch/some-cmhandle/modules/definitions")) - .andReturn().response + get("$ncmpBasePathV1/ch/some-cmhandle/modules/definitions")) + .andReturn().response then: 'ncmp service method to get module definitions is called' mockNetworkCmProxyDataService.getModuleDefinitionsByCmHandleId('some-cmhandle') - >> [new ModuleDefinition('sampleModuleName', '2021-10-03', - 'module sampleModuleName{ sample module content }')] + >> [new ModuleDefinition('sampleModuleName', '2021-10-03', + 'module sampleModuleName{ sample module content }')] and: 'response contains an array with the module name, revision and content' response.getContentAsString() == '[{"moduleName":"sampleModuleName","revision":"2021-10-03","content":"module sampleModuleName{ sample module content }"}]' and: 'response returns an OK http code' @@ -522,8 +534,8 @@ class NetworkCmProxyControllerSpec extends Specification { def 'Set the data sync enabled based on the cm handle id and the data sync flag is #scenario'() { when: 'the set data sync enabled request is invoked' def response = mvc.perform( - put("$ncmpBasePathV1/ch/some-cm-handle-id/data-sync?dataSyncEnabled=" + dataSyncEnabledFlag)) - .andReturn().response + put("$ncmpBasePathV1/ch/some-cm-handle-id/data-sync?dataSyncEnabled=" + dataSyncEnabledFlag)) + .andReturn().response then: 'method to set data sync enabled is called' 1 * mockNetworkCmProxyDataService.setDataSyncEnabled('some-cm-handle-id', dataSyncEnabledFlag) and: 'the response returns an OK http code' @@ -537,11 +549,11 @@ class NetworkCmProxyControllerSpec extends Specification { def 'Get Resource Data from operational with or without descendants'() { given: 'resource data url with descendants #enabled' def getUrl = "$ncmpBasePathV1/ch/testCmHandle/data/ds/ncmp-datastore:operational" + - "?resourceIdentifier=parent/child&include-descendants=${booleanValue}" + "?resourceIdentifier=parent/child&include-descendants=${booleanValue}" when: 'get data resource request is performed' def response = mvc.perform( - get(getUrl) - .contentType(MediaType.APPLICATION_JSON) + get(getUrl) + .contentType(MediaType.APPLICATION_JSON) ).andReturn().response then: 'the NCMP data service is called with getResourceDataOperational with #descendantsOption' 1 * mockNetworkCmProxyDataService.getResourceDataForCmHandle(OPERATIONAL.datastoreName, 'testCmHandle', 'parent/child', descendantsOption) @@ -558,8 +570,8 @@ class NetworkCmProxyControllerSpec extends Specification { def url = "$ncmpBasePathV1/ch/testCmHandle/data/ds/${datastoreInUrl}?resourceIdentifier=parent/child" when: 'selected request for data resource is performed on url' def response = mvc.perform( - executeRestOperation(operation, url)) - .andReturn().response + executeRestOperation(operation, url)) + .andReturn().response then: 'the response status is as expected' assert response.status == HttpStatus.BAD_REQUEST.value() and: 'the response is as expected' @@ -593,17 +605,17 @@ class NetworkCmProxyControllerSpec extends Specification { def dataStores() { DataStores.builder() - .operationalDataStore(Operational.builder() - .dataStoreSyncState(DataStoreSyncState.NONE_REQUESTED) - .lastSyncTime(formattedDateAndTime.toString()).build()).build() + .operationalDataStore(Operational.builder() + .dataStoreSyncState(DataStoreSyncState.NONE_REQUESTED) + .lastSyncTime(formattedDateAndTime.toString()).build()).build() } def compositeStateTestObject() { new CompositeState(cmHandleState: CmHandleState.ADVISED, - lockReason: CompositeState.LockReason.builder().lockReasonCategory(LockReasonCategory.MODULE_SYNC_FAILED).details("lock details").build(), - lastUpdateTime: formattedDateAndTime.toString(), - dataSyncEnabled: false, - dataStores: dataStores()) + lockReason: CompositeState.LockReason.builder().lockReasonCategory(LockReasonCategory.MODULE_SYNC_FAILED).details("lock details").build(), + lastUpdateTime: formattedDateAndTime.toString(), + dataSyncEnabled: false, + dataStores: dataStores()) } def assertContainsAll(response, assertContent) { @@ -613,25 +625,25 @@ class NetworkCmProxyControllerSpec extends Specification { def assertContainsState(response) { def expectedContent = [ - '"state":', - '"cmHandleState":"ADVISED"', - '"lockReason":{"reason":"MODULE_SYNC_FAILED","details":"lock details"}', - '"lastUpdateTime":"2022-12-31T20:30:40.000+0000"', - '"dataSyncEnabled":false', - '"dataSyncState":', - '"operational":', - '"syncState":"NONE_REQUESTED"', - '"lastSyncTime":"2022-12-31T20:30:40.000+0000"', - '"running":null' + '"state":', + '"cmHandleState":"ADVISED"', + '"lockReason":{"reason":"MODULE_SYNC_FAILED","details":"lock details"}', + '"lastUpdateTime":"2022-12-31T20:30:40.000+0000"', + '"dataSyncEnabled":false', + '"dataSyncState":', + '"operational":', + '"syncState":"NONE_REQUESTED"', + '"lastSyncTime":"2022-12-31T20:30:40.000+0000"', + '"running":null' ] return assertContainsAll(response, expectedContent) } def assertContainsPublicProperties(response) { def expectedContent = [ - '"publicCmHandleProperties":', - '"public prop"', - '"some public property"' + '"publicCmHandleProperties":', + '"public prop"', + '"some public property"' ] return assertContainsAll(response, expectedContent) } -- 2.16.6