diff options
13 files changed, 214 insertions, 97 deletions
diff --git a/cps-ncmp-rest/lombok.config b/cps-ncmp-rest/lombok.config new file mode 100644 index 000000000..0736fc58c --- /dev/null +++ b/cps-ncmp-rest/lombok.config @@ -0,0 +1,20 @@ +# ============LICENSE_START======================================================= +# Copyright (C) 2021 Nordix Foundation +# ================================================================================ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# SPDX-License-Identifier: Apache-2.0 +# ============LICENSE_END========================================================= + +config.stopBubbling = true +lombok.addLombokGeneratedAnnotation = true diff --git a/cps-ncmp-rest/pom.xml b/cps-ncmp-rest/pom.xml index 2c44c2480..b47ea1733 100644 --- a/cps-ncmp-rest/pom.xml +++ b/cps-ncmp-rest/pom.xml @@ -23,19 +23,15 @@ <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> -<modelVersion>4.0.0</modelVersion> -<parent> - <groupId>org.onap.cps</groupId> - <artifactId>cps-parent</artifactId> - <version>2.0.1-SNAPSHOT</version> - <relativePath>../cps-parent/pom.xml</relativePath> -</parent> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.onap.cps</groupId> + <artifactId>cps-parent</artifactId> + <version>2.0.1-SNAPSHOT</version> + <relativePath>../cps-parent/pom.xml</relativePath> + </parent> -<artifactId>cps-ncmp-rest</artifactId> - - <properties> - <minimum-coverage>0.95</minimum-coverage> - </properties> + <artifactId>cps-ncmp-rest</artifactId> <dependencies> <dependency> diff --git a/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/exceptions/NetworkCmProxyRestExceptionHandlerSpec.groovy b/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/exceptions/NetworkCmProxyRestExceptionHandlerSpec.groovy index 8153eeb70..3fcf818af 100644 --- a/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/exceptions/NetworkCmProxyRestExceptionHandlerSpec.groovy +++ b/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/exceptions/NetworkCmProxyRestExceptionHandlerSpec.groovy @@ -22,6 +22,7 @@ package org.onap.cps.ncmp.rest.exceptions import groovy.json.JsonSlurper import org.onap.cps.ncmp.api.NetworkCmProxyDataService +import org.onap.cps.ncmp.api.impl.exception.NcmpException import org.onap.cps.spi.FetchDescendantsOption import org.onap.cps.spi.exceptions.CpsException import org.spockframework.spring.SpringBean @@ -61,20 +62,17 @@ class NetworkCmProxyRestExceptionHandlerSpec extends Specification { dataNodeBaseEndpoint = "$basePath/v1" } - def 'Get request with runtime exception returns HTTP Status Internal Server Error.'() { - when: 'runtime exception is thrown by the service' - setupTestException(new IllegalStateException(errorMessage)) - def response = performTestRequest() - then: 'an HTTP Internal Server Error response is returned with correct message and details' - assertTestResponse(response, INTERNAL_SERVER_ERROR, errorMessage, null) - } - - def 'Get request with generic CPS exception returns HTTP Status Internal Server Error.'() { + def 'Get request with generic #scenario exception returns HTTP Status Internal Server Error.'() { when: 'generic CPS exception is thrown by the service' - setupTestException(new CpsException(errorMessage, errorDetails)) + setupTestException(exception) def response = performTestRequest() then: 'an HTTP Internal Server Error response is returned with correct message and details' - assertTestResponse(response, INTERNAL_SERVER_ERROR, errorMessage, errorDetails) + assertTestResponse(response, INTERNAL_SERVER_ERROR, errorMessage, expectedErrorDetails) + where: + scenario | exception || expectedErrorDetails + 'CPS' | new CpsException(errorMessage, errorDetails) || errorDetails + 'NCMP' | new NcmpException(errorMessage, errorDetails) || null + 'other' | new IllegalStateException(errorMessage) || null } def setupTestException(exception) { diff --git a/cps-ncmp-service/lombok.config b/cps-ncmp-service/lombok.config new file mode 100644 index 000000000..0736fc58c --- /dev/null +++ b/cps-ncmp-service/lombok.config @@ -0,0 +1,20 @@ +# ============LICENSE_START======================================================= +# Copyright (C) 2021 Nordix Foundation +# ================================================================================ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# SPDX-License-Identifier: Apache-2.0 +# ============LICENSE_END========================================================= + +config.stopBubbling = true +lombok.addLombokGeneratedAnnotation = true diff --git a/cps-ncmp-service/pom.xml b/cps-ncmp-service/pom.xml index 0ee81c784..96aa4e5cc 100644 --- a/cps-ncmp-service/pom.xml +++ b/cps-ncmp-service/pom.xml @@ -32,10 +32,6 @@ <artifactId>cps-ncmp-service</artifactId> - <properties> - <minimum-coverage>0.87</minimum-coverage> - </properties> - <dependencies> <dependency> <groupId>${project.groupId}</groupId> 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 ff9502d50..08370ab89 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 @@ -149,14 +149,18 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService @Override public void updateDmiRegistrationAndSyncModule(final DmiPluginRegistration dmiPluginRegistration) { - if (dmiPluginRegistration.getCreatedCmHandles() != null) { - parseAndCreateCmHandlesInDmiRegistrationAndSyncModule(dmiPluginRegistration); - } - if (dmiPluginRegistration.getUpdatedCmHandles() != null) { - parseAndUpdateCmHandlesInDmiRegistration(dmiPluginRegistration); - } - if (dmiPluginRegistration.getRemovedCmHandles() != null) { - parseAndRemoveCmHandlesInDmiRegistration(dmiPluginRegistration); + try { + if (dmiPluginRegistration.getCreatedCmHandles() != null) { + parseAndCreateCmHandlesInDmiRegistrationAndSyncModule(dmiPluginRegistration); + } + if (dmiPluginRegistration.getUpdatedCmHandles() != null) { + parseAndUpdateCmHandlesInDmiRegistration(dmiPluginRegistration); + } + if (dmiPluginRegistration.getRemovedCmHandles() != null) { + parseAndRemoveCmHandlesInDmiRegistration(dmiPluginRegistration); + } + } catch (final JsonProcessingException e) { + handleJsonProcessingException(dmiPluginRegistration, e); } } @@ -286,38 +290,32 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService return prepareOperationBody(requestBodyObject); } - private void parseAndUpdateCmHandlesInDmiRegistration(final DmiPluginRegistration dmiPluginRegistration) { - try { - final PersistenceCmHandlesList persistenceCmHandlesList = new PersistenceCmHandlesList(); - - for (final CmHandle cmHandle : dmiPluginRegistration.getUpdatedCmHandles()) { - final PersistenceCmHandle persistenceCmHandle = - toPersistenceCmHandle(dmiPluginRegistration.getDmiPlugin(), cmHandle); - persistenceCmHandlesList.add(persistenceCmHandle); - } - final String cmHandlesJsonData = objectMapper.writeValueAsString(persistenceCmHandlesList); - cpsDataService.updateNodeLeavesAndExistingDescendantLeaves(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, - "/dmi-registry", cmHandlesJsonData, NO_TIMESTAMP); - } catch (final JsonProcessingException e) { - handleJsonProcessingException(dmiPluginRegistration, e); - } + private void parseAndUpdateCmHandlesInDmiRegistration(final DmiPluginRegistration dmiPluginRegistration) + throws JsonProcessingException { + final PersistenceCmHandlesList updatedPersistenceCmHandlesList = toPersistenceCmHandlesList( + dmiPluginRegistration.getDmiPlugin(), + dmiPluginRegistration.getUpdatedCmHandles()); + final String cmHandlesAsJson = objectMapper.writeValueAsString(updatedPersistenceCmHandlesList); + cpsDataService.updateNodeLeavesAndExistingDescendantLeaves(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, + "/dmi-registry", cmHandlesAsJson, NO_TIMESTAMP); } private void parseAndCreateCmHandlesInDmiRegistrationAndSyncModule( - final DmiPluginRegistration dmiPluginRegistration) { - try { - final var persistenceCmHandlesList = new PersistenceCmHandlesList(); - for (final CmHandle cmHandle : dmiPluginRegistration.getCreatedCmHandles()) { - final PersistenceCmHandle persistenceCmHandle = - toPersistenceCmHandle(dmiPluginRegistration.getDmiPlugin(), cmHandle); - persistenceCmHandlesList.add(persistenceCmHandle); - } - final String cmHandleJsonData = objectMapper.writeValueAsString(persistenceCmHandlesList); + final DmiPluginRegistration dmiPluginRegistration) throws JsonProcessingException { + final PersistenceCmHandlesList createdPersistenceCmHandlesList = toPersistenceCmHandlesList( + dmiPluginRegistration.getDmiPlugin(), + dmiPluginRegistration.getCreatedCmHandles()); + registerAndSyncNewCmHandles(createdPersistenceCmHandlesList); + } - registerAndSyncNode(persistenceCmHandlesList, cmHandleJsonData); - } catch (final JsonProcessingException e) { - handleJsonProcessingException(dmiPluginRegistration, e); + private static PersistenceCmHandlesList toPersistenceCmHandlesList(final String dmiPlugin, + final Collection<CmHandle> cmHandles) { + final PersistenceCmHandlesList persistenceCmHandlesList = new PersistenceCmHandlesList(); + for (final CmHandle cmHandle : cmHandles) { + final PersistenceCmHandle persistenceCmHandle = toPersistenceCmHandle(dmiPlugin, cmHandle); + persistenceCmHandlesList.add(persistenceCmHandle); } + return persistenceCmHandlesList; } private static void handleJsonProcessingException(final DmiPluginRegistration dmiPluginRegistration, @@ -328,8 +326,9 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService throw new DataValidationException(message, e.getMessage(), e); } - private void registerAndSyncNode(final PersistenceCmHandlesList persistenceCmHandlesList, - final String cmHandleJsonData) { + private void registerAndSyncNewCmHandles(final PersistenceCmHandlesList persistenceCmHandlesList) + throws JsonProcessingException { + final String cmHandleJsonData = objectMapper.writeValueAsString(persistenceCmHandlesList); cpsDataService.saveListNodeData(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, "/dmi-registry", cmHandleJsonData, NO_TIMESTAMP); @@ -435,7 +434,7 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService private static YangResource toYangResource(final JsonObject yangResourceAsJson) { final YangResource yangResource = new YangResource(); yangResource.setModuleName(yangResourceAsJson.get("moduleName").getAsString()); - yangResource.setRevision(yangResourceAsJson.get("revision").getAsString()); + yangResource.setRevision(yangResourceAsJson.get(REVISION).getAsString()); final String yangSourceJson = yangResourceAsJson.get("yangSource").getAsString(); String yangSource = JsonUtils.removeWrappingTokens(yangSourceJson); @@ -460,7 +459,7 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService private static ModuleReference toModuleReference(final JsonObject moduleReferenceAsJson) { final var moduleReference = new ModuleReference(); moduleReference.setModuleName(moduleReferenceAsJson.get("moduleName").getAsString()); - moduleReference.setRevision(moduleReferenceAsJson.get("revision").getAsString()); + moduleReference.setRevision(moduleReferenceAsJson.get(REVISION).getAsString()); return moduleReference; } } 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 8739355c8..55dd26bda 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 @@ -67,14 +67,24 @@ class NetworkCmProxyDataServiceImplSpec extends Specification { def noTimestamp = null def cmHandleXPath = "/dmi-registry/cm-handles[@id='testCmHandle']" def cmHandleForModelSync = new PersistenceCmHandle(id:'some cm handle', dmiServiceName: 'some service name') - def expectedDataspaceName = 'NFP-Operational' + + + def 'Get data node.'() { + when: 'queryDataNodes is invoked' + objectUnderTest.getDataNode(cmHandle, 'some xpath', fetchDescendantsOption) + then: 'the persistence data service is called once with the correct parameters' + 1 * mockCpsDataService.getDataNode(expectedDataspaceName, cmHandle, 'some xpath', fetchDescendantsOption) + where: 'all fetch descendants options are supported' + fetchDescendantsOption << FetchDescendantsOption.values() + } + def 'Query data nodes by cps path with #fetchDescendantsOption.'() { given: 'a cm Handle and a cps path' def cpsPath = '/cps-path' when: 'queryDataNodes is invoked' objectUnderTest.queryDataNodes(cmHandle, cpsPath, fetchDescendantsOption) - then: 'the persistence service is called once with the correct parameters' + then: 'the persistence query service is called once with the correct parameters' 1 * mockCpsQueryService.queryDataNodes(expectedDataspaceName, cmHandle, cpsPath, fetchDescendantsOption) where: 'all fetch descendants options are supported' fetchDescendantsOption << FetchDescendantsOption.values() @@ -214,7 +224,7 @@ class NetworkCmProxyDataServiceImplSpec extends Specification { def 'Get resource data for pass-through operational from dmi.'() { given: 'data node representing cmHandle and its properties' - def cmHandleDataNode = getCmHandleDataNodeForTest() + def cmHandleDataNode = getCmHandleDataNodeForTest(true) and: 'data node is got from data service' mockCpsDataService.getDataNode('NCMP-Admin', 'ncmp-dmi-registry', cmHandleXPath, FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS) >> cmHandleDataNode @@ -238,7 +248,7 @@ class NetworkCmProxyDataServiceImplSpec extends Specification { def 'Get resource data for pass-through operational from dmi threw parsing exception.'() { given: 'data node representing cmHandle and its properties' - def cmHandleDataNode = getCmHandleDataNodeForTest() + def cmHandleDataNode = getCmHandleDataNodeForTest(true) and: 'cps data service returns valid cmHandle data node' mockCpsDataService.getDataNode('NCMP-Admin', 'ncmp-dmi-registry', cmHandleXPath, FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS) >> cmHandleDataNode @@ -259,7 +269,7 @@ class NetworkCmProxyDataServiceImplSpec extends Specification { def 'Get resource data for pass-through operational from dmi return NOK response.'() { given: 'data node representing cmHandle and its properties' - def cmHandleDataNode = getCmHandleDataNodeForTest() + def cmHandleDataNode = getCmHandleDataNodeForTest(true) and: 'cps data service returns valid cmHandle data node' mockCpsDataService.getDataNode('NCMP-Admin', 'ncmp-dmi-registry', cmHandleXPath, FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS) >> cmHandleDataNode @@ -286,7 +296,7 @@ class NetworkCmProxyDataServiceImplSpec extends Specification { def 'Get resource data for pass-through running from dmi.'() { given: 'data node representing cmHandle and its properties' - def cmHandleDataNode = getCmHandleDataNodeForTest() + def cmHandleDataNode = getCmHandleDataNodeForTest(true) and: 'cpsDataService returns valid dataNode' mockCpsDataService.getDataNode('NCMP-Admin', 'ncmp-dmi-registry', cmHandleXPath, FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS) >> cmHandleDataNode @@ -310,7 +320,7 @@ class NetworkCmProxyDataServiceImplSpec extends Specification { def 'Get resource data for pass-through running from dmi threw parsing exception.'() { given: 'data node representing cmHandle and its properties' - def cmHandleDataNode = getCmHandleDataNodeForTest() + def cmHandleDataNode = getCmHandleDataNodeForTest(true) and: 'cpsDataService returns valid dataNode' mockCpsDataService.getDataNode('NCMP-Admin', 'ncmp-dmi-registry', cmHandleXPath, FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS) >> cmHandleDataNode @@ -331,7 +341,7 @@ class NetworkCmProxyDataServiceImplSpec extends Specification { def 'Get resource data for pass-through running from dmi return NOK response.'() { given: 'data node representing cmHandle and its properties' - def cmHandleDataNode = getCmHandleDataNodeForTest() + def cmHandleDataNode = getCmHandleDataNodeForTest(true) and: 'cpsDataService returns valid dataNode' mockCpsDataService.getDataNode('NCMP-Admin', 'ncmp-dmi-registry', cmHandleXPath, FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS) >> cmHandleDataNode @@ -356,9 +366,9 @@ class NetworkCmProxyDataServiceImplSpec extends Specification { exceptionThrown.details.contains('NOK-json') } - def 'Write resource data for pass-through running from dmi using POST.'() { - given: 'data node representing cmHandle and its properties' - def cmHandleDataNode = getCmHandleDataNodeForTest() + def 'Write resource data for pass-through running from dmi using POST #scenario cm handle properties.'() { + given: 'data node representing cmHandle #scenario cm handle properties' + def cmHandleDataNode = getCmHandleDataNodeForTest(includeCmHandleProperties) and: 'cpsDataService returns valid cm-handle datanode' mockCpsDataService.getDataNode('NCMP-Admin', 'ncmp-dmi-registry', cmHandleXPath, FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS) >> cmHandleDataNode @@ -370,13 +380,18 @@ class NetworkCmProxyDataServiceImplSpec extends Specification { 1 * mockDmiOperations.createResourceDataPassThroughRunningFromDmi('testDmiService', 'testCmHandle', 'testResourceId', - '{"operation":"create","dataType":"application/json","data":"{some-json}","cmHandleProperties":{"testName":"testValue"}}') + '{"operation":"create","dataType":"application/json","data":"{some-json}","cmHandleProperties":' + + expectedJsonForCmhandleProperties+ '}') >> { new ResponseEntity<>(HttpStatus.OK) } + where: + scenario | includeCmHandleProperties || expectedJsonForCmhandleProperties + 'with' | true || '{"testName":"testValue"}' + 'without' | false || '{}' } def 'Write resource data for pass-through running from dmi using POST "not found" response (from DMI).'() { given: 'data node representing cmHandle and its properties' - def cmHandleDataNode = getCmHandleDataNodeForTest() + def cmHandleDataNode = getCmHandleDataNodeForTest(true) and: 'cpsDataService returns valid dataNode' mockCpsDataService.getDataNode('NCMP-Admin', 'ncmp-dmi-registry', cmHandleXPath, FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS) >> cmHandleDataNode @@ -394,7 +409,7 @@ class NetworkCmProxyDataServiceImplSpec extends Specification { } def 'Sync model for a (new) cm handle with #scenario'() { - given: 'DMI PLug-in returns a list of module references' + given: 'DMI Plug-in returns a list of module references' getModulesForCmHandle() def knownModule1 = new ModuleReference('module1', '1') def knownOtherModule = new ModuleReference('some other module', 'some revision') @@ -409,12 +424,13 @@ class NetworkCmProxyDataServiceImplSpec extends Specification { 1 * mockCpsModuleService.createSchemaSetFromModules(expectedDataspaceName, cmHandleForModelSync.getId(), expectedYangResourceToContentMap, [knownModule1]) and: 'admin service create anchor method has been called with correct parameters' 1 * mockCpsAdminService.createAnchor(expectedDataspaceName, cmHandleForModelSync.getId(), cmHandleForModelSync.getId()) - where: 'the following responses are recieved from SDNC' + where: 'the following responses are received from SDNC' scenario | sdncReponseBody || expectedYangResourceToContentMap 'one unknown module' | '[{"moduleName" : "someModule", "revision" : "1","yangSource": "[some yang source]"}]' || [someModule: 'some yang source'] 'no unknown module' | '[]' || [:] } + def 'Getting Yang Resources.'() { when: 'yang resources is called' objectUnderTest.getYangResourcesModuleReferences('some cm handle') @@ -426,7 +442,6 @@ class NetworkCmProxyDataServiceImplSpec extends Specification { def jsonData = TestUtils.getResourceFileContent('cmHandleModules.json') mockDmiProperties.getAuthUsername() >> 'someUser' mockDmiProperties.getAuthPassword() >> 'somePassword' - mockDmiProperties.getDmiPluginBasePath() >> 'someUrl' def moduleReferencesFromCmHandleAsJson = new ResponseEntity<String>(jsonData, HttpStatus.OK) mockDmiOperations.getResourceFromDmi(_, cmHandleForModelSync.getId(), 'modules') >> moduleReferencesFromCmHandleAsJson } @@ -438,12 +453,14 @@ class NetworkCmProxyDataServiceImplSpec extends Specification { return objectUnderTest } - def getCmHandleDataNodeForTest() { + def getCmHandleDataNodeForTest(boolean includeCmHandleProperties) { def cmHandleDataNode = new DataNode() cmHandleDataNode.leaves = ['dmi-service-name': 'testDmiService'] - def cmHandlePropertyDataNode = new DataNode() - cmHandlePropertyDataNode.leaves = ['name': 'testName', 'value': 'testValue'] - cmHandleDataNode.childDataNodes = [cmHandlePropertyDataNode] + if (includeCmHandleProperties) { + def cmHandlePropertyDataNode = new DataNode() + cmHandlePropertyDataNode.leaves = ['name': 'testName', 'value': 'testValue'] + cmHandleDataNode.childDataNodes = [cmHandlePropertyDataNode] + } return cmHandleDataNode } 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 bf6179ba1..a1779a757 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 @@ -41,27 +41,34 @@ class DmiRestClientSpec extends Specification { @Autowired DmiRestClient objectUnderTest + def resourceUrl = 'some url' def 'DMI PUT operation.'() { - given: 'a PUT url' - def getResourceDataUrl = 'http://some-uri/getResourceDataUrl' - and: 'the rest template returns a valid response entity' + given: 'the rest template returns a valid response entity' def mockResponseEntity = Mock(ResponseEntity) - mockRestTemplate.exchange(getResourceDataUrl, HttpMethod.PUT, _ as HttpEntity, Object.class) >> mockResponseEntity + mockRestTemplate.exchange(resourceUrl, HttpMethod.PUT, _ as HttpEntity, Object.class) >> mockResponseEntity when: 'PUT operation is invoked' - def result = objectUnderTest.putOperationWithJsonData(getResourceDataUrl, 'json-data', new HttpHeaders()) + def result = objectUnderTest.putOperationWithJsonData(resourceUrl, 'json-data', new HttpHeaders()) then: 'the output of the method is equal to the output from the test template' result == mockResponseEntity } - def 'DMI POST operation.'() { - given: 'a POST url' - def getResourceDataUrl = 'http://some-uri/createResourceDataUrl' - and: 'the rest template returns a valid response entity' + def 'DMI POST operation'() { + given: 'the rest template returns a valid response entity' def mockResponseEntity = Mock(ResponseEntity) - mockRestTemplate.postForEntity(getResourceDataUrl, _ as HttpEntity, String.class) >> mockResponseEntity + mockRestTemplate.exchange(resourceUrl, HttpMethod.POST, _ as HttpEntity, String.class) >> mockResponseEntity when: 'POST operation is invoked' - def result = objectUnderTest.postOperationWithJsonData(getResourceDataUrl, 'json-data', new HttpHeaders()) + def result = objectUnderTest.postOperation(resourceUrl, new HttpHeaders()) + then: 'the output of the method is equal to the output from the rest template' + result == mockResponseEntity + } + + def 'DMI POST operation with JSON.'() { + given: 'the rest template returns a valid response entity' + def mockResponseEntity = Mock(ResponseEntity) + mockRestTemplate.postForEntity(resourceUrl, _ as HttpEntity, String.class) >> mockResponseEntity + when: 'POST operation is invoked' + def result = objectUnderTest.postOperationWithJsonData(resourceUrl, 'json-data', new HttpHeaders()) then: 'the output of the method is equal to the output from the test template' result == mockResponseEntity } diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/config/NcmpConfigurationSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/config/NcmpConfigurationSpec.groovy index dd4c1375b..2c4ba68f2 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/config/NcmpConfigurationSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/config/NcmpConfigurationSpec.groovy @@ -33,6 +33,11 @@ class NcmpConfigurationSpec extends Specification{ @Autowired NcmpConfiguration.DmiProperties dmiProperties + def 'NcmpConfiguration Construction.'() { + expect: 'the system can create an instance' + new NcmpConfiguration() != null + } + def 'DMI Properties.'() { expect: 'properties are set to values in test configuration yaml file' dmiProperties.authUsername == 'some-user' diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/models/YangResourceTest.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/models/YangResourceTest.groovy new file mode 100644 index 000000000..0a0c84e25 --- /dev/null +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/models/YangResourceTest.groovy @@ -0,0 +1,20 @@ +package org.onap.cps.ncmp.api.models + +import spock.lang.Specification + +class YangResourceSpec extends Specification { + + YangResource objectUnderTest = new YangResource(moduleName: 'module name', + revision:'revision', + yangSource:'source') + + def 'Yang resource attributes'() { + expect: 'correct module name' + objectUnderTest.moduleName == 'module name' + and: 'correct revision (this property is not used in production code, hence the need for this test)' + objectUnderTest.revision == 'revision' + and: 'correct yang source' + objectUnderTest.yangSource == 'source' + } + +} diff --git a/cps-rest/lombok.config b/cps-rest/lombok.config new file mode 100644 index 000000000..0736fc58c --- /dev/null +++ b/cps-rest/lombok.config @@ -0,0 +1,20 @@ +# ============LICENSE_START======================================================= +# Copyright (C) 2021 Nordix Foundation +# ================================================================================ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# SPDX-License-Identifier: Apache-2.0 +# ============LICENSE_END========================================================= + +config.stopBubbling = true +lombok.addLombokGeneratedAnnotation = true diff --git a/docs/admin-guide.rst b/docs/admin-guide.rst new file mode 100644 index 000000000..8e917e1f5 --- /dev/null +++ b/docs/admin-guide.rst @@ -0,0 +1,18 @@ +.. This work is licensed under a Creative Commons Attribution 4.0 International License. +.. http://creativecommons.org/licenses/by/4.0 +.. Copyright (C) 2021 Nordix Foundation + +.. DO NOT CHANGE THIS LABEL FOR RELEASE NOTES - EVEN THOUGH IT GIVES A WARNING +.. _adminGuide: + + +CPS Admin Guide +############### + +.. warning:: draft + +.. toctree:: + :maxdepth: 1 + +Logging & Diagnostics +===================== diff --git a/docs/index.rst b/docs/index.rst index 793f41e27..3e6f1414b 100755 --- a/docs/index.rst +++ b/docs/index.rst @@ -18,6 +18,7 @@ CPS-Core Documentation overview.rst architecture.rst + admin-guide.rst design.rst modeling.rst deployment.rst |