diff options
author | ToineSiebelink <toine.siebelink@est.tech> | 2022-05-27 10:58:52 +0100 |
---|---|---|
committer | ToineSiebelink <toine.siebelink@est.tech> | 2022-05-31 17:53:58 +0100 |
commit | d1a7dad5af98a7f3397f8535ba88129a0f7dce11 (patch) | |
tree | e7b378bea44828aeff76196772819764e03b2251 /cps-ncmp-service/src/test | |
parent | f31c7f8bd4985c84f9126d071439c1a4de57f704 (diff) |
Handle RestTemplate Error handling so NCMP cna report correct server status
- Moved resposne handling to DmRestClient
- Clean up incorrect/redundant tests in CmProxyDataServiceImplSpec
Issue-ID: CPS-1056
Signed-off-by: ToineSiebelink <toine.siebelink@est.tech>
Change-Id: I78ba87d6af7255d85758893cfef237d75227875a
Diffstat (limited to 'cps-ncmp-service/src/test')
4 files changed, 67 insertions, 180 deletions
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 01f3bfed7b..161cf9892f 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 @@ -22,7 +22,6 @@ package org.onap.cps.ncmp.api.impl -import org.onap.cps.ncmp.api.impl.exception.HttpClientRequestException import org.onap.cps.ncmp.api.impl.operations.YangModelCmHandleRetriever import org.onap.cps.ncmp.api.impl.yangmodels.YangModelCmHandle import org.onap.cps.ncmp.api.models.DmiPluginRegistration @@ -34,11 +33,9 @@ import spock.lang.Shared import static org.onap.cps.ncmp.api.impl.operations.DmiOperations.DataStoreEnum.PASSTHROUGH_OPERATIONAL import static org.onap.cps.ncmp.api.impl.operations.DmiOperations.DataStoreEnum.PASSTHROUGH_RUNNING import static org.onap.cps.ncmp.api.impl.operations.DmiRequestBody.OperationEnum.CREATE -import static org.onap.cps.ncmp.api.impl.operations.DmiRequestBody.OperationEnum.READ import static org.onap.cps.ncmp.api.impl.operations.DmiRequestBody.OperationEnum.UPDATE import org.onap.cps.utils.JsonObjectMapper -import com.fasterxml.jackson.core.JsonProcessingException import com.fasterxml.jackson.databind.ObjectMapper import org.onap.cps.api.CpsAdminService import org.onap.cps.api.CpsDataService @@ -76,11 +73,11 @@ class NetworkCmProxyDataServiceImplSpec extends Specification { def dataNode = new DataNode(leaves: ['id': 'some-cm-handle', 'dmi-service-name': 'testDmiService']) - def 'Write resource data for pass-through running from DMI using POST #scenario cm handle properties.'() { + def 'Write resource data for pass-through running from DMI using POST.'() { given: 'cpsDataService returns valid datanode' mockCpsDataService.getDataNode('NCMP-Admin', 'ncmp-dmi-registry', cmHandleXPath, FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS) >> dataNode - when: 'get resource data is called' + when: 'write resource data is called' objectUnderTest.writeResourceDataPassThroughRunningForCmHandle('testCmHandle', 'testResourceId', CREATE, '{some-json}', 'application/json') @@ -101,102 +98,26 @@ class NetworkCmProxyDataServiceImplSpec extends Specification { 0 * mockDmiDataOperations.writeResourceDataPassThroughRunningFromDmi(_, _, _, _, _) } - def 'Write resource data for pass-through running from DMI using POST "not found" response (from DMI).'() { - given: 'cpsDataService returns valid dataNode' - mockCpsDataService.getDataNode('NCMP-Admin', 'ncmp-dmi-registry', - cmHandleXPath, FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS) >> dataNode - and: 'DMI returns a response with 404 status code' - mockDmiDataOperations.writeResourceDataPassThroughRunningFromDmi('testCmHandle', - 'testResourceId', CREATE, - '{some-json}', 'application/json') - >> { new ResponseEntity<>(HttpStatus.NOT_FOUND) } - when: 'write resource data is called' - objectUnderTest.writeResourceDataPassThroughRunningForCmHandle('testCmHandle', - 'testResourceId', CREATE, - '{some-json}', 'application/json') - then: 'exception is thrown' - def exceptionThrown = thrown(HttpClientRequestException.class) - and: 'http status (not found) error code: 404' - exceptionThrown.httpStatus == HttpStatus.NOT_FOUND.value() - } - def 'Get resource data for pass-through operational from DMI.'() { given: 'get data node is called' mockCpsDataService.getDataNode('NCMP-Admin', 'ncmp-dmi-registry', cmHandleXPath, FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS) >> dataNode and: 'get resource data from DMI is called' mockDmiDataOperations.getResourceDataFromDmi( - 'testCmHandle', - 'testResourceId', - OPTIONS_PARAM, - PASSTHROUGH_OPERATIONAL, - NO_REQUEST_ID, - NO_TOPIC) >> new ResponseEntity<>('dmi-response', HttpStatus.OK) + 'testCmHandle', + 'testResourceId', + OPTIONS_PARAM, + PASSTHROUGH_OPERATIONAL, + NO_REQUEST_ID, + NO_TOPIC) >> new ResponseEntity<>('dmi-response', HttpStatus.OK) when: 'get resource data operational for cm-handle is called' def response = objectUnderTest.getResourceDataOperationalForCmHandle('testCmHandle', - 'testResourceId', - OPTIONS_PARAM, - NO_TOPIC, - NO_REQUEST_ID) - then: 'DMI returns a json response' - response == 'dmi-response' - } - - def 'Get resource data for pass-through operational from DMI with invalid name.'() {\ - when: 'get resource data operational for cm-handle is called' - objectUnderTest.getResourceDataOperationalForCmHandle('invalid test cm handle', 'testResourceId', OPTIONS_PARAM, NO_TOPIC, NO_REQUEST_ID) - then: 'A data validation Exception is thrown' - thrown(DataValidationException) - } - - def 'Get resource data for pass-through operational from DMI with Json Processing Exception.'() { - given: 'cps data service returns valid data node' - mockCpsDataService.getDataNode('NCMP-Admin', 'ncmp-dmi-registry', - cmHandleXPath, FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS) >> dataNode - and: 'objectMapper not able to parse object' - spiedJsonObjectMapper.asJsonString(_) >> { throw new JsonProcessingException('testException') } - and: 'DMI returns NOK response' - mockDmiDataOperations.getResourceDataFromDmi(*_) - >> new ResponseEntity<>('NOK-json', HttpStatus.NOT_FOUND) - when: 'get resource data is called' - objectUnderTest.getResourceDataOperationalForCmHandle('testCmHandle', - 'testResourceId', - OPTIONS_PARAM, - NO_TOPIC, - NO_REQUEST_ID) - then: 'exception is thrown with the expected response code and details' - def exceptionThrown = thrown(HttpClientRequestException.class) - exceptionThrown.details.contains('NOK-json') - exceptionThrown.httpStatus == HttpStatus.NOT_FOUND.value() - } - - def 'Get resource data for pass-through operational from DMI return NOK response.'() { - given: 'cps data service returns valid data node' - mockCpsDataService.getDataNode('NCMP-Admin', 'ncmp-dmi-registry', - cmHandleXPath, FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS) >> dataNode - and: 'DMI returns NOK response' - mockDmiDataOperations.getResourceDataFromDmi('testCmHandle', - 'testResourceId', - OPTIONS_PARAM, - PASSTHROUGH_OPERATIONAL, - NO_REQUEST_ID, - NO_TOPIC) - >> new ResponseEntity<>('NOK-json', HttpStatus.NOT_FOUND) - when: 'get resource data is called' - objectUnderTest.getResourceDataOperationalForCmHandle('testCmHandle', - 'testResourceId', - OPTIONS_PARAM, - NO_TOPIC, - NO_REQUEST_ID) - then: 'exception is thrown' - def exceptionThrown = thrown(HttpClientRequestException.class) - and: 'details contain the original response' - exceptionThrown.httpStatus == HttpStatus.NOT_FOUND.value() - exceptionThrown.details.contains('NOK-json') + then: 'DMI returns a json response' + response == 'dmi-response' } def 'Get resource data for pass-through running from DMI.'() { @@ -205,55 +126,19 @@ class NetworkCmProxyDataServiceImplSpec extends Specification { cmHandleXPath, FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS) >> dataNode and: 'DMI returns valid response and data' mockDmiDataOperations.getResourceDataFromDmi('testCmHandle', - 'testResourceId', - OPTIONS_PARAM, - PASSTHROUGH_RUNNING, - NO_REQUEST_ID, - NO_TOPIC) >> new ResponseEntity<>('{dmi-response}', HttpStatus.OK) + 'testResourceId', + OPTIONS_PARAM, + PASSTHROUGH_RUNNING, + NO_REQUEST_ID, + NO_TOPIC) >> new ResponseEntity<>('{dmi-response}', HttpStatus.OK) when: 'get resource data is called' def response = objectUnderTest.getResourceDataPassThroughRunningForCmHandle('testCmHandle', - 'testResourceId', - OPTIONS_PARAM, - NO_TOPIC, - NO_REQUEST_ID) - then: 'get resource data returns expected response' - response == '{dmi-response}' - } - - def 'Get resource data for pass-through running from DMI with invalid name.'() { - when: 'get resource data operational for cm-handle is called' - objectUnderTest.getResourceDataPassThroughRunningForCmHandle('invalid test cm handle', 'testResourceId', OPTIONS_PARAM, NO_TOPIC, NO_REQUEST_ID) - then: 'A data validation Exception is thrown' - thrown(DataValidationException) - } - - def 'Get resource data for pass-through running from DMI return NOK response.'() { - given: 'cpsDataService returns valid dataNode' - mockCpsDataService.getDataNode('NCMP-Admin', 'ncmp-dmi-registry', - cmHandleXPath, FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS) >> dataNode - and: 'DMI returns NOK response' - mockDmiDataOperations.getResourceDataFromDmi('testCmHandle', - 'testResourceId', - OPTIONS_PARAM, - PASSTHROUGH_RUNNING, - NO_REQUEST_ID, - NO_TOPIC) - >> new ResponseEntity<>('NOK-json', HttpStatus.NOT_FOUND) - when: 'get resource data is called' - objectUnderTest.getResourceDataPassThroughRunningForCmHandle('testCmHandle', - 'testResourceId', - OPTIONS_PARAM, - NO_TOPIC, - NO_REQUEST_ID) - then: 'exception is thrown' - def exceptionThrown = thrown(HttpClientRequestException.class) - and: 'details contain the original response' - exceptionThrown.details.contains('NOK-json') - exceptionThrown.httpStatus == HttpStatus.NOT_FOUND.value() + then: 'get resource data returns expected response' + response == '{dmi-response}' } def 'Getting Yang Resources.'() { @@ -269,7 +154,7 @@ class NetworkCmProxyDataServiceImplSpec extends Specification { then: 'a data validation exception is thrown' thrown(DataValidationException) and: 'CPS module services is not invoked' - 0 * mockCpsModuleService.getYangResourcesModuleReferences(_, _) + 0 * mockCpsModuleService.getYangResourcesModuleReferences(*_) } def 'Get cm handle identifiers for the given module names.'() { @@ -282,17 +167,16 @@ class NetworkCmProxyDataServiceImplSpec extends Specification { def 'Get a cm handle.'() { given: 'the system returns a yang modelled cm handle' def dmiServiceName = 'some service name' - def dmiProperties = [new YangModelCmHandle.Property('Book', 'Romance Novel')] - def publicProperties = [new YangModelCmHandle.Property('Public Book', 'Public Romance Novel')] + def dmiProperties = [new YangModelCmHandle.Property('aDmiProperty', 'a dmi value')] + def publicProperties = [new YangModelCmHandle.Property('aPublicProperty', 'a public value')] def yangModelCmHandle = new YangModelCmHandle(id:'some-cm-handle', dmiServiceName: dmiServiceName, dmiProperties: dmiProperties, publicProperties: publicProperties) 1 * mockYangModelCmHandleRetriever.getYangModelCmHandle('some-cm-handle') >> yangModelCmHandle when: 'getting cm handle details for a given cm handle id from ncmp service' def result = objectUnderTest.getNcmpServiceCmHandle('some-cm-handle') then: 'the result returns the correct data' result.cmHandleId == 'some-cm-handle' - result.dmiProperties ==[ Book:'Romance Novel' ] - result.publicProperties == [ "Public Book":'Public Romance Novel' ] - + result.dmiProperties ==[ aDmiProperty:'a dmi value' ] + result.publicProperties == [ aPublicProperty:'a public value' ] } def 'Get a cm handle with an invalid id.'() { @@ -301,7 +185,7 @@ class NetworkCmProxyDataServiceImplSpec extends Specification { then: 'an exception is thrown' thrown(DataValidationException) and: 'the yang model cm handle retriever is not invoked' - 0 * mockYangModelCmHandleRetriever.getYangModelCmHandle(_) + 0 * mockYangModelCmHandleRetriever.getYangModelCmHandle(*_) } def 'Get cm handle public properties'() { @@ -323,7 +207,7 @@ class NetworkCmProxyDataServiceImplSpec extends Specification { then: 'an exception is thrown' thrown(DataValidationException) and: 'the yang model cm handle retriever is not invoked' - 0 * mockYangModelCmHandleRetriever.getYangModelCmHandle(_) + 0 * mockYangModelCmHandleRetriever.getYangModelCmHandle(*_) } def 'Update resource data for pass-through running from dmi using POST #scenario DMI properties.'() { @@ -340,40 +224,19 @@ class NetworkCmProxyDataServiceImplSpec extends Specification { >> { new ResponseEntity<>(HttpStatus.OK) } } - def 'Verify error message from handleResponse is correct for #scenario operation.'() { - given: 'writeResourceDataPassThroughRunningFromDmi fails to return OK HttpStatus' - mockDmiDataOperations.writeResourceDataPassThroughRunningFromDmi(*_) - >> new ResponseEntity<>(HttpStatus.NOT_FOUND) - when: 'get resource data is called' - objectUnderTest.writeResourceDataPassThroughRunningForCmHandle( - 'testCmHandle', - 'testResourceId', - givenOperation, - '{some-json}', - 'application/json') - then: 'an exception is thrown with the expected error message details with correct operation' - def exceptionThrown = thrown(HttpClientRequestException.class) - exceptionThrown.getMessage().contains(expectedResponseMessage) - where: - scenario | givenOperation || expectedResponseMessage - 'CREATE' | CREATE || 'Unable to create resource data.' - 'READ' | READ || 'Unable to read resource data.' - 'UPDATE' | UPDATE || 'Unable to update resource data.' - } - def 'Verify modules and create anchor params'() { given: 'dmi plugin registration return created cm handles' def dmiPluginRegistration = new DmiPluginRegistration(dmiPlugin: 'service1', dmiModelPlugin: 'service1', - dmiDataPlugin: 'service2') + dmiDataPlugin: 'service2') dmiPluginRegistration.createdCmHandles = [ncmpServiceCmHandle] 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 * mockCpsDataService.saveListElements('NCMP-Admin', 'ncmp-dmi-registry', - '/dmi-registry', '{"cm-handles":[{"id":"some-cm-handle-id",' + - '"additional-properties":[],"public-properties":[]}]}', null) + '/dmi-registry', '{"cm-handles":[{"id":"some-cm-handle-id",' + + '"additional-properties":[],"public-properties":[]}]}', null) 1 * mockCpsAdminService.createAnchor('NFP-Operational', null, - 'some-cm-handle-id') + 'some-cm-handle-id') } } diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/client/DmiRestClientSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/client/DmiRestClientSpec.groovy index 394df1d076..90839f8ac0 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/client/DmiRestClientSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/client/DmiRestClientSpec.groovy @@ -1,6 +1,6 @@ /* * ============LICENSE_START======================================================= - * Copyright (C) 2021 Nordix Foundation + * Copyright (C) 2021-2022 Nordix Foundation * Modifications Copyright (C) 2022 Bell Canada * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -22,17 +22,23 @@ package org.onap.cps.ncmp.api.impl.client import org.onap.cps.ncmp.api.impl.config.NcmpConfiguration +import org.onap.cps.ncmp.api.impl.exception.HttpClientRequestException import org.spockframework.spring.SpringBean import org.springframework.beans.factory.annotation.Autowired import org.springframework.boot.test.context.SpringBootTest import org.springframework.http.HttpEntity -import org.springframework.http.HttpHeaders -import org.springframework.http.HttpMethod +import org.springframework.http.HttpStatus import org.springframework.http.ResponseEntity import org.springframework.test.context.ContextConfiguration +import org.springframework.web.client.HttpServerErrorException import org.springframework.web.client.RestTemplate import spock.lang.Specification +import static org.onap.cps.ncmp.api.impl.operations.DmiRequestBody.OperationEnum.READ +import static org.onap.cps.ncmp.api.impl.operations.DmiRequestBody.OperationEnum.PATCH +import static org.onap.cps.ncmp.api.impl.operations.DmiRequestBody.OperationEnum.CREATE + + @SpringBootTest @ContextConfiguration(classes = [NcmpConfiguration.DmiProperties, DmiRestClient]) class DmiRestClientSpec extends Specification { @@ -44,14 +50,32 @@ class DmiRestClientSpec extends Specification { DmiRestClient objectUnderTest def resourceUrl = 'some url' + def mockResponseEntity = Mock(ResponseEntity) + def 'DMI POST operation with JSON.'() { given: 'the rest template returns a valid response entity' - def mockResponseEntity = Mock(ResponseEntity) mockRestTemplate.postForEntity(resourceUrl, _ as HttpEntity, Object.class) >> mockResponseEntity when: 'POST operation is invoked' - def result = objectUnderTest.postOperationWithJsonData(resourceUrl, 'json-data') + def result = objectUnderTest.postOperationWithJsonData(resourceUrl, 'json-data', READ) then: 'the output of the method is equal to the output from the test template' result == mockResponseEntity } + def 'Failing DMI POST operation.'() { + given: 'the rest template returns a valid response entity' + def serverResponse = 'server response'.getBytes() + def httpServerErrorException = new HttpServerErrorException(HttpStatus.FORBIDDEN, 'status text', serverResponse, null) + mockRestTemplate.postForEntity(*_) >> { throw httpServerErrorException } + when: 'POST operation is invoked' + def result = objectUnderTest.postOperationWithJsonData('some url', 'some json', operation) + then: 'a Http Client Exception is thrown' + def thrown = thrown(HttpClientRequestException) + and: 'the exception has the relevant details from the error response' + assert thrown.httpStatus == 403 + assert thrown.message == "Unable to ${operation} resource data." + assert thrown.details == 'server response' + where: 'the following operation is executed' + operation << [CREATE, READ, PATCH] + } + } diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/operations/DmiDataOperationsSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/operations/DmiDataOperationsSpec.groovy index 2a19df1723..b7ebf2965a 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/operations/DmiDataOperationsSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/operations/DmiDataOperationsSpec.groovy @@ -30,12 +30,12 @@ import org.springframework.beans.factory.annotation.Autowired import org.springframework.boot.test.context.SpringBootTest import org.springframework.http.ResponseEntity import org.springframework.test.context.ContextConfiguration -import org.springframework.util.MultiValueMap import spock.lang.Shared import static org.onap.cps.ncmp.api.impl.operations.DmiOperations.DataStoreEnum.PASSTHROUGH_OPERATIONAL import static org.onap.cps.ncmp.api.impl.operations.DmiOperations.DataStoreEnum.PASSTHROUGH_RUNNING import static org.onap.cps.ncmp.api.impl.operations.DmiRequestBody.OperationEnum.CREATE +import static org.onap.cps.ncmp.api.impl.operations.DmiRequestBody.OperationEnum.READ import static org.onap.cps.ncmp.api.impl.operations.DmiRequestBody.OperationEnum.UPDATE import org.springframework.http.HttpStatus @@ -63,7 +63,7 @@ class DmiDataOperationsSpec extends DmiOperationsBaseSpec { and: 'a positive response from DMI service when it is called with the expected parameters' def responseFromDmi = new ResponseEntity<Object>(HttpStatus.OK) def expectedUrl = dmiServiceBaseUrl + "${expectedDatastoreInUrl}?resourceIdentifier=${resourceIdentifier}${expectedOptionsInUrl}" - mockDmiRestClient.postOperationWithJsonData(expectedUrl, expectedJson) >> responseFromDmi + mockDmiRestClient.postOperationWithJsonData(expectedUrl, expectedJson, READ) >> responseFromDmi dmiServiceUrlBuilder.getDmiDatastoreUrl(_, _) >> expectedUrl when: 'get resource data is invoked' def result = objectUnderTest.getResourceDataFromDmi(cmHandleId, resourceIdentifier, @@ -88,7 +88,7 @@ class DmiDataOperationsSpec extends DmiOperationsBaseSpec { def expectedJson = '{"operation":"' + expectedOperationInUrl + '","dataType":"some data type","data":"requestData","cmHandleProperties":{"prop1":"val1"}}' def responseFromDmi = new ResponseEntity<Object>(HttpStatus.OK) dmiServiceUrlBuilder.getDmiDatastoreUrl(_, _) >> expectedUrl - mockDmiRestClient.postOperationWithJsonData(expectedUrl, expectedJson) >> responseFromDmi + mockDmiRestClient.postOperationWithJsonData(expectedUrl, expectedJson, operation) >> responseFromDmi when: 'write resource method is invoked' def result = objectUnderTest.writeResourceDataPassThroughRunningFromDmi(cmHandleId, 'parent/child', operation, 'requestData', 'some data type') then: 'the result is the response from the DMI service' @@ -98,4 +98,4 @@ class DmiDataOperationsSpec extends DmiOperationsBaseSpec { CREATE || 'create' UPDATE || 'update' } -}
\ No newline at end of file +} diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/operations/DmiModelOperationsSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/operations/DmiModelOperationsSpec.groovy index 574f609e9e..ed8f08698d 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/operations/DmiModelOperationsSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/operations/DmiModelOperationsSpec.groovy @@ -24,7 +24,6 @@ package org.onap.cps.ncmp.api.impl.operations import com.fasterxml.jackson.core.JsonProcessingException import com.fasterxml.jackson.databind.ObjectMapper import org.onap.cps.ncmp.api.impl.config.NcmpConfiguration -import org.onap.cps.ncmp.api.impl.utils.DmiServiceUrlBuilder import org.onap.cps.spi.model.ModuleReference import org.onap.cps.utils.JsonObjectMapper import org.spockframework.spring.SpringBean @@ -33,9 +32,10 @@ import org.springframework.boot.test.context.SpringBootTest import org.springframework.http.HttpStatus import org.springframework.http.ResponseEntity import org.springframework.test.context.ContextConfiguration -import org.springframework.web.util.UriComponentsBuilder import spock.lang.Shared +import static org.onap.cps.ncmp.api.impl.operations.DmiRequestBody.OperationEnum.READ + @SpringBootTest @ContextConfiguration(classes = [NcmpConfiguration.DmiProperties, DmiModelOperations]) class DmiModelOperationsSpec extends DmiOperationsBaseSpec { @@ -56,7 +56,7 @@ class DmiModelOperationsSpec extends DmiOperationsBaseSpec { def moduleReferencesAsLisOfMaps = [[moduleName: 'mod1', revision: 'A'], [moduleName: 'mod2', revision: 'X']] def expectedUrl = "${dmiServiceName}/dmi/v1/ch/${cmHandleId}/modules" def responseFromDmi = new ResponseEntity([schemas: moduleReferencesAsLisOfMaps], HttpStatus.OK) - mockDmiRestClient.postOperationWithJsonData(expectedUrl, '{"cmHandleProperties":{}}') + mockDmiRestClient.postOperationWithJsonData(expectedUrl, '{"cmHandleProperties":{}}', READ) >> responseFromDmi when: 'get module references is called' def result = objectUnderTest.getModuleReferences(yangModelCmHandle) @@ -89,7 +89,7 @@ class DmiModelOperationsSpec extends DmiOperationsBaseSpec { and: 'a positive response from DMI service when it is called with tha expected parameters' def responseFromDmi = new ResponseEntity<String>(HttpStatus.OK) mockDmiRestClient.postOperationWithJsonData("${dmiServiceName}/dmi/v1/ch/${cmHandleId}/modules", - '{"cmHandleProperties":' + expectedAdditionalPropertiesInRequest + '}') >> responseFromDmi + '{"cmHandleProperties":' + expectedAdditionalPropertiesInRequest + '}', READ) >> responseFromDmi when: 'a get module references is called' def result = objectUnderTest.getModuleReferences(yangModelCmHandle) then: 'the result is the response from DMI service' @@ -108,7 +108,7 @@ class DmiModelOperationsSpec extends DmiOperationsBaseSpec { [moduleName: 'mod2', revision: 'C', yangSource: 'other yang source']], HttpStatus.OK) def expectedModuleReferencesInRequest = '{"name":"mod1","revision":"A"},{"name":"mod2","revision":"X"}' mockDmiRestClient.postOperationWithJsonData("${dmiServiceName}/dmi/v1/ch/${cmHandleId}/moduleResources", - '{"data":{"modules":[' + expectedModuleReferencesInRequest + ']},"cmHandleProperties":{}}') >> responseFromDmi + '{"data":{"modules":[' + expectedModuleReferencesInRequest + ']},"cmHandleProperties":{}}', READ) >> responseFromDmi when: 'get new yang resources from DMI service' def result = objectUnderTest.getNewYangResourcesFromDmi(yangModelCmHandle, newModuleReferences) then: 'the result has the 2 expected yang (re)sources (order is not guaranteed)' @@ -140,7 +140,7 @@ class DmiModelOperationsSpec extends DmiOperationsBaseSpec { and: 'a positive response from DMI service when it is called with the expected parameters' def responseFromDmi = new ResponseEntity<>([[moduleName: 'mod1', revision: 'A', yangSource: 'some yang source']], HttpStatus.OK) mockDmiRestClient.postOperationWithJsonData("${dmiServiceName}/dmi/v1/ch/${cmHandleId}/moduleResources", - '{"data":{"modules":[' + expectedModuleReferencesInRequest + ']},"cmHandleProperties":'+expectedAdditionalPropertiesInRequest+'}') >> responseFromDmi + '{"data":{"modules":[' + expectedModuleReferencesInRequest + ']},"cmHandleProperties":' + expectedAdditionalPropertiesInRequest + '}', READ) >> responseFromDmi when: 'get new yang resources from DMI service' def result = objectUnderTest.getNewYangResourcesFromDmi(yangModelCmHandle, unknownModuleReferences) then: 'the result is the response from DMI service' |